]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/test/java/org/argeo/slc/core/execution/AbstractExecutionFlowTestCase.java
Refactor runtime
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / test / java / 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.core.test.SimpleTestResult;
8 import org.argeo.slc.execution.ExecutionFlow;
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 Log log = LogFactory.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, int expectedStatus) {
28 for(TestResultPart part : testResult.getParts()) {
29 if(part.getStatus() != expectedStatus) {
30 fail("Error found in TestResult: " + part.getMessage());
31 }
32 }
33 }
34
35 protected ConfigurableApplicationContext createApplicationContext(String applicationContextSuffix) {
36 ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(inPackage(applicationContextSuffix));
37 applicationContext.start();
38 return applicationContext;
39 }
40
41 protected void configureAndExecuteSlcFlow(String applicationContextSuffix, String beanName) {
42 ConfigurableApplicationContext applicationContext = createApplicationContext(applicationContextSuffix);
43 ExecutionFlow executionFlow = (ExecutionFlow) applicationContext.getBean(beanName);
44 executionFlow.run();
45 applicationContext.close();
46 }
47
48 protected String inPackage(String suffix) {
49 String prefix = getClass().getPackage().getName().replace('.', '/');
50 return prefix + '/' + suffix;
51 }
52 }