]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
Add JUnit Test for ExecutionFlow
authorOlivier Capillon <olivier.capillon@gmail.com>
Fri, 6 Mar 2009 16:31:44 +0000 (16:31 +0000)
committerOlivier Capillon <olivier.capillon@gmail.com>
Fri, 6 Mar 2009 16:31:44 +0000 (16:31 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@2237 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

12 files changed:
runtime/org.argeo.slc.support.simple/pom.xml
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ExecutionContext.java
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/unit/AbstractSpringTestCase.java
runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/core/execution/ExecutionFlowTest.java [new file with mode: 0644]
runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/applicationContext.xml [new file with mode: 0644]
runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/canonic-001.xml [new file with mode: 0644]
runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/canonic-002.xml [new file with mode: 0644]
runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/canonic-003.error.xml [new file with mode: 0644]
runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/canonic-004.error.xml [new file with mode: 0644]
runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/canonic.xml [new file with mode: 0644]
runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/imports.xml [new file with mode: 0644]
runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/minimal.xml [new file with mode: 0644]

index 3753cb57603533fd6bead6c9f1e6214b478015b5..c2fd56e940092f09ba5b34af3de5643c3e1ac7fc 100644 (file)
@@ -1,4 +1,5 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
                <groupId>org.argeo.slc</groupId>
                        <groupId>org.junit</groupId>
                        <artifactId>com.springsource.junit</artifactId>
                </dependency>
+               <dependency>
+                       <groupId>net.sourceforge.cglib</groupId>
+                       <artifactId>com.springsource.net.sf.cglib</artifactId>
+               </dependency>
 
                <!-- Required by DB Unit -->
                <dependency>
index 732dd819e3d71425b1fe5c09b5417a97e9e3268a..9332826084b29bdd972162b39960745961f2816f 100644 (file)
@@ -47,6 +47,20 @@ public class ExecutionContext {
                                        + " already registered.");
                executionContext.set(context);
        }
