]> git.argeo.org Git - gpl/argeo-slc.git/commitdiff
ExecutionParameterPostProcessor improved (placeholder resolved for each instance)
authorOlivier Capillon <olivier.capillon@gmail.com>
Mon, 23 Mar 2009 16:19:54 +0000 (16:19 +0000)
committerOlivier Capillon <olivier.capillon@gmail.com>
Mon, 23 Mar 2009 16:19:54 +0000 (16:19 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@2300 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionContext.java
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/ExecutionParameterPostProcessor.java
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/InstantiationManager.java
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/MapExecutionContext.java
runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/core/execution/ExecutionFlowTest.java
runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/listSetMapMultipleFlow.xml [new file with mode: 0644]
runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/multipleFlow.xml [new file with mode: 0644]
runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/test.xml

index b5d467f7e5d2542ce1a9eb5be5db91e3fd3c418f..0176d006378cc4d9687cfaf9e99797158fe30c9d 100644 (file)
@@ -20,6 +20,8 @@ public interface ExecutionContext {
        \r
        public Object getVariable(String key);\r
        \r
+       public Object findVariable(String key);\r
+       \r
        //TODO: replace with setVariable(String Key, Object value)\r
        public void addVariables(Map<? extends String, ? extends Object> variablesToAdd);\r
 }\r
index a76820465d452692bbe310010e5237b3d39445c2..175ef778c68ce5cc502dd576616d57567eb82d1d 100644 (file)
-package org.argeo.slc.core.execution;
-
-import java.beans.PropertyDescriptor;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.slc.SlcException;
-import org.argeo.slc.execution.ExecutionContext;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.MutablePropertyValues;
-import org.springframework.beans.PropertyValue;
-import org.springframework.beans.PropertyValues;
-import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;
-import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
-import org.springframework.beans.factory.config.TypedStringValue;
-import org.springframework.beans.factory.support.ManagedList;
-import org.springframework.beans.factory.support.ManagedMap;
-import org.springframework.beans.factory.support.ManagedSet;
-import org.springframework.util.ObjectUtils;
-
-public class ExecutionParameterPostProcessor extends
-               InstantiationAwareBeanPostProcessorAdapter {
-
-       private final static Log log = LogFactory
-                       .getLog(ExecutionParameterPostProcessor.class);
-
-//     private CustomPpc ppc = new CustomPpc(new Properties());
-       
-       private ExecutionContext executionContext;
-
-       private ExecutionScope executionScope;
-
-       private InstantiationManager instantiationManager;
-
-       public InstantiationManager getInstantiationManager() {
-               return instantiationManager;
-       }
-
-       public void setInstantiationManager(
-                       InstantiationManager instantiationManager) {
-               this.instantiationManager = instantiationManager;
-       }
-
-       public void setExecutionScope(ExecutionScope executionScope) {
-               this.executionScope = executionScope;
-       }
-
-       public ExecutionContext getExecutionContext() {
-               return executionContext;
-       }
-
-       public void setExecutionContext(ExecutionContext executionContext) {
-               this.executionContext = executionContext;
-       }
-
-       private String placeholderPrefix = "@{";
-       private String placeholderSuffix = "}";
-       private String nullValue;
-
-       protected Object resolveValue(Object value, CustomPpc ppc) {            
-               if (value instanceof TypedStringValue) {
-                       TypedStringValue tsv = (TypedStringValue) value;
-                       return ppc.process(tsv.getValue());
-               }
-               else if (value instanceof String) {
-                       return ppc.process(value.toString());
-               }               
-               else if (value instanceof Map) {
-                       Map mapVal = (Map) value;
-                       
-                       Map newContent = new LinkedHashMap();
-                       boolean entriesModified = false;
-                       for (Iterator it = mapVal.entrySet().iterator(); it.hasNext();) {
-                               Map.Entry entry = (Map.Entry) it.next();
-                               Object key = entry.getKey();
-                               int keyHash = (key != null ? key.hashCode() : 0);
-                               Object newKey = resolveValue(key,ppc);
-                               int newKeyHash = (newKey != null ? newKey.hashCode() : 0);
-                               Object val = entry.getValue();
-                               Object newVal = resolveValue(val,ppc);
-                               newContent.put(newKey, newVal);
-                               entriesModified = entriesModified || (newVal != val || newKey != key || newKeyHash != keyHash);
-                       }
-                       if (entriesModified) {
-                               mapVal.clear();
-                               mapVal.putAll(newContent);
-                       }
-                       return mapVal;
-               }
-               else if (value instanceof List) {
-                       List listVal = (List) value;
-                       for (int i = 0; i < listVal.size(); i++) {
-                               Object elem = listVal.get(i);
-                               Object newVal = resolveValue(elem,ppc);
-                               if (!ObjectUtils.nullSafeEquals(newVal, elem)) {
-                                       listVal.set(i, newVal);
-                               }
-                       }                       
-                       return value;
-               }
-               else if (value instanceof Set) {
-                       Set setVal = (Set) value;
-                       Set newContent = new LinkedHashSet();
-                       boolean entriesModified = false;
-                       for (Iterator it = setVal.iterator(); it.hasNext();) {
-                               Object elem = it.next();
-                               int elemHash = (elem != null ? elem.hashCode() : 0);
-                               Object newVal = resolveValue(elem,ppc);
-                               int newValHash = (newVal != null ? newVal.hashCode() : 0);
-                               newContent.add(newVal);
-                               entriesModified = entriesModified || (newVal != elem || newValHash != elemHash);
-                       }
-                       if (entriesModified) {
-                               setVal.clear();
-                               setVal.addAll(newContent);
-                       }       
-                       return value;
-               }
-               else {
-                       return value;
-               }
-       }
-       
-       @Override
-       public PropertyValues postProcessPropertyValues(PropertyValues pvs,
-                       PropertyDescriptor[] pds, Object bean, String beanName)
-                       throws BeansException {
-
-               //TODO: resolve at execution only if scope is execution
-               
-//             boolean inFlowInitialization = instantiationManager
-//                             .isInFlowInitialization();
-//
-//             if (((executionScope == null) || (!executionScope.hasExecutionContext()))
-//                             && !inFlowInitialization) {
-//                     // log.info("Skip parameter conversion for bean " + beanName);
-//                     return pvs;
-//             } else {
-//                     // log.info("Execute parameter conversion for bean " + beanName);
-//             }
-
-               // copy the property values
-               //MutablePropertyValues newPv = new MutablePropertyValues(pvs);
-               
-               Properties props = new Properties();
-               CustomPpc ppc = new CustomPpc(props);
-
-               for (PropertyValue pv : pvs.getPropertyValues()) {
-                       // log.info("   PropertyValue pv " + pv.getValue() + " - "
-                       // + pv.getValue().getClass());
-                       String originalValue = null;
-                       String convertedValue = null;
-                                               
-                       if (pv.getValue() instanceof TypedStringValue) {
-                               TypedStringValue tsv = (TypedStringValue) pv.getValue();
-                               originalValue = tsv.getValue();
-                               convertedValue = ppc.process(originalValue);
-                               if (!convertedValue.equals(originalValue)) 
-                                       tsv.setValue(convertedValue);
-                       }
-                       else if (pv.getValue() instanceof String) {
-                               originalValue = pv.getValue().toString();
-                               convertedValue = ppc.process(originalValue);
-                               // Setting the convertedValue can be problematic since
-                               // calling setConvertedValue also sets a flag setConvertedValue
-                               if (!convertedValue.equals(originalValue))
-                                       pv.setConvertedValue(convertedValue);
-                       }       
-                       
-                       else if ((pv.getValue() instanceof ManagedMap)
-                                       ||(pv.getValue() instanceof ManagedList)
-                                       ||(pv.getValue() instanceof ManagedSet)){
-                               resolveValue(pv.getValue(),ppc);                        
-                       }
-                       
-                       if (convertedValue != null && log.isTraceEnabled()) {
-                               if (!originalValue.equals(convertedValue))
-                                       log.trace("Converted field '" + pv.getName() + "': '"
-                                                       + originalValue + "' to '" + convertedValue
-                                                       + "' in bean " + beanName);
-                       }
-               }
-
-               return pvs;
-       }
-
-       public void setPlaceholderPrefix(String placeholderPrefix) {
-               this.placeholderPrefix = placeholderPrefix;
-       }
-
-       public void setPlaceholderSuffix(String placeholderSuffix) {
-               this.placeholderSuffix = placeholderSuffix;
-       }
-
-       public void setNullValue(String nullValue) {
-               this.nullValue = nullValue;
-       }
-
-       private class CustomPpc extends PropertyPlaceholderConfigurer {
-               private final Properties props;
-
-               public CustomPpc(Properties props) {
-                       super();
-                       this.props = props;
-                       setPlaceholderPrefix(placeholderPrefix);
-                       setPlaceholderSuffix(placeholderSuffix);
-                       setSystemPropertiesMode(SYSTEM_PROPERTIES_MODE_NEVER);
-               }
-
-               /** Public access to the internals of PropertyPlaceholderConfigurer*/
-               public String process(String strVal) {
-                       String value = parseStringValue(strVal, this.props,
-                                       new HashSet<String>());
-                       return (value.equals(nullValue) ? null : value);
-               }
-
-               @Override
-               protected String resolvePlaceholder(String placeholder, Properties props) {
-                       // log.info("Try convert placeholder " + placeholder);
-                       if ((executionScope != null)
-                                       && (executionScope.hasExecutionContext()))
-                               return executionContext.getVariable(placeholder).toString();
-                       else if (instantiationManager.isInFlowInitialization())
-                               return instantiationManager.getInitializingFlowParameter(
-                                               placeholder).toString();
-                       else
-                               return super.resolvePlaceholder(placeholder, props);
-               }
-       }
-}
+package org.argeo.slc.core.execution;\r
+\r
+import java.beans.PropertyDescriptor;\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.HashSet;\r
+import java.util.Iterator;\r
+import java.util.LinkedHashMap;\r
+import java.util.LinkedHashSet;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Properties;\r
+import java.util.Set;\r
+\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+import org.argeo.slc.SlcException;\r
+import org.argeo.slc.execution.ExecutionContext;\r
+import org.springframework.beans.BeansException;\r
+import org.springframework.beans.MutablePropertyValues;\r
+import org.springframework.beans.PropertyValue;\r
+import org.springframework.beans.PropertyValues;\r
+import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;\r
+import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;\r
+import org.springframework.beans.factory.config.TypedStringValue;\r
+import org.springframework.beans.factory.support.ManagedList;\r
+import org.springframework.beans.factory.support.ManagedMap;\r
+import org.springframework.beans.factory.support.ManagedSet;\r
+import org.springframework.util.ObjectUtils;\r
+\r
+public class ExecutionParameterPostProcessor extends\r
+               InstantiationAwareBeanPostProcessorAdapter {\r
+\r
+       private final static Log log = LogFactory\r
+                       .getLog(ExecutionParameterPostProcessor.class);\r
+       \r
+       private ExecutionContext executionContext;\r
+\r
+       private ExecutionScope executionScope;\r
+\r
+       private InstantiationManager instantiationManager;\r
+       \r
+       private Map<String, PropertyValues> storedPvsMap = new HashMap<String, PropertyValues>();\r
+\r
+       public InstantiationManager getInstantiationManager() {\r
+               return instantiationManager;\r
+       }\r
+\r
+       public void setInstantiationManager(\r
+                       InstantiationManager instantiationManager) {\r
+               this.instantiationManager = instantiationManager;\r
+       }\r
+\r
+       public void setExecutionScope(ExecutionScope executionScope) {\r
+               this.executionScope = executionScope;\r
+       }\r
+\r
+       public ExecutionContext getExecutionContext() {\r
+               return executionContext;\r
+       }\r
+\r
+       public void setExecutionContext(ExecutionContext executionContext) {\r
+               this.executionContext = executionContext;\r
+       }\r
+\r
+       private String placeholderPrefix = "@{";\r
+       private String placeholderSuffix = "}";\r
+       private String nullValue;\r
+\r
+       @Override\r
+       public PropertyValues postProcessPropertyValues(PropertyValues pvs,\r
+                       PropertyDescriptor[] pds, Object bean, String beanName)\r
+                       throws BeansException {\r
+\r
+               //TODO: resolve at execution only if scope is execution\r
+                       \r
+               // if \r
+               PropertyValues sourcePvs = pvs;\r
+               if(storedPvsMap.containsKey(beanName)) {\r
+                       sourcePvs = storedPvsMap.get(beanName);\r
+                       log.info("Use storedPvsMap for bean " + beanName);\r
+               }\r
+               \r
+               MutablePropertyValues newPvs = new MutablePropertyValues();\r
+               \r
+               boolean changesOccured = false;\r
+                               \r
+               CustomPpc ppc = new CustomPpc(beanName);\r
+               \r
+               for(int i=0; i<sourcePvs.getPropertyValues().length; i++) {\r
+                       \r
+                       PropertyValue pv = pvs.getPropertyValues()[i];\r
+                       \r
+                       if (pv.getValue() instanceof TypedStringValue) {\r
+                               TypedStringValue tsv = (TypedStringValue) pv.getValue();\r
+                               String originalValue = tsv.getValue();\r
+                               String convertedValue = ppc.resolveString(originalValue);\r
+                               // add a new Property value to newPvs, identical to pv\r
+                               // except for the value\r
+                               newPvs.addPropertyValue(new PropertyValue(pv, new TypedStringValue(convertedValue)));\r
+                               if (!convertedValue.equals(originalValue)) {\r
+                                       changesOccured = true;\r
+                               }\r
+                       }\r
+                       else if (pv.getValue() instanceof String) {\r
+                               String originalValue = pv.getValue().toString();                        \r
+                               String convertedValue = ppc.resolveString(originalValue);\r
+                               newPvs.addPropertyValue(new PropertyValue(pv, convertedValue));\r
+                               if (!convertedValue.equals(originalValue)) {\r
+                                       changesOccured = true;\r
+                               }\r
+                       }               \r
+                       else if ((pv.getValue() instanceof ManagedMap)\r
+                                       ||(pv.getValue() instanceof ManagedList)\r
+                                       ||(pv.getValue() instanceof ManagedSet)){\r
+\r
+                               Object convertedValue = ppc.resolveValue(pv.getValue());\r
+                               newPvs.addPropertyValue(new PropertyValue(pv, convertedValue));\r
+                               if(convertedValue != pv.getValue()) {\r
+                                       changesOccured = true;\r
+                               }\r
+                       }               \r
+                       else {\r
+                               newPvs.addPropertyValue(new PropertyValue(pv));\r
+                       }\r
+               }\r
+               \r
+               if(changesOccured) {\r
+                       storedPvsMap.put(beanName, pvs);\r
+                       log.info("Add storedPvsMap for Bean " + beanName);\r
+                       return newPvs;\r
+               }\r
+               else {\r
+                       // no change, return pvs\r
+                       return pvs;\r
+               }\r
+       }\r
+\r
+       public void setPlaceholderPrefix(String placeholderPrefix) {\r
+               this.placeholderPrefix = placeholderPrefix;\r
+       }\r
+\r
+       public void setPlaceholderSuffix(String placeholderSuffix) {\r
+               this.placeholderSuffix = placeholderSuffix;\r
+       }\r
+\r
+       public void setNullValue(String nullValue) {\r
+               this.nullValue = nullValue;\r
+       }\r
+       \r
+       private class CustomPpc extends PropertyPlaceholderConfigurer {\r
+               private final Properties props;\r
+               String beanName;\r
+               \r
+               public CustomPpc(String beanName) {\r
+                       super();\r
+                       this.props = new Properties();\r
+                       this.beanName = beanName;\r
+                       setPlaceholderPrefix(placeholderPrefix);\r
+                       setPlaceholderSuffix(placeholderSuffix);\r
+                       setSystemPropertiesMode(SYSTEM_PROPERTIES_MODE_NEVER);\r
+               }\r
+\r
+               /** Public access to the internals of PropertyPlaceholderConfigurer*/\r
+               public String resolveString(String strVal) {\r
+                       String value = parseStringValue(strVal, this.props,\r
+                                       new HashSet<String>());\r
+                       return (value.equals(nullValue) ? null : value);\r
+               }\r
+               \r
+               public Object resolveValue(Object value) {\r
+                       if (value instanceof TypedStringValue) {\r
+                               TypedStringValue tsv = (TypedStringValue) value;\r
+                               String originalValue = tsv.getValue();\r
+\r
+                               String convertedValue = resolveString(originalValue);\r
+                               return convertedValue.equals(originalValue) ? value : new TypedStringValue(convertedValue);\r
+                       }\r
+                       else if (value instanceof String) {\r
+                               String originalValue = value.toString();                        \r
+                               String convertedValue = resolveString(originalValue);\r
+                               return convertedValue.equals(originalValue) ? value : convertedValue;\r
+                       }               \r
+                       else if (value instanceof Map) {\r
+                               Map mapVal = (Map) value;\r
+                               \r
+                               Map newContent = new ManagedMap();\r
+                               boolean entriesModified = false;\r
+                               for (Iterator it = mapVal.entrySet().iterator(); it.hasNext();) {\r
+                                       Map.Entry entry = (Map.Entry) it.next();\r
+                                       Object key = entry.getKey();\r
+                                       int keyHash = (key != null ? key.hashCode() : 0);\r
+                                       Object newKey = resolveValue(key);\r
+                                       int newKeyHash = (newKey != null ? newKey.hashCode() : 0);\r
+                                       Object val = entry.getValue();\r
+                                       Object newVal = resolveValue(val);\r
+                                       newContent.put(newKey, newVal);\r
+                                       entriesModified = entriesModified || (newVal != val || newKey != key || newKeyHash != keyHash);\r
+                               }\r
+                               \r
+                               return entriesModified ? newContent : value;\r
+                       }\r
+                       else if (value instanceof List) {\r
+                               List listVal = (List) value;\r
+                               List newContent = new ManagedList();\r
+                               boolean valueModified = false;\r
+                               \r
+                               for (int i = 0; i < listVal.size(); i++) {\r
+                                       Object elem = listVal.get(i);\r
+                                       Object newVal = resolveValue(elem);\r
+                                       newContent.add(newVal);\r
+                                       if (!ObjectUtils.nullSafeEquals(newVal, elem)) {\r
+                                               valueModified = true;\r
+                                       }\r
+                               }                       \r
+                               return valueModified ? newContent : value;\r
+                       }\r
+                       else if (value instanceof Set) {\r
+                               Set setVal = (Set) value;\r
+                               Set newContent = new ManagedSet();\r
+                               boolean entriesModified = false;\r
+                               for (Iterator it = setVal.iterator(); it.hasNext();) {\r
+                                       Object elem = it.next();\r
+                                       int elemHash = (elem != null ? elem.hashCode() : 0);\r
+                                       Object newVal = resolveValue(elem);\r
+                                       int newValHash = (newVal != null ? newVal.hashCode() : 0);\r
+                                       newContent.add(newVal);\r
+                                       entriesModified = entriesModified || (newVal != elem || newValHash != elemHash);\r
+                               }       \r
+                               return entriesModified ? newContent : value;\r
+                       }\r
+                       else {\r
+                               return value;\r
+                       }                       \r
+               }\r
+\r
+               @Override\r
+               protected String resolvePlaceholder(String placeholder, Properties props) {                                             \r
+                       if ((executionScope != null)\r
+                                       && (executionScope.hasExecutionContext())) {\r
+                               Object obj = executionContext.findVariable(placeholder);\r
+                               if(obj != null) {\r
+                                       return obj.toString();\r
+                               }\r
+                       }\r
+                       if (instantiationManager.isInFlowInitialization())\r
+                               return instantiationManager.getInitializingFlowParameter(\r
+                                               placeholder).toString();\r
+                       else\r
+                               throw new SlcException("Could not resolve placeholder '" \r
+                                               + placeholder + "' in bean '" + beanName + "'");\r
+               }\r
+       }\r
+}\r
index 143a8f90e823b0eacdb06b851be50da4984176e8..39c2edf7af525ea43d319ac11ca262532afdc4fe 100644 (file)
@@ -9,7 +9,7 @@ import org.argeo.slc.execution.ExecutionFlow;
 \r
 public class InstantiationManager {\r
 \r
-       private final static Log log = LogFactory.getLog(DefaultExecutionSpec.class);\r
+       private final static Log log = LogFactory.getLog(InstantiationManager.class);\r
        \r
        private ThreadLocal<Stack<ExecutionFlow> > flowStack = new ThreadLocal<Stack<ExecutionFlow> >();\r
        \r
index a700ca3b810801e05f67db3ec11e0a026cc34152..c985fd1dc7a5d5c2a432f9fe19b45e6cbd75a419 100644 (file)
@@ -59,7 +59,7 @@ public class MapExecutionContext implements ExecutionContext {
                return obj;
        }
 
-       protected Object findVariable(String key) {
+       public Object findVariable(String key) {
                Object obj = null;
                
                // Look if the variable is set in the global execution variables
index d3030e95fca3564d2dfc862a4f68a4addea89bcd..721162ebb17ffa2fd85cfaf96d4ff7b80c46d429 100644 (file)
@@ -21,7 +21,25 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
 public class ExecutionFlowTest extends TestCase {\r
        \r
        protected final Log log = LogFactory.getLog(getClass());\r
-               \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
@@ -109,28 +127,42 @@ public class ExecutionFlowTest extends TestCase {
                ConfigurableApplicationContext applicationContext = createApplicationContext("listSetMap.xml");\r
                ExecutionFlow executionFlow = (ExecutionFlow) applicationContext.getBean("myFlow");\r
                executionFlow.execute();                \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
+//             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 validateTestResult(SimpleTestResult testResult) {\r
+               validateTestResult(testResult, TestStatus.PASSED);\r
+       }\r
+       \r
+       protected void validateTestResult(SimpleTestResult testResult, int expectedStatus) {\r
                for(TestResultPart part : testResult.getParts()) {\r
-                       if(part.getStatus() != TestStatus.PASSED) {\r
+                       if(part.getStatus() != expectedStatus) {\r
                                fail("Error found in TestResult: " + part.getMessage());\r
                        }\r
                }               \r
-       }\r
+       }       \r
        \r
        protected ConfigurableApplicationContext createApplicationContext(String applicationContextSuffix) {\r
                ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(inPackage(applicationContextSuffix));\r
diff --git a/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/listSetMapMultipleFlow.xml b/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/listSetMapMultipleFlow.xml
new file mode 100644 (file)
index 0000000..a493aa2
--- /dev/null
@@ -0,0 +1,309 @@
+<?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="myTestRunTemplate" class="org.argeo.slc.core.test.SimpleTestRun" abstract="true">\r
+               <property name="testDefinition" ref="basic.testDef" />\r
+               <property name="testResult" ref="myTestResult"/>\r
+       </bean>         \r
+\r
+       <bean id="abstractFlow" parent="slcTemplate.simpleFlow" abstract="true">\r
+               <property name="executables">\r
+                       <list>\r
+                               <ref local="echo1" />\r
+                               <bean parent="myTestRunTemplate">\r
+                                       <property name="testData" ref="simpleMap.testData" />\r
+                               </bean>                         \r
+                               <bean parent="myTestRunTemplate">\r
+                                       <property name="testData" ref="cascadingMap.testData" />\r
+                               </bean>                         \r
+                                               \r
+                               <bean parent="myTestRunTemplate">\r
+                                       <property name="testData" ref="simpleList.testData" />\r
+                               </bean>                         \r
+                               <bean parent="myTestRunTemplate">\r
+                                       <property name="testData" ref="cascadingList.testData" />\r
+                               </bean>                         \r
+                                                       \r
+                               <bean parent="myTestRunTemplate">\r
+                                       <property name="testData" ref="simpleSet.testData" />\r
+                               </bean>                         \r
+                               <bean parent="myTestRunTemplate">\r
+                                       <property name="testData" ref="cascadingSet.testData" />\r
+                               </bean> \r
+                                                       \r
+                               <bean parent="myTestRunTemplate">\r
+                                       <property name="testData" ref="cascadingListMap.testData" />\r
+                               </bean>                         \r
+                               <bean parent="myTestRunTemplate">\r
+                                       <property name="testData" ref="cascadingSetMap.testData" />\r
+                               </bean> \r
+                               <bean parent="myTestRunTemplate">\r
+                                       <property name="testData" ref="cascadingComplex.testData" />\r
+                               </bean>                                 \r
+       \r
+                       </list>\r
+               </property>\r
+       </bean>\r
+\r
+       <bean id="flow1" parent="abstractFlow" scope="prototype">\r
+               <constructor-arg>\r
+                       <bean parent="slcTemplate.simpleSpec">\r
+                               <property name="attributes">\r
+                                       <map>\r
+                                               <entry key="testKey">\r
+                                                       <bean parent="specAttr.primitive" p:value="myValue" />\r
+                                               </entry>\r
+                                       </map>\r
+                               </property>\r
+                       </bean>\r
+               </constructor-arg>\r
+       </bean> \r
+\r
+       <bean id="flow2" parent="abstractFlow" scope="prototype">\r
+               <constructor-arg>\r
+                       <bean parent="slcTemplate.simpleSpec">\r
+                               <property name="attributes">\r
+                                       <map>\r
+                                               <entry key="testKey">\r
+                                                       <bean parent="specAttr.primitive" p:value="myValue2" />\r
+                                               </entry>\r
+                                       </map>\r
+                               </property>\r
+                       </bean>\r
+               </constructor-arg>\r
+       </bean> \r
+\r
+\r
+       <bean id="simpleMap.testData" class="org.argeo.slc.core.test.BasicTestData" scope="prototype">\r
+               <property name="expected">\r
+                       <map>\r
+                               <entry key="key1" value="myValue_myValue" />\r
+                       </map>\r
+               </property>\r
+               <property name="reached">\r
+                       <map>\r
+                               <entry key="key1" value="@{testKey}_@{testKey}" />\r
+                       </map>\r
+               </property>\r
+       </bean>\r
+       \r
+       <bean id="cascadingMap.testData" class="org.argeo.slc.core.test.BasicTestData" scope="prototype">\r
+               <property name="expected">\r
+                       <map>\r
+                               <entry key="key3">\r
+                                       <map>\r
+                                               <entry key="key2">\r
+                                                       <map>\r
+                                                               <entry key="key1" value="myValue" />\r
+                                                       </map>\r
+                                               </entry>\r
+                                               <entry key="key2bis" value="myValue" />\r
+                                       </map>\r
+                               </entry>\r
+                       </map>\r
+               </property>\r
+               <property name="reached">\r
+                       <map>\r
+                               <entry key="key3">\r
+                                       <map>\r
+                                               <entry key="key2">\r
+                                                       <map>\r
+                                                               <entry key="key1" value="@{testKey}" />\r
+                                                       </map>\r
+                                               </entry>\r
+                                               <entry key="key2bis" value="@{testKey}" />\r
+                                       </map>\r
+                               </entry>\r
+                       </map>\r
+               </property>\r
+       </bean> \r
+       \r
+       <bean id="simpleList.testData" class="org.argeo.slc.core.test.BasicTestData" scope="prototype">\r
+               <property name="expected">\r
+                       <list>\r
+                               <value>myValue</value>\r
+                               <value>_myValue_</value>\r
+                       </list>\r
+               </property>\r
+               <property name="reached">\r
+                       <list>\r
+                               <value>@{testKey}</value>\r
+                               <value>_@{testKey}_</value>                             \r
+                       </list>\r
+               </property>\r
+       </bean>         \r
+       \r
+       <bean id="cascadingList.testData" class="org.argeo.slc.core.test.BasicTestData" scope="prototype">\r
+               <property name="expected">\r
+                       <list>\r
+                               <list>\r
+                                       <value>myValue</value>\r
+                                       <value>_myValue_</value>\r
+                               </list>\r
+                               <value>myValue</value>\r
+                       </list>\r
+               </property>\r
+               <property name="reached">\r
+                       <list>\r
+                               <list>\r
+                                       <value>@{testKey}</value>\r
+                                       <value>_@{testKey}_</value>\r
+                               </list>\r
+                               <value>@{testKey}</value>\r
+                       </list>\r
+               </property>\r
+       </bean>         \r
+       \r
+       <bean id="simpleSet.testData" class="org.argeo.slc.core.test.BasicTestData" scope="prototype">\r
+               <property name="expected">\r
+                       <set>\r
+                               <value>myValue</value>\r
+                               <value>_myValue_</value>\r
+                       </set>\r
+               </property>\r
+               <property name="reached">\r
+                       <set>\r
+                               <value>@{testKey}</value>\r
+                               <value>_@{testKey}_</value>                             \r
+                       </set>\r
+               </property>\r
+       </bean>         \r
+       \r
+       <bean id="cascadingSet.testData" class="org.argeo.slc.core.test.BasicTestData" scope="prototype">\r
+               <property name="expected">\r
+                       <set>\r
+                               <set>\r
+                                       <value>myValue</value>\r
+                                       <value>_myValue_</value>\r
+                               </set>\r
+                               <value>myValue</value>\r
+                       </set>\r
+               </property>\r
+               <property name="reached">\r
+                       <set>\r
+                               <set>\r
+                                       <value>@{testKey}</value>\r
+                                       <value>_@{testKey}_</value>\r
+                               </set>\r
+                               <value>@{testKey}</value>\r
+                       </set>\r
+               </property>\r
+       </bean>         \r
+       \r
+       <bean id="cascadingListMap.testData" class="org.argeo.slc.core.test.BasicTestData" scope="prototype">\r
+               <property name="expected">\r
+                       <list>\r
+                               <map>\r
+                                       <entry key="key1" value="myValue" />\r
+                               </map>                                          \r
+                       </list>\r
+               </property>\r
+               <property name="reached">\r
+                       <list>\r
+                               <map>\r
+                                       <entry key="key1" value="@{testKey}" />\r
+                               </map>                                  \r
+                       </list>\r
+               </property>\r
+       </bean> \r
+       \r
+       <bean id="cascadingSetMap.testData" class="org.argeo.slc.core.test.BasicTestData" scope="prototype">\r
+               <property name="expected">\r
+                       <set>\r
+                               <map>\r
+                                       <entry key="key1" value="myValue" />\r
+                               </map>                                          \r
+                       </set>\r
+               </property>\r
+               <property name="reached">\r
+                       <set>\r
+                               <map>\r
+                                       <entry key="key1" value="@{testKey}" />\r
+                               </map>                                  \r
+                       </set>\r
+               </property>\r
+       </bean>         \r
+       \r
+       <bean id="cascadingComplex.testData" class="org.argeo.slc.core.test.BasicTestData" scope="prototype">\r
+               <property name="expected">\r
+                       <set>\r
+                               <map>\r
+                                       <entry key="key1" value="myValue" />\r
+                               </map>  \r
+                               <list>\r
+                                       <map>\r
+                                               <entry key="key1" value="myValue" />\r
+                                       </map>          \r
+                                       <set>\r
+                                               <set>\r
+                                                       <value>myValue</value>\r
+                                                       <value>_myValue_</value>\r
+                                                       <list>\r
+                                                               <list>\r
+                                                                       <value>myValue</value>\r
+                                                                       <value>_myValue_</value>\r
+                                                               </list>\r
+                                                               <value>myValue</value>\r
+                                                       </list>                                                 \r
+                                               </set>\r
+                                               <value>myValue</value>\r
+                                       </set>                                                                  \r
+                               </list> \r
+                               <set>\r
+                                       <map>\r
+                                               <entry key="key1" value="myValue" />\r
+                                       </map>  \r
+                               </set>                                                                                          \r
+                       </set>\r
+               </property>\r
+               <property name="reached">\r
+                       <set>\r
+                               <map>\r
+                                       <entry key="key1" value="@{testKey}" />\r
+                               </map>  \r
+                               <list>\r
+                                       <map>\r
+                                               <entry key="key1" value="@{testKey}" />\r
+                                       </map>          \r
+                                       <set>\r
+                                               <set>\r
+                                                       <value>@{testKey}</value>\r
+                                                       <value>_@{testKey}_</value>\r
+                                                       <list>\r
+                                                               <list>\r
+                                                                       <value>@{testKey}</value>\r
+                                                                       <value>_@{testKey}_</value>\r
+                                                               </list>\r
+                                                               <value>@{testKey}</value>\r
+                                                       </list>                                                 \r
+                                               </set>\r
+                                               <value>@{testKey}</value>\r
+                                       </set>                                                                  \r
+                               </list> \r
+                               <set>\r
+                                       <map>\r
+                                               <entry key="key1" value="@{testKey}" />\r
+                                       </map>  \r
+                               </set>                                                                                          \r
+                       </set>\r
+               </property>\r
+       </bean>                 \r
+               \r
+       <bean id="basic.testDef" class="org.argeo.slc.core.test.BasicTestDefinition">\r
+       </bean> \r
+\r
+\r
+       <bean id="echo1" parent="task.echo" scope="prototype">\r
+               <property name="message"\r
+                       value="testKey=@{testKey}" />\r
+       </bean>\r
+       \r
+       <bean id="myTestResult" class="org.argeo.slc.core.test.SimpleTestResult" />\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/multipleFlow.xml b/runtime/org.argeo.slc.support.simple/src/test/resources/org/argeo/slc/core/execution/multipleFlow.xml
new file mode 100644 (file)
index 0000000..c8b04d2
--- /dev/null
@@ -0,0 +1,104 @@
+<?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="fileDiff.spec" parent="slcTemplate.simpleSpec">\r
+               <property name="attributes">\r
+                       <map>\r
+                               <entry key="fileName">\r
+                                       <bean parent="specAttr.primitive" p:isParameter="true" p:type="string"\r
+                                               p:isFrozen="true" />\r
+                               </entry>\r
+                       </map>\r
+               </property>\r
+       </bean>\r
+\r
+\r
+       <bean id="fileDiff.flowTemplate" parent="slcTemplate.simpleFlow"\r
+               abstract="true">\r
+               <property name="path" value="/fileDiff/testcases" />\r
+               <constructor-arg ref="fileDiff.spec" />\r
+               <property name="executables">\r
+                       <list>                  \r
+                               <bean parent="task.echo">\r
+                                       <property name="message" value="fileName=@{fileName}" />\r
+                               </bean>\r
+                       </list>\r
+               </property>\r
+       </bean>\r
+       \r
+       <bean id="echo" parent="task.echo" scope="execution">\r
+               <property name="message" value="fileName=@{fileName}" />\r
+               <aop:scoped-proxy />\r
+       </bean>                 \r
+       \r
+       <bean id="flow1" parent="fileDiff.flowTemplate" scope="prototype">\r
+               <constructor-arg>\r
+                       <map>\r
+                               <entry key="fileName" value="file1" />\r
+                       </map>\r
+               </constructor-arg>\r
+       </bean> \r
+\r
+       <bean id="flow2" parent="fileDiff.flowTemplate"  scope="prototype">\r
+               <constructor-arg>\r
+                       <map>\r
+                               <entry key="fileName" value="file2" />\r
+                       </map>\r
+               </constructor-arg>\r
+       </bean> \r
\r
\r
+ <!-- \r
+       <bean id="flow1" parent="slcTemplate.simpleFlow">\r
+               <property name="path" value="/fileDiff/testcases" />\r
+               <constructor-arg ref="fileDiff.spec" />\r
+               <constructor-arg>\r
+                       <map>\r
+                               <entry key="fileName" value="file1" />\r
+                       </map>\r
+               </constructor-arg>              \r
+               <property name="executables">\r
+                       <list>                  \r
+                               <bean parent="task.echo" scope="execution">\r
+                                       <property name="message" value="fileName=@{fileName}" />\r
+                                       <aop:scoped-proxy />\r
+                               </bean>\r
+                       </list>\r
+               </property>\r
+       </bean>\r
+\r
+       <bean id="flow2" parent="slcTemplate.simpleFlow">\r
+               <property name="path" value="/fileDiff/testcases" />\r
+               <constructor-arg ref="fileDiff.spec" />\r
+               <constructor-arg>\r
+                       <map>\r
+                               <entry key="fileName" value="file2" />\r
+                       </map>\r
+               </constructor-arg>              \r
+               <property name="executables">\r
+                       <list>                  \r
+                               <bean parent="task.echo" scope="execution">\r
+                                       <property name="message" value="fileName=@{fileName}" />\r
+                                       <aop:scoped-proxy />\r
+                               </bean>\r
+                       </list>\r
+               </property>\r
+       </bean>\r
+ -->\r
+<!-- \r
+       <bean id="main" parent="slcTemplate.simpleFlow">\r
+               <property name="executables">\r
+                       <list>          \r
+                               <ref bean="flow1"/>     \r
+                               <ref bean="flow2"/>     \r
+                       </list>\r
+               </property>\r
+       </bean>\r
+ -->\r
+</beans>
\ No newline at end of file
index fda8c2a2e1d99e8049d0023853b8e443c3c98de6..a1dbc7ed972083abd2d78c2918d85e52a6720168 100644 (file)
@@ -1,79 +1,87 @@
 <?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: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="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd\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="second" parent="slcTemplate.simpleFlow">\r
-               <constructor-arg>\r
-                       <bean parent="slcTemplate.simpleSpec">\r
-                               <property name="attributes">\r
-                                       <map>\r
-                                               <entry key="testKey">\r
-                                                       <bean parent="specAttr.primitive" p:value="second" />\r
-                                               </entry>\r
-                                       </map>\r
-                               </property>\r
-                       </bean>\r
-               </constructor-arg>\r
-               <property name="executables">\r
-                       <list>\r
-                               <ref local="echo1" />\r
-                               <bean class="org.argeo.slc.core.test.SimpleTestRun">\r
-                                       <property name="testDefinition" ref="basic.testDef" />\r
-                                       <property name="testData" ref="basic.testData" />\r
-                                       <property name="testResult" ref="basicTestResult"/>\r
-                               </bean>                         \r
-                       </list>\r
+       <bean id="fileDiff.spec" parent="slcTemplate.simpleSpec">\r
+               <property name="attributes">\r
+                       <map>\r
+                               <entry key="fileName">\r
+                                       <bean parent="specAttr.primitive" p:isParameter="true" p:type="string"\r
+                                               p:isFrozen="true" />\r
+                               </entry>\r
+                       </map>\r
                </property>\r
        </bean>\r
 \r
-<!-- \r
-       <bean id="first" parent="slcTemplate.simpleFlow">\r
-               <constructor-arg>\r
-                       <bean parent="slcTemplate.simpleSpec">\r
-                               <property name="attributes">\r
-                                       <map>\r
-                                               <entry key="testKey">\r
-                                                       <bean parent="specAttr.primitive" p:value="first" />\r
-                                               </entry>\r
-                                       </map>\r
-                               </property>\r
-                       </bean>\r
-               </constructor-arg>\r
+       <bean id="fileDiff.flowTemplate" parent="slcTemplate.simpleFlow"\r
+               abstract="true">\r
+               <property name="path" value="/fileDiff/testcases" />\r
+               <constructor-arg ref="fileDiff.spec" />\r
                <property name="executables">\r
                        <list>\r
-                               <ref local="second" />\r
-                               <ref local="echo1" />\r
+                               <bean parent="task.echo" scope="execution">\r
+                                       <property name="message" value="From FileDiff @{fileName}" />\r
+                                       <aop:scoped-proxy />\r
+                               </bean>\r
+\r
+\r
+                               <bean class="org.argeo.slc.core.test.SimpleTestRun">\r
+                                       <property name="testDefinition">\r
+                                               <bean class="org.argeo.slc.core.test.BasicTestDefinition" />\r
+                                       </property>\r
+                                       <property name="testData">\r
+                                               <bean id="simpleList.testData" class="org.argeo.slc.core.test.BasicTestData" scope="prototype">\r
+                                                       <property name="expected">\r
+                                                               <value>myValue</value>\r
+                                                       </property>\r
+                                                       <property name="reached">\r
+                                                               <value>myValue2</value>\r
+                                                       </property>\r
+                                               </bean>                                                 \r
+                                       </property>\r
+                                       <property name="testResult" ref="fileDiff.testResult" />\r
+                               </bean>\r
+\r
+                               <bean class="org.argeo.slc.core.execution.tasks.CloseTestResultTask" scope="execution">\r
+                                       <property name="testResult" ref="fileDiff.testResult" />\r
+                               </bean>\r
                        </list>\r
                </property>\r
        </bean>\r
- -->\r
-       <bean id="basic.testData" class="org.argeo.slc.core.test.BasicTestData" scope="prototype">\r
-               <property name="expected">\r
+\r
+       <bean id="fileDiff.testResult" parent="slcDefault.test.basicTreeTestResult"\r
+               scope="execution">\r
+               <aop:scoped-proxy />\r
+               <property name="attributes">\r
                        <map>\r
-                               <entry key="test" value="second" />\r
+                               <entry key="testCase" value="@{fileName}" />\r
+                               <entry key="testCaseType" value="csvdiff" />\r
                        </map>\r
                </property>\r
-               <property name="reached">\r
+               <property name="listeners" ref="resultListeners" /> \r
+       </bean>\r
+\r
+       <bean id="fileDiff.SimulationView_Risk" parent="fileDiff.flowTemplate">\r
+               <constructor-arg>\r
                        <map>\r
-                               <entry key="test" value="@{testKey}" />\r
+                               <entry key="fileName" value="SimulationView_Risk" />\r
                        </map>\r
-               </property>\r
+               </constructor-arg>\r
        </bean>\r
-       \r
-       <bean id="basic.testDef" class="org.argeo.slc.core.test.BasicTestDefinition">\r
-       </bean> \r
-\r
 \r
-       <bean id="echo1" parent="task.echo" scope="prototype">\r
-               <property name="message"\r
-                       value="testKey=@{testKey}" />\r
+       <bean id="fileDiff.SimulationView_Risk2" parent="fileDiff.flowTemplate">\r
+               <constructor-arg>\r
+                       <map>\r
+                               <entry key="fileName" value="SimulationView_Risk2" />\r
+                       </map>\r
+               </constructor-arg>\r
        </bean>\r
-       \r
-       <bean id="basicTestResult" class="org.argeo.slc.core.test.SimpleTestResult" />\r
 \r
 </beans>
\ No newline at end of file