2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org
.argeo
.slc
.core
.execution
;
19 import java
.util
.HashMap
;
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
;
29 public class BasicExecutionFlowTest
extends AbstractExecutionFlowTestCase
{
31 // - post-processing for @{} replacement in beans with complex properties
32 // - bean of scope other than execution are not resolved at execution
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();
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
);
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();
63 * Test placeholder resolution in a context without scope execution or proxy
64 * and with cascading flows (the flow A contains the flow B)
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();
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)
83 public void testPlaceHoldersWithExecutionValues() throws Exception
{
84 ConfigurableApplicationContext applicationContext
= createApplicationContext("placeHolders.cascading.xml");
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
);
99 ((ExecutionFlow
) applicationContext
.getBean("flowA")).run();
100 validateTestResult((SimpleTestResult
) applicationContext
101 .getBean("myTestResult"));
102 applicationContext
.close();
105 public void testPlaceHoldersExec() throws Exception
{
106 ConfigurableApplicationContext applicationContext
= createApplicationContext("placeHolders.cascading.exec.xml");
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
);
119 ((ExecutionFlow
) applicationContext
.getBean("flowA")).run();
120 validateTestResult((SimpleTestResult
) applicationContext
121 .getBean("myTestResult"));
122 applicationContext
.close();
125 public void testCanonicFlowParameters() throws Exception
{
126 configureAndExecuteSlcFlow("canonic-001.xml", "canonic.001");
129 public void testCanonicDefaultValues() throws Exception
{
130 configureAndExecuteSlcFlow("canonic-002.xml", "canonic.002");
133 public void testCanonicMissingValues() throws Exception
{
135 configureAndExecuteSlcFlow("canonic-003.error.xml", "canonic.003");
136 fail("Parameter not set - should be rejected.");
137 } catch (BeanCreationException e
) {
138 // exception expected
143 public void testCanonicUnknownParameter() throws Exception
{
145 configureAndExecuteSlcFlow("canonic-004.error.xml", "canonic.004");
146 fail("Unknown parameter set - should be rejected.");
147 } catch (BeanCreationException e
) {
148 // exception expected
153 public void testListSetMap() throws Exception
{
154 ConfigurableApplicationContext applicationContext
= createApplicationContext("listSetMap.xml");
155 ExecutionFlow executionFlow
= (ExecutionFlow
) applicationContext
159 validateTestResult((SimpleTestResult
) applicationContext
160 .getBean("myTestResult"));
162 // BasicTestData res = (BasicTestData)
163 // applicationContext.getBean("cascadingComplex.testData");
164 // log.info("res=" + res.getReached().toString());
166 applicationContext
.close();
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();
181 protected void addVariables(ExecutionContext executionContext
,
182 Map
<String
, String
> vars
) {
183 for (String key
: vars
.keySet())
184 executionContext
.setVariable(key
, vars
.get(key
));