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 * Test placeholder resolution in a context without scope execution or proxy
27 * and with cascading flows (the flow A contains the flow B)
30 public void testPlaceHolders() throws Exception
{
31 ConfigurableApplicationContext applicationContext
= createApplicationContext("placeHolders.cascading.xml");
32 ((ExecutionFlow
) applicationContext
.getBean("flowA")).execute();
33 validateTestResult((SimpleTestResult
) applicationContext
.getBean("myTestResult"));
34 applicationContext
.close();
38 * Test placeholder resolution in a context without scope execution or proxy
39 * and with cascading flows (the flow A contains the flow B)
40 * setting execution values (should have no effect)
43 public void testPlaceHoldersWithExecutionValues() throws Exception
{
44 ConfigurableApplicationContext applicationContext
= createApplicationContext("placeHolders.cascading.xml");
46 ExecutionContext executionContext
= (ExecutionContext
)applicationContext
.getBean("executionContext");
47 Map
<String
, String
> executionParameters
= new HashMap
<String
,String
>();
48 executionParameters
.put("p1", "e1");
49 executionParameters
.put("p2", "e2");
50 executionParameters
.put("p3", "e3");
51 executionParameters
.put("p4", "e4");
52 executionParameters
.put("p5", "e5");
53 executionParameters
.put("p6", "e6");
54 executionParameters
.put("p7", "e7");
55 executionParameters
.put("p8", "e8");
56 executionContext
.addVariables(executionParameters
);
58 ((ExecutionFlow
) applicationContext
.getBean("flowA")).execute();
59 validateTestResult((SimpleTestResult
) applicationContext
.getBean("myTestResult"));
60 applicationContext
.close();
63 public void testPlaceHoldersExec() throws Exception
{
64 ConfigurableApplicationContext applicationContext
= createApplicationContext("placeHolders.cascading.exec.xml");
66 ExecutionContext executionContext
= (ExecutionContext
)applicationContext
.getBean("executionContext");
67 Map
<String
, String
> executionParameters
= new HashMap
<String
,String
>();
68 executionParameters
.put("p1", "e1");
69 executionParameters
.put("p2", "e2");
70 executionParameters
.put("p3", "e3");
71 executionParameters
.put("p4", "e4");
72 executionParameters
.put("p5", "e5");
73 executionParameters
.put("p6", "e6");
74 executionContext
.addVariables(executionParameters
);
76 ((ExecutionFlow
) applicationContext
.getBean("flowA")).execute();
77 validateTestResult((SimpleTestResult
) applicationContext
.getBean("myTestResult"));
78 applicationContext
.close();
81 public void testCanonicFlowParameters() throws Exception
{
82 configureAndExecuteSlcFlow("canonic-001.xml", "canonic.001");
85 public void testCanonicDefaultValues() throws Exception
{
86 configureAndExecuteSlcFlow("canonic-002.xml", "canonic.002");
89 public void testCanonicMissingValues() throws Exception
{
91 configureAndExecuteSlcFlow("canonic-003.error.xml", "canonic.003");
92 fail("Parameter not set - should be rejected.");
93 } catch (BeanCreationException e
) {
98 public void testCanonicUnknownParameter() throws Exception
{
100 configureAndExecuteSlcFlow("canonic-004.error.xml", "canonic.004");
101 fail("Unknown parameter set - should be rejected.");
102 } catch (BeanCreationException e
) {
103 // exception expected
108 public void testListSetMap() throws Exception
{
109 ConfigurableApplicationContext applicationContext
= createApplicationContext("listSetMap.xml");
110 ExecutionFlow executionFlow
= (ExecutionFlow
) applicationContext
.getBean("myFlow");
111 executionFlow
.execute();
113 validateTestResult((SimpleTestResult
) applicationContext
.getBean("myTestResult"));
115 BasicTestData res
= (BasicTestData
) applicationContext
.getBean("cascadingComplex.testData");
116 log
.info("res=" + res
.getReached().toString());
118 applicationContext
.close();
122 protected void logException(Throwable ex
) {
123 log
.info("Got Exception of class " + ex
.getClass().toString()
124 + " with message '" + ex
.getMessage() + "'.");
127 protected void validateTestResult(SimpleTestResult testResult
) {
128 for(TestResultPart part
: testResult
.getParts()) {
129 if(part
.getStatus() != TestStatus
.PASSED
) {
130 fail("Error found in TestResult: " + part
.getMessage());
135 protected ConfigurableApplicationContext
createApplicationContext(String applicationContextSuffix
) {
136 ConfigurableApplicationContext applicationContext
= new ClassPathXmlApplicationContext(inPackage(applicationContextSuffix
));
137 applicationContext
.start();
138 return applicationContext
;
141 protected void configureAndExecuteSlcFlow(String applicationContextSuffix
, String beanName
) {
142 ConfigurableApplicationContext applicationContext
= createApplicationContext(applicationContextSuffix
);
143 ExecutionFlow executionFlow
= (ExecutionFlow
) applicationContext
.getBean(beanName
);
144 executionFlow
.execute();
145 applicationContext
.close();
148 protected String
inPackage(String suffix
) {
149 String prefix
= getClass().getPackage().getName().replace('.', '/');
150 return prefix
+ '/' + suffix
;