]> 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 supported in maps
[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 public void testRecursive() throws Exception {
27 ConfigurableApplicationContext applicationContext = createApplicationContext("test.xml");
28 ExecutionFlow executionFlow = (ExecutionFlow) applicationContext.getBean("second");
29 executionFlow.execute();
30
31 BasicTestData res = (BasicTestData) applicationContext.getBean("basic.testData");
32
33 log.info("res=" + res.getReached().toString());
34
35 applicationContext.close();
36 }
37
38
39 /**
40 * Test placeholder resolution in a context without scope execution or proxy
41 * and with cascading flows (the flow A contains the flow B)
42 * @throws Exception
43 */
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();
49 }
50
51 /**
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)
55 * @throws Exception
56 */
57 public void testPlaceHoldersWithExecutionValues() throws Exception {
58 ConfigurableApplicationContext applicationContext = createApplicationContext("placeHolders.cascading.xml");
59
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);
71
72 ((ExecutionFlow) applicationContext.getBean("flowA")).execute();
73 validateTestResult((SimpleTestResult) applicationContext.getBean("myTestResult"));
74 applicationContext.close();
75 }
76
77 public void testPlaceHoldersExec() throws Exception {
78 ConfigurableApplicationContext applicationContext = createApplicationContext("placeHolders.cascading.exec.xml");
79
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);
89
90 ((ExecutionFlow) applicationContext.getBean("flowA")).execute();
91 validateTestResult((SimpleTestResult) applicationContext.getBean("myTestResult"));
92 applicationContext.close();
93 }
94
95 public void testSimpleExecution() throws Exception {
96 // configureAndExecuteSlcFlow("applicationContext.xml", "main");
97 }
98
99 public void testCanonicFlowParameters() throws Exception {
100 configureAndExecuteSlcFlow("canonic-001.xml", "canonic.001");
101 }
102
103 public void testCanonicDefaultValues() throws Exception {
104 configureAndExecuteSlcFlow("canonic-002.xml", "canonic.002");
105 }
106
107 public void testCanonicMissingValues() throws Exception {
108 try {
109 configureAndExecuteSlcFlow("canonic-003.error.xml", "canonic.003");
110 fail("Parameter not set - should be rejected.");
111 } catch (BeanCreationException e) {
112 // exception expected
113 logException(e);
114 } }
115
116 public void testCanonicUnknownParameter() throws Exception {
117 try {
118 configureAndExecuteSlcFlow("canonic-004.error.xml", "canonic.004");
119 fail("Unknown parameter set - should be rejected.");
120 } catch (BeanCreationException e) {
121 // exception expected
122 logException(e);
123 }
124 }
125
126
127
128
129 protected void logException(Throwable ex) {
130 log.info("Got Exception of class " + ex.getClass().toString()
131 + " with message '" + ex.getMessage() + "'.");
132 }
133
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());
138 }
139 }
140 }
141
142 protected ConfigurableApplicationContext createApplicationContext(String applicationContextSuffix) {
143 ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(inPackage(applicationContextSuffix));
144 applicationContext.start();
145 return applicationContext;
146 }
147
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();
153 }
154
155 protected String inPackage(String suffix) {
156 String prefix = getClass().getPackage().getName().replace('.', '/');
157 return prefix + '/' + suffix;
158 }
159 }