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