import java.util.Properties;\r
import java.util.Vector;\r
\r
-import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;\r
-import org.springframework.context.ApplicationContext;\r
+import org.springframework.context.support.AbstractApplicationContext;\r
import org.springframework.context.support.FileSystemXmlApplicationContext;\r
\r
import org.apache.commons.logging.Log;\r
System.getProperties().putAll(project.getProperties());\r
String acPath = project\r
.getUserProperty(SlcAntConfig.APPLICATION_CONTEXT_PROPERTY);\r
- ApplicationContext context = new FileSystemXmlApplicationContext(acPath);\r
+ AbstractApplicationContext context = new FileSystemXmlApplicationContext(acPath);\r
+ context.registerShutdownHook();\r
project.addReference(REF_ROOT_CONTEXT, context);\r
}\r
\r
import org.argeo.slc.core.structure.tree.TreeSPath;\r
\r
/** Ant task that can be registered within a structure. */\r
-public abstract class SAwareTask extends AbstractSpringTask implements StructureElement {\r
+public abstract class SAwareTask extends AbstractSpringTask implements\r
+ StructureElement {\r
private TreeSPath path;\r
- //private final DefaultTreeSAware sAware = new DefaultTreeSAware();\r
private final List<AbstractSpringArg> sAwareArgs = new Vector<AbstractSpringArg>();\r
\r
@Override\r
+ targetPath.listChildren(getRegistry()).size());\r
getRegistry().register(taskPath, this);\r
path = taskPath;\r
- \r
+\r
// notify registered args\r
for (AbstractSpringArg arg : sAwareArgs) {\r
Object obj = arg.getBeanInstance();\r
@Override\r
public String getDescription() {\r
String description = super.getDescription();\r
- if(description==null){\r
+ if (description == null) {\r
return "<no task def>";\r
- }\r
- else{\r
+ } else {\r
return description;\r
}\r
}\r
- \r
- \r
+\r
}\r
package org.argeo.slc.ant.test;\r
\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
import org.apache.tools.ant.BuildException;\r
\r
import org.argeo.slc.ant.SlcAntConfig;\r
import org.argeo.slc.ant.spring.AbstractSpringArg;\r
import org.argeo.slc.ant.structure.SAwareTask;\r
+import org.argeo.slc.core.deploy.DeployedSystem;\r
import org.argeo.slc.core.structure.StructureAware;\r
-import org.argeo.slc.core.test.SimpleTestRun;\r
import org.argeo.slc.core.test.TestData;\r
import org.argeo.slc.core.test.TestDefinition;\r
import org.argeo.slc.core.test.TestResult;\r
+import org.argeo.slc.core.test.WritableTestRun;\r
\r
/** Ant task wrapping a test run. */\r
public class SlcTestTask extends SAwareTask {\r
+ Log log = LogFactory.getLog(SlcTestTask.class);\r
\r
private TestDefinitionArg testDefinitionArg;\r
private TestDataArg testDataArg;\r
+ private DeployedSystemArg deployedSystemArg;\r
+ private TestResultArg testResultArg;\r
\r
@Override\r
public void executeActions(String mode) throws BuildException {\r
- SimpleTestRun simpleTestRun = (SimpleTestRun) getContext().getBean(\r
+ WritableTestRun testRun = (WritableTestRun) getContext().getBean(\r
getProject().getUserProperty(\r
SlcAntConfig.DEFAULT_TEST_RUN_PROPERTY));\r
+\r
+ // set overriden references\r
+ if (testDataArg != null){\r
+ testRun.setTestData(testDataArg.getTestData());\r
+ log.trace("Overrides test data");\r
+ }\r
\r
- if (testDataArg != null)\r
- simpleTestRun.setTestData(testDataArg.getTestData());\r
- if (testDefinitionArg != null)\r
- simpleTestRun.setTestDefinition(testDefinitionArg\r
- .getTestDefinition());\r
-\r
- TestResult result = simpleTestRun.getTestResult();\r
- if(result!=null && result instanceof StructureAware){\r
- ((StructureAware)result).notifyCurrentPath(getRegistry(), getPath());\r
+ if (testDefinitionArg != null){\r
+ testRun.setTestDefinition(testDefinitionArg.getTestDefinition());\r
+ log.trace("Overrides test definition");\r
}\r
\r
- simpleTestRun.execute();\r
+ if (deployedSystemArg != null){\r
+ testRun.setDeployedSystem(deployedSystemArg.getDeployedSystem());\r
+ log.trace("Overrides deployed system");\r
+ }\r
+ \r
+ if (testResultArg != null){\r
+ testRun.setTestResult(testResultArg.getTestResult());\r
+ log.trace("Overrides test result");\r
+ }\r
+\r
+ // notify path to test result\r
+ TestResult result = testRun.getTestResult();\r
+ if (result != null && result instanceof StructureAware) {\r
+ ((StructureAware) result).notifyCurrentPath(getRegistry(),\r
+ getPath());\r
+ }\r
+\r
+ testRun.execute();\r
}\r
\r
public TestDefinitionArg createTestDefinition() {\r
testDefinitionArg = new TestDefinitionArg();\r
+ // only test definitions can add to path\r
addSAwareArg(testDefinitionArg);\r
return testDefinitionArg;\r
}\r
\r
public TestDataArg createTestData() {\r
testDataArg = new TestDataArg();\r
- addSAwareArg(testDataArg);\r
return testDataArg;\r
}\r
\r
+ public DeployedSystemArg createDeployedSystem() {\r
+ deployedSystemArg = new DeployedSystemArg();\r
+ return deployedSystemArg;\r
+ }\r
+\r
+ public TestResultArg createTestResult() {\r
+ testResultArg = new TestResultArg();\r
+ return testResultArg;\r
+ }\r
+\r
}\r
\r
class TestDefinitionArg extends AbstractSpringArg {\r
}\r
\r
}\r
+\r
+class DeployedSystemArg extends AbstractSpringArg {\r
+ public DeployedSystem getDeployedSystem() {\r
+ return (DeployedSystem) getBeanInstance();\r
+ }\r
+\r
+}\r
+\r
+class TestResultArg extends AbstractSpringArg {\r
+ public TestResult getTestResult() {\r
+ return (TestResult) getBeanInstance();\r
+ }\r
+\r
+}\r
\r
import org.argeo.slc.core.deploy.DeployedSystem;\r
\r
-public class SimpleTestRun implements TestRun {\r
+public class SimpleTestRun implements WritableTestRun {\r
private DeployedSystem deployedSystem;\r
private TestData testData;\r
private TestDefinition testDefinition;\r
public DeployedSystem getDeployedSystem();\r
\r
public TestResult getTestResult();\r
+ \r
+ public void execute();\r
}\r
--- /dev/null
+package org.argeo.slc.core.test;\r
+\r
+import org.argeo.slc.core.deploy.DeployedSystem;\r
+\r
+public interface WritableTestRun extends TestRun {\r
+ public void setDeployedSystem(DeployedSystem deployedSystem);\r
+\r
+ public void setTestData(TestData testData);\r
+\r
+ public void setTestDefinition(TestDefinition testDefinition);\r
+\r
+ public void setTestResult(TestResult testResult);\r
+}\r
\r
public class ExampleDeployedSystem implements DeployedSystem {\r
private DeployedSystemId deployedSystemId;\r
+ private int skipFreq = 2;\r
\r
public DeployedSystemId getDeployedSystemId() {\r
return deployedSystemId;\r
this.deployedSystemId = deployedSystemId;\r
}\r
\r
- public ExampleAppli getExampleAppliInstance(){\r
- return new ExampleAppli();\r
+ public ExampleAppli getExampleAppliInstance() {\r
+ ExampleAppli appli = new ExampleAppli();\r
+ appli.setSkipFreq(skipFreq);\r
+ return appli;\r
}\r
+\r
+ public void setSkipFreq(int skipFreq) {\r
+ this.skipFreq = skipFreq;\r
+ }\r
+\r
}\r
import java.io.IOException;\r
\r
public class ExampleAppli {\r
+ private int skipFreq = 2;\r
\r
public void filter(String[] args) {\r
if (args.length < 2) {\r
}\r
String input = args[0];\r
String output = args[1];\r
- int skipFreq = 2;\r
if(args.length>2){\r
skipFreq = Integer.parseInt(args[2]);\r
}\r
}\r
}\r
\r
+ public void setSkipFreq(int skipFreq) {\r
+ this.skipFreq = skipFreq;\r
+ }\r
+\r
}\r
<property name="deployedSystem" ref="exampleDeployedSystem" />\r
</bean>\r
\r
- <bean id="testResultId" class="org.argeo.slc.core.test.NumericTRId"\r
- init-method="init">\r
- </bean>\r
-\r
<bean id="testResult"\r
class="org.argeo.slc.core.test.tree.TreeTestResult">\r
<property name="numericResultId" ref="testResultId" />\r
</property>\r
</bean>\r
\r
+ <bean id="testResult2"\r
+ class="org.argeo.slc.core.test.tree.TreeTestResult"\r
+ destroy-method="close">\r
+ <property name="numericResultId" ref="testResultId" />\r
+ <property name="listeners">\r
+ <list>\r
+ <ref bean="resultLogger" />\r
+ <ref bean="resultPersister" />\r
+ </list>\r
+ </property>\r
+ </bean>\r
+\r
+ <bean id="testResultId" class="org.argeo.slc.core.test.NumericTRId"\r
+ init-method="init" scope="prototype">\r
+ </bean>\r
+\r
<bean\r
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />\r
\r
\r
<bean id="exampleDeployedSystem"\r
class="org.argeo.slc.example.ExampleDeployedSystem">\r
+ <property name="skipFreq" value="2"/>\r
<property name="deployedSystemId">\r
<bean class="org.argeo.slc.core.deploy.NumericDSId">\r
<property name="value" value="123456" />\r
</property>\r
</bean>\r
\r
+ <bean id="exampleDeployedSystem2"\r
+ class="org.argeo.slc.example.ExampleDeployedSystem">\r
+ <property name="skipFreq" value="3"/>\r
+ <property name="deployedSystemId">\r
+ <bean class="org.argeo.slc.core.deploy.NumericDSId">\r
+ <property name="value" value="654321" />\r
+ <property name="distributionId">\r
+ <bean\r
+ class="org.argeo.slc.core.build.VersionDistributionId">\r
+ <property name="versionString" value="0.3.1" />\r
+ </bean>\r
+ </property>\r
+ </bean>\r
+ </property>\r
+ </bean>\r
+\r
</beans>
\ No newline at end of file
<testDefinition bean="simpleExampleTestDef" />\r
<testData bean="testData.eu-reform" />\r
</slc.test>\r
+ \r
+ <slc.test description="Distinct test">\r
+ <testDefinition bean="simpleExampleTestDef" />\r
+ <testData bean="testData.eu-reform" />\r
+ <deployedSystem bean="exampleDeployedSystem2"/>\r
+ <testResult bean="testResult2"/>\r
+ </slc.test>\r
+\r
</target>\r
\r
<target name="testComplex" description="A complex test">\r