-<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>
+ " 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;
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
--- /dev/null
+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
--- /dev/null
+<?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
--- /dev/null
+<?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
--- /dev/null
+<?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
--- /dev/null
+<?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
--- /dev/null
+<?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
--- /dev/null
+<?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
--- /dev/null
+<?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
--- /dev/null
+<?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