+       
+       /**
+        * Unregisters the ExecutionContext for the current Thread
+        * @throws a SlcException if no ExecutionContext was registered for the Thread
+        * @return the unregistered ExecutionContext
+        */
+       public static ExecutionContext unregisterExecutionContext() {
+               ExecutionContext current = executionContext.get();
+               if(current == null) {
+                       throw new SlcException("No Context registered.");
+               }
+               executionContext.remove();
+               return current;
+       }
 
        public static void enterFlow(ExecutionFlow executionFlow) {
                Stack<ExecutionFlowRuntime> stack = executionContext.get().stack;
index ee95e3eee92854a55b045c3b085d16ae07e36046..65d917cfe1755bf20786b83c40ffdb5d31f3e62d 100644 (file)
@@ -23,9 +23,16 @@ public abstract class AbstractSpringTestCase extends TestCase {
                if (context == null) {\r
                        context = new ClassPathXmlApplicationContext(\r
                                        getApplicationContextLocation());\r
+                       if(getIsStartContext())\r
+                               context.start();\r
                }\r
                return context;\r
        }\r
+       \r
+       /** Whether the context should be started after being created. */\r
+       protected Boolean getIsStartContext(){\r
+               return false;\r
+       }\r
 \r
        /** Returns a bean from the underlying context */\r
        protected <T> T getBean(String beanId) {\r
diff --git a/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/core/execution/ExecutionFlowTest.java b/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/core/execution/ExecutionFlowTest.java
new file mode 100644 (file)
index 0000000..5fdfb99
--- /dev/null
@@ -0,0 +1,96 @@
+package org.argeo.slc.core.execution;\r
+\r
+import org.argeo.slc.execution.ExecutionFlow;\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
+       \r
+       public void testSimpleExecution() throws Exception {\r
+//             configureAndExecuteSlcFlow("main");\r
+               configureAndExecuteSlcFlow("applicationContext.xml", "main");\r
+       }\r
+       \r
+       public void testCanonic() throws Exception {\r
+               configureAndExecuteSlcFlow("minimal.xml", "minimal");\r
+               // Parameter without default value in specification\r
+//             configureAndExecuteSlcFlow("canonic-001.xml", "canonic.001");\r
+//             configureAndExecuteSlcFlow("canonic-002.xml", "canonic.002");\r
+\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
+                       //e.printStackTrace();\r
+               }*/\r
+               \r
+/*             try {\r
+                       configureAndExecuteSlcFlow("canonic-004.error.xml", "canonic.004");\r
+                       fail("Unkown parameter set - should be rejected.");\r
+               } catch (BeanCreationException e) {\r
+                       // exception expected\r
+                       //e.printStackTrace();\r
+               }               */\r
+       }       \r
+       \r
+       protected void configureSlcFlow(String beanName) {\r
+               // if an execution context was registered, unregister it\r
+               if(ExecutionContext.getCurrent() != null) {\r
+                       ExecutionContext.unregisterExecutionContext();\r
+               }\r
+               // register a new ExecutionContext\r
+               ExecutionContext.registerExecutionContext(new ExecutionContext());\r
+               \r
+//             ExecutionContext.getVariables().put("slc.flows", beanName);\r
+       }\r
+       \r
+/*     \r
+       @Override\r
+       protected Boolean getIsStartContext() {\r
+               return true;\r
+       }\r
+\r
+       @Override\r
+       protected ConfigurableApplicationContext getContext() {\r
+               return getStaticContext();\r
+       }\r
+\r
+       private static ConfigurableApplicationContext staticContext;    \r
+               \r
+       protected ConfigurableApplicationContext getStaticContext() {\r
+               if (staticContext == null) {\r
+                       staticContext = new ClassPathXmlApplicationContext(\r
+                                       getApplicationContextLocation());\r
+                       if(getIsStartContext())\r
+                               staticContext.start();\r
+               }\r
+               return staticContext;           \r
+       }\r
+       \r
+       protected void configureAndExecuteSlcFlow(String beanName) {\r
+               // Triggers a start of the ApplicationContext\r
+               // Required before starting some tests\r
+               // TODO: understand why !\r
+               getContext(); \r
+               configureSlcFlow(beanName);\r
+               ExecutionFlow executionFlow = (ExecutionFlow) getContext().getBean(beanName);\r
+               executionFlow.execute();                \r
+       }\r
+       */\r
+       \r
+       protected void configureAndExecuteSlcFlow(String applicationContextSuffix, String beanName) {\r
+               // create a new context\r
+               ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(\r
+                               inPackage(applicationContextSuffix));\r
+               applicationContext.start();\r
+               \r
+               configureSlcFlow(beanName);\r
+               ExecutionFlow executionFlow = (ExecutionFlow) applicationContext.getBean(beanName);\r
+               executionFlow.execute();                \r
+//             applicationContext.stop();\r
+               applicationContext.close();\r
+       }       \r
+}\r
diff --git a/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/applicationContext.xml b/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/applicationContext.xml
new file mode 100644 (file)
index 0000000..e592269
--- /dev/null
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<beans xmlns="http://www.springframework.org/schema/beans"\r
+       xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+       xmlns:aop="http://www.springframework.org/schema/aop"\r
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd\r
+       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">\r
+\r
+       <import resource="imports.xml" /> \r
+\r
+       <bean id="main" parent="slcTemplate.simpleFlow">\r
+               <property name="executionSpec">\r
+                       <bean parent="slcTemplate.simpleSpec">\r
+                               <property name="attributes">\r
+                                       <map>\r
+                                               <entry key="testKey">\r
+                                                       <bean parent="specAttr.primitive" p:value="660" />\r
+                                               </entry>\r
+                                       </map>\r
+                               </property>\r
+                       </bean>\r
+               </property>\r
+               <property name="executables">\r
+                       <list>\r
+                               <ref local="echo1" />\r
+                       </list>\r
+               </property>\r
+       </bean>\r
+\r
+       <bean id="echo1" parent="task.echo" scope="execution">\r
+               <property name="message"\r
+                       value="From main! @{testKey}" />\r
+               <aop:scoped-proxy />\r
+       </bean>\r
+\r
+</beans>
\ No newline at end of file
diff --git a/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/canonic-001.xml b/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/canonic-001.xml
new file mode 100644 (file)
index 0000000..71f8461
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<beans xmlns="http://www.springframework.org/schema/beans"\r
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"\r
+       xmlns:aop="http://www.springframework.org/schema/aop"\r
+       xsi:schemaLocation="\r
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd\r
+       http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd\r
+       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">\r
+\r
+       <import resource="canonic.xml" />\r
+\r
+       <bean id="canonic.001" parent="canonic.flowTemplate">\r
+               <constructor-arg>\r
+                       <map>\r
+                               <entry key="parameterAtInstantiation" value="1" />\r
+                       </map>\r
+               </constructor-arg>\r
+       </bean>\r
+</beans>\r
diff --git a/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/canonic-002.xml b/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/canonic-002.xml
new file mode 100644 (file)
index 0000000..d912d51
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<beans xmlns="http://www.springframework.org/schema/beans"\r
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"\r
+       xmlns:aop="http://www.springframework.org/schema/aop"\r
+       xsi:schemaLocation="\r
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd\r
+       http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd\r
+       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">\r
+\r
+       <import resource="canonic.xml" />\r
+\r
+       <bean id="canonic.002" parent="canonic.flowTemplate">\r
+               <constructor-arg>\r
+                       <map>\r
+                               <entry key="parameterAtInstantiation" value="2" />\r
+                               <entry key="displayWithoutControl" value="102" />\r
+                               <entry key="displayWithControl" value="202" />\r
+                               <entry key="hide" value="202" />\r
+                       </map>\r
+               </constructor-arg>\r
+       </bean>\r
+</beans>\r
diff --git a/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/canonic-003.error.xml b/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/canonic-003.error.xml
new file mode 100644 (file)
index 0000000..b339cb0
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<beans xmlns="http://www.springframework.org/schema/beans"\r
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"\r
+       xmlns:aop="http://www.springframework.org/schema/aop"\r
+       xsi:schemaLocation="\r
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd\r
+       http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd\r
+       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">\r
+\r
+       <import resource="canonic.xml" />\r
+\r
+       <bean id="canonic.003" parent="canonic.flowTemplate">\r
+               <constructor-arg>\r
+                       <map>\r
+                               <entry key="displayWithoutControl" value="102" />\r
+                               <entry key="displayWithControl" value="202" />\r
+                               <entry key="hide" value="202" />\r
+                       </map>\r
+               </constructor-arg>\r
+       </bean>\r
+</beans>\r
diff --git a/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/canonic-004.error.xml b/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/canonic-004.error.xml
new file mode 100644 (file)
index 0000000..b0f556b
--- /dev/null
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<beans xmlns="http://www.springframework.org/schema/beans"\r
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"\r
+       xmlns:aop="http://www.springframework.org/schema/aop"\r
+       xsi:schemaLocation="\r
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd\r
+       http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd\r
+       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">\r
+\r
+       <import resource="canonic.xml" />\r
+\r
+       <bean id="canonic.004" parent="canonic.flowTemplate">\r
+               <constructor-arg>\r
+                       <map>\r
+                               <entry key="parameterAtInstantiation" value="2" />\r
+                               <entry key="displayWithoutControl" value="102" />\r
+                               <entry key="displayWithControl" value="202" />\r
+                               <entry key="hide" value="202" />\r
+                               <entry key="unknownParameter" value="1" />\r
+                       </map>\r
+               </constructor-arg>\r
+       </bean>\r
+</beans>\r
diff --git a/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/canonic.xml b/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/canonic.xml
new file mode 100644 (file)
index 0000000..b5d7d5d
--- /dev/null
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<beans xmlns="http://www.springframework.org/schema/beans"\r
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"\r
+       xmlns:aop="http://www.springframework.org/schema/aop"\r
+       xsi:schemaLocation="\r
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd\r
+       http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd\r
+       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">\r
+\r
+       <import resource="imports.xml" /> \r
+\r
+       <bean id="canonic.spec" parent="slcTemplate.simpleSpec">\r
+               <property name="attributes">\r
+                       <map>\r
+                               <entry key="parameterAtInstantiation">\r
+                                       <bean parent="specAttr.primitive" p:isParameter="true" p:type="integer" />\r
+                               </entry>\r
+                               <entry key="displayWithoutControl">\r
+                                       <bean parent="specAttr.primitive" p:value="100" p:isParameter="true"\r
+                                               p:isFrozen="true" p:type="integer" />\r
+                               </entry>\r
+                               <entry key="displayWithControl">\r
+                                       <bean parent="specAttr.primitive" p:value="200" p:isParameter="true"\r
+                                               p:isFrozen="false" p:type="integer" />\r
+                               </entry>\r
+                               <entry key="hide">\r
+                                       <bean parent="specAttr.primitive" p:value="300" p:isParameter="true"\r
+                                               p:isFrozen="false" p:isHidden="true" p:type="integer" />\r
+                               </entry>\r
+                       </map>\r
+               </property>\r
+       </bean>\r
+\r
+       <bean id="canonic.flowTemplate" parent="slcTemplate.simpleFlow"\r
+               abstract="true">\r
+               <property name="executionSpec" ref="canonic.spec" />\r
+               <property name="executables">\r
+                       <list>\r
+                               <bean parent="task.echo"\r
+                                       p:message="Canonical: displayWithControl=@{displayWithControl}, displayWithoutControl=@{displayWithoutControl}, hide=@{hide}"\r
+                                       scope="execution">\r
+                                       <aop:scoped-proxy />\r
+                               </bean>\r
+                       </list>\r
+               </property>\r
+       </bean>\r
+</beans>
\ No newline at end of file
diff --git a/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/imports.xml b/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/imports.xml
new file mode 100644 (file)
index 0000000..6bff52f
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+
+       <import resource="classpath:org/argeo/slc/core/execution/spring.xml" />
+
+       <import
+               resource="classpath:/org/argeo/slc/core/test/spring/applicationContext.xml" />
+
+</beans>
\ No newline at end of file
diff --git a/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/minimal.xml b/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/minimal.xml
new file mode 100644 (file)
index 0000000..af4ffec
--- /dev/null
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<beans xmlns="http://www.springframework.org/schema/beans"\r
+       xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+       xmlns:aop="http://www.springframework.org/schema/aop"\r
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd\r
+       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">\r
+\r
+       <import resource="imports.xml" /> \r
+\r
+       <bean id="minimal" parent="slcTemplate.simpleFlow">\r
+               <property name="executionSpec">\r
+                       <bean parent="slcTemplate.simpleSpec">\r
+<!--                           <property name="attributes">\r
+                                       <map>\r
+                                               <entry key="testKey">\r
+                                                       <bean parent="specAttr.primitive" p:value="660" />\r
+                                               </entry>\r
+                                       </map>\r
+                               </property> -->\r
+                       </bean>\r
+               </property>\r
+               <property name="executables">\r
+                       <list>\r
+                               <ref local="echo1" />\r
+                       </list>\r
+               </property>\r
+       </bean>\r
+\r
+       <bean id="echo1" parent="task.echo" scope="execution">\r
+               <property name="message"\r
+                       value="From minimal" />\r
+               <aop:scoped-proxy />\r
+       </bean>\r
+\r
+</beans>
\ No newline at end of file