From: Olivier Capillon Date: Mon, 2 Nov 2009 16:30:08 +0000 (+0000) Subject: Adds Unit Tests for ExcelGeneratorSource and AutouiRunnableFactory X-Git-Tag: argeo-slc-2.1.7~1539 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=f3850fe5e4bd5fb3f5a55144e834b51606a0f2c1;p=gpl%2Fargeo-slc.git Adds Unit Tests for ExcelGeneratorSource and AutouiRunnableFactory git-svn-id: https://svn.argeo.org/slc/trunk@3059 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/generator/ExecutionFlowGenerator.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/generator/ExecutionFlowGenerator.java index 5451402ff..db1d276d7 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/generator/ExecutionFlowGenerator.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/generator/ExecutionFlowGenerator.java @@ -26,10 +26,6 @@ import org.springframework.core.PriorityOrdered; * Application Context after configuring the ExecutionContext, * and outputs of a RunnableFactory. */ -/** - * @author Olivier Capillon - * - */ public class ExecutionFlowGenerator implements BeanFactoryPostProcessor, PriorityOrdered { @@ -63,6 +59,12 @@ public class ExecutionFlowGenerator implements BeanFactoryPostProcessor, * RunnableCallFlow beans. */ private String contextValuesBeanName = "executionFlowGenerator.contextValues"; + + /** + * Prefix added to the bean names defined in each + * RunnableCallFlowDescriptor + */ + private String flowBeanNamesPrefix = ""; public void postProcessBeanFactory( ConfigurableListableBeanFactory beanFactory) throws BeansException { @@ -100,11 +102,13 @@ public class ExecutionFlowGenerator implements BeanFactoryPostProcessor, GenericBeanDefinition flowBean = new GenericBeanDefinition(); flowBean.setBeanClass(RunnableCallFlow.class); + String beanName = flowBeanNamesPrefix + flowDescriptor.getBeanName(); + MutablePropertyValues mpv = new MutablePropertyValues(); mpv.addPropertyValue("runnableCalls", flowDescriptor.getRunnableCalls()); mpv.addPropertyValue("sharedContextValuesMap", new RuntimeBeanReference(contextValuesBeanName)); - mpv.addPropertyValue("name", flowDescriptor.getBeanName()); + mpv.addPropertyValue("name", beanName); mpv.addPropertyValue("path", flowDescriptor.getPath()); mpv.addPropertyValue("executionContext", new RuntimeBeanReference(executionContextBeanName)); @@ -113,9 +117,9 @@ public class ExecutionFlowGenerator implements BeanFactoryPostProcessor, // register it if(log.isDebugEnabled()) { - log.debug("Registering bean definition for RunnableCallFlow " + flowDescriptor.getBeanName()); + log.debug("Registering bean definition for RunnableCallFlow " + beanName); } - registry.registerBeanDefinition(flowDescriptor.getBeanName(), flowBean); + registry.registerBeanDefinition(beanName, flowBean); } /** @@ -151,5 +155,7 @@ public class ExecutionFlowGenerator implements BeanFactoryPostProcessor, this.contextValuesBeanName = contextValuesBeanName; } - + public void setFlowBeanNamesPrefix(String flowBeanNamesPrefix) { + this.flowBeanNamesPrefix = flowBeanNamesPrefix; + } } diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/OverrideContextAware.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/OverrideContextAware.java index bb095684d..55a03ed7b 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/OverrideContextAware.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/OverrideContextAware.java @@ -4,28 +4,30 @@ import org.argeo.slc.SlcException; import org.argeo.slc.core.test.context.SimpleContextAware; import org.argeo.slc.test.context.ContextAware; +/** + * Overrides Values and Expected values of a target + * SimpleContextAware with the corresponding + * values and expected values of a source ContextAware + * + */ public class OverrideContextAware implements Runnable { private ContextAware source; private SimpleContextAware target; - - public void setSource(ContextAware source) { - this.source = source; - } - - - public void setTarget(SimpleContextAware target) { - this.target = target; - } - - + /** + * Whether an exception shall be thrown if a value + * or expected value of the source is not defined + * in the target + */ + private Boolean failIfUndefinedInSource = true; + public void run() { // override values if(source.getValues() != null) for(String key : source.getValues().keySet()) { - if(!target.getValues().containsKey(key)) { + if(failIfUndefinedInSource && !target.getValues().containsKey(key)) { throw new SlcException("No entry in target values for key '" + key + "'"); } target.getValues().put(key, source.getValues().get(key)); @@ -34,10 +36,22 @@ public class OverrideContextAware implements Runnable { // override expected values if(source.getExpectedValues() != null) for(String key : source.getExpectedValues().keySet()) { - if(!target.getExpectedValues().containsKey(key)) { + if(failIfUndefinedInSource && !target.getExpectedValues().containsKey(key)) { throw new SlcException("No entry in target expected values for key '" + key + "'"); } target.getExpectedValues().put(key, source.getExpectedValues().get(key)); } } + + public void setSource(ContextAware source) { + this.source = source; + } + + public void setTarget(SimpleContextAware target) { + this.target = target; + } + + public void setFailIfUndefinedInSource(Boolean failIfUndefinedInSource) { + this.failIfUndefinedInSource = failIfUndefinedInSource; + } }