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