2 * Copyright (C) 2007-2012 Argeo GmbH
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.
16 package org
.argeo
.slc
.core
.execution
;
18 import java
.util
.HashMap
;
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
;
28 public class BasicExecutionFlowTest
extends AbstractExecutionFlowTestCase
{
30 // - post-processing for @{} replacement in beans with complex properties
31 // - bean of scope other than execution are not resolved at execution
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();
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
);
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();
62 * Test placeholder resolution in a context without scope execution or proxy
63 * and with cascading flows (the flow A contains the flow B)
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();
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)
82 public void testPlaceHoldersWithExecutionValues() throws Exception
{
83 ConfigurableApplicationContext applicationContext
= createApplicationContext("placeHolders.cascading.xml");
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
);
98 ((ExecutionFlow
) applicationContext
.getBean("flowA")).run();
99 validateTestResult((SimpleTestResult
) applicationContext
100 .getBean("myTestResult"));
101 applicationContext
.close();
104 public void testPlaceHoldersExec() throws Exception
{
105 ConfigurableApplicationContext applicationContext
= createApplicationContext("placeHolders.cascading.exec.xml");
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
);
118 ((ExecutionFlow
) applicationContext
.getBean("flowA")).run();
119 validateTestResult((SimpleTestResult
) applicationContext
120 .getBean("myTestResult"));
121 applicationContext
.close();
124 public void testCanonicFlowParameters() throws Exception
{
125 configureAndExecuteSlcFlow("canonic-001.xml", "canonic.001");
128 public void testCanonicDefaultValues() throws Exception
{
129 configureAndExecuteSlcFlow("canonic-002.xml", "canonic.002");
132 public void testCanonicMissingValues() throws Exception
{
134 configureAndExecuteSlcFlow("canonic-003.error.xml", "canonic.003");
135 fail("Parameter not set - should be rejected.");
136 } catch (BeanCreationException e
) {
137 // exception expected
142 public void testCanonicUnknownParameter() throws Exception
{
144 configureAndExecuteSlcFlow("canonic-004.error.xml", "canonic.004");
145 fail("Unknown parameter set - should be rejected.");
146 } catch (BeanCreationException e
) {
147 // exception expected
152 public void testListSetMap() throws Exception
{
153 ConfigurableApplicationContext applicationContext
= createApplicationContext("listSetMap.xml");
154 ExecutionFlow executionFlow
= (ExecutionFlow
) applicationContext
158 validateTestResult((SimpleTestResult
) applicationContext
159 .getBean("myTestResult"));
161 // BasicTestData res = (BasicTestData)
162 // applicationContext.getBean("cascadingComplex.testData");
163 // log.info("res=" + res.getReached().toString());
165 applicationContext
.close();
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();
180 protected void addVariables(ExecutionContext executionContext
,
181 Map
<String
, String
> vars
) {
182 for (String key
: vars
.keySet())
183 executionContext
.setVariable(key
, vars
.get(key
));