1 package org
.argeo
.slc
.core
.execution
;
3 import java
.util
.HashMap
;
6 import junit
.framework
.TestCase
;
8 import org
.apache
.commons
.logging
.Log
;
9 import org
.apache
.commons
.logging
.LogFactory
;
10 import org
.argeo
.slc
.core
.test
.BasicTestData
;
11 import org
.argeo
.slc
.core
.test
.SimpleTestResult
;
12 import org
.argeo
.slc
.execution
.ExecutionContext
;
13 import org
.argeo
.slc
.execution
.ExecutionFlow
;
14 import org
.argeo
.slc
.test
.TestResultPart
;
15 import org
.argeo
.slc
.test
.TestStatus
;
16 import org
.argeo
.slc
.unit
.AbstractSpringTestCase
;
17 import org
.springframework
.beans
.factory
.BeanCreationException
;
18 import org
.springframework
.context
.ConfigurableApplicationContext
;
19 import org
.springframework
.context
.support
.ClassPathXmlApplicationContext
;
21 public class ExecutionFlowTest
extends TestCase
{
23 protected final Log log
= LogFactory
.getLog(getClass());
26 // to test: case with listener
28 // public void testMyTest() throws Exception {
29 // ConfigurableApplicationContext applicationContext = createApplicationContext("test.xml");
30 // log.info("Start Execution");
31 // ((ExecutionFlow) applicationContext.getBean("fileDiff.SimulationView_Risk")).execute();
32 // applicationContext.close();
35 public void testMultipleFlows() throws Exception
{
36 ConfigurableApplicationContext applicationContext
= createApplicationContext("multipleFlow.xml");
37 log
.info("Start Execution");
38 ((ExecutionFlow
) applicationContext
.getBean("flow1")).execute();
39 ((ExecutionFlow
) applicationContext
.getBean("flow2")).execute();
40 applicationContext
.close();
44 * Test placeholder resolution in a context without scope execution or proxy
45 * and with cascading flows (the flow A contains the flow B)
48 public void testPlaceHolders() throws Exception
{
49 ConfigurableApplicationContext applicationContext
= createApplicationContext("placeHolders.cascading.xml");
50 ((ExecutionFlow
) applicationContext
.getBean("flowA")).execute();
51 validateTestResult((SimpleTestResult
) applicationContext
.getBean("myTestResult"));
52 applicationContext
.close();
56 * Test placeholder resolution in a context without scope execution or proxy
57 * and with cascading flows (the flow A contains the flow B)
58 * setting execution values (should have no effect)
61 public void testPlaceHoldersWithExecutionValues() throws Exception
{
62 ConfigurableApplicationContext applicationContext
= createApplicationContext("placeHolders.cascading.xml");
64 ExecutionContext executionContext
= (ExecutionContext
)applicationContext
.getBean("executionContext");
65 Map
<String
, String
> executionParameters
= new HashMap
<String
,String
>();
66 executionParameters
.put("p1", "e1");
67 executionParameters
.put("p2", "e2");
68 executionParameters
.put("p3", "e3");
69 executionParameters
.put("p4", "e4");
70 executionParameters
.put("p5", "e5");
71 executionParameters
.put("p6", "e6");
72 executionParameters
.put("p7", "e7");
73 executionParameters
.put("p8", "e8");
74 executionContext
.addVariables(executionParameters
);
76 ((ExecutionFlow
) applicationContext
.getBean("flowA")).execute();
77 validateTestResult((SimpleTestResult
) applicationContext
.getBean("myTestResult"));
78 applicationContext
.close();
81 public void testPlaceHoldersExec() throws Exception
{
82 ConfigurableApplicationContext applicationContext
= createApplicationContext("placeHolders.cascading.exec.xml");
84 ExecutionContext executionContext
= (ExecutionContext
)applicationContext
.getBean("executionContext");
85 Map
<String
, String
> executionParameters
= new HashMap
<String
,String
>();
86 executionParameters
.put("p1", "e1");
87 executionParameters
.put("p2", "e2");
88 executionParameters
.put("p3", "e3");
89 executionParameters
.put("p4", "e4");
90 executionParameters
.put("p5", "e5");
91 executionParameters
.put("p6", "e6");
92 executionContext
.addVariables(executionParameters
);
94 ((ExecutionFlow
) applicationContext
.getBean("flowA")).execute();
95 validateTestResult((SimpleTestResult
) applicationContext
.getBean("myTestResult"));
96 applicationContext
.close();
99 public void testCanonicFlowParameters() throws Exception
{
100 configureAndExecuteSlcFlow("canonic-001.xml", "canonic.001");
103 public void testCanonicDefaultValues() throws Exception
{
104 configureAndExecuteSlcFlow("canonic-002.xml", "canonic.002");
107 public void testCanonicMissingValues() throws Exception
{
109 configureAndExecuteSlcFlow("canonic-003.error.xml", "canonic.003");
110 fail("Parameter not set - should be rejected.");
111 } catch (BeanCreationException e
) {
112 // exception expected
116 public void testCanonicUnknownParameter() throws Exception
{
118 configureAndExecuteSlcFlow("canonic-004.error.xml", "canonic.004");
119 fail("Unknown parameter set - should be rejected.");
120 } catch (BeanCreationException e
) {
121 // exception expected
126 public void testListSetMap() throws Exception
{
127 ConfigurableApplicationContext applicationContext
= createApplicationContext("listSetMap.xml");
128 ExecutionFlow executionFlow
= (ExecutionFlow
) applicationContext
.getBean("myFlow");
129 executionFlow
.execute();
131 validateTestResult((SimpleTestResult
) applicationContext
.getBean("myTestResult"));
133 // BasicTestData res = (BasicTestData) applicationContext.getBean("cascadingComplex.testData");
134 // log.info("res=" + res.getReached().toString());
136 applicationContext
.close();
139 // public void testListSetMapMultipleFlows() throws Exception {
140 // ConfigurableApplicationContext applicationContext = createApplicationContext("listSetMapMultipleFlow.xml");
141 // ((ExecutionFlow) applicationContext.getBean("flow1")).execute();
142 // SimpleTestResult res = (SimpleTestResult) applicationContext.getBean("myTestResult");
143 // validateTestResult(res);
144 // res.getParts().clear();
145 // ((ExecutionFlow) applicationContext.getBean("flow2")).execute();
146 // validateTestResult(res, TestStatus.FAILED);
147 // applicationContext.close();
150 protected void logException(Throwable ex
) {
151 log
.info("Got Exception of class " + ex
.getClass().toString()
152 + " with message '" + ex
.getMessage() + "'.");
155 protected void validateTestResult(SimpleTestResult testResult
) {
156 validateTestResult(testResult
, TestStatus
.PASSED
);
159 protected void validateTestResult(SimpleTestResult testResult
, int expectedStatus
) {
160 for(TestResultPart part
: testResult
.getParts()) {
161 if(part
.getStatus() != expectedStatus
) {
162 fail("Error found in TestResult: " + part
.getMessage());
167 protected ConfigurableApplicationContext
createApplicationContext(String applicationContextSuffix
) {
168 ConfigurableApplicationContext applicationContext
= new ClassPathXmlApplicationContext(inPackage(applicationContextSuffix
));
169 applicationContext
.start();
170 return applicationContext
;
173 protected void configureAndExecuteSlcFlow(String applicationContextSuffix
, String beanName
) {
174 ConfigurableApplicationContext applicationContext
= createApplicationContext(applicationContextSuffix
);
175 ExecutionFlow executionFlow
= (ExecutionFlow
) applicationContext
.getBean(beanName
);
176 executionFlow
.execute();
177 applicationContext
.close();
180 protected String
inPackage(String suffix
) {
181 String prefix
= getClass().getPackage().getName().replace('.', '/');
182 return prefix
+ '/' + suffix
;