Move unit tests
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 4 Jun 2009 18:27:19 +0000 (18:27 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 4 Jun 2009 18:27:19 +0000 (18:27 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@2472 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

21 files changed:
demo/src/test/java/org/argeo/slc/demo/StartStopDemoTest.java
integration-tests/org.argeo.slc.it.webapp/pom.xml
org.argeo.slc/pom.xml
runtime/org.argeo.slc.server/pom.xml
runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/unit/AbstractHttpClientTestCase.java [new file with mode: 0644]
runtime/org.argeo.slc.server/src/test/java/org/argeo/slc/server/unit/AbstractHttpClientTestCase.java [deleted file]
runtime/org.argeo.slc.support.castor/pom.xml
runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/equinox/unit/AbstractOsgiRuntimeTestCase.java [new file with mode: 0644]
runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/AbstractOsgiRuntimeTestCase.java [deleted file]
runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/HelloTest.java
runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/PlatformStartStopTest.java
runtime/org.argeo.slc.support.hibernate/pom.xml
runtime/org.argeo.slc.support.simple/pom.xml
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/unit/execution/ExecutionFlowDescriptorTestUtils.java [new file with mode: 0644]
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/unit/process/SlcExecutionTestUtils.java [new file with mode: 0644]
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/unit/test/tree/TreeTestResultTestUtils.java [new file with mode: 0644]
runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/unit/test/tree/UnitTestTreeUtil.java [new file with mode: 0644]
runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/unit/execution/ExecutionFlowDescriptorTestUtils.java [deleted file]
runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/unit/process/SlcExecutionTestUtils.java [deleted file]
runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/unit/test/tree/TreeTestResultTestUtils.java [deleted file]
runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/unit/test/tree/UnitTestTreeUtil.java [deleted file]

index 603ac265bb4f48a2ff751d2448f0626f2f069e57..78dc8ac5d590912a6f98faf46bd7bf62c29ecbff 100644 (file)
@@ -3,7 +3,7 @@ package org.argeo.slc.demo;
 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 {
index b2f369655c8743c75bd6a174227753ed22165afd..8464e034bb2e938310e462973ee94bd21565ca7c 100644 (file)
        <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>
index 665f1dcfddd0b212d1e10645cc443b539df755aa..33e4544642ea9f7fc8333e9d90e3b37aabcd06fe 100644 (file)
@@ -221,12 +221,6 @@ limitations under the License.
                                <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>
@@ -252,12 +246,6 @@ limitations under the License.
                                <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>
@@ -268,13 +256,6 @@ limitations under the License.
                                <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>
index a810403989773a4a30c4aa450b74cfc032fdab56..7ca71464fa18f94d0d0955a0e65ffdfbfa56ecb9 100644 (file)
@@ -24,6 +24,7 @@
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-jar-plugin</artifactId>
+                               <!-- 
                                <executions>
                                        <execution>
                                                <goals>
@@ -31,6 +32,7 @@
                                                </goals>
                                        </execution>
                                </executions>
+                                -->
                        </plugin>
                        <plugin>
                                <groupId>org.apache.felix</groupId>
diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/unit/AbstractHttpClientTestCase.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/unit/AbstractHttpClientTestCase.java
new file mode 100644 (file)
index 0000000..5d5dcea
--- /dev/null
@@ -0,0 +1,38 @@
+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;
+       }
+}
diff --git a/runtime/org.argeo.slc.server/src/test/java/org/argeo/slc/server/unit/AbstractHttpClientTestCase.java b/runtime/org.argeo.slc.server/src/test/java/org/argeo/slc/server/unit/AbstractHttpClientTestCase.java
deleted file mode 100644 (file)
index 5d5dcea..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-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;
-       }
-}
index 32d4aa701c3351bb7ab49a28f8ec037143c6b198..1b6e46670ba4dce61df91eb984e41f6f97350e79 100644 (file)
                        <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>
diff --git a/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/equinox/unit/AbstractOsgiRuntimeTestCase.java b/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/equinox/unit/AbstractOsgiRuntimeTestCase.java
new file mode 100644 (file)
index 0000000..7055c06
--- /dev/null
@@ -0,0 +1,232 @@
+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
+               }
+       }
+}
diff --git a/runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/AbstractOsgiRuntimeTestCase.java b/runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/AbstractOsgiRuntimeTestCase.java
deleted file mode 100644 (file)
index 36a0da9..0000000
+++ /dev/null
@@ -1,232 +0,0 @@
-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
-               }
-       }
-}
index 02d2ad5478fef8d7f0d2ba017d4ebdccef3a57c8..2c55612bf066ddf2d777a3f531d9ef652575c172 100644 (file)
@@ -5,6 +5,7 @@ import java.util.List;
 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 {
index 8fd2dcacb7a59284611bb2bd4f7676a3be438399..c7fafd3ddfd312976985436dd4af62e5b1e91570 100644 (file)
@@ -1,5 +1,6 @@
 package org.argeo.slc.osgi.test;
 
+import org.argeo.slc.equinox.unit.AbstractOsgiRuntimeTestCase;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 
index ced338e3d516ba430fb7acb959392ae51f7cb091..4c06b0ccd45158bd84341c2b10ee2041b8d1eb05 100644 (file)
                                        <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>
index d65ef683a4b374f4907ab60cd3e708c70ccd348b..f05ade58d2f8b71a59234e9ec20aa678074cfd06 100644 (file)
@@ -27,6 +27,7 @@
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-jar-plugin</artifactId>
+                               <!-- 
                                <executions>
                                        <execution>
                                                <goals>
@@ -39,6 +40,7 @@
                                                </configuration>
                                        </execution>
                                </executions>
+                                -->
                        </plugin>
                        <plugin>
                                <groupId>org.apache.felix</groupId>
diff --git a/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/unit/execution/ExecutionFlowDescriptorTestUtils.java b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/unit/execution/ExecutionFlowDescriptorTestUtils.java
new file mode 100644 (file)
index 0000000..14a34c7
--- /dev/null
@@ -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<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;
+       }
+}
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
new file mode 100644 (file)
index 0000000..bbea1bb
--- /dev/null
@@ -0,0 +1,63 @@
+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
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
new file mode 100644 (file)
index 0000000..cf4b0c1
--- /dev/null
@@ -0,0 +1,130 @@
+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
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
new file mode 100644 (file)
index 0000000..91467f3
--- /dev/null
@@ -0,0 +1,187 @@
+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
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
deleted file mode 100644 (file)
index 14a34c7..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-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;
-       }
-}
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
deleted file mode 100644 (file)
index bbea1bb..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-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
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
deleted file mode 100644 (file)
index cf4b0c1..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-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
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
deleted file mode 100644 (file)
index 91467f3..0000000
+++ /dev/null
@@ -1,187 +0,0 @@
-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