]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/core/execution/ExecutionFlowTest.java
ExecutionParameterPostProcessor improved (placeholder resolved for each instance)
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / src / test / java / org / argeo / slc / core / execution / ExecutionFlowTest.java
index d97a501ab4cc869223ef2b82601b1328f1571e0c..721162ebb17ffa2fd85cfaf96d4ff7b80c46d429 100644 (file)
 package org.argeo.slc.core.execution;\r
 \r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import junit.framework.TestCase;\r
+\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+import org.argeo.slc.core.test.BasicTestData;\r
 import org.argeo.slc.core.test.SimpleTestResult;\r
+import org.argeo.slc.execution.ExecutionContext;\r
 import org.argeo.slc.execution.ExecutionFlow;\r
+import org.argeo.slc.test.TestResultPart;\r
 import org.argeo.slc.test.TestStatus;\r
 import org.argeo.slc.unit.AbstractSpringTestCase;\r
 import org.springframework.beans.factory.BeanCreationException;\r
 import org.springframework.context.ConfigurableApplicationContext;\r
 import org.springframework.context.support.ClassPathXmlApplicationContext;\r
 \r
-public class ExecutionFlowTest extends AbstractSpringTestCase {\r
+public class ExecutionFlowTest extends TestCase {\r
        \r
-       public void testSimpleExecution() throws Exception {\r
-               configureAndExecuteSlcFlow("applicationContext.xml", "main");\r
-       }\r
+       protected final Log log = LogFactory.getLog(getClass());\r
+                       \r
+       \r
+// to test: case with listener \r
+       \r
+//     public void testMyTest() throws Exception {\r
+//             ConfigurableApplicationContext applicationContext = createApplicationContext("test.xml");\r
+//             log.info("Start Execution");\r
+//             ((ExecutionFlow) applicationContext.getBean("fileDiff.SimulationView_Risk")).execute();\r
+//             applicationContext.close();             \r
+//     }\r
+//     \r
+       public void testMultipleFlows() throws Exception {\r
+               ConfigurableApplicationContext applicationContext = createApplicationContext("multipleFlow.xml");\r
+               log.info("Start Execution");\r
+               ((ExecutionFlow) applicationContext.getBean("flow1")).execute();\r
+               ((ExecutionFlow) applicationContext.getBean("flow2")).execute();\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
+        * @throws Exception\r
+        */\r
+       public void testPlaceHolders() throws Exception {\r
+               ConfigurableApplicationContext applicationContext = createApplicationContext("placeHolders.cascading.xml");\r
+               ((ExecutionFlow) applicationContext.getBean("flowA")).execute();\r
+               validateTestResult((SimpleTestResult) applicationContext.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)\r
+        * setting execution values (should have no effect)\r
+        * @throws Exception\r
+        */\r
+       public void testPlaceHoldersWithExecutionValues() throws Exception {\r
+               ConfigurableApplicationContext applicationContext = createApplicationContext("placeHolders.cascading.xml");\r
+               \r
+               ExecutionContext executionContext = (ExecutionContext)applicationContext.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
+               executionContext.addVariables(executionParameters);\r
+               \r
+               ((ExecutionFlow) applicationContext.getBean("flowA")).execute();\r
+               validateTestResult((SimpleTestResult) applicationContext.getBean("myTestResult"));\r
+               applicationContext.close();\r
+       }               \r
+       \r
+       public void testPlaceHoldersExec() throws Exception {\r
+               ConfigurableApplicationContext applicationContext = createApplicationContext("placeHolders.cascading.exec.xml");\r
+               \r
+               ExecutionContext executionContext = (ExecutionContext)applicationContext.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
+               executionContext.addVariables(executionParameters);\r
+               \r
+               ((ExecutionFlow) applicationContext.getBean("flowA")).execute();\r
+               validateTestResult((SimpleTestResult) applicationContext.getBean("myTestResult"));\r
+               applicationContext.close();\r
+       }               \r
        \r
-       public void testCanonic() throws Exception {\r
-               // Parameter without default value in specification\r
+       public void testCanonicFlowParameters()  throws Exception {\r
                configureAndExecuteSlcFlow("canonic-001.xml", "canonic.001");\r
-               configureAndExecuteSlcFlow("canonic-002.xml", "canonic.002");\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
-/*             try {\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
        \r
-/*     public void testRecursive() throws Exception {\r
-               ConfigurableApplicationContext applicationContext = prepareExecution("test.xml");\r
-               ExecutionFlow executionFlow = (ExecutionFlow) applicationContext.getBean("first");\r
+       public void testListSetMap() throws Exception {\r
+               ConfigurableApplicationContext applicationContext = createApplicationContext("listSetMap.xml");\r
+               ExecutionFlow executionFlow = (ExecutionFlow) applicationContext.getBean("myFlow");\r
                executionFlow.execute();                \r
-               SimpleTestResult res = (SimpleTestResult) applicationContext.getBean("basicTestResult");\r
-               if(res.getParts().get(0).getStatus() != TestStatus.PASSED) {\r
-                       fail("Unexpected string returned");\r
-               }\r
+                               \r
+               validateTestResult((SimpleTestResult) applicationContext.getBean("myTestResult"));\r
+               \r
+//             BasicTestData res = (BasicTestData) applicationContext.getBean("cascadingComplex.testData");\r
+//             log.info("res=" + res.getReached().toString());\r
+               \r
                applicationContext.close();             \r
-       }*/\r
+       }               \r
+\r
+//     public void testListSetMapMultipleFlows() throws Exception {\r
+//             ConfigurableApplicationContext applicationContext = createApplicationContext("listSetMapMultipleFlow.xml");\r
+//             ((ExecutionFlow) applicationContext.getBean("flow1")).execute();\r
+//             SimpleTestResult res = (SimpleTestResult) applicationContext.getBean("myTestResult");\r
+//             validateTestResult(res);                \r
+//             res.getParts().clear();\r
+//             ((ExecutionFlow) applicationContext.getBean("flow2")).execute();\r
+//             validateTestResult(res, TestStatus.FAILED);\r
+//             applicationContext.close();             \r
+//     }                       \r
        \r
        protected void logException(Throwable ex) {\r
                log.info("Got Exception of class " + ex.getClass().toString()\r
                                + " with message '" + ex.getMessage() + "'.");\r
        }\r
-       \r
-       protected void initExecutionContext() {\r
-/*             // if an execution context was registered, unregister it\r
-               if(MapExecutionContext.getCurrent() != null) {\r
-                       MapExecutionContext.unregisterExecutionContext();\r
-               }\r
-               // register a new ExecutionContext\r
-               MapExecutionContext.registerExecutionContext(new MapExecutionContext());                */\r
+               \r
+       protected void validateTestResult(SimpleTestResult testResult) {\r
+               validateTestResult(testResult, TestStatus.PASSED);\r
        }\r
        \r
-       protected ConfigurableApplicationContext prepareExecution(String applicationContextSuffix) {\r
+       protected void validateTestResult(SimpleTestResult testResult, int expectedStatus) {\r
+               for(TestResultPart part : testResult.getParts()) {\r
+                       if(part.getStatus() != expectedStatus) {\r
+                               fail("Error found in TestResult: " + part.getMessage());\r
+                       }\r
+               }               \r
+       }       \r
+       \r
+       protected ConfigurableApplicationContext createApplicationContext(String applicationContextSuffix) {\r
                ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(inPackage(applicationContextSuffix));\r
                applicationContext.start();\r
-               initExecutionContext();\r
                return applicationContext;\r
        }\r
        \r
        protected void configureAndExecuteSlcFlow(String applicationContextSuffix, String beanName) {\r
-               ConfigurableApplicationContext applicationContext = prepareExecution(applicationContextSuffix);\r
+               ConfigurableApplicationContext applicationContext = createApplicationContext(applicationContextSuffix);\r
                ExecutionFlow executionFlow = (ExecutionFlow) applicationContext.getBean(beanName);\r
                executionFlow.execute();                \r
                applicationContext.close();\r
        }       \r
+       \r
+       protected String inPackage(String suffix) {\r
+               String prefix = getClass().getPackage().getName().replace('.', '/');\r
+               return prefix + '/' + suffix;\r
+       }       \r
 }\r