import java.util.ArrayList;
import java.util.List;
-import org.argeo.slc.osgi.test.AbstractOsgiRuntimeTestCase;
+import org.argeo.slc.equinox.unit.AbstractOsgiRuntimeTestCase;
import org.argeo.slc.osgiboot.OsgiBoot;
public class StartStopDemoTest extends AbstractOsgiRuntimeTestCase {
<name>Argeo SLC Web Application Integration Tests</name>
<build>
<plugins>
- <!--
- <plugin> <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId> <executions>
- <execution> <id>copy-dependencies</id>
- <phase>pre-integration-test</phase> <goals>
- <goal>copy-dependencies</goal> </goals> <configuration>
- <overWriteReleases>true</overWriteReleases>
- <overWriteSnapshots>true</overWriteSnapshots> </configuration>
- </execution> </executions> </plugin>
- -->
<plugin>
<groupId>org.argeo.slc.maven</groupId>
<artifactId>maven-argeo-osgi-plugin</artifactId>
<dependency>
<groupId>org.argeo.slc.runtime</groupId>
<artifactId>org.argeo.slc.server</artifactId>
- <classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<artifactId>org.argeo.slc.support.simple</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.argeo.slc.runtime</groupId>
- <artifactId>org.argeo.slc.support.simple</artifactId>
- <version>${project.version}</version>
- <classifier>tests</classifier>
- </dependency>
<!--
<dependency> <groupId>org.argeo.slc.runtime</groupId>
<artifactId>org.argeo.slc.support.ant</artifactId>
<artifactId>org.argeo.slc.server</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.argeo.slc.runtime</groupId>
- <artifactId>org.argeo.slc.server</artifactId>
- <version>${project.version}</version>
- <classifier>tests</classifier>
- </dependency>
<dependency>
<groupId>org.argeo.slc.runtime</groupId>
<artifactId>org.argeo.slc.osgiboot</artifactId>
<artifactId>org.argeo.slc.support.equinox</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.argeo.slc.runtime</groupId>
- <artifactId>org.argeo.slc.support.equinox</artifactId>
- <classifier>tests</classifier>
- <scope>test</scope>
- <version>${project.version}</version>
- </dependency>
<dependency>
<groupId>org.argeo.slc.runtime</groupId>
<artifactId>org.argeo.slc.support.ws.client</artifactId>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
+ <!--
<executions>
<execution>
<goals>
</goals>
</execution>
</executions>
+ -->
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
--- /dev/null
+package org.argeo.slc.server.unit;
+
+import org.argeo.slc.SlcException;
+import org.argeo.slc.msg.ExecutionAnswer;
+import org.argeo.slc.server.client.SlcServerHttpClient;
+import org.argeo.slc.unit.AbstractSpringTestCase;
+
+public abstract class AbstractHttpClientTestCase extends AbstractSpringTestCase {
+ private SlcServerHttpClient httpClient = null;
+
+ private String isServerReadyService = "isServerReady.service";
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ httpClient = createHttpClient();
+ }
+
+ protected void waitForServerToBeReady() {
+ ExecutionAnswer answer = httpClient.callServiceSafe(
+ isServerReadyService, null, getServerReadyTimeout());
+ if (!answer.isOk())
+ throw new SlcException("Server is not ready: " + answer);
+ }
+
+ protected SlcServerHttpClient createHttpClient() {
+ SlcServerHttpClient httpClient = getBean(SlcServerHttpClient.class);
+ return httpClient;
+ }
+
+ protected SlcServerHttpClient getHttpClient() {
+ return httpClient;
+ }
+
+ /** Default is 120s */
+ protected Long getServerReadyTimeout() {
+ return 120 * 1000l;
+ }
+}
+++ /dev/null
-package org.argeo.slc.server.unit;
-
-import org.argeo.slc.SlcException;
-import org.argeo.slc.msg.ExecutionAnswer;
-import org.argeo.slc.server.client.SlcServerHttpClient;
-import org.argeo.slc.unit.AbstractSpringTestCase;
-
-public abstract class AbstractHttpClientTestCase extends AbstractSpringTestCase {
- private SlcServerHttpClient httpClient = null;
-
- private String isServerReadyService = "isServerReady.service";
-
- protected void setUp() throws Exception {
- super.setUp();
- httpClient = createHttpClient();
- }
-
- protected void waitForServerToBeReady() {
- ExecutionAnswer answer = httpClient.callServiceSafe(
- isServerReadyService, null, getServerReadyTimeout());
- if (!answer.isOk())
- throw new SlcException("Server is not ready: " + answer);
- }
-
- protected SlcServerHttpClient createHttpClient() {
- SlcServerHttpClient httpClient = getBean(SlcServerHttpClient.class);
- return httpClient;
- }
-
- protected SlcServerHttpClient getHttpClient() {
- return httpClient;
- }
-
- /** Default is 120s */
- protected Long getServerReadyTimeout() {
- return 120 * 1000l;
- }
-}
<groupId>org.argeo.slc.runtime</groupId>
<artifactId>org.argeo.slc.support.simple</artifactId>
</dependency>
- <dependency>
- <groupId>org.argeo.slc.runtime</groupId>
- <artifactId>org.argeo.slc.support.simple</artifactId>
- <classifier>tests</classifier>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
--- /dev/null
+package org.argeo.slc.equinox.unit;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.management.BadBinaryOpValueExpException;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.osgiboot.OsgiBoot;
+import org.eclipse.core.runtime.adaptor.EclipseStarter;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.springframework.context.ApplicationContext;
+import org.springframework.osgi.util.OsgiStringUtils;
+
+public abstract class AbstractOsgiRuntimeTestCase extends TestCase {
+ private final static Log log = LogFactory
+ .getLog(AbstractOsgiRuntimeTestCase.class);
+
+ protected OsgiBoot osgiBoot = null;
+
+ protected void installBundles() throws Exception {
+
+ }
+
+ public void setUp() throws Exception {
+ // To avoid xerces from the classpath being detected as the provider
+ System
+ .setProperty("javax.xml.parsers.DocumentBuilderFactory",
+ "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
+ System.setProperty("javax.xml.parsers.SAXParserFactory",
+ "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
+
+ BundleContext bundleContext = startRuntime();
+ osgiBoot = new OsgiBoot(bundleContext);
+ log.info("OSGi runtime started.");
+
+ installBundles();
+
+ List<String> bundlesToStart = getBundlesToStart();
+ osgiBoot.startBundles(bundlesToStart);
+ waitAllBundlesOk(bundlesToStart);
+ if (log.isTraceEnabled())
+ listInstalledBundles();
+ }
+
+ public void tearDown() throws Exception {
+ osgiBoot = null;
+ stopRuntime();
+ log.info("OSGi runtime stopped.");
+ }
+
+ protected BundleContext startRuntime() throws Exception {
+ String[] args = { "-console", "-clean" };
+ BundleContext bundleContext = EclipseStarter.startup(args, null);
+ return bundleContext;
+ }
+
+ protected void stopRuntime() throws Exception {
+ EclipseStarter.shutdown();
+ }
+
+ protected List<String> getBundlesToStart() {
+ return new ArrayList<String>();
+ }
+
+ protected void listInstalledBundles() {
+ BundleContext bundleContext = osgiBoot.getBundleContext();
+ Bundle[] bundles = bundleContext.getBundles();
+ for (int i = 0; i < bundles.length; i++) {
+ System.out.println(OsgiStringUtils.nullSafeSymbolicName(bundles[i])
+ + " [" + OsgiStringUtils.bundleStateAsString(bundles[i])
+ + "] " + bundles[i].getLocation());
+ }
+
+ }
+
+ protected Map<Bundle, ApplicationContext> getOsgiApplicationContexts()
+ throws Exception {
+ Map<Bundle, ApplicationContext> map = new HashMap<Bundle, ApplicationContext>();
+ BundleContext bundleContext = osgiBoot.getBundleContext();
+ ServiceReference[] srs = bundleContext.getServiceReferences(
+ ApplicationContext.class.getName(), null);
+ for (ServiceReference sr : srs) {
+ ApplicationContext context = (ApplicationContext) bundleContext
+ .getService(sr);
+ map.put(sr.getBundle(), context);
+ }
+ return map;
+ }
+
+ /** Wait for all bundles to be either RESOLVED or ACTIVE. */
+ protected void waitAllBundlesOk(List<String> bundlesToStart) {
+ BundleContext bundleContext = osgiBoot.getBundleContext();
+ long begin = System.currentTimeMillis();
+ long duration = 0;
+ boolean allBundlesOk = true;
+ StringBuffer badBundles = null;
+ while (duration < getResolvedTimeout()) {
+ badBundles = new StringBuffer();
+ for (Bundle bundle : bundleContext.getBundles()) {
+ if (bundle.getSymbolicName() != null
+ && bundle.getSymbolicName().startsWith(
+ "org.eclipse.jdt")) {
+ // don't check Eclipse SDK bundles
+ continue;
+ }
+
+ if (bundle.getState() == Bundle.INSTALLED) {
+ allBundlesOk = false;
+ badBundles
+ .append(OsgiStringUtils
+ .nullSafeSymbolicName(bundle)
+ + " ["
+ + OsgiStringUtils
+ .bundleStateAsString(bundle) + "]");
+ }
+
+ if (bundlesToStart.contains(bundle.getSymbolicName())
+ && bundle.getState() != Bundle.ACTIVE) {
+ allBundlesOk = false;
+ badBundles.append(OsgiStringUtils
+ .nullSafeSymbolicName(bundle)
+ + " ["
+ + OsgiStringUtils.bundleStateAsString(bundle)
+ + "]\n");
+ }
+ }
+
+ if (allBundlesOk)
+ break;// while
+
+ sleep(1000);
+
+ duration = System.currentTimeMillis() - begin;
+ }
+
+ if (!allBundlesOk) {
+ listInstalledBundles();
+ throw new SlcException(
+ "Some bundles are not at the proper status:\n" + badBundles);
+ }
+ }
+
+ /**
+ * Make sure that the application context of the started bundles starting
+ * with this prefix are properly initialized
+ */
+ protected void assertStartedBundlesApplicationContext(
+ String bundleSymbolicNamesPrefix) {
+ List<String> bundlesToStart = getBundlesToStart();
+ for (String bundleSName : bundlesToStart) {
+ if (bundleSName.startsWith(bundleSymbolicNamesPrefix))
+ assertBundleApplicationContext(bundleSName);
+ }
+ }
+
+ /**
+ * Make sure that the application context of this bundle is properly
+ * initialized
+ */
+ protected void assertBundleApplicationContext(String bundleSymbolicName) {
+ String filter = "(Bundle-SymbolicName=" + bundleSymbolicName + ")";
+ // Wait for application context to be ready
+ try {
+ ServiceReference[] srs = getServiceRefSynchronous(
+ ApplicationContext.class.getName(), filter);
+ if (srs == null)
+ throw new SlcException("No application context for "
+ + bundleSymbolicName);
+ } catch (InvalidSyntaxException e) {
+ throw new SlcException(
+ "Unexpected exception when looking for application context for bundle "
+ + bundleSymbolicName, e);
+ }
+ log.info("Application context of bundle " + bundleSymbolicName
+ + " is initalized.");
+ }
+
+ protected ServiceReference[] getServiceRefSynchronous(String clss,
+ String filter) throws InvalidSyntaxException {
+ // FIXME: factorize
+ if (log.isTraceEnabled())
+ log.debug("Filter: '" + filter + "'");
+ ServiceReference[] sfs = null;
+ boolean waiting = true;
+ long begin = System.currentTimeMillis();
+ do {
+ sfs = getBundleContext().getServiceReferences(clss, filter);
+
+ if (sfs != null)
+ waiting = false;
+
+ sleep(100);
+ if (System.currentTimeMillis() - begin > getDefaultTimeout())
+ throw new SlcException("Search of services " + clss
+ + " with filter " + filter + " timed out.");
+ } while (waiting);
+
+ return sfs;
+ }
+
+ protected BundleContext getBundleContext() {
+ return osgiBoot.getBundleContext();
+ }
+
+ /** Default is 30s */
+ protected long getResolvedTimeout() {
+ return 30 * 1000l;
+ }
+
+ /** Default is 10s */
+ protected long getDefaultTimeout() {
+ return 10 * 1000l;
+ }
+
+ final protected void sleep(long duration) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // silent
+ }
+ }
+}
+++ /dev/null
-package org.argeo.slc.osgi.test;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.management.BadBinaryOpValueExpException;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.slc.SlcException;
-import org.argeo.slc.osgiboot.OsgiBoot;
-import org.eclipse.core.runtime.adaptor.EclipseStarter;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.springframework.context.ApplicationContext;
-import org.springframework.osgi.util.OsgiStringUtils;
-
-public abstract class AbstractOsgiRuntimeTestCase extends TestCase {
- private final static Log log = LogFactory
- .getLog(AbstractOsgiRuntimeTestCase.class);
-
- protected OsgiBoot osgiBoot = null;
-
- protected void installBundles() throws Exception {
-
- }
-
- public void setUp() throws Exception {
- // To avoid xerces from the classpath being detected as the provider
- System
- .setProperty("javax.xml.parsers.DocumentBuilderFactory",
- "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
- System.setProperty("javax.xml.parsers.SAXParserFactory",
- "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
-
- BundleContext bundleContext = startRuntime();
- osgiBoot = new OsgiBoot(bundleContext);
- log.info("OSGi runtime started.");
-
- installBundles();
-
- List<String> bundlesToStart = getBundlesToStart();
- osgiBoot.startBundles(bundlesToStart);
- waitAllBundlesOk(bundlesToStart);
- if (log.isTraceEnabled())
- listInstalledBundles();
- }
-
- public void tearDown() throws Exception {
- osgiBoot = null;
- stopRuntime();
- log.info("OSGi runtime stopped.");
- }
-
- protected BundleContext startRuntime() throws Exception {
- String[] args = { "-console", "-clean" };
- BundleContext bundleContext = EclipseStarter.startup(args, null);
- return bundleContext;
- }
-
- protected void stopRuntime() throws Exception {
- EclipseStarter.shutdown();
- }
-
- protected List<String> getBundlesToStart() {
- return new ArrayList<String>();
- }
-
- protected void listInstalledBundles() {
- BundleContext bundleContext = osgiBoot.getBundleContext();
- Bundle[] bundles = bundleContext.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- System.out.println(OsgiStringUtils.nullSafeSymbolicName(bundles[i])
- + " [" + OsgiStringUtils.bundleStateAsString(bundles[i])
- + "] " + bundles[i].getLocation());
- }
-
- }
-
- protected Map<Bundle, ApplicationContext> getOsgiApplicationContexts()
- throws Exception {
- Map<Bundle, ApplicationContext> map = new HashMap<Bundle, ApplicationContext>();
- BundleContext bundleContext = osgiBoot.getBundleContext();
- ServiceReference[] srs = bundleContext.getServiceReferences(
- ApplicationContext.class.getName(), null);
- for (ServiceReference sr : srs) {
- ApplicationContext context = (ApplicationContext) bundleContext
- .getService(sr);
- map.put(sr.getBundle(), context);
- }
- return map;
- }
-
- /** Wait for all bundles to be either RESOLVED or ACTIVE. */
- protected void waitAllBundlesOk(List<String> bundlesToStart) {
- BundleContext bundleContext = osgiBoot.getBundleContext();
- long begin = System.currentTimeMillis();
- long duration = 0;
- boolean allBundlesOk = true;
- StringBuffer badBundles = null;
- while (duration < getResolvedTimeout()) {
- badBundles = new StringBuffer();
- for (Bundle bundle : bundleContext.getBundles()) {
- if (bundle.getSymbolicName() != null
- && bundle.getSymbolicName().startsWith(
- "org.eclipse.jdt")) {
- // don't check Eclipse SDK bundles
- continue;
- }
-
- if (bundle.getState() == Bundle.INSTALLED) {
- allBundlesOk = false;
- badBundles
- .append(OsgiStringUtils
- .nullSafeSymbolicName(bundle)
- + " ["
- + OsgiStringUtils
- .bundleStateAsString(bundle) + "]");
- }
-
- if (bundlesToStart.contains(bundle.getSymbolicName())
- && bundle.getState() != Bundle.ACTIVE) {
- allBundlesOk = false;
- badBundles.append(OsgiStringUtils
- .nullSafeSymbolicName(bundle)
- + " ["
- + OsgiStringUtils.bundleStateAsString(bundle)
- + "]\n");
- }
- }
-
- if (allBundlesOk)
- break;// while
-
- sleep(1000);
-
- duration = System.currentTimeMillis() - begin;
- }
-
- if (!allBundlesOk) {
- listInstalledBundles();
- throw new SlcException(
- "Some bundles are not at the proper status:\n" + badBundles);
- }
- }
-
- /**
- * Make sure that the application context of the started bundles starting
- * with this prefix are properly initialized
- */
- protected void assertStartedBundlesApplicationContext(
- String bundleSymbolicNamesPrefix) {
- List<String> bundlesToStart = getBundlesToStart();
- for (String bundleSName : bundlesToStart) {
- if (bundleSName.startsWith(bundleSymbolicNamesPrefix))
- assertBundleApplicationContext(bundleSName);
- }
- }
-
- /**
- * Make sure that the application context of this bundle is properly
- * initialized
- */
- protected void assertBundleApplicationContext(String bundleSymbolicName) {
- String filter = "(Bundle-SymbolicName=" + bundleSymbolicName + ")";
- // Wait for application context to be ready
- try {
- ServiceReference[] srs = getServiceRefSynchronous(
- ApplicationContext.class.getName(), filter);
- if (srs == null)
- throw new SlcException("No application context for "
- + bundleSymbolicName);
- } catch (InvalidSyntaxException e) {
- throw new SlcException(
- "Unexpected exception when looking for application context for bundle "
- + bundleSymbolicName, e);
- }
- log.info("Application context of bundle " + bundleSymbolicName
- + " is initalized.");
- }
-
- protected ServiceReference[] getServiceRefSynchronous(String clss,
- String filter) throws InvalidSyntaxException {
- // FIXME: factorize
- if (log.isTraceEnabled())
- log.debug("Filter: '" + filter + "'");
- ServiceReference[] sfs = null;
- boolean waiting = true;
- long begin = System.currentTimeMillis();
- do {
- sfs = getBundleContext().getServiceReferences(clss, filter);
-
- if (sfs != null)
- waiting = false;
-
- sleep(100);
- if (System.currentTimeMillis() - begin > getDefaultTimeout())
- throw new SlcException("Search of services " + clss
- + " with filter " + filter + " timed out.");
- } while (waiting);
-
- return sfs;
- }
-
- protected BundleContext getBundleContext() {
- return osgiBoot.getBundleContext();
- }
-
- /** Default is 30s */
- protected long getResolvedTimeout() {
- return 30 * 1000l;
- }
-
- /** Default is 10s */
- protected long getDefaultTimeout() {
- return 10 * 1000l;
- }
-
- final protected void sleep(long duration) {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- // silent
- }
- }
-}
import java.util.Map;
import java.util.TreeMap;
+import org.argeo.slc.equinox.unit.AbstractOsgiRuntimeTestCase;
import org.argeo.slc.osgiboot.OsgiBoot;
public class HelloTest extends AbstractOsgiRuntimeTestCase {
package org.argeo.slc.osgi.test;
+import org.argeo.slc.equinox.unit.AbstractOsgiRuntimeTestCase;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
<instructions>
<Fragment-Host>org.argeo.slc.support.simple</Fragment-Host>
<Import-Package>*,org.hibernate.proxy</Import-Package>
-
- <!--
- <Export-Package> org.argeo.slc.hibernate.* </Export-Package>
- <Import-Package>*,org.argeo.slc.*;resolution:=optional,
- org.argeo.slc.execution;resolution:=optional,
- org.argeo.slc.runtime;resolution:=optional,
- org.argeo.slc.structure;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.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
- </Import-Package>
- <Fragment-Host>com.springsource.org.hibernate</Fragment-Host>
- -->
</instructions>
</configuration>
</plugin>
<groupId>org.argeo.slc.runtime</groupId>
<artifactId>org.argeo.slc.support.simple</artifactId>
</dependency>
- <dependency>
- <groupId>org.argeo.slc.runtime</groupId>
- <artifactId>org.argeo.slc.support.simple</artifactId>
- <classifier>tests</classifier>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>javax.transaction</groupId>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
+ <!--
<executions>
<execution>
<goals>
</configuration>
</execution>
</executions>
+ -->
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
--- /dev/null
+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<String, Object> values = new HashMap<String, Object>();
+ 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<String, ExecutionSpecAttribute> attributes = new HashMap<String, ExecutionSpecAttribute>();
+
+ 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;
+ }
+}
--- /dev/null
+package org.argeo.slc.unit.process;\r
+\r
+import static junit.framework.Assert.assertEquals;\r
+import static junit.framework.Assert.assertNotNull;\r
+import static org.argeo.slc.unit.UnitUtils.assertDateSec;\r
+\r
+import java.util.UUID;\r
+\r
+import org.argeo.slc.process.SlcExecution;\r
+import org.argeo.slc.process.SlcExecutionStep;\r
+\r
+public abstract class SlcExecutionTestUtils {\r
+\r
+ public static SlcExecution createSimpleSlcExecution() {\r
+ SlcExecution slcExec = new SlcExecution();\r
+ slcExec.setUuid(UUID.randomUUID().toString());\r
+ slcExec.setHost("localhost");\r
+ slcExec.setUser("user");\r
+ slcExec.setType("slcAnt");\r
+ slcExec.setStatus("STARTED");\r
+ slcExec.getAttributes().put("ant.file", "/test");\r
+ return slcExec;\r
+ }\r
+\r
+ public static void assertSlcExecution(SlcExecution expected,\r
+ SlcExecution reached) {\r
+ assertNotNull(reached);\r
+ assertEquals(expected.getHost(), reached.getHost());\r
+ assertEquals(expected.getUser(), reached.getUser());\r
+ assertEquals(expected.getType(), reached.getType());\r
+ assertEquals(expected.getStatus(), reached.getStatus());\r
+\r
+ // Attributes\r
+ assertEquals(expected.getAttributes().size(), reached.getAttributes()\r
+ .size());\r
+ for (String key : expected.getAttributes().keySet()) {\r
+ String expectedValue = expected.getAttributes().get(key);\r
+ String reachedValue = reached.getAttributes().get(key);\r
+ assertNotNull(reachedValue);\r
+ assertEquals(expectedValue, reachedValue);\r
+ }\r
+\r
+ assertEquals(expected.getSteps().size(), reached.getSteps().size());\r
+ for (int i = 0; i < expected.getSteps().size(); i++) {\r
+ SlcExecutionStep stepExpected = expected.getSteps().get(i);\r
+ SlcExecutionStep stepReached = reached.getSteps().get(i);\r
+ assertSlcExecutionStep(stepExpected, stepReached);\r
+ }\r
+ }\r
+\r
+ public static void assertSlcExecutionStep(SlcExecutionStep expected,\r
+ SlcExecutionStep reached) {\r
+ assertNotNull(reached);\r
+ assertEquals(expected.getUuid(), reached.getUuid());\r
+ assertEquals(expected.getType(), reached.getType());\r
+ assertEquals(expected.logAsString(), reached.logAsString());\r
+ assertDateSec(expected.getBegin(), reached.getBegin());\r
+ }\r
+\r
+ private SlcExecutionTestUtils() {\r
+\r
+ }\r
+}\r
--- /dev/null
+package org.argeo.slc.unit.test.tree;\r
+\r
+import java.util.UUID;\r
+\r
+import org.argeo.slc.build.Distribution;\r
+import org.argeo.slc.core.structure.SimpleSElement;\r
+import org.argeo.slc.core.structure.tree.TreeSPath;\r
+import org.argeo.slc.core.structure.tree.TreeSRegistry;\r
+import org.argeo.slc.core.test.SimpleResultPart;\r
+import org.argeo.slc.core.test.SimpleTestRun;\r
+import org.argeo.slc.core.test.tree.PartSubList;\r
+import org.argeo.slc.core.test.tree.TreeTestResult;\r
+import org.argeo.slc.deploy.DeployedSystem;\r
+import org.argeo.slc.deploy.DeploymentData;\r
+import org.argeo.slc.deploy.TargetData;\r
+import org.argeo.slc.msg.test.tree.ResultPartRequest;\r
+import org.argeo.slc.process.SlcExecution;\r
+import org.argeo.slc.process.SlcExecutionStep;\r
+import org.argeo.slc.test.TestStatus;\r
+import org.argeo.slc.unit.process.SlcExecutionTestUtils;\r
+\r
+public abstract class TreeTestResultTestUtils {\r
+\r
+ public static TreeTestResult createSimpleTreeTestResult() {\r
+ TreeTestResult treeTestResult = new TreeTestResult();\r
+ treeTestResult.setUuid(UUID.randomUUID().toString());\r
+ return treeTestResult;\r
+ }\r
+\r
+ public static TreeTestResult createCompleteTreeTestResult() {\r
+ SlcExecution slcExecution = SlcExecutionTestUtils\r
+ .createSimpleSlcExecution();\r
+ SlcExecutionStep step = new SlcExecutionStep("JUnit step");\r
+ slcExecution.getSteps().add(step);\r
+\r
+ TreeTestResult ttr = createMinimalConsistentTreeTestResult(slcExecution);\r
+\r
+ ttr.addResultPart(createSimpleResultPartPassed());\r
+ ttr.addResultPart(createSimpleResultPartFailed());\r
+ ttr.addResultPart(createSimpleResultPartError());\r
+ return ttr;\r
+ }\r
+\r
+ public static TreeTestResult createMinimalConsistentTreeTestResult(\r
+ SlcExecution slcExecution) {\r
+ SimpleTestRun testRun = new SimpleTestRun();\r
+ testRun.setUuid(UUID.randomUUID().toString());\r
+\r
+ String pathStr = "/test";\r
+ TreeSPath path = new TreeSPath(pathStr);\r
+\r
+ TreeSRegistry registry = new TreeSRegistry();\r
+ SimpleSElement elem = new SimpleSElement("Unit Test");\r
+ elem.getTags().put("myTag", "myTagValue");\r
+ registry.register(path, elem);\r
+\r
+ TreeTestResult ttr = createSimpleTreeTestResult();\r
+ ttr.getAttributes().put("testCase", "UNIT");\r
+\r
+ // Simulate test run\r
+ ttr.notifyCurrentPath(registry, path);\r
+ ttr.notifyTestRun(testRun);\r
+ testRun.setTestResult(ttr);\r
+ testRun.setDeployedSystem(new DeployedSystem() {\r
+ private String uuid = UUID.randomUUID().toString();\r
+\r
+ public String getDeployedSystemId() {\r
+ return uuid;\r
+ }\r
+\r
+ public Distribution getDistribution() {\r
+ return null;\r
+ }\r
+\r
+ public DeploymentData getDeploymentData() {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ public TargetData getTargetData() {\r
+ // TODO Auto-generated method stub\r
+ return null;\r
+ }\r
+\r
+ });\r
+ testRun.notifySlcExecution(slcExecution);\r
+ return ttr;\r
+ }\r
+\r
+ public static SimpleResultPart createSimpleResultPartPassed() {\r
+ SimpleResultPart partPassed = new SimpleResultPart();\r
+ String msgPassed = "message\nnew line";\r
+ partPassed.setStatus(TestStatus.PASSED);\r
+ partPassed.setMessage(msgPassed);\r
+ return partPassed;\r
+ }\r
+\r
+ public static SimpleResultPart createSimpleResultPartFailed() {\r
+ SimpleResultPart partFailed = new SimpleResultPart();\r
+ String msgFailed = "too bad";\r
+ partFailed.setStatus(TestStatus.FAILED);\r
+ partFailed.setMessage(msgFailed);\r
+ return partFailed;\r
+ }\r
+\r
+ public static SimpleResultPart createSimpleResultPartError() {\r
+ SimpleResultPart partFailed = new SimpleResultPart();\r
+ String msgFailed = "crashed\nanother line";\r
+ partFailed.setStatus(TestStatus.ERROR);\r
+ partFailed.setMessage(msgFailed);\r
+ partFailed.setException(new Exception("Test Exception"));\r
+ return partFailed;\r
+ }\r
+\r
+ public static ResultPartRequest createSimpleResultPartRequest(\r
+ TreeTestResult ttr) {\r
+ TreeSPath path = ttr.getCurrentPath();\r
+ PartSubList lst = ttr.getResultParts().get(path);\r
+ SimpleResultPart part = (SimpleResultPart) lst.getParts().get(2);\r
+\r
+ ResultPartRequest req = new ResultPartRequest(ttr, path, part);\r
+ req.setPath(ttr.getCurrentPath());\r
+\r
+ return req;\r
+ }\r
+\r
+ private TreeTestResultTestUtils() {\r
+\r
+ }\r
+}\r
--- /dev/null
+package org.argeo.slc.unit.test.tree;\r
+\r
+import static junit.framework.Assert.assertEquals;\r
+import static junit.framework.Assert.assertNotNull;\r
+import static junit.framework.Assert.assertNull;\r
+import static junit.framework.Assert.fail;\r
+import static org.argeo.slc.unit.UnitUtils.assertDateSec;\r
+\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+import org.argeo.slc.core.structure.SimpleSElement;\r
+import org.argeo.slc.core.structure.tree.TreeSPath;\r
+import org.argeo.slc.core.test.SimpleResultPart;\r
+import org.argeo.slc.core.test.tree.PartSubList;\r
+import org.argeo.slc.core.test.tree.TreeTestResult;\r
+import org.argeo.slc.test.TestResultPart;\r
+\r
+/** Utilities for unit tests. */\r
+public class UnitTestTreeUtil {\r
+ private final static Log log = LogFactory.getLog(UnitTestTreeUtil.class);\r
+\r
+ public static void assertTreeTestResult(TreeTestResult expected,\r
+ TreeTestResult reached) {\r
+ assertEquals(expected.getUuid(), reached.getUuid());\r
+ assertDateSec(expected.getCloseDate(), reached.getCloseDate());\r
+\r
+ // Attributes\r
+ assertEquals(expected.getAttributes().size(), reached.getAttributes()\r
+ .size());\r
+ for (String key : expected.getAttributes().keySet()) {\r
+ String expectedValue = expected.getAttributes().get(key);\r
+ String reachedValue = reached.getAttributes().get(key);\r
+ assertNotNull(reachedValue);\r
+ assertEquals(expectedValue, reachedValue);\r
+ }\r
+\r
+ // Result parts\r
+ assertEquals(expected.getResultParts().size(), reached.getResultParts()\r
+ .size());\r
+ for (TreeSPath path : expected.getResultParts().keySet()) {\r
+ PartSubList lstExpected = expected.getResultParts().get(path);\r
+ PartSubList lstReached = expected.getResultParts().get(path);\r
+ if (lstReached == null) {\r
+ fail("No result for path " + path);\r
+ return;\r
+ }\r
+ assertPartSubList(lstExpected, lstReached);\r
+ }\r
+\r
+ // Elements\r
+ assertEquals(expected.getElements().size(), reached.getElements()\r
+ .size());\r
+ for (TreeSPath path : expected.getElements().keySet()) {\r
+ // String nameExpected = expected.getElements().get(path);\r
+ // String nameReached = expected.getElements().get(path);\r
+ SimpleSElement elemExpected = (SimpleSElement) expected\r
+ .getElements().get(path);\r
+ SimpleSElement elemReached = (SimpleSElement) expected\r
+ .getElements().get(path);\r
+ assertNotNull(elemReached);\r
+ assertElements(elemExpected, elemReached);\r
+ }\r
+\r
+ }\r
+\r
+ public static void assertElements(SimpleSElement expected,\r
+ SimpleSElement reached) {\r
+ assertEquals(expected.getLabel(), reached.getLabel());\r
+ assertEquals(expected.getTags().size(), reached.getTags().size());\r
+ for (String tagName : expected.getTags().keySet()) {\r
+ String expectedTagValue = expected.getTags().get(tagName);\r
+ String reachedTagValue = reached.getTags().get(tagName);\r
+ assertNotNull(reachedTagValue);\r
+ assertEquals(expectedTagValue, reachedTagValue);\r
+ }\r
+ }\r
+\r
+ public static void assertPartSubList(PartSubList lstExpected,\r
+ PartSubList lstReached) {\r
+ assertEquals(lstExpected.getParts().size(), lstReached.getParts()\r
+ .size());\r
+ for (int i = 0; i < lstExpected.getParts().size(); i++) {\r
+ assertPart(lstExpected.getParts().get(i), lstReached.getParts()\r
+ .get(i));\r
+ }\r
+ }\r
+\r
+ /** Asserts one part of a tree test result */\r
+ public static void assertPart(TreeTestResult testResult, String pathStr,\r
+ int index, Integer status, String message) {\r
+ TreeSPath path = new TreeSPath(pathStr);\r
+ PartSubList list = testResult.getResultParts().get(path);\r
+ if (list == null) {\r
+ fail("No result for path " + path);\r
+ return;\r
+ }\r
+ if (index >= list.getParts().size()) {\r
+ fail("Not enough parts.");\r
+ }\r
+ SimpleResultPart part = (SimpleResultPart) list.getParts().get(index);\r
+ assertPart(part, status, message, null, part.getTestRunUuid(), true);\r
+ }\r
+\r
+ public static void assertPart(TestResultPart expected,\r
+ TestResultPart reached) {\r
+ String expectedTestRunUuid = null;\r
+ if (expected instanceof SimpleResultPart) {\r
+ expectedTestRunUuid = ((SimpleResultPart) expected)\r
+ .getTestRunUuid();\r
+ }\r
+\r
+ assertPart(reached, expected.getStatus(), expected.getMessage(),\r
+ expected.getExceptionMessage(), expectedTestRunUuid, false);\r
+ }\r
+\r
+ /** Assert one part of a tree test result. */\r
+ private static void assertPart(TestResultPart part, Integer status,\r
+ String message, String exceptionDescription,\r
+ String expectedTestRunUuid, boolean skipExceptionMessage) {\r
+ assertEquals(status, part.getStatus());\r
+\r
+ if (message != null) {\r
+ if (log.isTraceEnabled()) {\r
+ log.trace("Expected message:" + message);\r
+ log.trace("Reached message:" + part.getMessage());\r
+ }\r
+ assertEquals(message, part.getMessage());\r
+ }\r
+\r
+ if (!skipExceptionMessage) {\r
+ if (exceptionDescription == null) {\r
+ assertNull(part.getExceptionMessage());\r
+ } else {\r
+ if (log.isTraceEnabled()) {\r
+ log.trace("Expected exception message:"\r
+ + exceptionDescription);\r
+ log.trace("Reached exception message:"\r
+ + part.getExceptionMessage());\r
+ }\r
+\r
+ assertEquals(exceptionDescription, part.getExceptionMessage());\r
+ }\r
+ }\r
+\r
+ if (expectedTestRunUuid != null) {\r
+ SimpleResultPart reachedPart = (SimpleResultPart) part;\r
+ assertNotNull(reachedPart.getTestRunUuid());\r
+ assertEquals(expectedTestRunUuid, reachedPart.getTestRunUuid());\r
+ } else {\r
+ if (part instanceof SimpleResultPart) {\r
+ assertNull(((SimpleResultPart) part).getTestRunUuid());\r
+ }\r
+\r
+ }\r
+\r
+ }\r
+\r
+ public static void describeTreeTestResult(TreeTestResult ttr) {\r
+ log.info("TreeTestResult #" + ttr.getUuid());\r
+ log.info(" Close date: " + ttr.getCloseDate());\r
+ log.info(" Attributes:");\r
+ for (String key : ttr.getAttributes().keySet())\r
+ log.info(" " + key + "=" + ttr.getAttributes().get(key));\r
+\r
+ log.info(" Result parts: (size=" + ttr.getResultParts().size() + ")");\r
+ for (TreeSPath path : ttr.getResultParts().keySet()) {\r
+ log.info(" Path: " + path);\r
+ PartSubList lst = ttr.getResultParts().get(path);\r
+ for (TestResultPart part : lst.getParts())\r
+ log.info(" " + part);\r
+ }\r
+\r
+ log.info(" Elements: (size=" + ttr.getElements().size() + ")");\r
+ for (TreeSPath path : ttr.getElements().keySet()) {\r
+ SimpleSElement elem = (SimpleSElement) ttr.getElements().get(path);\r
+ log.info(" Path: " + path + ", Element: " + elem.getLabel());\r
+ for (String tag : elem.getTags().keySet())\r
+ log.info(" " + tag + "=" + elem.getTags().get(tag));\r
+ }\r
+\r
+ }\r
+\r
+ /** Makes sure this is a singleton */\r
+ private UnitTestTreeUtil() {\r
+\r
+ }\r
+}\r
+++ /dev/null
-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<String, Object> values = new HashMap<String, Object>();
- 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<String, ExecutionSpecAttribute> attributes = new HashMap<String, ExecutionSpecAttribute>();
-
- 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;
- }
-}
+++ /dev/null
-package org.argeo.slc.unit.process;\r
-\r
-import static junit.framework.Assert.assertEquals;\r
-import static junit.framework.Assert.assertNotNull;\r
-import static org.argeo.slc.unit.UnitUtils.assertDateSec;\r
-\r
-import java.util.UUID;\r
-\r
-import org.argeo.slc.process.SlcExecution;\r
-import org.argeo.slc.process.SlcExecutionStep;\r
-\r
-public abstract class SlcExecutionTestUtils {\r
-\r
- public static SlcExecution createSimpleSlcExecution() {\r
- SlcExecution slcExec = new SlcExecution();\r
- slcExec.setUuid(UUID.randomUUID().toString());\r
- slcExec.setHost("localhost");\r
- slcExec.setUser("user");\r
- slcExec.setType("slcAnt");\r
- slcExec.setStatus("STARTED");\r
- slcExec.getAttributes().put("ant.file", "/test");\r
- return slcExec;\r
- }\r
-\r
- public static void assertSlcExecution(SlcExecution expected,\r
- SlcExecution reached) {\r
- assertNotNull(reached);\r
- assertEquals(expected.getHost(), reached.getHost());\r
- assertEquals(expected.getUser(), reached.getUser());\r
- assertEquals(expected.getType(), reached.getType());\r
- assertEquals(expected.getStatus(), reached.getStatus());\r
-\r
- // Attributes\r
- assertEquals(expected.getAttributes().size(), reached.getAttributes()\r
- .size());\r
- for (String key : expected.getAttributes().keySet()) {\r
- String expectedValue = expected.getAttributes().get(key);\r
- String reachedValue = reached.getAttributes().get(key);\r
- assertNotNull(reachedValue);\r
- assertEquals(expectedValue, reachedValue);\r
- }\r
-\r
- assertEquals(expected.getSteps().size(), reached.getSteps().size());\r
- for (int i = 0; i < expected.getSteps().size(); i++) {\r
- SlcExecutionStep stepExpected = expected.getSteps().get(i);\r
- SlcExecutionStep stepReached = reached.getSteps().get(i);\r
- assertSlcExecutionStep(stepExpected, stepReached);\r
- }\r
- }\r
-\r
- public static void assertSlcExecutionStep(SlcExecutionStep expected,\r
- SlcExecutionStep reached) {\r
- assertNotNull(reached);\r
- assertEquals(expected.getUuid(), reached.getUuid());\r
- assertEquals(expected.getType(), reached.getType());\r
- assertEquals(expected.logAsString(), reached.logAsString());\r
- assertDateSec(expected.getBegin(), reached.getBegin());\r
- }\r
-\r
- private SlcExecutionTestUtils() {\r
-\r
- }\r
-}\r
+++ /dev/null
-package org.argeo.slc.unit.test.tree;\r
-\r
-import java.util.UUID;\r
-\r
-import org.argeo.slc.build.Distribution;\r
-import org.argeo.slc.core.structure.SimpleSElement;\r
-import org.argeo.slc.core.structure.tree.TreeSPath;\r
-import org.argeo.slc.core.structure.tree.TreeSRegistry;\r
-import org.argeo.slc.core.test.SimpleResultPart;\r
-import org.argeo.slc.core.test.SimpleTestRun;\r
-import org.argeo.slc.core.test.tree.PartSubList;\r
-import org.argeo.slc.core.test.tree.TreeTestResult;\r
-import org.argeo.slc.deploy.DeployedSystem;\r
-import org.argeo.slc.deploy.DeploymentData;\r
-import org.argeo.slc.deploy.TargetData;\r
-import org.argeo.slc.msg.test.tree.ResultPartRequest;\r
-import org.argeo.slc.process.SlcExecution;\r
-import org.argeo.slc.process.SlcExecutionStep;\r
-import org.argeo.slc.test.TestStatus;\r
-import org.argeo.slc.unit.process.SlcExecutionTestUtils;\r
-\r
-public abstract class TreeTestResultTestUtils {\r
-\r
- public static TreeTestResult createSimpleTreeTestResult() {\r
- TreeTestResult treeTestResult = new TreeTestResult();\r
- treeTestResult.setUuid(UUID.randomUUID().toString());\r
- return treeTestResult;\r
- }\r
-\r
- public static TreeTestResult createCompleteTreeTestResult() {\r
- SlcExecution slcExecution = SlcExecutionTestUtils\r
- .createSimpleSlcExecution();\r
- SlcExecutionStep step = new SlcExecutionStep("JUnit step");\r
- slcExecution.getSteps().add(step);\r
-\r
- TreeTestResult ttr = createMinimalConsistentTreeTestResult(slcExecution);\r
-\r
- ttr.addResultPart(createSimpleResultPartPassed());\r
- ttr.addResultPart(createSimpleResultPartFailed());\r
- ttr.addResultPart(createSimpleResultPartError());\r
- return ttr;\r
- }\r
-\r
- public static TreeTestResult createMinimalConsistentTreeTestResult(\r
- SlcExecution slcExecution) {\r
- SimpleTestRun testRun = new SimpleTestRun();\r
- testRun.setUuid(UUID.randomUUID().toString());\r
-\r
- String pathStr = "/test";\r
- TreeSPath path = new TreeSPath(pathStr);\r
-\r
- TreeSRegistry registry = new TreeSRegistry();\r
- SimpleSElement elem = new SimpleSElement("Unit Test");\r
- elem.getTags().put("myTag", "myTagValue");\r
- registry.register(path, elem);\r
-\r
- TreeTestResult ttr = createSimpleTreeTestResult();\r
- ttr.getAttributes().put("testCase", "UNIT");\r
-\r
- // Simulate test run\r
- ttr.notifyCurrentPath(registry, path);\r
- ttr.notifyTestRun(testRun);\r
- testRun.setTestResult(ttr);\r
- testRun.setDeployedSystem(new DeployedSystem() {\r
- private String uuid = UUID.randomUUID().toString();\r
-\r
- public String getDeployedSystemId() {\r
- return uuid;\r
- }\r
-\r
- public Distribution getDistribution() {\r
- return null;\r
- }\r
-\r
- public DeploymentData getDeploymentData() {\r
- // TODO Auto-generated method stub\r
- return null;\r
- }\r
-\r
- public TargetData getTargetData() {\r
- // TODO Auto-generated method stub\r
- return null;\r
- }\r
-\r
- });\r
- testRun.notifySlcExecution(slcExecution);\r
- return ttr;\r
- }\r
-\r
- public static SimpleResultPart createSimpleResultPartPassed() {\r
- SimpleResultPart partPassed = new SimpleResultPart();\r
- String msgPassed = "message\nnew line";\r
- partPassed.setStatus(TestStatus.PASSED);\r
- partPassed.setMessage(msgPassed);\r
- return partPassed;\r
- }\r
-\r
- public static SimpleResultPart createSimpleResultPartFailed() {\r
- SimpleResultPart partFailed = new SimpleResultPart();\r
- String msgFailed = "too bad";\r
- partFailed.setStatus(TestStatus.FAILED);\r
- partFailed.setMessage(msgFailed);\r
- return partFailed;\r
- }\r
-\r
- public static SimpleResultPart createSimpleResultPartError() {\r
- SimpleResultPart partFailed = new SimpleResultPart();\r
- String msgFailed = "crashed\nanother line";\r
- partFailed.setStatus(TestStatus.ERROR);\r
- partFailed.setMessage(msgFailed);\r
- partFailed.setException(new Exception("Test Exception"));\r
- return partFailed;\r
- }\r
-\r
- public static ResultPartRequest createSimpleResultPartRequest(\r
- TreeTestResult ttr) {\r
- TreeSPath path = ttr.getCurrentPath();\r
- PartSubList lst = ttr.getResultParts().get(path);\r
- SimpleResultPart part = (SimpleResultPart) lst.getParts().get(2);\r
-\r
- ResultPartRequest req = new ResultPartRequest(ttr, path, part);\r
- req.setPath(ttr.getCurrentPath());\r
-\r
- return req;\r
- }\r
-\r
- private TreeTestResultTestUtils() {\r
-\r
- }\r
-}\r
+++ /dev/null
-package org.argeo.slc.unit.test.tree;\r
-\r
-import static junit.framework.Assert.assertEquals;\r
-import static junit.framework.Assert.assertNotNull;\r
-import static junit.framework.Assert.assertNull;\r
-import static junit.framework.Assert.fail;\r
-import static org.argeo.slc.unit.UnitUtils.assertDateSec;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.argeo.slc.core.structure.SimpleSElement;\r
-import org.argeo.slc.core.structure.tree.TreeSPath;\r
-import org.argeo.slc.core.test.SimpleResultPart;\r
-import org.argeo.slc.core.test.tree.PartSubList;\r
-import org.argeo.slc.core.test.tree.TreeTestResult;\r
-import org.argeo.slc.test.TestResultPart;\r
-\r
-/** Utilities for unit tests. */\r
-public class UnitTestTreeUtil {\r
- private final static Log log = LogFactory.getLog(UnitTestTreeUtil.class);\r
-\r
- public static void assertTreeTestResult(TreeTestResult expected,\r
- TreeTestResult reached) {\r
- assertEquals(expected.getUuid(), reached.getUuid());\r
- assertDateSec(expected.getCloseDate(), reached.getCloseDate());\r
-\r
- // Attributes\r
- assertEquals(expected.getAttributes().size(), reached.getAttributes()\r
- .size());\r
- for (String key : expected.getAttributes().keySet()) {\r
- String expectedValue = expected.getAttributes().get(key);\r
- String reachedValue = reached.getAttributes().get(key);\r
- assertNotNull(reachedValue);\r
- assertEquals(expectedValue, reachedValue);\r
- }\r
-\r
- // Result parts\r
- assertEquals(expected.getResultParts().size(), reached.getResultParts()\r
- .size());\r
- for (TreeSPath path : expected.getResultParts().keySet()) {\r
- PartSubList lstExpected = expected.getResultParts().get(path);\r
- PartSubList lstReached = expected.getResultParts().get(path);\r
- if (lstReached == null) {\r
- fail("No result for path " + path);\r
- return;\r
- }\r
- assertPartSubList(lstExpected, lstReached);\r
- }\r
-\r
- // Elements\r
- assertEquals(expected.getElements().size(), reached.getElements()\r
- .size());\r
- for (TreeSPath path : expected.getElements().keySet()) {\r
- // String nameExpected = expected.getElements().get(path);\r
- // String nameReached = expected.getElements().get(path);\r
- SimpleSElement elemExpected = (SimpleSElement) expected\r
- .getElements().get(path);\r
- SimpleSElement elemReached = (SimpleSElement) expected\r
- .getElements().get(path);\r
- assertNotNull(elemReached);\r
- assertElements(elemExpected, elemReached);\r
- }\r
-\r
- }\r
-\r
- public static void assertElements(SimpleSElement expected,\r
- SimpleSElement reached) {\r
- assertEquals(expected.getLabel(), reached.getLabel());\r
- assertEquals(expected.getTags().size(), reached.getTags().size());\r
- for (String tagName : expected.getTags().keySet()) {\r
- String expectedTagValue = expected.getTags().get(tagName);\r
- String reachedTagValue = reached.getTags().get(tagName);\r
- assertNotNull(reachedTagValue);\r
- assertEquals(expectedTagValue, reachedTagValue);\r
- }\r
- }\r
-\r
- public static void assertPartSubList(PartSubList lstExpected,\r
- PartSubList lstReached) {\r
- assertEquals(lstExpected.getParts().size(), lstReached.getParts()\r
- .size());\r
- for (int i = 0; i < lstExpected.getParts().size(); i++) {\r
- assertPart(lstExpected.getParts().get(i), lstReached.getParts()\r
- .get(i));\r
- }\r
- }\r
-\r
- /** Asserts one part of a tree test result */\r
- public static void assertPart(TreeTestResult testResult, String pathStr,\r
- int index, Integer status, String message) {\r
- TreeSPath path = new TreeSPath(pathStr);\r
- PartSubList list = testResult.getResultParts().get(path);\r
- if (list == null) {\r
- fail("No result for path " + path);\r
- return;\r
- }\r
- if (index >= list.getParts().size()) {\r
- fail("Not enough parts.");\r
- }\r
- SimpleResultPart part = (SimpleResultPart) list.getParts().get(index);\r
- assertPart(part, status, message, null, part.getTestRunUuid(), true);\r
- }\r
-\r
- public static void assertPart(TestResultPart expected,\r
- TestResultPart reached) {\r
- String expectedTestRunUuid = null;\r
- if (expected instanceof SimpleResultPart) {\r
- expectedTestRunUuid = ((SimpleResultPart) expected)\r
- .getTestRunUuid();\r
- }\r
-\r
- assertPart(reached, expected.getStatus(), expected.getMessage(),\r
- expected.getExceptionMessage(), expectedTestRunUuid, false);\r
- }\r
-\r
- /** Assert one part of a tree test result. */\r
- private static void assertPart(TestResultPart part, Integer status,\r
- String message, String exceptionDescription,\r
- String expectedTestRunUuid, boolean skipExceptionMessage) {\r
- assertEquals(status, part.getStatus());\r
-\r
- if (message != null) {\r
- if (log.isTraceEnabled()) {\r
- log.trace("Expected message:" + message);\r
- log.trace("Reached message:" + part.getMessage());\r
- }\r
- assertEquals(message, part.getMessage());\r
- }\r
-\r
- if (!skipExceptionMessage) {\r
- if (exceptionDescription == null) {\r
- assertNull(part.getExceptionMessage());\r
- } else {\r
- if (log.isTraceEnabled()) {\r
- log.trace("Expected exception message:"\r
- + exceptionDescription);\r
- log.trace("Reached exception message:"\r
- + part.getExceptionMessage());\r
- }\r
-\r
- assertEquals(exceptionDescription, part.getExceptionMessage());\r
- }\r
- }\r
-\r
- if (expectedTestRunUuid != null) {\r
- SimpleResultPart reachedPart = (SimpleResultPart) part;\r
- assertNotNull(reachedPart.getTestRunUuid());\r
- assertEquals(expectedTestRunUuid, reachedPart.getTestRunUuid());\r
- } else {\r
- if (part instanceof SimpleResultPart) {\r
- assertNull(((SimpleResultPart) part).getTestRunUuid());\r
- }\r
-\r
- }\r
-\r
- }\r
-\r
- public static void describeTreeTestResult(TreeTestResult ttr) {\r
- log.info("TreeTestResult #" + ttr.getUuid());\r
- log.info(" Close date: " + ttr.getCloseDate());\r
- log.info(" Attributes:");\r
- for (String key : ttr.getAttributes().keySet())\r
- log.info(" " + key + "=" + ttr.getAttributes().get(key));\r
-\r
- log.info(" Result parts: (size=" + ttr.getResultParts().size() + ")");\r
- for (TreeSPath path : ttr.getResultParts().keySet()) {\r
- log.info(" Path: " + path);\r
- PartSubList lst = ttr.getResultParts().get(path);\r
- for (TestResultPart part : lst.getParts())\r
- log.info(" " + part);\r
- }\r
-\r
- log.info(" Elements: (size=" + ttr.getElements().size() + ")");\r
- for (TreeSPath path : ttr.getElements().keySet()) {\r
- SimpleSElement elem = (SimpleSElement) ttr.getElements().get(path);\r
- log.info(" Path: " + path + ", Element: " + elem.getLabel());\r
- for (String tag : elem.getTags().keySet())\r
- log.info(" " + tag + "=" + elem.getTags().get(tag));\r
- }\r
-\r
- }\r
-\r
- /** Makes sure this is a singleton */\r
- private UnitTestTreeUtil() {\r
-\r
- }\r
-}\r