]> git.argeo.org Git - gpl/argeo-slc.git/blob - legacy/org.argeo.slc.spring/ext/test/org/argeo/slc/core/execution/AbstractExecutionFlowTestCase.java
10478378024141366de92fa351165e69afd8a9c5
[gpl/argeo-slc.git] / legacy / org.argeo.slc.spring / ext / test / org / argeo / slc / core / execution / AbstractExecutionFlowTestCase.java
1 package org.argeo.slc.core.execution;
2
3 import junit.framework.TestCase;
4
5 import org.argeo.api.cms.CmsLog;
6 import org.argeo.slc.execution.ExecutionContext;
7 import org.argeo.slc.execution.ExecutionFlow;
8 import org.argeo.slc.runtime.test.SimpleTestResult;
9 import org.argeo.slc.test.TestResultPart;
10 import org.argeo.slc.test.TestStatus;
11 import org.springframework.context.ConfigurableApplicationContext;
12 import org.springframework.context.support.ClassPathXmlApplicationContext;
13
14 public abstract class AbstractExecutionFlowTestCase extends TestCase {
15
16 protected final CmsLog log = CmsLog.getLog(getClass());
17
18 protected void logException(Throwable ex) {
19 log.info("Got Exception of class " + ex.getClass().toString()
20 + " with message '" + ex.getMessage() + "'.");
21 }
22
23 protected void validateTestResult(SimpleTestResult testResult) {
24 validateTestResult(testResult, TestStatus.PASSED);
25 }
26
27 protected void validateTestResult(SimpleTestResult testResult,
28 int expectedStatus) {
29 for (TestResultPart part : testResult.getParts()) {
30 if (part.getStatus() != expectedStatus) {
31 fail("Error found in TestResult: " + part.getMessage());
32 }
33 }
34 }
35
36 protected ConfigurableApplicationContext createApplicationContext(
37 String applicationContextSuffix) {
38 ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(
39 inPackage(applicationContextSuffix));
40 // applicationContext.start();
41 return applicationContext;
42 }
43
44 protected void configureAndExecuteSlcFlow(String applicationContextSuffix,
45 String beanName) {
46 ConfigurableApplicationContext applicationContext = createApplicationContext(applicationContextSuffix);
47 ExecutionContext executionContext = (ExecutionContext) applicationContext
48 .getBean("executionContext");
49 ExecutionFlow executionFlow = (ExecutionFlow) applicationContext
50 .getBean(beanName);
51 if (executionFlow instanceof DefaultExecutionFlow)
52 ((DefaultExecutionFlow) executionFlow)
53 .setExecutionContext(executionContext);
54 try {
55 executionContext.beforeFlow(executionFlow);
56 executionFlow.run();
57 } finally {
58 executionContext.afterFlow(executionFlow);
59 }
60 applicationContext.close();
61 }
62
63 protected String inPackage(String suffix) {
64 String prefix = getClass().getPackage().getName().replace('.', '/');
65 return prefix + '/' + suffix;
66 }
67 }