Remove old license headers
[gpl/argeo-slc.git] / org.argeo.slc.spring / ext / test / org / argeo / slc / core / execution / BasicExecutionFlowTest.java
index c2ecd09dcbcc0fffef5089fefc339dd7db2b4890..b79fe44c5a0eb5bdc22d6a240848d78a62d72128 100644 (file)
-/*\r
- * Copyright (C) 2007-2012 Argeo GmbH\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *         http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.core.execution;\r
-\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-import org.argeo.slc.execution.ExecutionContext;\r
-import org.argeo.slc.execution.ExecutionFlow;\r
-import org.argeo.slc.runtime.test.SimpleTestResult;\r
-import org.argeo.slc.test.TestStatus;\r
-import org.springframework.beans.factory.BeanCreationException;\r
-import org.springframework.context.ConfigurableApplicationContext;\r
-\r
-public class BasicExecutionFlowTest extends AbstractExecutionFlowTestCase {\r
-       // TO TEST\r
-       // - post-processing for @{} replacement in beans with complex properties\r
-       // - bean of scope other than execution are not resolved at execution\r
-\r
-       // public void testMyTest() throws Exception {\r
-       // ConfigurableApplicationContext applicationContext =\r
-       // createApplicationContext("test.xml");\r
-       // log.info("Start Execution");\r
-       // ((ExecutionFlow) applicationContext.getBean("flow1")).execute();\r
-       // applicationContext.close();\r
-       // }\r
-\r
-       public void XXXtestSpecOverriding() throws Exception {\r
-               ConfigurableApplicationContext applicationContext = createApplicationContext("specOverriding.xml");\r
-               ((ExecutionFlow) applicationContext.getBean("flow2")).run();\r
-               SimpleTestResult res = (SimpleTestResult) applicationContext\r
-                               .getBean("myTestResult");\r
-               validateTestResult(res);\r
-       }\r
-\r
-       public void testMultipleFlows() throws Exception {\r
-               ConfigurableApplicationContext applicationContext = createApplicationContext("multipleFlow.xml");\r
-               ((ExecutionFlow) applicationContext.getBean("flow1")).run();\r
-               SimpleTestResult res = (SimpleTestResult) applicationContext\r
-                               .getBean("myTestResult");\r
-               validateTestResult(res);\r
-               res.getParts().clear();\r
-               ((ExecutionFlow) applicationContext.getBean("flow2")).run();\r
-               validateTestResult(res, TestStatus.FAILED);\r
-               applicationContext.close();\r
-       }\r
-\r
-       /**\r
-        * Test placeholder resolution in a context without scope execution or proxy\r
-        * and with cascading flows (the flow A contains the flow B)\r
-        * \r
-        * @throws Exception\r
-        */\r
-       public void testPlaceHolders() throws Exception {\r
-               ConfigurableApplicationContext applicationContext = createApplicationContext("placeHolders.cascading.xml");\r
-               ((ExecutionFlow) applicationContext.getBean("flowA")).run();\r
-               validateTestResult((SimpleTestResult) applicationContext\r
-                               .getBean("myTestResult"));\r
-               applicationContext.close();\r
-       }\r
-\r
-       /**\r
-        * Test placeholder resolution in a context without scope execution or proxy\r
-        * and with cascading flows (the flow A contains the flow B) setting\r
-        * execution values (should have no effect)\r
-        * \r
-        * @throws Exception\r
-        */\r
-       public void testPlaceHoldersWithExecutionValues() throws Exception {\r
-               ConfigurableApplicationContext applicationContext = createApplicationContext("placeHolders.cascading.xml");\r
-\r
-               ExecutionContext executionContext = (ExecutionContext) applicationContext\r
-                               .getBean("executionContext");\r
-               Map<String, String> executionParameters = new HashMap<String, String>();\r
-               executionParameters.put("p1", "e1");\r
-               executionParameters.put("p2", "e2");\r
-               executionParameters.put("p3", "e3");\r
-               executionParameters.put("p4", "e4");\r
-               executionParameters.put("p5", "e5");\r
-               executionParameters.put("p6", "e6");\r
-               executionParameters.put("p7", "e7");\r
-               executionParameters.put("p8", "e8");\r
-               addVariables(executionContext, executionParameters);\r
-\r
-               ((ExecutionFlow) applicationContext.getBean("flowA")).run();\r
-               validateTestResult((SimpleTestResult) applicationContext\r
-                               .getBean("myTestResult"));\r
-               applicationContext.close();\r
-       }\r
-\r
-       public void XXXtestPlaceHoldersExec() throws Exception {\r
-               ConfigurableApplicationContext applicationContext = createApplicationContext("placeHolders.cascading.exec.xml");\r
-\r
-               ExecutionContext executionContext = (ExecutionContext) applicationContext\r
-                               .getBean("executionContext");\r
-               Map<String, String> executionParameters = new HashMap<String, String>();\r
-               executionParameters.put("p1", "e1");\r
-               executionParameters.put("p2", "e2");\r
-               executionParameters.put("p3", "e3");\r
-               executionParameters.put("p4", "e4");\r
-               executionParameters.put("p5", "e5");\r
-               executionParameters.put("p6", "e6");\r
-               addVariables(executionContext, executionParameters);\r
-\r
-               ((ExecutionFlow) applicationContext.getBean("flowA")).run();\r
-               validateTestResult((SimpleTestResult) applicationContext\r
-                               .getBean("myTestResult"));\r
-               applicationContext.close();\r
-       }\r
-\r
-       public void testCanonicFlowParameters() throws Exception {\r
-               configureAndExecuteSlcFlow("canonic-001.xml", "canonic.001");\r
-       }\r
-\r
-       public void testCanonicDefaultValues() throws Exception {\r
-               configureAndExecuteSlcFlow("canonic-002.xml", "canonic.002");\r
-       }\r
-\r
-       public void testCanonicMissingValues() throws Exception {\r
-               try {\r
-                       configureAndExecuteSlcFlow("canonic-003.error.xml", "canonic.003");\r
-                       fail("Parameter not set - should be rejected.");\r
-               } catch (BeanCreationException e) {\r
-                       // exception expected\r
-                       logException(e);\r
-               }\r
-       }\r
-\r
-       public void testCanonicUnknownParameter() throws Exception {\r
-               try {\r
-                       configureAndExecuteSlcFlow("canonic-004.error.xml", "canonic.004");\r
-                       fail("Unknown parameter set - should be rejected.");\r
-               } catch (BeanCreationException e) {\r
-                       // exception expected\r
-                       logException(e);\r
-               }\r
-       }\r
-\r
-       public void testListSetMap() throws Exception {\r
-               ConfigurableApplicationContext applicationContext = createApplicationContext("listSetMap.xml");\r
-               ExecutionFlow executionFlow = (ExecutionFlow) applicationContext\r
-                               .getBean("myFlow");\r
-               executionFlow.run();\r
-\r
-               validateTestResult((SimpleTestResult) applicationContext\r
-                               .getBean("myTestResult"));\r
-\r
-               // BasicTestData res = (BasicTestData)\r
-               // applicationContext.getBean("cascadingComplex.testData");\r
-               // log.info("res=" + res.getReached().toString());\r
-\r
-               applicationContext.close();\r
-       }\r
-\r
-       public void testListSetMapMultipleFlows() throws Exception {\r
-               ConfigurableApplicationContext applicationContext = createApplicationContext("listSetMapMultipleFlow.xml");\r
-               ((ExecutionFlow) applicationContext.getBean("flow1")).run();\r
-               SimpleTestResult res = (SimpleTestResult) applicationContext\r
-                               .getBean("myTestResult");\r
-               validateTestResult(res);\r
-               res.getParts().clear();\r
-               ((ExecutionFlow) applicationContext.getBean("flow2")).run();\r
-               validateTestResult(res, TestStatus.FAILED);\r
-               applicationContext.close();\r
-       }\r
-\r
-       protected void addVariables(ExecutionContext executionContext,\r
-                       Map<String, String> vars) {\r
-               for (String key : vars.keySet())\r
-                       executionContext.setVariable(key, vars.get(key));\r
-       }\r
-}\r
+package org.argeo.slc.core.execution;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.argeo.slc.execution.ExecutionContext;
+import org.argeo.slc.execution.ExecutionFlow;
+import org.argeo.slc.runtime.test.SimpleTestResult;
+import org.argeo.slc.test.TestStatus;
+import org.springframework.beans.factory.BeanCreationException;
+import org.springframework.context.ConfigurableApplicationContext;
+
+public class BasicExecutionFlowTest extends AbstractExecutionFlowTestCase {
+       // TO TEST
+       // - post-processing for @{} replacement in beans with complex properties
+       // - bean of scope other than execution are not resolved at execution
+
+       // public void testMyTest() throws Exception {
+       // ConfigurableApplicationContext applicationContext =
+       // createApplicationContext("test.xml");
+       // log.info("Start Execution");
+       // ((ExecutionFlow) applicationContext.getBean("flow1")).execute();
+       // applicationContext.close();
+       // }
+
+       public void XXXtestSpecOverriding() throws Exception {
+               ConfigurableApplicationContext applicationContext = createApplicationContext("specOverriding.xml");
+               ((ExecutionFlow) applicationContext.getBean("flow2")).run();
+               SimpleTestResult res = (SimpleTestResult) applicationContext
+                               .getBean("myTestResult");
+               validateTestResult(res);
+       }
+
+       public void testMultipleFlows() throws Exception {
+               ConfigurableApplicationContext applicationContext = createApplicationContext("multipleFlow.xml");
+               ((ExecutionFlow) applicationContext.getBean("flow1")).run();
+               SimpleTestResult res = (SimpleTestResult) applicationContext
+                               .getBean("myTestResult");
+               validateTestResult(res);
+               res.getParts().clear();
+               ((ExecutionFlow) applicationContext.getBean("flow2")).run();
+               validateTestResult(res, TestStatus.FAILED);
+               applicationContext.close();
+       }
+
+       /**
+        * Test placeholder resolution in a context without scope execution or proxy
+        * and with cascading flows (the flow A contains the flow B)
+        * 
+        * @throws Exception
+        */
+       public void testPlaceHolders() throws Exception {
+               ConfigurableApplicationContext applicationContext = createApplicationContext("placeHolders.cascading.xml");
+               ((ExecutionFlow) applicationContext.getBean("flowA")).run();
+               validateTestResult((SimpleTestResult) applicationContext
+                               .getBean("myTestResult"));
+               applicationContext.close();
+       }
+
+       /**
+        * Test placeholder resolution in a context without scope execution or proxy
+        * and with cascading flows (the flow A contains the flow B) setting
+        * execution values (should have no effect)
+        * 
+        * @throws Exception
+        */
+       public void testPlaceHoldersWithExecutionValues() throws Exception {
+               ConfigurableApplicationContext applicationContext = createApplicationContext("placeHolders.cascading.xml");
+
+               ExecutionContext executionContext = (ExecutionContext) applicationContext
+                               .getBean("executionContext");
+               Map<String, String> executionParameters = new HashMap<String, String>();
+               executionParameters.put("p1", "e1");
+               executionParameters.put("p2", "e2");
+               executionParameters.put("p3", "e3");
+               executionParameters.put("p4", "e4");
+               executionParameters.put("p5", "e5");
+               executionParameters.put("p6", "e6");
+               executionParameters.put("p7", "e7");
+               executionParameters.put("p8", "e8");
+               addVariables(executionContext, executionParameters);
+
+               ((ExecutionFlow) applicationContext.getBean("flowA")).run();
+               validateTestResult((SimpleTestResult) applicationContext
+                               .getBean("myTestResult"));
+               applicationContext.close();
+       }
+
+       public void XXXtestPlaceHoldersExec() throws Exception {
+               ConfigurableApplicationContext applicationContext = createApplicationContext("placeHolders.cascading.exec.xml");
+
+               ExecutionContext executionContext = (ExecutionContext) applicationContext
+                               .getBean("executionContext");
+               Map<String, String> executionParameters = new HashMap<String, String>();
+               executionParameters.put("p1", "e1");
+               executionParameters.put("p2", "e2");
+               executionParameters.put("p3", "e3");
+               executionParameters.put("p4", "e4");
+               executionParameters.put("p5", "e5");
+               executionParameters.put("p6", "e6");
+               addVariables(executionContext, executionParameters);
+
+               ((ExecutionFlow) applicationContext.getBean("flowA")).run();
+               validateTestResult((SimpleTestResult) applicationContext
+                               .getBean("myTestResult"));
+               applicationContext.close();
+       }
+
+       public void testCanonicFlowParameters() throws Exception {
+               configureAndExecuteSlcFlow("canonic-001.xml", "canonic.001");
+       }
+
+       public void testCanonicDefaultValues() throws Exception {
+               configureAndExecuteSlcFlow("canonic-002.xml", "canonic.002");
+       }
+
+       public void testCanonicMissingValues() throws Exception {
+               try {
+                       configureAndExecuteSlcFlow("canonic-003.error.xml", "canonic.003");
+                       fail("Parameter not set - should be rejected.");
+               } catch (BeanCreationException e) {
+                       // exception expected
+                       logException(e);
+               }
+       }
+
+       public void testCanonicUnknownParameter() throws Exception {
+               try {
+                       configureAndExecuteSlcFlow("canonic-004.error.xml", "canonic.004");
+                       fail("Unknown parameter set - should be rejected.");
+               } catch (BeanCreationException e) {
+                       // exception expected
+                       logException(e);
+               }
+       }
+
+       public void testListSetMap() throws Exception {
+               ConfigurableApplicationContext applicationContext = createApplicationContext("listSetMap.xml");
+               ExecutionFlow executionFlow = (ExecutionFlow) applicationContext
+                               .getBean("myFlow");
+               executionFlow.run();
+
+               validateTestResult((SimpleTestResult) applicationContext
+                               .getBean("myTestResult"));
+
+               // BasicTestData res = (BasicTestData)
+               // applicationContext.getBean("cascadingComplex.testData");
+               // log.info("res=" + res.getReached().toString());
+
+               applicationContext.close();
+       }
+
+       public void testListSetMapMultipleFlows() throws Exception {
+               ConfigurableApplicationContext applicationContext = createApplicationContext("listSetMapMultipleFlow.xml");
+               ((ExecutionFlow) applicationContext.getBean("flow1")).run();
+               SimpleTestResult res = (SimpleTestResult) applicationContext
+                               .getBean("myTestResult");
+               validateTestResult(res);
+               res.getParts().clear();
+               ((ExecutionFlow) applicationContext.getBean("flow2")).run();
+               validateTestResult(res, TestStatus.FAILED);
+               applicationContext.close();
+       }
+
+       protected void addVariables(ExecutionContext executionContext,
+                       Map<String, String> vars) {
+               for (String key : vars.keySet())
+                       executionContext.setVariable(key, vars.get(key));
+       }
+}