From: Mathieu Baudier Date: Wed, 11 Mar 2009 13:13:21 +0000 (+0000) Subject: XML format for executions X-Git-Tag: argeo-slc-2.1.7~2063 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=34e590f37109dd9ff9aa4e12af04ee98779aa9e1;p=gpl%2Fargeo-slc.git XML format for executions git-svn-id: https://svn.argeo.org/slc/trunk@2246 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/org.argeo.slc/pom.xml b/org.argeo.slc/pom.xml index 203eb669f..ef9663569 100644 --- a/org.argeo.slc/pom.xml +++ b/org.argeo.slc/pom.xml @@ -89,6 +89,13 @@ limitations under the License. target/classes/META-INF/MANIFEST.MF + + + + test-jar + + + org.apache.maven.plugins @@ -268,6 +275,12 @@ limitations under the License. org.argeo.slc.support.simple ${project.version} + + org.argeo.slc.runtime + org.argeo.slc.support.simple + ${project.version} + tests + org.argeo.slc.runtime org.argeo.slc.support.ant diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/Deployment.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/Deployment.java index 7e471f590..13d393136 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/Deployment.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/deploy/Deployment.java @@ -1,7 +1,7 @@ package org.argeo.slc.deploy; import org.argeo.slc.build.Distribution; -import org.argeo.slc.process.Executable; +import org.argeo.slc.execution.Executable; public interface Deployment extends Executable{ public DeployedSystem getDeployedSystem(); diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/Executable.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/Executable.java new file mode 100644 index 000000000..bc804bdf1 --- /dev/null +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/Executable.java @@ -0,0 +1,7 @@ +package org.argeo.slc.execution; + +/** Any object which can perform processing */ +public interface Executable { + /** Executes the actions specified by the object */ + public void execute(); +} diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionFlow.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionFlow.java index ce6a80583..ed9272e01 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionFlow.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/execution/ExecutionFlow.java @@ -1,6 +1,5 @@ package org.argeo.slc.execution; -import org.argeo.slc.process.Executable; public interface ExecutionFlow extends Executable { public Object getParameter(String key); diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/Executable.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/Executable.java deleted file mode 100644 index 129b1c636..000000000 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/Executable.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.argeo.slc.process; - -/** Any object which can perform processing */ -public interface Executable { - /** Executes the actions specified by the object */ - public void execute(); -} diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/RealizedFlow.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/RealizedFlow.java new file mode 100644 index 000000000..c47308eef --- /dev/null +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/RealizedFlow.java @@ -0,0 +1,44 @@ +package org.argeo.slc.process; + +import org.argeo.slc.execution.ExecutionFlowDescriptor; +import org.argeo.slc.execution.ExecutionSpec; + +public class RealizedFlow { + private String moduleName; + private String moduleVersion; + private ExecutionFlowDescriptor flowDescriptor; + private ExecutionSpec executionSpec; + + public String getModuleName() { + return moduleName; + } + + public void setModuleName(String moduleName) { + this.moduleName = moduleName; + } + + public String getModuleVersion() { + return moduleVersion; + } + + public void setModuleVersion(String moduleVersion) { + this.moduleVersion = moduleVersion; + } + + public ExecutionFlowDescriptor getFlowDescriptor() { + return flowDescriptor; + } + + public void setFlowDescriptor(ExecutionFlowDescriptor flowDescriptor) { + this.flowDescriptor = flowDescriptor; + } + + public ExecutionSpec getExecutionSpec() { + return executionSpec; + } + + public void setExecutionSpec(ExecutionSpec executionSpec) { + this.executionSpec = executionSpec; + } + +} diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecution.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecution.java index a52fea533..cfef48033 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecution.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecution.java @@ -22,6 +22,15 @@ public class SlcExecution { private Map attributes = new TreeMap(); private List steps = new ArrayList(); + private List realizedFlows = new ArrayList(); + + public List getRealizedFlows() { + return realizedFlows; + } + + public void setRealizedFlows(List realizedFlows) { + this.realizedFlows = realizedFlows; + } public List getSteps() { return steps; diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecutionSpec.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecutionSpec.java deleted file mode 100644 index 72ab0e48d..000000000 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecutionSpec.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.argeo.slc.process; - -import java.util.HashMap; -import java.util.Map; - -public class SlcExecutionSpec { - private Long tid; - private Map executionSpecFields = new HashMap(); - - public Long getTid() { - return tid; - } - - public void setTid(Long tid) { - this.tid = tid; - } - - public Map getExecutionSpecFields() { - return executionSpecFields; - } - - public void setExecutionSpecFields( - Map executionSpecFields) { - this.executionSpecFields = executionSpecFields; - } - -} diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecutionSpecField.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecutionSpecField.java deleted file mode 100644 index 88bd6501c..000000000 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/process/SlcExecutionSpecField.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.argeo.slc.process; - -public class SlcExecutionSpecField { - private String label; - private String type; - private String defaultValue; - private String listValues; - - public String getLabel() { - return label; - } - - public void setLabel(String label) { - this.label = label; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getDefaultValue() { - return defaultValue; - } - - public void setDefaultValue(String defaultValue) { - this.defaultValue = defaultValue; - } - - public String getListValues() { - return listValues; - } - - public void setListValues(String listValues) { - this.listValues = listValues; - } - -} diff --git a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/test/ExecutableTestRun.java b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/test/ExecutableTestRun.java index 5b8811377..37843d183 100644 --- a/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/test/ExecutableTestRun.java +++ b/runtime/org.argeo.slc.specs/src/main/java/org/argeo/slc/test/ExecutableTestRun.java @@ -1,6 +1,6 @@ package org.argeo.slc.test; -import org.argeo.slc.process.Executable; +import org.argeo.slc.execution.Executable; /** A test run that can be executed */ public interface ExecutableTestRun extends TestRun, Executable { diff --git a/runtime/org.argeo.slc.support.castor/pom.xml b/runtime/org.argeo.slc.support.castor/pom.xml index 263bf7d70..a1c8fb791 100644 --- a/runtime/org.argeo.slc.support.castor/pom.xml +++ b/runtime/org.argeo.slc.support.castor/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 org.argeo.slc @@ -38,30 +39,28 @@ org.argeo.slc.* org.argeo.slc.*;resolution:=optional, - org.argeo.slc.execution;resolution:=optional, - org.argeo.slc.core.structure;resolution:=optional, - org.argeo.slc.core.structure.tree;resolution:=optional, - org.argeo.slc.core.test;resolution:=optional, - org.argeo.slc.core.test.tree;resolution:=optional, - org.argeo.slc.runtime;resolution:=optional, - org.argeo.slc.core.execution;resolution:=optional, - org.argeo.slc.msg;resolution:=optional, - org.argeo.slc.msg.process;resolution:=optional, - org.argeo.slc.msg.test.tree;resolution:=optional + org.argeo.slc.execution;resolution:=optional, + org.argeo.slc.core.structure;resolution:=optional, + org.argeo.slc.core.structure.tree;resolution:=optional, + org.argeo.slc.core.test;resolution:=optional, + org.argeo.slc.core.test.tree;resolution:=optional, + org.argeo.slc.runtime;resolution:=optional, + org.argeo.slc.core.execution;resolution:=optional, + org.argeo.slc.msg;resolution:=optional, + org.argeo.slc.msg.process;resolution:=optional, + org.argeo.slc.msg.test.tree;resolution:=optional com.springsource.org.castor - + @@ -74,6 +73,12 @@ org.argeo.slc.runtime org.argeo.slc.support.simple + + org.argeo.slc.runtime + org.argeo.slc.support.simple + tests + test + org.springframework.ws diff --git a/runtime/org.argeo.slc.support.castor/src/main/java/org/argeo/slc/castor/execution/PrimitiveFieldHandler.java b/runtime/org.argeo.slc.support.castor/src/main/java/org/argeo/slc/castor/execution/PrimitiveFieldHandler.java index e27a3af79..bee2acb66 100644 --- a/runtime/org.argeo.slc.support.castor/src/main/java/org/argeo/slc/castor/execution/PrimitiveFieldHandler.java +++ b/runtime/org.argeo.slc.support.castor/src/main/java/org/argeo/slc/castor/execution/PrimitiveFieldHandler.java @@ -1,7 +1,7 @@ package org.argeo.slc.castor.execution; +import org.argeo.slc.core.execution.PrimitiveAccessor; import org.argeo.slc.core.execution.PrimitiveSpecAttribute; -import org.argeo.slc.core.execution.PrimitiveValue; import org.exolab.castor.mapping.AbstractFieldHandler; public class PrimitiveFieldHandler extends AbstractFieldHandler { @@ -11,53 +11,32 @@ public class PrimitiveFieldHandler extends AbstractFieldHandler { if (object == null) return null; - Object value = null; - if (object instanceof PrimitiveSpecAttribute) - value = ((PrimitiveSpecAttribute) object).getValue(); - else if (object instanceof PrimitiveValue) - value = ((PrimitiveValue) object).getValue(); - else - throw new IllegalStateException("Unkown type " + object.getClass()); - - return value != null ? value.toString() : null; + return ((PrimitiveAccessor) object).getValue().toString(); } @Override public Object newInstance(Object parent, Object[] args) throws IllegalStateException { - // TODO Auto-generated method stub return null; } @Override public Object newInstance(Object parent) throws IllegalStateException { - // TODO Auto-generated method stub return null; } @Override public void resetValue(Object object) throws IllegalStateException, IllegalArgumentException { - // TODO Auto-generated method stub - } @Override public void setValue(Object object, Object value) throws IllegalStateException, IllegalArgumentException { - // TODO: could probably be more generic - - PrimitiveSpecAttribute attr = (PrimitiveSpecAttribute) object; - String type = attr.getType(); + PrimitiveAccessor primitiveAccessor = (PrimitiveAccessor) object; + String type = primitiveAccessor.getType(); String str = value.toString(); - - // FIXME: generalize - if (object instanceof PrimitiveSpecAttribute) - ((PrimitiveSpecAttribute) object).setValue(convert(type, str)); - else if (object instanceof PrimitiveValue) - ((PrimitiveValue) object).setValue(convert(type, str)); - else - throw new IllegalStateException("Unkown type " + object.getClass()); + primitiveAccessor.setValue(convert(type, str)); } protected Object convert(String type, String str) { diff --git a/runtime/org.argeo.slc.support.castor/src/main/resources/org/argeo/slc/castor/execution.xml b/runtime/org.argeo.slc.support.castor/src/main/resources/org/argeo/slc/castor/execution.xml index 4c9a256cc..a0489e810 100644 --- a/runtime/org.argeo.slc.support.castor/src/main/resources/org/argeo/slc/castor/execution.xml +++ b/runtime/org.argeo.slc.support.castor/src/main/resources/org/argeo/slc/castor/execution.xml @@ -37,7 +37,8 @@ - + @@ -60,7 +61,8 @@ - + @@ -90,7 +92,9 @@ + handler="org.argeo.slc.castor.execution.PrimitiveFieldHandler"> + + - + + + + + + handler="org.argeo.slc.castor.execution.PrimitiveFieldHandler"> + + - + diff --git a/runtime/org.argeo.slc.support.castor/src/main/resources/org/argeo/slc/castor/process.xml b/runtime/org.argeo.slc.support.castor/src/main/resources/org/argeo/slc/castor/process.xml index be807ff0f..401e7a663 100644 --- a/runtime/org.argeo.slc.support.castor/src/main/resources/org/argeo/slc/castor/process.xml +++ b/runtime/org.argeo.slc.support.castor/src/main/resources/org/argeo/slc/castor/process.xml @@ -15,6 +15,10 @@ + + + @@ -35,6 +39,19 @@ + + + + + + + + + + + + @@ -48,32 +65,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/ExecutionModuleDescriptorCastorTest.java b/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/ExecutionModuleDescriptorCastorTest.java new file mode 100644 index 000000000..5adbd62c3 --- /dev/null +++ b/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/ExecutionModuleDescriptorCastorTest.java @@ -0,0 +1,30 @@ +package org.argeo.slc.castor; + +import java.util.ArrayList; +import java.util.List; + +import org.argeo.slc.execution.ExecutionFlowDescriptor; +import org.argeo.slc.execution.ExecutionModuleDescriptor; +import org.argeo.slc.execution.ExecutionSpec; +import org.argeo.slc.unit.execution.ExecutionFlowDescriptorTestUtils; + +public class ExecutionModuleDescriptorCastorTest extends AbstractCastorTestCase { + public void testMarshUnmarsh() throws Exception { + ExecutionModuleDescriptor moduleDescriptor = new ExecutionModuleDescriptor(); + moduleDescriptor.setName("test.moodule"); + moduleDescriptor.setVersion("1.0.0"); + + ExecutionFlowDescriptor flowDescriptor = ExecutionFlowDescriptorTestUtils + .createSimpleExecutionFlowDescriptor(); + + List flows = new ArrayList(); + flows.add(flowDescriptor); + moduleDescriptor.setExecutionFlows(flows); + + List specs = new ArrayList(); + specs.add(flowDescriptor.getExecutionSpec()); + moduleDescriptor.setExecutionSpecs(specs); + + marshUnmarsh(moduleDescriptor, false); + } +} diff --git a/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/SlcExecutionCastorTest.java b/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/SlcExecutionCastorTest.java index a8f724f25..bfd6a7e11 100644 --- a/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/SlcExecutionCastorTest.java +++ b/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/SlcExecutionCastorTest.java @@ -1,12 +1,17 @@ package org.argeo.slc.castor; import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; +import org.argeo.slc.execution.ExecutionFlowDescriptor; import org.argeo.slc.msg.process.SlcExecutionRequest; import org.argeo.slc.msg.process.SlcExecutionStepsRequest; +import org.argeo.slc.process.RealizedFlow; import org.argeo.slc.process.SlcExecution; import org.argeo.slc.process.SlcExecutionStep; +import org.argeo.slc.unit.execution.ExecutionFlowDescriptorTestUtils; import org.argeo.slc.unit.process.SlcExecutionTestUtils; import org.springframework.xml.transform.StringResult; @@ -63,4 +68,20 @@ public class SlcExecutionCastorTest extends AbstractCastorTestCase { SlcExecutionRequest msgUpdateUnm = unmarshal(msgUpdateXml); assertNotNull(msgUpdateUnm); } + + public void testMarshUnmarsh() throws Exception { + SlcExecution slcExec = SlcExecutionTestUtils.createSimpleSlcExecution(); + List realizedFlows = new ArrayList(); + RealizedFlow realizedFlow = new RealizedFlow(); + ExecutionFlowDescriptor flowDescriptor = ExecutionFlowDescriptorTestUtils + .createSimpleExecutionFlowDescriptor(); + realizedFlow.setModuleName("test.module"); + realizedFlow.setModuleVersion("1.0.0"); + realizedFlow.setFlowDescriptor(flowDescriptor); + realizedFlow.setExecutionSpec(flowDescriptor.getExecutionSpec()); + realizedFlows.add(realizedFlow); + slcExec.setRealizedFlows(realizedFlows); + + marshUnmarsh(slcExec, false); + } } diff --git a/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/SlcExecutionSpecCastorTest.java b/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/SlcExecutionSpecCastorTest.java deleted file mode 100644 index 51d4c47ee..000000000 --- a/runtime/org.argeo.slc.support.castor/src/test/java/org/argeo/slc/castor/SlcExecutionSpecCastorTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.argeo.slc.castor; - -import org.argeo.slc.process.SlcExecutionSpec; -import org.argeo.slc.process.SlcExecutionSpecField; - -public class SlcExecutionSpecCastorTest extends AbstractCastorTestCase { - public void testMarshalling() throws Exception { - SlcExecutionSpec spec = new SlcExecutionSpec(); - - SlcExecutionSpecField field1 = new SlcExecutionSpecField(); - field1.setLabel("Field1"); - field1.setType("text"); - field1.setDefaultValue("def"); - spec.getExecutionSpecFields().put("field1", field1); - - SlcExecutionSpecField field2 = new SlcExecutionSpecField(); - field2.setLabel("Field2"); - field2.setType("list"); - field2.setListValues("def,nodef"); - field2.setDefaultValue("def"); - spec.getExecutionSpecFields().put("field2", field2); - - SlcExecutionSpec specUnm = marshUnmarsh(spec,false); - - - } -} diff --git a/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/execution/old/ExecutionFlowFactory.java b/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/execution/old/ExecutionFlowFactory.java index c38d866d7..8b35dda71 100644 --- a/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/execution/old/ExecutionFlowFactory.java +++ b/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/execution/old/ExecutionFlowFactory.java @@ -5,8 +5,8 @@ import java.util.List; import java.util.Map; import org.argeo.slc.core.execution.DefaultExecutionFlow; +import org.argeo.slc.execution.Executable; import org.argeo.slc.execution.ExecutionFlow; -import org.argeo.slc.process.Executable; public class ExecutionFlowFactory { private List executables = new ArrayList(); diff --git a/runtime/org.argeo.slc.support.hibernate/pom.xml b/runtime/org.argeo.slc.support.hibernate/pom.xml index 6b3b43828..2ec107925 100644 --- a/runtime/org.argeo.slc.support.hibernate/pom.xml +++ b/runtime/org.argeo.slc.support.hibernate/pom.xml @@ -60,6 +60,12 @@ org.argeo.slc.runtime org.argeo.slc.support.simple + + org.argeo.slc.runtime + org.argeo.slc.support.simple + tests + test + javax.transaction diff --git a/runtime/org.argeo.slc.support.hibernate/src/main/resources/org/argeo/slc/hibernate/process/SlcExecutionSpec.hbm.xml b/runtime/org.argeo.slc.support.hibernate/src/main/resources/org/argeo/slc/hibernate/process/SlcExecutionSpec.hbm.xml deleted file mode 100644 index e86cffe31..000000000 --- a/runtime/org.argeo.slc.support.hibernate/src/main/resources/org/argeo/slc/hibernate/process/SlcExecutionSpec.hbm.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/runtime/org.argeo.slc.support.hibernate/src/main/resources/org/argeo/slc/hibernate/spring/applicationContext.xml b/runtime/org.argeo.slc.support.hibernate/src/main/resources/org/argeo/slc/hibernate/spring/applicationContext.xml index 08064c4af..ed5252933 100644 --- a/runtime/org.argeo.slc.support.hibernate/src/main/resources/org/argeo/slc/hibernate/spring/applicationContext.xml +++ b/runtime/org.argeo.slc.support.hibernate/src/main/resources/org/argeo/slc/hibernate/spring/applicationContext.xml @@ -42,9 +42,6 @@ org/argeo/slc/hibernate/process/SlcExecutionStep.hbm.xml - - org/argeo/slc/hibernate/process/SlcExecutionSpec.hbm.xml - org/argeo/slc/hibernate/runtime/SlcAgentDescriptor.hbm.xml diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/AbstractExecutionValue.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/AbstractExecutionValue.java new file mode 100644 index 000000000..ce69a4f98 --- /dev/null +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/AbstractExecutionValue.java @@ -0,0 +1,5 @@ +package org.argeo.slc.core.execution; + +public class AbstractExecutionValue { + +} diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlow.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlow.java index e2c343de3..b0e212abf 100644 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlow.java +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/DefaultExecutionFlow.java @@ -8,10 +8,10 @@ import java.util.UUID; import org.apache.commons.lang.math.RandomUtils; import org.argeo.slc.SlcException; +import org.argeo.slc.execution.Executable; import org.argeo.slc.execution.ExecutionFlow; import org.argeo.slc.execution.ExecutionSpec; import org.argeo.slc.execution.ExecutionSpecAttribute; -import org.argeo.slc.process.Executable; import org.argeo.slc.test.ExecutableTestRun; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.InitializingBean; diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/PrimitiveAccessor.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/PrimitiveAccessor.java new file mode 100644 index 000000000..c3859d5b2 --- /dev/null +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/PrimitiveAccessor.java @@ -0,0 +1,9 @@ +package org.argeo.slc.core.execution; + +public interface PrimitiveAccessor { + public String getType(); + + public Object getValue(); + + public void setValue(Object value); +} diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/PrimitiveSpecAttribute.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/PrimitiveSpecAttribute.java index daddc0aa8..da2a6a0d8 100644 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/PrimitiveSpecAttribute.java +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/PrimitiveSpecAttribute.java @@ -1,9 +1,10 @@ package org.argeo.slc.core.execution; -public class PrimitiveSpecAttribute extends AbstractSpecAttribute { -// public enum Type { -// string, integer -// } +public class PrimitiveSpecAttribute extends AbstractSpecAttribute implements + PrimitiveAccessor { + // public enum Type { + // string, integer + // } public final static String TYPE_STRING = "string"; public final static String TYPE_INTEGER = "integer"; diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/PrimitiveValue.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/PrimitiveValue.java index e29d67e90..01793268a 100644 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/PrimitiveValue.java +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/PrimitiveValue.java @@ -1,10 +1,20 @@ package org.argeo.slc.core.execution; -public class PrimitiveValue { +public class PrimitiveValue extends AbstractExecutionValue implements + PrimitiveAccessor { private String type; private Object value; + public PrimitiveValue() { + } + + public PrimitiveValue(String type, Object value) { + super(); + this.type = type; + this.value = value; + } + public String getType() { return type; } diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/RefValue.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/RefValue.java index bc5336caa..516a15e3b 100644 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/RefValue.java +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/RefValue.java @@ -1,8 +1,16 @@ package org.argeo.slc.core.execution; -public class RefValue { +public class RefValue extends AbstractExecutionValue { private String label; + public RefValue() { + } + + public RefValue(String label) { + super(); + this.label = label; + } + public String getLabel() { return label; } diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/tasks/Echo.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/tasks/Echo.java index 51e06602f..eeead3888 100644 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/tasks/Echo.java +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/execution/tasks/Echo.java @@ -2,7 +2,7 @@ package org.argeo.slc.core.execution.tasks; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.slc.process.Executable; +import org.argeo.slc.execution.Executable; public class Echo implements Executable { private final static Log defaultLog = LogFactory.getLog(Echo.class); diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/unit/process/SlcExecutionTestUtils.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/unit/process/SlcExecutionTestUtils.java deleted file mode 100644 index bbea1bb25..000000000 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/unit/process/SlcExecutionTestUtils.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.argeo.slc.unit.process; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; -import static org.argeo.slc.unit.UnitUtils.assertDateSec; - -import java.util.UUID; - -import org.argeo.slc.process.SlcExecution; -import org.argeo.slc.process.SlcExecutionStep; - -public abstract class SlcExecutionTestUtils { - - public static SlcExecution createSimpleSlcExecution() { - SlcExecution slcExec = new SlcExecution(); - slcExec.setUuid(UUID.randomUUID().toString()); - slcExec.setHost("localhost"); - slcExec.setUser("user"); - slcExec.setType("slcAnt"); - slcExec.setStatus("STARTED"); - slcExec.getAttributes().put("ant.file", "/test"); - return slcExec; - } - - public static void assertSlcExecution(SlcExecution expected, - SlcExecution reached) { - assertNotNull(reached); - assertEquals(expected.getHost(), reached.getHost()); - assertEquals(expected.getUser(), reached.getUser()); - assertEquals(expected.getType(), reached.getType()); - assertEquals(expected.getStatus(), reached.getStatus()); - - // Attributes - assertEquals(expected.getAttributes().size(), reached.getAttributes() - .size()); - for (String key : expected.getAttributes().keySet()) { - String expectedValue = expected.getAttributes().get(key); - String reachedValue = reached.getAttributes().get(key); - assertNotNull(reachedValue); - assertEquals(expectedValue, reachedValue); - } - - assertEquals(expected.getSteps().size(), reached.getSteps().size()); - for (int i = 0; i < expected.getSteps().size(); i++) { - SlcExecutionStep stepExpected = expected.getSteps().get(i); - SlcExecutionStep stepReached = reached.getSteps().get(i); - assertSlcExecutionStep(stepExpected, stepReached); - } - } - - public static void assertSlcExecutionStep(SlcExecutionStep expected, - SlcExecutionStep reached) { - assertNotNull(reached); - assertEquals(expected.getUuid(), reached.getUuid()); - assertEquals(expected.getType(), reached.getType()); - assertEquals(expected.logAsString(), reached.logAsString()); - assertDateSec(expected.getBegin(), reached.getBegin()); - } - - private SlcExecutionTestUtils() { - - } -} diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/unit/test/tree/TreeTestResultTestUtils.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/unit/test/tree/TreeTestResultTestUtils.java deleted file mode 100644 index cf4b0c1e4..000000000 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/unit/test/tree/TreeTestResultTestUtils.java +++ /dev/null @@ -1,130 +0,0 @@ -package org.argeo.slc.unit.test.tree; - -import java.util.UUID; - -import org.argeo.slc.build.Distribution; -import org.argeo.slc.core.structure.SimpleSElement; -import org.argeo.slc.core.structure.tree.TreeSPath; -import org.argeo.slc.core.structure.tree.TreeSRegistry; -import org.argeo.slc.core.test.SimpleResultPart; -import org.argeo.slc.core.test.SimpleTestRun; -import org.argeo.slc.core.test.tree.PartSubList; -import org.argeo.slc.core.test.tree.TreeTestResult; -import org.argeo.slc.deploy.DeployedSystem; -import org.argeo.slc.deploy.DeploymentData; -import org.argeo.slc.deploy.TargetData; -import org.argeo.slc.msg.test.tree.ResultPartRequest; -import org.argeo.slc.process.SlcExecution; -import org.argeo.slc.process.SlcExecutionStep; -import org.argeo.slc.test.TestStatus; -import org.argeo.slc.unit.process.SlcExecutionTestUtils; - -public abstract class TreeTestResultTestUtils { - - public static TreeTestResult createSimpleTreeTestResult() { - TreeTestResult treeTestResult = new TreeTestResult(); - treeTestResult.setUuid(UUID.randomUUID().toString()); - return treeTestResult; - } - - public static TreeTestResult createCompleteTreeTestResult() { - SlcExecution slcExecution = SlcExecutionTestUtils - .createSimpleSlcExecution(); - SlcExecutionStep step = new SlcExecutionStep("JUnit step"); - slcExecution.getSteps().add(step); - - TreeTestResult ttr = createMinimalConsistentTreeTestResult(slcExecution); - - ttr.addResultPart(createSimpleResultPartPassed()); - ttr.addResultPart(createSimpleResultPartFailed()); - ttr.addResultPart(createSimpleResultPartError()); - return ttr; - } - - public static TreeTestResult createMinimalConsistentTreeTestResult( - SlcExecution slcExecution) { - SimpleTestRun testRun = new SimpleTestRun(); - testRun.setUuid(UUID.randomUUID().toString()); - - String pathStr = "/test"; - TreeSPath path = new TreeSPath(pathStr); - - TreeSRegistry registry = new TreeSRegistry(); - SimpleSElement elem = new SimpleSElement("Unit Test"); - elem.getTags().put("myTag", "myTagValue"); - registry.register(path, elem); - - TreeTestResult ttr = createSimpleTreeTestResult(); - ttr.getAttributes().put("testCase", "UNIT"); - - // Simulate test run - ttr.notifyCurrentPath(registry, path); - ttr.notifyTestRun(testRun); - testRun.setTestResult(ttr); - testRun.setDeployedSystem(new DeployedSystem() { - private String uuid = UUID.randomUUID().toString(); - - public String getDeployedSystemId() { - return uuid; - } - - public Distribution getDistribution() { - return null; - } - - public DeploymentData getDeploymentData() { - // TODO Auto-generated method stub - return null; - } - - public TargetData getTargetData() { - // TODO Auto-generated method stub - return null; - } - - }); - testRun.notifySlcExecution(slcExecution); - return ttr; - } - - public static SimpleResultPart createSimpleResultPartPassed() { - SimpleResultPart partPassed = new SimpleResultPart(); - String msgPassed = "message\nnew line"; - partPassed.setStatus(TestStatus.PASSED); - partPassed.setMessage(msgPassed); - return partPassed; - } - - public static SimpleResultPart createSimpleResultPartFailed() { - SimpleResultPart partFailed = new SimpleResultPart(); - String msgFailed = "too bad"; - partFailed.setStatus(TestStatus.FAILED); - partFailed.setMessage(msgFailed); - return partFailed; - } - - public static SimpleResultPart createSimpleResultPartError() { - SimpleResultPart partFailed = new SimpleResultPart(); - String msgFailed = "crashed\nanother line"; - partFailed.setStatus(TestStatus.ERROR); - partFailed.setMessage(msgFailed); - partFailed.setException(new Exception("Test Exception")); - return partFailed; - } - - public static ResultPartRequest createSimpleResultPartRequest( - TreeTestResult ttr) { - TreeSPath path = ttr.getCurrentPath(); - PartSubList lst = ttr.getResultParts().get(path); - SimpleResultPart part = (SimpleResultPart) lst.getParts().get(2); - - ResultPartRequest req = new ResultPartRequest(ttr, path, part); - req.setPath(ttr.getCurrentPath()); - - return req; - } - - private TreeTestResultTestUtils() { - - } -} diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/unit/test/tree/UnitTestTreeUtil.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/unit/test/tree/UnitTestTreeUtil.java deleted file mode 100644 index 91467f3ea..000000000 --- a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/unit/test/tree/UnitTestTreeUtil.java +++ /dev/null @@ -1,187 +0,0 @@ -package org.argeo.slc.unit.test.tree; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertNull; -import static junit.framework.Assert.fail; -import static org.argeo.slc.unit.UnitUtils.assertDateSec; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.slc.core.structure.SimpleSElement; -import org.argeo.slc.core.structure.tree.TreeSPath; -import org.argeo.slc.core.test.SimpleResultPart; -import org.argeo.slc.core.test.tree.PartSubList; -import org.argeo.slc.core.test.tree.TreeTestResult; -import org.argeo.slc.test.TestResultPart; - -/** Utilities for unit tests. */ -public class UnitTestTreeUtil { - private final static Log log = LogFactory.getLog(UnitTestTreeUtil.class); - - public static void assertTreeTestResult(TreeTestResult expected, - TreeTestResult reached) { - assertEquals(expected.getUuid(), reached.getUuid()); - assertDateSec(expected.getCloseDate(), reached.getCloseDate()); - - // Attributes - assertEquals(expected.getAttributes().size(), reached.getAttributes() - .size()); - for (String key : expected.getAttributes().keySet()) { - String expectedValue = expected.getAttributes().get(key); - String reachedValue = reached.getAttributes().get(key); - assertNotNull(reachedValue); - assertEquals(expectedValue, reachedValue); - } - - // Result parts - assertEquals(expected.getResultParts().size(), reached.getResultParts() - .size()); - for (TreeSPath path : expected.getResultParts().keySet()) { - PartSubList lstExpected = expected.getResultParts().get(path); - PartSubList lstReached = expected.getResultParts().get(path); - if (lstReached == null) { - fail("No result for path " + path); - return; - } - assertPartSubList(lstExpected, lstReached); - } - - // Elements - assertEquals(expected.getElements().size(), reached.getElements() - .size()); - for (TreeSPath path : expected.getElements().keySet()) { - // String nameExpected = expected.getElements().get(path); - // String nameReached = expected.getElements().get(path); - SimpleSElement elemExpected = (SimpleSElement) expected - .getElements().get(path); - SimpleSElement elemReached = (SimpleSElement) expected - .getElements().get(path); - assertNotNull(elemReached); - assertElements(elemExpected, elemReached); - } - - } - - public static void assertElements(SimpleSElement expected, - SimpleSElement reached) { - assertEquals(expected.getLabel(), reached.getLabel()); - assertEquals(expected.getTags().size(), reached.getTags().size()); - for (String tagName : expected.getTags().keySet()) { - String expectedTagValue = expected.getTags().get(tagName); - String reachedTagValue = reached.getTags().get(tagName); - assertNotNull(reachedTagValue); - assertEquals(expectedTagValue, reachedTagValue); - } - } - - public static void assertPartSubList(PartSubList lstExpected, - PartSubList lstReached) { - assertEquals(lstExpected.getParts().size(), lstReached.getParts() - .size()); - for (int i = 0; i < lstExpected.getParts().size(); i++) { - assertPart(lstExpected.getParts().get(i), lstReached.getParts() - .get(i)); - } - } - - /** Asserts one part of a tree test result */ - public static void assertPart(TreeTestResult testResult, String pathStr, - int index, Integer status, String message) { - TreeSPath path = new TreeSPath(pathStr); - PartSubList list = testResult.getResultParts().get(path); - if (list == null) { - fail("No result for path " + path); - return; - } - if (index >= list.getParts().size()) { - fail("Not enough parts."); - } - SimpleResultPart part = (SimpleResultPart) list.getParts().get(index); - assertPart(part, status, message, null, part.getTestRunUuid(), true); - } - - public static void assertPart(TestResultPart expected, - TestResultPart reached) { - String expectedTestRunUuid = null; - if (expected instanceof SimpleResultPart) { - expectedTestRunUuid = ((SimpleResultPart) expected) - .getTestRunUuid(); - } - - assertPart(reached, expected.getStatus(), expected.getMessage(), - expected.getExceptionMessage(), expectedTestRunUuid, false); - } - - /** Assert one part of a tree test result. */ - private static void assertPart(TestResultPart part, Integer status, - String message, String exceptionDescription, - String expectedTestRunUuid, boolean skipExceptionMessage) { - assertEquals(status, part.getStatus()); - - if (message != null) { - if (log.isTraceEnabled()) { - log.trace("Expected message:" + message); - log.trace("Reached message:" + part.getMessage()); - } - assertEquals(message, part.getMessage()); - } - - if (!skipExceptionMessage) { - if (exceptionDescription == null) { - assertNull(part.getExceptionMessage()); - } else { - if (log.isTraceEnabled()) { - log.trace("Expected exception message:" - + exceptionDescription); - log.trace("Reached exception message:" - + part.getExceptionMessage()); - } - - assertEquals(exceptionDescription, part.getExceptionMessage()); - } - } - - if (expectedTestRunUuid != null) { - SimpleResultPart reachedPart = (SimpleResultPart) part; - assertNotNull(reachedPart.getTestRunUuid()); - assertEquals(expectedTestRunUuid, reachedPart.getTestRunUuid()); - } else { - if (part instanceof SimpleResultPart) { - assertNull(((SimpleResultPart) part).getTestRunUuid()); - } - - } - - } - - public static void describeTreeTestResult(TreeTestResult ttr) { - log.info("TreeTestResult #" + ttr.getUuid()); - log.info(" Close date: " + ttr.getCloseDate()); - log.info(" Attributes:"); - for (String key : ttr.getAttributes().keySet()) - log.info(" " + key + "=" + ttr.getAttributes().get(key)); - - log.info(" Result parts: (size=" + ttr.getResultParts().size() + ")"); - for (TreeSPath path : ttr.getResultParts().keySet()) { - log.info(" Path: " + path); - PartSubList lst = ttr.getResultParts().get(path); - for (TestResultPart part : lst.getParts()) - log.info(" " + part); - } - - log.info(" Elements: (size=" + ttr.getElements().size() + ")"); - for (TreeSPath path : ttr.getElements().keySet()) { - SimpleSElement elem = (SimpleSElement) ttr.getElements().get(path); - log.info(" Path: " + path + ", Element: " + elem.getLabel()); - for (String tag : elem.getTags().keySet()) - log.info(" " + tag + "=" + elem.getTags().get(tag)); - } - - } - - /** Makes sure this is a singleton */ - private UnitTestTreeUtil() { - - } -} diff --git a/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/unit/execution/ExecutionFlowDescriptorTestUtils.java b/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/unit/execution/ExecutionFlowDescriptorTestUtils.java new file mode 100644 index 000000000..14a34c7fb --- /dev/null +++ b/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/unit/execution/ExecutionFlowDescriptorTestUtils.java @@ -0,0 +1,48 @@ +package org.argeo.slc.unit.execution; + +import java.util.HashMap; +import java.util.Map; + +import org.argeo.slc.core.deploy.SimpleExecutables; +import org.argeo.slc.core.execution.DefaultExecutionSpec; +import org.argeo.slc.core.execution.PrimitiveSpecAttribute; +import org.argeo.slc.core.execution.PrimitiveValue; +import org.argeo.slc.core.execution.RefSpecAttribute; +import org.argeo.slc.core.execution.RefValue; +import org.argeo.slc.core.test.BasicTestData; +import org.argeo.slc.execution.ExecutionFlowDescriptor; +import org.argeo.slc.execution.ExecutionSpecAttribute; + +public class ExecutionFlowDescriptorTestUtils { + public static ExecutionFlowDescriptor createSimpleExecutionFlowDescriptor() { + ExecutionFlowDescriptor flowDescriptor = new ExecutionFlowDescriptor(); + flowDescriptor.setName("simpleFlow"); + Map values = new HashMap(); + values.put("primitiveInteger", new PrimitiveValue( + PrimitiveSpecAttribute.TYPE_INTEGER, 100)); + values.put("ref1", new RefValue("Just a label")); + flowDescriptor.setValues(values); + + flowDescriptor.setExecutionSpec(createRelatedSimpleSpec()); + return flowDescriptor; + } + + protected static DefaultExecutionSpec createRelatedSimpleSpec() { + DefaultExecutionSpec spec = new DefaultExecutionSpec(); + spec.setBeanName("simpleSpec"); + Map attributes = new HashMap(); + + PrimitiveSpecAttribute primitiveInteger = new PrimitiveSpecAttribute(); + primitiveInteger.setType(PrimitiveSpecAttribute.TYPE_INTEGER); + primitiveInteger.setValue(50); + attributes.put("primitiveInteger", primitiveInteger); + + RefSpecAttribute ref1 = new RefSpecAttribute(); + ref1.setTargetClass(BasicTestData.class); + attributes.put("ref1", ref1); + + spec.setAttributes(attributes); + + return spec; + } +} diff --git a/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/unit/process/SlcExecutionTestUtils.java b/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/unit/process/SlcExecutionTestUtils.java new file mode 100644 index 000000000..bbea1bb25 --- /dev/null +++ b/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/unit/process/SlcExecutionTestUtils.java @@ -0,0 +1,63 @@ +package org.argeo.slc.unit.process; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; +import static org.argeo.slc.unit.UnitUtils.assertDateSec; + +import java.util.UUID; + +import org.argeo.slc.process.SlcExecution; +import org.argeo.slc.process.SlcExecutionStep; + +public abstract class SlcExecutionTestUtils { + + public static SlcExecution createSimpleSlcExecution() { + SlcExecution slcExec = new SlcExecution(); + slcExec.setUuid(UUID.randomUUID().toString()); + slcExec.setHost("localhost"); + slcExec.setUser("user"); + slcExec.setType("slcAnt"); + slcExec.setStatus("STARTED"); + slcExec.getAttributes().put("ant.file", "/test"); + return slcExec; + } + + public static void assertSlcExecution(SlcExecution expected, + SlcExecution reached) { + assertNotNull(reached); + assertEquals(expected.getHost(), reached.getHost()); + assertEquals(expected.getUser(), reached.getUser()); + assertEquals(expected.getType(), reached.getType()); + assertEquals(expected.getStatus(), reached.getStatus()); + + // Attributes + assertEquals(expected.getAttributes().size(), reached.getAttributes() + .size()); + for (String key : expected.getAttributes().keySet()) { + String expectedValue = expected.getAttributes().get(key); + String reachedValue = reached.getAttributes().get(key); + assertNotNull(reachedValue); + assertEquals(expectedValue, reachedValue); + } + + assertEquals(expected.getSteps().size(), reached.getSteps().size()); + for (int i = 0; i < expected.getSteps().size(); i++) { + SlcExecutionStep stepExpected = expected.getSteps().get(i); + SlcExecutionStep stepReached = reached.getSteps().get(i); + assertSlcExecutionStep(stepExpected, stepReached); + } + } + + public static void assertSlcExecutionStep(SlcExecutionStep expected, + SlcExecutionStep reached) { + assertNotNull(reached); + assertEquals(expected.getUuid(), reached.getUuid()); + assertEquals(expected.getType(), reached.getType()); + assertEquals(expected.logAsString(), reached.logAsString()); + assertDateSec(expected.getBegin(), reached.getBegin()); + } + + private SlcExecutionTestUtils() { + + } +} diff --git a/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/unit/test/tree/TreeTestResultTestUtils.java b/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/unit/test/tree/TreeTestResultTestUtils.java new file mode 100644 index 000000000..cf4b0c1e4 --- /dev/null +++ b/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/unit/test/tree/TreeTestResultTestUtils.java @@ -0,0 +1,130 @@ +package org.argeo.slc.unit.test.tree; + +import java.util.UUID; + +import org.argeo.slc.build.Distribution; +import org.argeo.slc.core.structure.SimpleSElement; +import org.argeo.slc.core.structure.tree.TreeSPath; +import org.argeo.slc.core.structure.tree.TreeSRegistry; +import org.argeo.slc.core.test.SimpleResultPart; +import org.argeo.slc.core.test.SimpleTestRun; +import org.argeo.slc.core.test.tree.PartSubList; +import org.argeo.slc.core.test.tree.TreeTestResult; +import org.argeo.slc.deploy.DeployedSystem; +import org.argeo.slc.deploy.DeploymentData; +import org.argeo.slc.deploy.TargetData; +import org.argeo.slc.msg.test.tree.ResultPartRequest; +import org.argeo.slc.process.SlcExecution; +import org.argeo.slc.process.SlcExecutionStep; +import org.argeo.slc.test.TestStatus; +import org.argeo.slc.unit.process.SlcExecutionTestUtils; + +public abstract class TreeTestResultTestUtils { + + public static TreeTestResult createSimpleTreeTestResult() { + TreeTestResult treeTestResult = new TreeTestResult(); + treeTestResult.setUuid(UUID.randomUUID().toString()); + return treeTestResult; + } + + public static TreeTestResult createCompleteTreeTestResult() { + SlcExecution slcExecution = SlcExecutionTestUtils + .createSimpleSlcExecution(); + SlcExecutionStep step = new SlcExecutionStep("JUnit step"); + slcExecution.getSteps().add(step); + + TreeTestResult ttr = createMinimalConsistentTreeTestResult(slcExecution); + + ttr.addResultPart(createSimpleResultPartPassed()); + ttr.addResultPart(createSimpleResultPartFailed()); + ttr.addResultPart(createSimpleResultPartError()); + return ttr; + } + + public static TreeTestResult createMinimalConsistentTreeTestResult( + SlcExecution slcExecution) { + SimpleTestRun testRun = new SimpleTestRun(); + testRun.setUuid(UUID.randomUUID().toString()); + + String pathStr = "/test"; + TreeSPath path = new TreeSPath(pathStr); + + TreeSRegistry registry = new TreeSRegistry(); + SimpleSElement elem = new SimpleSElement("Unit Test"); + elem.getTags().put("myTag", "myTagValue"); + registry.register(path, elem); + + TreeTestResult ttr = createSimpleTreeTestResult(); + ttr.getAttributes().put("testCase", "UNIT"); + + // Simulate test run + ttr.notifyCurrentPath(registry, path); + ttr.notifyTestRun(testRun); + testRun.setTestResult(ttr); + testRun.setDeployedSystem(new DeployedSystem() { + private String uuid = UUID.randomUUID().toString(); + + public String getDeployedSystemId() { + return uuid; + } + + public Distribution getDistribution() { + return null; + } + + public DeploymentData getDeploymentData() { + // TODO Auto-generated method stub + return null; + } + + public TargetData getTargetData() { + // TODO Auto-generated method stub + return null; + } + + }); + testRun.notifySlcExecution(slcExecution); + return ttr; + } + + public static SimpleResultPart createSimpleResultPartPassed() { + SimpleResultPart partPassed = new SimpleResultPart(); + String msgPassed = "message\nnew line"; + partPassed.setStatus(TestStatus.PASSED); + partPassed.setMessage(msgPassed); + return partPassed; + } + + public static SimpleResultPart createSimpleResultPartFailed() { + SimpleResultPart partFailed = new SimpleResultPart(); + String msgFailed = "too bad"; + partFailed.setStatus(TestStatus.FAILED); + partFailed.setMessage(msgFailed); + return partFailed; + } + + public static SimpleResultPart createSimpleResultPartError() { + SimpleResultPart partFailed = new SimpleResultPart(); + String msgFailed = "crashed\nanother line"; + partFailed.setStatus(TestStatus.ERROR); + partFailed.setMessage(msgFailed); + partFailed.setException(new Exception("Test Exception")); + return partFailed; + } + + public static ResultPartRequest createSimpleResultPartRequest( + TreeTestResult ttr) { + TreeSPath path = ttr.getCurrentPath(); + PartSubList lst = ttr.getResultParts().get(path); + SimpleResultPart part = (SimpleResultPart) lst.getParts().get(2); + + ResultPartRequest req = new ResultPartRequest(ttr, path, part); + req.setPath(ttr.getCurrentPath()); + + return req; + } + + private TreeTestResultTestUtils() { + + } +} diff --git a/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/unit/test/tree/UnitTestTreeUtil.java b/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/unit/test/tree/UnitTestTreeUtil.java new file mode 100644 index 000000000..91467f3ea --- /dev/null +++ b/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/unit/test/tree/UnitTestTreeUtil.java @@ -0,0 +1,187 @@ +package org.argeo.slc.unit.test.tree; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; +import static junit.framework.Assert.assertNull; +import static junit.framework.Assert.fail; +import static org.argeo.slc.unit.UnitUtils.assertDateSec; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.slc.core.structure.SimpleSElement; +import org.argeo.slc.core.structure.tree.TreeSPath; +import org.argeo.slc.core.test.SimpleResultPart; +import org.argeo.slc.core.test.tree.PartSubList; +import org.argeo.slc.core.test.tree.TreeTestResult; +import org.argeo.slc.test.TestResultPart; + +/** Utilities for unit tests. */ +public class UnitTestTreeUtil { + private final static Log log = LogFactory.getLog(UnitTestTreeUtil.class); + + public static void assertTreeTestResult(TreeTestResult expected, + TreeTestResult reached) { + assertEquals(expected.getUuid(), reached.getUuid()); + assertDateSec(expected.getCloseDate(), reached.getCloseDate()); + + // Attributes + assertEquals(expected.getAttributes().size(), reached.getAttributes() + .size()); + for (String key : expected.getAttributes().keySet()) { + String expectedValue = expected.getAttributes().get(key); + String reachedValue = reached.getAttributes().get(key); + assertNotNull(reachedValue); + assertEquals(expectedValue, reachedValue); + } + + // Result parts + assertEquals(expected.getResultParts().size(), reached.getResultParts() + .size()); + for (TreeSPath path : expected.getResultParts().keySet()) { + PartSubList lstExpected = expected.getResultParts().get(path); + PartSubList lstReached = expected.getResultParts().get(path); + if (lstReached == null) { + fail("No result for path " + path); + return; + } + assertPartSubList(lstExpected, lstReached); + } + + // Elements + assertEquals(expected.getElements().size(), reached.getElements() + .size()); + for (TreeSPath path : expected.getElements().keySet()) { + // String nameExpected = expected.getElements().get(path); + // String nameReached = expected.getElements().get(path); + SimpleSElement elemExpected = (SimpleSElement) expected + .getElements().get(path); + SimpleSElement elemReached = (SimpleSElement) expected + .getElements().get(path); + assertNotNull(elemReached); + assertElements(elemExpected, elemReached); + } + + } + + public static void assertElements(SimpleSElement expected, + SimpleSElement reached) { + assertEquals(expected.getLabel(), reached.getLabel()); + assertEquals(expected.getTags().size(), reached.getTags().size()); + for (String tagName : expected.getTags().keySet()) { + String expectedTagValue = expected.getTags().get(tagName); + String reachedTagValue = reached.getTags().get(tagName); + assertNotNull(reachedTagValue); + assertEquals(expectedTagValue, reachedTagValue); + } + } + + public static void assertPartSubList(PartSubList lstExpected, + PartSubList lstReached) { + assertEquals(lstExpected.getParts().size(), lstReached.getParts() + .size()); + for (int i = 0; i < lstExpected.getParts().size(); i++) { + assertPart(lstExpected.getParts().get(i), lstReached.getParts() + .get(i)); + } + } + + /** Asserts one part of a tree test result */ + public static void assertPart(TreeTestResult testResult, String pathStr, + int index, Integer status, String message) { + TreeSPath path = new TreeSPath(pathStr); + PartSubList list = testResult.getResultParts().get(path); + if (list == null) { + fail("No result for path " + path); + return; + } + if (index >= list.getParts().size()) { + fail("Not enough parts."); + } + SimpleResultPart part = (SimpleResultPart) list.getParts().get(index); + assertPart(part, status, message, null, part.getTestRunUuid(), true); + } + + public static void assertPart(TestResultPart expected, + TestResultPart reached) { + String expectedTestRunUuid = null; + if (expected instanceof SimpleResultPart) { + expectedTestRunUuid = ((SimpleResultPart) expected) + .getTestRunUuid(); + } + + assertPart(reached, expected.getStatus(), expected.getMessage(), + expected.getExceptionMessage(), expectedTestRunUuid, false); + } + + /** Assert one part of a tree test result. */ + private static void assertPart(TestResultPart part, Integer status, + String message, String exceptionDescription, + String expectedTestRunUuid, boolean skipExceptionMessage) { + assertEquals(status, part.getStatus()); + + if (message != null) { + if (log.isTraceEnabled()) { + log.trace("Expected message:" + message); + log.trace("Reached message:" + part.getMessage()); + } + assertEquals(message, part.getMessage()); + } + + if (!skipExceptionMessage) { + if (exceptionDescription == null) { + assertNull(part.getExceptionMessage()); + } else { + if (log.isTraceEnabled()) { + log.trace("Expected exception message:" + + exceptionDescription); + log.trace("Reached exception message:" + + part.getExceptionMessage()); + } + + assertEquals(exceptionDescription, part.getExceptionMessage()); + } + } + + if (expectedTestRunUuid != null) { + SimpleResultPart reachedPart = (SimpleResultPart) part; + assertNotNull(reachedPart.getTestRunUuid()); + assertEquals(expectedTestRunUuid, reachedPart.getTestRunUuid()); + } else { + if (part instanceof SimpleResultPart) { + assertNull(((SimpleResultPart) part).getTestRunUuid()); + } + + } + + } + + public static void describeTreeTestResult(TreeTestResult ttr) { + log.info("TreeTestResult #" + ttr.getUuid()); + log.info(" Close date: " + ttr.getCloseDate()); + log.info(" Attributes:"); + for (String key : ttr.getAttributes().keySet()) + log.info(" " + key + "=" + ttr.getAttributes().get(key)); + + log.info(" Result parts: (size=" + ttr.getResultParts().size() + ")"); + for (TreeSPath path : ttr.getResultParts().keySet()) { + log.info(" Path: " + path); + PartSubList lst = ttr.getResultParts().get(path); + for (TestResultPart part : lst.getParts()) + log.info(" " + part); + } + + log.info(" Elements: (size=" + ttr.getElements().size() + ")"); + for (TreeSPath path : ttr.getElements().keySet()) { + SimpleSElement elem = (SimpleSElement) ttr.getElements().get(path); + log.info(" Path: " + path + ", Element: " + elem.getLabel()); + for (String tag : elem.getTags().keySet()) + log.info(" " + tag + "=" + elem.getTags().get(tag)); + } + + } + + /** Makes sure this is a singleton */ + private UnitTestTreeUtil() { + + } +}