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 public void testRecursive() throws Exception
{
27 ConfigurableApplicationContext applicationContext
= createApplicationContext("test.xml");
28 ExecutionFlow executionFlow
= (ExecutionFlow
) applicationContext
.getBean("second");
29 executionFlow
.execute();
31 BasicTestData res
= (BasicTestData
) applicationContext
.getBean("basic.testData");
33 log
.info("res=" + res
.getReached().toString());
35 applicationContext
.close();
40 * Test placeholder resolution in a context without scope execution or proxy
41 * and with cascading flows (the flow A contains the flow B)
44 public void testPlaceHolders() throws Exception
{
45 ConfigurableApplicationContext applicationContext
= createApplicationContext("placeHolders.cascading.xml");
46 ((ExecutionFlow
) applicationContext
.getBean("flowA")).execute();
47 validateTestResult((SimpleTestResult
) applicationContext
.getBean("myTestResult"));
48 applicationContext
.close();
52 * Test placeholder resolution in a context without scope execution or proxy
53 * and with cascading flows (the flow A contains the flow B)
54 * setting execution values (should have no effect)
57 public void testPlaceHoldersWithExecutionValues() throws Exception
{
58 ConfigurableApplicationContext applicationContext
= createApplicationContext("placeHolders.cascading.xml");
60 ExecutionContext executionContext
= (ExecutionContext
)applicationContext
.getBean("executionContext");
61 Map
<String
, String
> executionParameters
= new HashMap
<String
,String
>();
62 executionParameters
.put("p1", "e1");
63 executionParameters
.put("p2", "e2");
64 executionParameters
.put("p3", "e3");
65 executionParameters
.put("p4", "e4");
66 executionParameters
.put("p5", "e5");
67 executionParameters
.put("p6", "e6");
68 executionParameters
.put("p7", "e7");
69 executionParameters
.put("p8", "e8");
70 executionContext
.addVariables(executionParameters
);
72 ((ExecutionFlow
) applicationContext
.getBean("flowA")).execute();
73 validateTestResult((SimpleTestResult
) applicationContext
.getBean("myTestResult"));
74 applicationContext
.close();
77 public void testPlaceHoldersExec() throws Exception
{
78 ConfigurableApplicationContext applicationContext
= createApplicationContext("placeHolders.cascading.exec.xml");
80 ExecutionContext executionContext
= (ExecutionContext
)applicationContext
.getBean("executionContext");
81 Map
<String
, String
> executionParameters
= new HashMap
<String
,String
>();
82 executionParameters
.put("p1", "e1");
83 executionParameters
.put("p2", "e2");
84 executionParameters
.put("p3", "e3");
85 executionParameters
.put("p4", "e4");
86 executionParameters
.put("p5", "e5");
87 executionParameters
.put("p6", "e6");
88 executionContext
.addVariables(executionParameters
);
90 ((ExecutionFlow
) applicationContext
.getBean("flowA")).execute();
91 validateTestResult((SimpleTestResult
) applicationContext
.getBean("myTestResult"));
92 applicationContext
.close();
95 public void testSimpleExecution() throws Exception
{
96 // configureAndExecuteSlcFlow("applicationContext.xml", "main");
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
129 protected void logException(Throwable ex
) {
130 log
.info("Got Exception of class " + ex
.getClass().toString()
131 + " with message '" + ex
.getMessage() + "'.");
134 protected void validateTestResult(SimpleTestResult testResult
) {
135 for(TestResultPart part
: testResult
.getParts()) {
136 if(part
.getStatus() != TestStatus
.PASSED
) {
137 fail("Error found in TestResult: " + part
.getMessage());
142 protected ConfigurableApplicationContext
createApplicationContext(String applicationContextSuffix
) {
143 ConfigurableApplicationContext applicationContext
= new ClassPathXmlApplicationContext(inPackage(applicationContextSuffix
));
144 applicationContext
.start();
145 return applicationContext
;
148 protected void configureAndExecuteSlcFlow(String applicationContextSuffix
, String beanName
) {
149 ConfigurableApplicationContext applicationContext
= createApplicationContext(applicationContextSuffix
);
150 ExecutionFlow executionFlow
= (ExecutionFlow
) applicationContext
.getBean(beanName
);
151 executionFlow
.execute();
152 applicationContext
.close();
155 protected String
inPackage(String suffix
) {
156 String prefix
= getClass().getPackage().getName().replace('.', '/');
157 return prefix
+ '/' + suffix
;