2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.core
.execution
;
18 import junit
.framework
.TestCase
;
20 import org
.apache
.commons
.logging
.Log
;
21 import org
.apache
.commons
.logging
.LogFactory
;
22 import org
.argeo
.slc
.core
.test
.SimpleTestResult
;
23 import org
.argeo
.slc
.execution
.ExecutionContext
;
24 import org
.argeo
.slc
.execution
.ExecutionFlow
;
25 import org
.argeo
.slc
.test
.TestResultPart
;
26 import org
.argeo
.slc
.test
.TestStatus
;
27 import org
.springframework
.context
.ConfigurableApplicationContext
;
28 import org
.springframework
.context
.support
.ClassPathXmlApplicationContext
;
30 public abstract class AbstractExecutionFlowTestCase
extends TestCase
{
32 protected final Log log
= LogFactory
.getLog(getClass());
34 protected void logException(Throwable ex
) {
35 log
.info("Got Exception of class " + ex
.getClass().toString()
36 + " with message '" + ex
.getMessage() + "'.");
39 protected void validateTestResult(SimpleTestResult testResult
) {
40 validateTestResult(testResult
, TestStatus
.PASSED
);
43 protected void validateTestResult(SimpleTestResult testResult
,
45 for (TestResultPart part
: testResult
.getParts()) {
46 if (part
.getStatus() != expectedStatus
) {
47 fail("Error found in TestResult: " + part
.getMessage());
52 protected ConfigurableApplicationContext
createApplicationContext(
53 String applicationContextSuffix
) {
54 ConfigurableApplicationContext applicationContext
= new ClassPathXmlApplicationContext(
55 inPackage(applicationContextSuffix
));
56 // applicationContext.start();
57 return applicationContext
;
60 protected void configureAndExecuteSlcFlow(String applicationContextSuffix
,
62 ConfigurableApplicationContext applicationContext
= createApplicationContext(applicationContextSuffix
);
63 ExecutionContext executionContext
= (ExecutionContext
) applicationContext
64 .getBean("executionContext");
65 ExecutionFlow executionFlow
= (ExecutionFlow
) applicationContext
67 if (executionFlow
instanceof DefaultExecutionFlow
)
68 ((DefaultExecutionFlow
) executionFlow
)
69 .setExecutionContext(executionContext
);
71 executionContext
.beforeFlow(executionFlow
);
74 executionContext
.afterFlow(executionFlow
);
76 applicationContext
.close();
79 protected String
inPackage(String suffix
) {
80 String prefix
= getClass().getPackage().getName().replace('.', '/');
81 return prefix
+ '/' + suffix
;