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