]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/test/java/org/argeo/slc/core/execution/BasicExecutionFlowTest.java
67aad4de5b44979eda3d5b80063fe98d700fdb99
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / test / java / org / argeo / slc / core / execution / BasicExecutionFlowTest.java
1 package org.argeo.slc.core.execution;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import org.argeo.slc.core.test.SimpleTestResult;
7 import org.argeo.slc.execution.ExecutionContext;
8 import org.argeo.slc.execution.ExecutionFlow;
9 import org.argeo.slc.test.TestStatus;
10 import org.springframework.beans.factory.BeanCreationException;
11 import org.springframework.context.ConfigurableApplicationContext;
12
13 public class BasicExecutionFlowTest extends AbstractExecutionFlowTestCase {
14 // TO TEST
15 // - post-processing for @{} replacement in beans with complex properties
16 // - bean of scope other than execution are not resolved at execution
17
18 // public void testMyTest() throws Exception {
19 // ConfigurableApplicationContext applicationContext =
20 // createApplicationContext("test.xml");
21 // log.info("Start Execution");
22 // ((ExecutionFlow) applicationContext.getBean("flow1")).execute();
23 // applicationContext.close();
24 // }
25
26 public void testSpecOverriding() throws Exception {
27 ConfigurableApplicationContext applicationContext = createApplicationContext("specOverriding.xml");
28 ((ExecutionFlow) applicationContext.getBean("flow2")).run();
29 SimpleTestResult res = (SimpleTestResult) applicationContext
30 .getBean("myTestResult");
31 validateTestResult(res);
32 }
33
34 public void testMultipleFlows() throws Exception {
35 ConfigurableApplicationContext applicationContext = createApplicationContext("multipleFlow.xml");
36 ((ExecutionFlow) applicationContext.getBean("flow1")).run();
37 SimpleTestResult res = (SimpleTestResult) applicationContext
38 .getBean("myTestResult");
39 validateTestResult(res);
40 res.getParts().clear();
41 ((ExecutionFlow) applicationContext.getBean("flow2")).run();
42 validateTestResult(res, TestStatus.FAILED);
43 applicationContext.close();
44 }
45
46 /**
47 * Test placeholder resolution in a context without scope execution or proxy
48 * and with cascading flows (the flow A contains the flow B)
49 *
50 * @throws Exception
51 */
52 public void testPlaceHolders() throws Exception {
53 ConfigurableApplicationContext applicationContext = createApplicationContext("placeHolders.cascading.xml");
54 ((ExecutionFlow) applicationContext.getBean("flowA")).run();
55 validateTestResult((SimpleTestResult) applicationContext
56 .getBean("myTestResult"));
57 applicationContext.close();
58 }
59
60 /**
61 * Test placeholder resolution in a context without scope execution or proxy
62 * and with cascading flows (the flow A contains the flow B) setting
63 * execution values (should have no effect)
64 *
65 * @throws Exception
66 */
67 public void testPlaceHoldersWithExecutionValues() throws Exception {
68 ConfigurableApplicationContext applicationContext = createApplicationContext("placeHolders.cascading.xml");
69
70 ExecutionContext executionContext = (ExecutionContext) applicationContext
71 .getBean("executionContext");
72 Map<String, String> executionParameters = new HashMap<String, String>();
73 executionParameters.put("p1", "e1");
74 executionParameters.put("p2", "e2");
75 executionParameters.put("p3", "e3");
76 executionParameters.put("p4", "e4");
77 executionParameters.put("p5", "e5");
78 executionParameters.put("p6", "e6");
79 executionParameters.put("p7", "e7");
80 executionParameters.put("p8", "e8");
81 addVariables(executionContext, executionParameters);
82
83 ((ExecutionFlow) applicationContext.getBean("flowA")).run();
84 validateTestResult((SimpleTestResult) applicationContext
85 .getBean("myTestResult"));
86 applicationContext.close();
87 }
88
89 public void testPlaceHoldersExec() throws Exception {
90 ConfigurableApplicationContext applicationContext = createApplicationContext("placeHolders.cascading.exec.xml");
91
92 ExecutionContext executionContext = (ExecutionContext) applicationContext
93 .getBean("executionContext");
94 Map<String, String> executionParameters = new HashMap<String, String>();
95 executionParameters.put("p1", "e1");
96 executionParameters.put("p2", "e2");
97 executionParameters.put("p3", "e3");
98 executionParameters.put("p4", "e4");
99 executionParameters.put("p5", "e5");
100 executionParameters.put("p6", "e6");
101 addVariables(executionContext, executionParameters);
102
103 ((ExecutionFlow) applicationContext.getBean("flowA")).run();
104 validateTestResult((SimpleTestResult) applicationContext
105 .getBean("myTestResult"));
106 applicationContext.close();
107 }
108
109 public void testCanonicFlowParameters() throws Exception {
110 configureAndExecuteSlcFlow("canonic-001.xml", "canonic.001");
111 }
112
113 public void testCanonicDefaultValues() throws Exception {
114 configureAndExecuteSlcFlow("canonic-002.xml", "canonic.002");
115 }
116
117 public void testCanonicMissingValues() throws Exception {
118 try {
119 configureAndExecuteSlcFlow("canonic-003.error.xml", "canonic.003");
120 fail("Parameter not set - should be rejected.");
121 } catch (BeanCreationException e) {
122 // exception expected
123 logException(e);
124 }
125 }
126
127 public void testCanonicUnknownParameter() throws Exception {
128 try {
129 configureAndExecuteSlcFlow("canonic-004.error.xml", "canonic.004");
130 fail("Unknown parameter set - should be rejected.");
131 } catch (BeanCreationException e) {
132 // exception expected
133 logException(e);
134 }
135 }
136
137 public void testListSetMap() throws Exception {
138 ConfigurableApplicationContext applicationContext = createApplicationContext("listSetMap.xml");
139 ExecutionFlow executionFlow = (ExecutionFlow) applicationContext
140 .getBean("myFlow");
141 executionFlow.run();
142
143 validateTestResult((SimpleTestResult) applicationContext
144 .getBean("myTestResult"));
145
146 // BasicTestData res = (BasicTestData)
147 // applicationContext.getBean("cascadingComplex.testData");
148 // log.info("res=" + res.getReached().toString());
149
150 applicationContext.close();
151 }
152
153 public void testListSetMapMultipleFlows() throws Exception {
154 ConfigurableApplicationContext applicationContext = createApplicationContext("listSetMapMultipleFlow.xml");
155 ((ExecutionFlow) applicationContext.getBean("flow1")).run();
156 SimpleTestResult res = (SimpleTestResult) applicationContext
157 .getBean("myTestResult");
158 validateTestResult(res);
159 res.getParts().clear();
160 ((ExecutionFlow) applicationContext.getBean("flow2")).run();
161 validateTestResult(res, TestStatus.FAILED);
162 applicationContext.close();
163 }
164
165 protected void addVariables(ExecutionContext executionContext,
166 Map<String, String> vars) {
167 for (String key : vars.keySet())
168 executionContext.setVariable(key, vars.get(key));
169 }
170 }