From: Mathieu Baudier Date: Thu, 4 Jun 2009 18:27:19 +0000 (+0000) Subject: Move unit tests X-Git-Tag: argeo-slc-2.1.7~1854 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=3f86e5c908d7db1d85e3f12b0798104654a1e12b;p=gpl%2Fargeo-slc.git Move unit tests git-svn-id: https://svn.argeo.org/slc/trunk@2472 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/demo/src/test/java/org/argeo/slc/demo/StartStopDemoTest.java b/demo/src/test/java/org/argeo/slc/demo/StartStopDemoTest.java index 603ac265b..78dc8ac5d 100644 --- a/demo/src/test/java/org/argeo/slc/demo/StartStopDemoTest.java +++ b/demo/src/test/java/org/argeo/slc/demo/StartStopDemoTest.java @@ -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 { diff --git a/integration-tests/org.argeo.slc.it.webapp/pom.xml b/integration-tests/org.argeo.slc.it.webapp/pom.xml index b2f369655..8464e034b 100644 --- a/integration-tests/org.argeo.slc.it.webapp/pom.xml +++ b/integration-tests/org.argeo.slc.it.webapp/pom.xml @@ -12,16 +12,6 @@ Argeo SLC Web Application Integration Tests - org.argeo.slc.maven maven-argeo-osgi-plugin @@ -104,7 +94,6 @@ org.argeo.slc.runtime org.argeo.slc.server - tests test diff --git a/org.argeo.slc/pom.xml b/org.argeo.slc/pom.xml index 665f1dcfd..33e454464 100644 --- a/org.argeo.slc/pom.xml +++ b/org.argeo.slc/pom.xml @@ -221,12 +221,6 @@ limitations under the License. org.argeo.slc.support.simple ${project.version} - - org.argeo.slc.runtime - org.argeo.slc.support.simple - ${project.version} - tests - org.apache.felix 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 index 000000000..5d5dcea5e --- /dev/null +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/server/unit/AbstractHttpClientTestCase.java @@ -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 index 5d5dcea5e..000000000 --- a/runtime/org.argeo.slc.server/src/test/java/org/argeo/slc/server/unit/AbstractHttpClientTestCase.java +++ /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; - } -} diff --git a/runtime/org.argeo.slc.support.castor/pom.xml b/runtime/org.argeo.slc.support.castor/pom.xml index 32d4aa701..1b6e46670 100644 --- a/runtime/org.argeo.slc.support.castor/pom.xml +++ b/runtime/org.argeo.slc.support.castor/pom.xml @@ -76,12 +76,6 @@ org.argeo.slc.runtime org.argeo.slc.support.simple - - org.argeo.slc.runtime - org.argeo.slc.support.simple - tests - test - org.springframework.ws diff --git a/runtime/org.argeo.slc.support.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 index 000000000..7055c063e --- /dev/null +++ b/runtime/org.argeo.slc.support.equinox/src/main/java/org/argeo/slc/equinox/unit/AbstractOsgiRuntimeTestCase.java @@ -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 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 getBundlesToStart() { + return new ArrayList(); + } + + 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 getOsgiApplicationContexts() + throws Exception { + Map map = new HashMap(); + 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 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 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 index 36a0da9f4..000000000 --- a/runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/AbstractOsgiRuntimeTestCase.java +++ /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 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 getBundlesToStart() { - return new ArrayList(); - } - - 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 getOsgiApplicationContexts() - throws Exception { - Map map = new HashMap(); - 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 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 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/HelloTest.java b/runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/HelloTest.java index 02d2ad547..2c55612bf 100644 --- a/runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/HelloTest.java +++ b/runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/HelloTest.java @@ -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 { diff --git a/runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/PlatformStartStopTest.java b/runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/PlatformStartStopTest.java index 8fd2dcacb..c7fafd3dd 100644 --- a/runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/PlatformStartStopTest.java +++ b/runtime/org.argeo.slc.support.equinox/src/test/java/org/argeo/slc/osgi/test/PlatformStartStopTest.java @@ -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; diff --git a/runtime/org.argeo.slc.support.hibernate/pom.xml b/runtime/org.argeo.slc.support.hibernate/pom.xml index ced338e3d..4c06b0ccd 100644 --- a/runtime/org.argeo.slc.support.hibernate/pom.xml +++ b/runtime/org.argeo.slc.support.hibernate/pom.xml @@ -35,24 +35,6 @@ org.argeo.slc.support.simple *,org.hibernate.proxy - - @@ -63,12 +45,6 @@ org.argeo.slc.runtime org.argeo.slc.support.simple - - org.argeo.slc.runtime - org.argeo.slc.support.simple - tests - test - javax.transaction diff --git a/runtime/org.argeo.slc.support.simple/pom.xml b/runtime/org.argeo.slc.support.simple/pom.xml index d65ef683a..f05ade58d 100644 --- a/runtime/org.argeo.slc.support.simple/pom.xml +++ b/runtime/org.argeo.slc.support.simple/pom.xml @@ -27,6 +27,7 @@ org.apache.maven.plugins maven-jar-plugin + org.apache.felix 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 index 000000000..14a34c7fb --- /dev/null +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/unit/execution/ExecutionFlowDescriptorTestUtils.java @@ -0,0 +1,48 @@ +package org.argeo.slc.unit.execution; + +import java.util.HashMap; +import java.util.Map; + +import org.argeo.slc.core.deploy.SimpleExecutables; +import org.argeo.slc.core.execution.DefaultExecutionSpec; +import org.argeo.slc.core.execution.PrimitiveSpecAttribute; +import org.argeo.slc.core.execution.PrimitiveValue; +import org.argeo.slc.core.execution.RefSpecAttribute; +import org.argeo.slc.core.execution.RefValue; +import org.argeo.slc.core.test.BasicTestData; +import org.argeo.slc.execution.ExecutionFlowDescriptor; +import org.argeo.slc.execution.ExecutionSpecAttribute; + +public class ExecutionFlowDescriptorTestUtils { + public static ExecutionFlowDescriptor createSimpleExecutionFlowDescriptor() { + ExecutionFlowDescriptor flowDescriptor = new ExecutionFlowDescriptor(); + flowDescriptor.setName("simpleFlow"); + Map values = new HashMap(); + values.put("primitiveInteger", new PrimitiveValue( + PrimitiveSpecAttribute.TYPE_INTEGER, 100)); + values.put("ref1", new RefValue("Just a label")); + flowDescriptor.setValues(values); + + flowDescriptor.setExecutionSpec(createRelatedSimpleSpec()); + return flowDescriptor; + } + + protected static DefaultExecutionSpec createRelatedSimpleSpec() { + DefaultExecutionSpec spec = new DefaultExecutionSpec(); + spec.setBeanName("simpleSpec"); + Map attributes = new HashMap(); + + PrimitiveSpecAttribute primitiveInteger = new PrimitiveSpecAttribute(); + primitiveInteger.setType(PrimitiveSpecAttribute.TYPE_INTEGER); + primitiveInteger.setValue(50); + attributes.put("primitiveInteger", primitiveInteger); + + RefSpecAttribute ref1 = new RefSpecAttribute(); + ref1.setTargetClass(BasicTestData.class); + attributes.put("ref1", ref1); + + spec.setAttributes(attributes); + + return spec; + } +} diff --git a/runtime/org.argeo.slc.support.simple/src/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 index 000000000..bbea1bb25 --- /dev/null +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/unit/process/SlcExecutionTestUtils.java @@ -0,0 +1,63 @@ +package org.argeo.slc.unit.process; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; +import static org.argeo.slc.unit.UnitUtils.assertDateSec; + +import java.util.UUID; + +import org.argeo.slc.process.SlcExecution; +import org.argeo.slc.process.SlcExecutionStep; + +public abstract class SlcExecutionTestUtils { + + public static SlcExecution createSimpleSlcExecution() { + SlcExecution slcExec = new SlcExecution(); + slcExec.setUuid(UUID.randomUUID().toString()); + slcExec.setHost("localhost"); + slcExec.setUser("user"); + slcExec.setType("slcAnt"); + slcExec.setStatus("STARTED"); + slcExec.getAttributes().put("ant.file", "/test"); + return slcExec; + } + + public static void assertSlcExecution(SlcExecution expected, + SlcExecution reached) { + assertNotNull(reached); + assertEquals(expected.getHost(), reached.getHost()); + assertEquals(expected.getUser(), reached.getUser()); + assertEquals(expected.getType(), reached.getType()); + assertEquals(expected.getStatus(), reached.getStatus()); + + // Attributes + assertEquals(expected.getAttributes().size(), reached.getAttributes() + .size()); + for (String key : expected.getAttributes().keySet()) { + String expectedValue = expected.getAttributes().get(key); + String reachedValue = reached.getAttributes().get(key); + assertNotNull(reachedValue); + assertEquals(expectedValue, reachedValue); + } + + assertEquals(expected.getSteps().size(), reached.getSteps().size()); + for (int i = 0; i < expected.getSteps().size(); i++) { + SlcExecutionStep stepExpected = expected.getSteps().get(i); + SlcExecutionStep stepReached = reached.getSteps().get(i); + assertSlcExecutionStep(stepExpected, stepReached); + } + } + + public static void assertSlcExecutionStep(SlcExecutionStep expected, + SlcExecutionStep reached) { + assertNotNull(reached); + assertEquals(expected.getUuid(), reached.getUuid()); + assertEquals(expected.getType(), reached.getType()); + assertEquals(expected.logAsString(), reached.logAsString()); + assertDateSec(expected.getBegin(), reached.getBegin()); + } + + private SlcExecutionTestUtils() { + + } +} diff --git a/runtime/org.argeo.slc.support.simple/src/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 index 000000000..cf4b0c1e4 --- /dev/null +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/unit/test/tree/TreeTestResultTestUtils.java @@ -0,0 +1,130 @@ +package org.argeo.slc.unit.test.tree; + +import java.util.UUID; + +import org.argeo.slc.build.Distribution; +import org.argeo.slc.core.structure.SimpleSElement; +import org.argeo.slc.core.structure.tree.TreeSPath; +import org.argeo.slc.core.structure.tree.TreeSRegistry; +import org.argeo.slc.core.test.SimpleResultPart; +import org.argeo.slc.core.test.SimpleTestRun; +import org.argeo.slc.core.test.tree.PartSubList; +import org.argeo.slc.core.test.tree.TreeTestResult; +import org.argeo.slc.deploy.DeployedSystem; +import org.argeo.slc.deploy.DeploymentData; +import org.argeo.slc.deploy.TargetData; +import org.argeo.slc.msg.test.tree.ResultPartRequest; +import org.argeo.slc.process.SlcExecution; +import org.argeo.slc.process.SlcExecutionStep; +import org.argeo.slc.test.TestStatus; +import org.argeo.slc.unit.process.SlcExecutionTestUtils; + +public abstract class TreeTestResultTestUtils { + + public static TreeTestResult createSimpleTreeTestResult() { + TreeTestResult treeTestResult = new TreeTestResult(); + treeTestResult.setUuid(UUID.randomUUID().toString()); + return treeTestResult; + } + + public static TreeTestResult createCompleteTreeTestResult() { + SlcExecution slcExecution = SlcExecutionTestUtils + .createSimpleSlcExecution(); + SlcExecutionStep step = new SlcExecutionStep("JUnit step"); + slcExecution.getSteps().add(step); + + TreeTestResult ttr = createMinimalConsistentTreeTestResult(slcExecution); + + ttr.addResultPart(createSimpleResultPartPassed()); + ttr.addResultPart(createSimpleResultPartFailed()); + ttr.addResultPart(createSimpleResultPartError()); + return ttr; + } + + public static TreeTestResult createMinimalConsistentTreeTestResult( + SlcExecution slcExecution) { + SimpleTestRun testRun = new SimpleTestRun(); + testRun.setUuid(UUID.randomUUID().toString()); + + String pathStr = "/test"; + TreeSPath path = new TreeSPath(pathStr); + + TreeSRegistry registry = new TreeSRegistry(); + SimpleSElement elem = new SimpleSElement("Unit Test"); + elem.getTags().put("myTag", "myTagValue"); + registry.register(path, elem); + + TreeTestResult ttr = createSimpleTreeTestResult(); + ttr.getAttributes().put("testCase", "UNIT"); + + // Simulate test run + ttr.notifyCurrentPath(registry, path); + ttr.notifyTestRun(testRun); + testRun.setTestResult(ttr); + testRun.setDeployedSystem(new DeployedSystem() { + private String uuid = UUID.randomUUID().toString(); + + public String getDeployedSystemId() { + return uuid; + } + + public Distribution getDistribution() { + return null; + } + + public DeploymentData getDeploymentData() { + // TODO Auto-generated method stub + return null; + } + + public TargetData getTargetData() { + // TODO Auto-generated method stub + return null; + } + + }); + testRun.notifySlcExecution(slcExecution); + return ttr; + } + + public static SimpleResultPart createSimpleResultPartPassed() { + SimpleResultPart partPassed = new SimpleResultPart(); + String msgPassed = "message\nnew line"; + partPassed.setStatus(TestStatus.PASSED); + partPassed.setMessage(msgPassed); + return partPassed; + } + + public static SimpleResultPart createSimpleResultPartFailed() { + SimpleResultPart partFailed = new SimpleResultPart(); + String msgFailed = "too bad"; + partFailed.setStatus(TestStatus.FAILED); + partFailed.setMessage(msgFailed); + return partFailed; + } + + public static SimpleResultPart createSimpleResultPartError() { + SimpleResultPart partFailed = new SimpleResultPart(); + String msgFailed = "crashed\nanother line"; + partFailed.setStatus(TestStatus.ERROR); + partFailed.setMessage(msgFailed); + partFailed.setException(new Exception("Test Exception")); + return partFailed; + } + + public static ResultPartRequest createSimpleResultPartRequest( + TreeTestResult ttr) { + TreeSPath path = ttr.getCurrentPath(); + PartSubList lst = ttr.getResultParts().get(path); + SimpleResultPart part = (SimpleResultPart) lst.getParts().get(2); + + ResultPartRequest req = new ResultPartRequest(ttr, path, part); + req.setPath(ttr.getCurrentPath()); + + return req; + } + + private TreeTestResultTestUtils() { + + } +} diff --git a/runtime/org.argeo.slc.support.simple/src/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 index 000000000..91467f3ea --- /dev/null +++ b/runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/unit/test/tree/UnitTestTreeUtil.java @@ -0,0 +1,187 @@ +package org.argeo.slc.unit.test.tree; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; +import static junit.framework.Assert.assertNull; +import static junit.framework.Assert.fail; +import static org.argeo.slc.unit.UnitUtils.assertDateSec; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.slc.core.structure.SimpleSElement; +import org.argeo.slc.core.structure.tree.TreeSPath; +import org.argeo.slc.core.test.SimpleResultPart; +import org.argeo.slc.core.test.tree.PartSubList; +import org.argeo.slc.core.test.tree.TreeTestResult; +import org.argeo.slc.test.TestResultPart; + +/** Utilities for unit tests. */ +public class UnitTestTreeUtil { + private final static Log log = LogFactory.getLog(UnitTestTreeUtil.class); + + public static void assertTreeTestResult(TreeTestResult expected, + TreeTestResult reached) { + assertEquals(expected.getUuid(), reached.getUuid()); + assertDateSec(expected.getCloseDate(), reached.getCloseDate()); + + // Attributes + assertEquals(expected.getAttributes().size(), reached.getAttributes() + .size()); + for (String key : expected.getAttributes().keySet()) { + String expectedValue = expected.getAttributes().get(key); + String reachedValue = reached.getAttributes().get(key); + assertNotNull(reachedValue); + assertEquals(expectedValue, reachedValue); + } + + // Result parts + assertEquals(expected.getResultParts().size(), reached.getResultParts() + .size()); + for (TreeSPath path : expected.getResultParts().keySet()) { + PartSubList lstExpected = expected.getResultParts().get(path); + PartSubList lstReached = expected.getResultParts().get(path); + if (lstReached == null) { + fail("No result for path " + path); + return; + } + assertPartSubList(lstExpected, lstReached); + } + + // Elements + assertEquals(expected.getElements().size(), reached.getElements() + .size()); + for (TreeSPath path : expected.getElements().keySet()) { + // String nameExpected = expected.getElements().get(path); + // String nameReached = expected.getElements().get(path); + SimpleSElement elemExpected = (SimpleSElement) expected + .getElements().get(path); + SimpleSElement elemReached = (SimpleSElement) expected + .getElements().get(path); + assertNotNull(elemReached); + assertElements(elemExpected, elemReached); + } + + } + + public static void assertElements(SimpleSElement expected, + SimpleSElement reached) { + assertEquals(expected.getLabel(), reached.getLabel()); + assertEquals(expected.getTags().size(), reached.getTags().size()); + for (String tagName : expected.getTags().keySet()) { + String expectedTagValue = expected.getTags().get(tagName); + String reachedTagValue = reached.getTags().get(tagName); + assertNotNull(reachedTagValue); + assertEquals(expectedTagValue, reachedTagValue); + } + } + + public static void assertPartSubList(PartSubList lstExpected, + PartSubList lstReached) { + assertEquals(lstExpected.getParts().size(), lstReached.getParts() + .size()); + for (int i = 0; i < lstExpected.getParts().size(); i++) { + assertPart(lstExpected.getParts().get(i), lstReached.getParts() + .get(i)); + } + } + + /** Asserts one part of a tree test result */ + public static void assertPart(TreeTestResult testResult, String pathStr, + int index, Integer status, String message) { + TreeSPath path = new TreeSPath(pathStr); + PartSubList list = testResult.getResultParts().get(path); + if (list == null) { + fail("No result for path " + path); + return; + } + if (index >= list.getParts().size()) { + fail("Not enough parts."); + } + SimpleResultPart part = (SimpleResultPart) list.getParts().get(index); + assertPart(part, status, message, null, part.getTestRunUuid(), true); + } + + public static void assertPart(TestResultPart expected, + TestResultPart reached) { + String expectedTestRunUuid = null; + if (expected instanceof SimpleResultPart) { + expectedTestRunUuid = ((SimpleResultPart) expected) + .getTestRunUuid(); + } + + assertPart(reached, expected.getStatus(), expected.getMessage(), + expected.getExceptionMessage(), expectedTestRunUuid, false); + } + + /** Assert one part of a tree test result. */ + private static void assertPart(TestResultPart part, Integer status, + String message, String exceptionDescription, + String expectedTestRunUuid, boolean skipExceptionMessage) { + assertEquals(status, part.getStatus()); + + if (message != null) { + if (log.isTraceEnabled()) { + log.trace("Expected message:" + message); + log.trace("Reached message:" + part.getMessage()); + } + assertEquals(message, part.getMessage()); + } + + if (!skipExceptionMessage) { + if (exceptionDescription == null) { + assertNull(part.getExceptionMessage()); + } else { + if (log.isTraceEnabled()) { + log.trace("Expected exception message:" + + exceptionDescription); + log.trace("Reached exception message:" + + part.getExceptionMessage()); + } + + assertEquals(exceptionDescription, part.getExceptionMessage()); + } + } + + if (expectedTestRunUuid != null) { + SimpleResultPart reachedPart = (SimpleResultPart) part; + assertNotNull(reachedPart.getTestRunUuid()); + assertEquals(expectedTestRunUuid, reachedPart.getTestRunUuid()); + } else { + if (part instanceof SimpleResultPart) { + assertNull(((SimpleResultPart) part).getTestRunUuid()); + } + + } + + } + + public static void describeTreeTestResult(TreeTestResult ttr) { + log.info("TreeTestResult #" + ttr.getUuid()); + log.info(" Close date: " + ttr.getCloseDate()); + log.info(" Attributes:"); + for (String key : ttr.getAttributes().keySet()) + log.info(" " + key + "=" + ttr.getAttributes().get(key)); + + log.info(" Result parts: (size=" + ttr.getResultParts().size() + ")"); + for (TreeSPath path : ttr.getResultParts().keySet()) { + log.info(" Path: " + path); + PartSubList lst = ttr.getResultParts().get(path); + for (TestResultPart part : lst.getParts()) + log.info(" " + part); + } + + log.info(" Elements: (size=" + ttr.getElements().size() + ")"); + for (TreeSPath path : ttr.getElements().keySet()) { + SimpleSElement elem = (SimpleSElement) ttr.getElements().get(path); + log.info(" Path: " + path + ", Element: " + elem.getLabel()); + for (String tag : elem.getTags().keySet()) + log.info(" " + tag + "=" + elem.getTags().get(tag)); + } + + } + + /** Makes sure this is a singleton */ + private UnitTestTreeUtil() { + + } +} 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 index 14a34c7fb..000000000 --- a/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/unit/execution/ExecutionFlowDescriptorTestUtils.java +++ /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 values = new HashMap(); - values.put("primitiveInteger", new PrimitiveValue( - PrimitiveSpecAttribute.TYPE_INTEGER, 100)); - values.put("ref1", new RefValue("Just a label")); - flowDescriptor.setValues(values); - - flowDescriptor.setExecutionSpec(createRelatedSimpleSpec()); - return flowDescriptor; - } - - protected static DefaultExecutionSpec createRelatedSimpleSpec() { - DefaultExecutionSpec spec = new DefaultExecutionSpec(); - spec.setBeanName("simpleSpec"); - Map attributes = new HashMap(); - - PrimitiveSpecAttribute primitiveInteger = new PrimitiveSpecAttribute(); - primitiveInteger.setType(PrimitiveSpecAttribute.TYPE_INTEGER); - primitiveInteger.setValue(50); - attributes.put("primitiveInteger", primitiveInteger); - - RefSpecAttribute ref1 = new RefSpecAttribute(); - ref1.setTargetClass(BasicTestData.class); - attributes.put("ref1", ref1); - - spec.setAttributes(attributes); - - return spec; - } -} diff --git a/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/unit/process/SlcExecutionTestUtils.java b/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/unit/process/SlcExecutionTestUtils.java deleted file mode 100644 index bbea1bb25..000000000 --- a/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/unit/process/SlcExecutionTestUtils.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.argeo.slc.unit.process; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; -import static org.argeo.slc.unit.UnitUtils.assertDateSec; - -import java.util.UUID; - -import org.argeo.slc.process.SlcExecution; -import org.argeo.slc.process.SlcExecutionStep; - -public abstract class SlcExecutionTestUtils { - - public static SlcExecution createSimpleSlcExecution() { - SlcExecution slcExec = new SlcExecution(); - slcExec.setUuid(UUID.randomUUID().toString()); - slcExec.setHost("localhost"); - slcExec.setUser("user"); - slcExec.setType("slcAnt"); - slcExec.setStatus("STARTED"); - slcExec.getAttributes().put("ant.file", "/test"); - return slcExec; - } - - public static void assertSlcExecution(SlcExecution expected, - SlcExecution reached) { - assertNotNull(reached); - assertEquals(expected.getHost(), reached.getHost()); - assertEquals(expected.getUser(), reached.getUser()); - assertEquals(expected.getType(), reached.getType()); - assertEquals(expected.getStatus(), reached.getStatus()); - - // Attributes - assertEquals(expected.getAttributes().size(), reached.getAttributes() - .size()); - for (String key : expected.getAttributes().keySet()) { - String expectedValue = expected.getAttributes().get(key); - String reachedValue = reached.getAttributes().get(key); - assertNotNull(reachedValue); - assertEquals(expectedValue, reachedValue); - } - - assertEquals(expected.getSteps().size(), reached.getSteps().size()); - for (int i = 0; i < expected.getSteps().size(); i++) { - SlcExecutionStep stepExpected = expected.getSteps().get(i); - SlcExecutionStep stepReached = reached.getSteps().get(i); - assertSlcExecutionStep(stepExpected, stepReached); - } - } - - public static void assertSlcExecutionStep(SlcExecutionStep expected, - SlcExecutionStep reached) { - assertNotNull(reached); - assertEquals(expected.getUuid(), reached.getUuid()); - assertEquals(expected.getType(), reached.getType()); - assertEquals(expected.logAsString(), reached.logAsString()); - assertDateSec(expected.getBegin(), reached.getBegin()); - } - - private SlcExecutionTestUtils() { - - } -} diff --git a/runtime/org.argeo.slc.support.simple/src/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 index cf4b0c1e4..000000000 --- a/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/unit/test/tree/TreeTestResultTestUtils.java +++ /dev/null @@ -1,130 +0,0 @@ -package org.argeo.slc.unit.test.tree; - -import java.util.UUID; - -import org.argeo.slc.build.Distribution; -import org.argeo.slc.core.structure.SimpleSElement; -import org.argeo.slc.core.structure.tree.TreeSPath; -import org.argeo.slc.core.structure.tree.TreeSRegistry; -import org.argeo.slc.core.test.SimpleResultPart; -import org.argeo.slc.core.test.SimpleTestRun; -import org.argeo.slc.core.test.tree.PartSubList; -import org.argeo.slc.core.test.tree.TreeTestResult; -import org.argeo.slc.deploy.DeployedSystem; -import org.argeo.slc.deploy.DeploymentData; -import org.argeo.slc.deploy.TargetData; -import org.argeo.slc.msg.test.tree.ResultPartRequest; -import org.argeo.slc.process.SlcExecution; -import org.argeo.slc.process.SlcExecutionStep; -import org.argeo.slc.test.TestStatus; -import org.argeo.slc.unit.process.SlcExecutionTestUtils; - -public abstract class TreeTestResultTestUtils { - - public static TreeTestResult createSimpleTreeTestResult() { - TreeTestResult treeTestResult = new TreeTestResult(); - treeTestResult.setUuid(UUID.randomUUID().toString()); - return treeTestResult; - } - - public static TreeTestResult createCompleteTreeTestResult() { - SlcExecution slcExecution = SlcExecutionTestUtils - .createSimpleSlcExecution(); - SlcExecutionStep step = new SlcExecutionStep("JUnit step"); - slcExecution.getSteps().add(step); - - TreeTestResult ttr = createMinimalConsistentTreeTestResult(slcExecution); - - ttr.addResultPart(createSimpleResultPartPassed()); - ttr.addResultPart(createSimpleResultPartFailed()); - ttr.addResultPart(createSimpleResultPartError()); - return ttr; - } - - public static TreeTestResult createMinimalConsistentTreeTestResult( - SlcExecution slcExecution) { - SimpleTestRun testRun = new SimpleTestRun(); - testRun.setUuid(UUID.randomUUID().toString()); - - String pathStr = "/test"; - TreeSPath path = new TreeSPath(pathStr); - - TreeSRegistry registry = new TreeSRegistry(); - SimpleSElement elem = new SimpleSElement("Unit Test"); - elem.getTags().put("myTag", "myTagValue"); - registry.register(path, elem); - - TreeTestResult ttr = createSimpleTreeTestResult(); - ttr.getAttributes().put("testCase", "UNIT"); - - // Simulate test run - ttr.notifyCurrentPath(registry, path); - ttr.notifyTestRun(testRun); - testRun.setTestResult(ttr); - testRun.setDeployedSystem(new DeployedSystem() { - private String uuid = UUID.randomUUID().toString(); - - public String getDeployedSystemId() { - return uuid; - } - - public Distribution getDistribution() { - return null; - } - - public DeploymentData getDeploymentData() { - // TODO Auto-generated method stub - return null; - } - - public TargetData getTargetData() { - // TODO Auto-generated method stub - return null; - } - - }); - testRun.notifySlcExecution(slcExecution); - return ttr; - } - - public static SimpleResultPart createSimpleResultPartPassed() { - SimpleResultPart partPassed = new SimpleResultPart(); - String msgPassed = "message\nnew line"; - partPassed.setStatus(TestStatus.PASSED); - partPassed.setMessage(msgPassed); - return partPassed; - } - - public static SimpleResultPart createSimpleResultPartFailed() { - SimpleResultPart partFailed = new SimpleResultPart(); - String msgFailed = "too bad"; - partFailed.setStatus(TestStatus.FAILED); - partFailed.setMessage(msgFailed); - return partFailed; - } - - public static SimpleResultPart createSimpleResultPartError() { - SimpleResultPart partFailed = new SimpleResultPart(); - String msgFailed = "crashed\nanother line"; - partFailed.setStatus(TestStatus.ERROR); - partFailed.setMessage(msgFailed); - partFailed.setException(new Exception("Test Exception")); - return partFailed; - } - - public static ResultPartRequest createSimpleResultPartRequest( - TreeTestResult ttr) { - TreeSPath path = ttr.getCurrentPath(); - PartSubList lst = ttr.getResultParts().get(path); - SimpleResultPart part = (SimpleResultPart) lst.getParts().get(2); - - ResultPartRequest req = new ResultPartRequest(ttr, path, part); - req.setPath(ttr.getCurrentPath()); - - return req; - } - - private TreeTestResultTestUtils() { - - } -} diff --git a/runtime/org.argeo.slc.support.simple/src/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 index 91467f3ea..000000000 --- a/runtime/org.argeo.slc.support.simple/src/test/java/org/argeo/slc/unit/test/tree/UnitTestTreeUtil.java +++ /dev/null @@ -1,187 +0,0 @@ -package org.argeo.slc.unit.test.tree; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertNull; -import static junit.framework.Assert.fail; -import static org.argeo.slc.unit.UnitUtils.assertDateSec; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.slc.core.structure.SimpleSElement; -import org.argeo.slc.core.structure.tree.TreeSPath; -import org.argeo.slc.core.test.SimpleResultPart; -import org.argeo.slc.core.test.tree.PartSubList; -import org.argeo.slc.core.test.tree.TreeTestResult; -import org.argeo.slc.test.TestResultPart; - -/** Utilities for unit tests. */ -public class UnitTestTreeUtil { - private final static Log log = LogFactory.getLog(UnitTestTreeUtil.class); - - public static void assertTreeTestResult(TreeTestResult expected, - TreeTestResult reached) { - assertEquals(expected.getUuid(), reached.getUuid()); - assertDateSec(expected.getCloseDate(), reached.getCloseDate()); - - // Attributes - assertEquals(expected.getAttributes().size(), reached.getAttributes() - .size()); - for (String key : expected.getAttributes().keySet()) { - String expectedValue = expected.getAttributes().get(key); - String reachedValue = reached.getAttributes().get(key); - assertNotNull(reachedValue); - assertEquals(expectedValue, reachedValue); - } - - // Result parts - assertEquals(expected.getResultParts().size(), reached.getResultParts() - .size()); - for (TreeSPath path : expected.getResultParts().keySet()) { - PartSubList lstExpected = expected.getResultParts().get(path); - PartSubList lstReached = expected.getResultParts().get(path); - if (lstReached == null) { - fail("No result for path " + path); - return; - } - assertPartSubList(lstExpected, lstReached); - } - - // Elements - assertEquals(expected.getElements().size(), reached.getElements() - .size()); - for (TreeSPath path : expected.getElements().keySet()) { - // String nameExpected = expected.getElements().get(path); - // String nameReached = expected.getElements().get(path); - SimpleSElement elemExpected = (SimpleSElement) expected - .getElements().get(path); - SimpleSElement elemReached = (SimpleSElement) expected - .getElements().get(path); - assertNotNull(elemReached); - assertElements(elemExpected, elemReached); - } - - } - - public static void assertElements(SimpleSElement expected, - SimpleSElement reached) { - assertEquals(expected.getLabel(), reached.getLabel()); - assertEquals(expected.getTags().size(), reached.getTags().size()); - for (String tagName : expected.getTags().keySet()) { - String expectedTagValue = expected.getTags().get(tagName); - String reachedTagValue = reached.getTags().get(tagName); - assertNotNull(reachedTagValue); - assertEquals(expectedTagValue, reachedTagValue); - } - } - - public static void assertPartSubList(PartSubList lstExpected, - PartSubList lstReached) { - assertEquals(lstExpected.getParts().size(), lstReached.getParts() - .size()); - for (int i = 0; i < lstExpected.getParts().size(); i++) { - assertPart(lstExpected.getParts().get(i), lstReached.getParts() - .get(i)); - } - } - - /** Asserts one part of a tree test result */ - public static void assertPart(TreeTestResult testResult, String pathStr, - int index, Integer status, String message) { - TreeSPath path = new TreeSPath(pathStr); - PartSubList list = testResult.getResultParts().get(path); - if (list == null) { - fail("No result for path " + path); - return; - } - if (index >= list.getParts().size()) { - fail("Not enough parts."); - } - SimpleResultPart part = (SimpleResultPart) list.getParts().get(index); - assertPart(part, status, message, null, part.getTestRunUuid(), true); - } - - public static void assertPart(TestResultPart expected, - TestResultPart reached) { - String expectedTestRunUuid = null; - if (expected instanceof SimpleResultPart) { - expectedTestRunUuid = ((SimpleResultPart) expected) - .getTestRunUuid(); - } - - assertPart(reached, expected.getStatus(), expected.getMessage(), - expected.getExceptionMessage(), expectedTestRunUuid, false); - } - - /** Assert one part of a tree test result. */ - private static void assertPart(TestResultPart part, Integer status, - String message, String exceptionDescription, - String expectedTestRunUuid, boolean skipExceptionMessage) { - assertEquals(status, part.getStatus()); - - if (message != null) { - if (log.isTraceEnabled()) { - log.trace("Expected message:" + message); - log.trace("Reached message:" + part.getMessage()); - } - assertEquals(message, part.getMessage()); - } - - if (!skipExceptionMessage) { - if (exceptionDescription == null) { - assertNull(part.getExceptionMessage()); - } else { - if (log.isTraceEnabled()) { - log.trace("Expected exception message:" - + exceptionDescription); - log.trace("Reached exception message:" - + part.getExceptionMessage()); - } - - assertEquals(exceptionDescription, part.getExceptionMessage()); - } - } - - if (expectedTestRunUuid != null) { - SimpleResultPart reachedPart = (SimpleResultPart) part; - assertNotNull(reachedPart.getTestRunUuid()); - assertEquals(expectedTestRunUuid, reachedPart.getTestRunUuid()); - } else { - if (part instanceof SimpleResultPart) { - assertNull(((SimpleResultPart) part).getTestRunUuid()); - } - - } - - } - - public static void describeTreeTestResult(TreeTestResult ttr) { - log.info("TreeTestResult #" + ttr.getUuid()); - log.info(" Close date: " + ttr.getCloseDate()); - log.info(" Attributes:"); - for (String key : ttr.getAttributes().keySet()) - log.info(" " + key + "=" + ttr.getAttributes().get(key)); - - log.info(" Result parts: (size=" + ttr.getResultParts().size() + ")"); - for (TreeSPath path : ttr.getResultParts().keySet()) { - log.info(" Path: " + path); - PartSubList lst = ttr.getResultParts().get(path); - for (TestResultPart part : lst.getParts()) - log.info(" " + part); - } - - log.info(" Elements: (size=" + ttr.getElements().size() + ")"); - for (TreeSPath path : ttr.getElements().keySet()) { - SimpleSElement elem = (SimpleSElement) ttr.getElements().get(path); - log.info(" Path: " + path + ", Element: " + elem.getLabel()); - for (String tag : elem.getTags().keySet()) - log.info(" " + tag + "=" + elem.getTags().get(tag)); - } - - } - - /** Makes sure this is a singleton */ - private UnitTestTreeUtil() { - - } -}