]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/core/execution/ExecutionFlowTest.java
Placeholder resolution in Map, List and Set supported
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / test / java / org / argeo / slc / core / execution / ExecutionFlowTest.java
1 package org.argeo.slc.core.execution;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import junit.framework.TestCase;
7
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;
20
21 public class ExecutionFlowTest extends TestCase {
22
23 protected final Log log = LogFactory.getLog(getClass());
24
25 /**
26 * Test placeholder resolution in a context without scope execution or proxy
27 * and with cascading flows (the flow A contains the flow B)
28 * @throws Exception
29 */
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();
35 }
36
37 /**
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)
41 * @throws Exception
42 */
43 public void testPlaceHoldersWithExecutionValues() throws Exception {
44 ConfigurableApplicationContext applicationContext = createApplicationContext("placeHolders.cascading.xml");
45
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);
57
58 ((ExecutionFlow) applicationContext.getBean("flowA")).execute();
59 validateTestResult((SimpleTestResult) applicationContext.getBean("myTestResult"));
60 applicationContext.close();
61 }
62
63 public void testPlaceHoldersExec() throws Exception {
64 ConfigurableApplicationContext applicationContext = createApplicationContext("placeHolders.cascading.exec.xml");
65
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);
75
76 ((ExecutionFlow) applicationContext.getBean("flowA")).execute();
77 validateTestResult((SimpleTestResult) applicationContext.getBean("myTestResult"));
78 applicationContext.close();
79 }
80
81 public void testCanonicFlowParameters() throws Exception {
82 configureAndExecuteSlcFlow("canonic-001.xml", "canonic.001");
83 }
84
85 public void testCanonicDefaultValues() throws Exception {
86 configureAndExecuteSlcFlow("canonic-002.xml", "canonic.002");
87 }
88
89 public void testCanonicMissingValues() throws Exception {
90 try {
91 configureAndExecuteSlcFlow("canonic-003.error.xml", "canonic.003");
92 fail("Parameter not set - should be rejected.");
93 } catch (BeanCreationException e) {
94 // exception expected
95 logException(e);
96 } }
97
98 public void testCanonicUnknownParameter() throws Exception {
99 try {
100 configureAndExecuteSlcFlow("canonic-004.error.xml", "canonic.004");
101 fail("Unknown parameter set - should be rejected.");
102 } catch (BeanCreationException e) {
103 // exception expected
104 logException(e);
105 }
106 }
107
108 public void testListSetMap() throws Exception {
109 ConfigurableApplicationContext applicationContext = createApplicationContext("listSetMap.xml");
110 ExecutionFlow executionFlow = (ExecutionFlow) applicationContext.getBean("myFlow");
111 executionFlow.execute();
112
113 validateTestResult((SimpleTestResult) applicationContext.getBean("myTestResult"));
114
115 BasicTestData res = (BasicTestData) applicationContext.getBean("cascadingComplex.testData");
116 log.info("res=" + res.getReached().toString());
117
118 applicationContext.close();
119 }
120
121
122 protected void logException(Throwable ex) {
123 log.info("Got Exception of class " + ex.getClass().toString()
124 + " with message '" + ex.getMessage() + "'.");
125 }
126
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());
131 }
132 }
133 }
134
135 protected ConfigurableApplicationContext createApplicationContext(String applicationContextSuffix) {
136 ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(inPackage(applicationContextSuffix));
137 applicationContext.start();
138 return applicationContext;
139 }
140
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();
146 }
147
148 protected String inPackage(String suffix) {
149 String prefix = getClass().getPackage().getName().replace('.', '/');
150 return prefix + '/' + suffix;
151 }
152 }