SLC Unit
authorMathieu Baudier <mbaudier@argeo.org>
Fri, 13 Feb 2015 09:33:41 +0000 (09:33 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Fri, 13 Feb 2015 09:33:41 +0000 (09:33 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@7839 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

19 files changed:
org.argeo.slc.unit/pom.xml
org.argeo.slc.unit/src/org/argeo/slc/equinox/unit/AbstractOsgiRuntimeTestCase.java [new file with mode: 0644]
org.argeo.slc.unit/src/org/argeo/slc/unit/AbstractSpringTestCase.java [new file with mode: 0644]
org.argeo.slc.unit/src/org/argeo/slc/unit/UnitUtils.java [new file with mode: 0644]
org.argeo.slc.unit/src/org/argeo/slc/unit/execution/AbstractExecutionFlowTestcase.java [new file with mode: 0644]
org.argeo.slc.unit/src/org/argeo/slc/unit/execution/ExecutionFlowDescriptorTestUtils.java [new file with mode: 0644]
org.argeo.slc.unit/src/org/argeo/slc/unit/package.html [new file with mode: 0644]
pom.xml
runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/equinox/unit/AbstractOsgiRuntimeTestCase.java [deleted file]
runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/hibernate/unit/DbModelHibernate.java [deleted file]
runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/hibernate/unit/IndependentDbTestCase.java [deleted file]
runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/AbstractSpringTestCase.java [deleted file]
runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/UnitUtils.java [deleted file]
runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/UnitXmlUtils.java [deleted file]
runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/db/DbUnitDeployment.java [deleted file]
runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/db/DbUnitDeploymentData.java [deleted file]
runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/execution/AbstractExecutionFlowTestcase.java [deleted file]
runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/execution/ExecutionFlowDescriptorTestUtils.java [deleted file]
runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/package.html [deleted file]

index 580d58cd13bcc79624579cfbecef6ee3093e1a2f..8c1ceca6aa02e3343e7c2f3fefc37d8142101b41 100644 (file)
@@ -1,4 +1,5 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
                <groupId>org.argeo.slc</groupId>
@@ -8,4 +9,19 @@
        </parent>
        <artifactId>org.argeo.slc.unit</artifactId>
        <name>SLC Unit Testing Support</name>
+       <dependencies>
+               <!-- Commons -->
+               <dependency>
+                       <groupId>org.argeo.commons</groupId>
+                       <artifactId>org.argeo.osgi.boot</artifactId>
+                       <version>${version.argeo-commons}</version>
+               </dependency>
+               
+               <!-- SLC -->
+               <dependency>
+                       <groupId>org.argeo.slc</groupId>
+                       <artifactId>org.argeo.slc.core</artifactId>
+                       <version>2.1.1-SNAPSHOT</version>
+               </dependency>
+       </dependencies>
 </project>
\ No newline at end of file
diff --git a/org.argeo.slc.unit/src/org/argeo/slc/equinox/unit/AbstractOsgiRuntimeTestCase.java b/org.argeo.slc.unit/src/org/argeo/slc/equinox/unit/AbstractOsgiRuntimeTestCase.java
new file mode 100644 (file)
index 0000000..b5bd8aa
--- /dev/null
@@ -0,0 +1,246 @@
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.equinox.unit;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.SlcException;
+import org.argeo.osgi.boot.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.eclipse.gemini.blueprint.util.OsgiStringUtils;
+
+@SuppressWarnings("restriction")
+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/org.argeo.slc.unit/src/org/argeo/slc/unit/AbstractSpringTestCase.java b/org.argeo.slc.unit/src/org/argeo/slc/unit/AbstractSpringTestCase.java
new file mode 100644 (file)
index 0000000..76b7fb6
--- /dev/null
@@ -0,0 +1,115 @@
+/*\r
+ * Copyright (C) 2007-2012 Argeo GmbH\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *         http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.argeo.slc.unit;\r
+\r
+import java.util.Map;\r
+\r
+import junit.framework.TestCase;\r
+\r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+import org.argeo.slc.SlcException;\r
+import org.springframework.beans.factory.BeanFactoryUtils;\r
+import org.springframework.beans.factory.ListableBeanFactory;\r
+import org.springframework.context.ConfigurableApplicationContext;\r
+import org.springframework.context.support.ClassPathXmlApplicationContext;\r
+\r
+/** Helper for tests using a Spring application co,text. */\r
+public abstract class AbstractSpringTestCase extends TestCase {\r
+       protected final Log log = LogFactory.getLog(getClass());\r
+       private ConfigurableApplicationContext context;\r
+\r
+       /**\r
+        * Gets (and create if necessary) the application context to use. Default\r
+        * implementation uses a class path xml application context and calls\r
+        * {@link #getApplicationContextLocation()}.\r
+        */\r
+       protected ConfigurableApplicationContext getContext() {\r
+               if (context == null) {\r
+                       context = new ClassPathXmlApplicationContext(\r
+                                       getApplicationContextLocation());\r
+                       if (getIsStartContext())\r
+                               context.start();\r
+               }\r
+               return context;\r
+       }\r
+\r
+       @Override\r
+       protected void tearDown() throws Exception {\r
+               if (context != null && context.isActive())\r
+                       context.close();\r
+               super.tearDown();\r
+       }\r
+\r
+       /** Whether the context should be started after being created. */\r
+       protected Boolean getIsStartContext() {\r
+               return false;\r
+       }\r
+\r
+       /** Returns a bean from the underlying context */\r
+       @SuppressWarnings(value = { "unchecked" })\r
+       protected <T> T getBean(String beanId) {\r
+               return (T) getContext().getBean(beanId);\r
+       }\r
+\r
+       protected <T> T getBean(Class<? extends T> clss) {\r
+               T bean = loadSingleFromContext(getContext(), clss);\r
+               if (bean == null) {\r
+                       throw new SlcException("Cannot retrieve a unique bean of type "\r
+                                       + clss);\r
+               } else {\r
+                       return bean;\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Th location of the application to load. The default implementation\r
+        * returns <i>applicationContext.xml</i> found in the same package as the\r
+        * test.\r
+        */\r
+       protected String getApplicationContextLocation() {\r
+               return inPackage("applicationContext.xml");\r
+       }\r
+\r
+       /**\r
+        * Prefixes the package of the class after converting the '.' to '/' in\r
+        * order to have a resource path.\r
+        */\r
+       protected String inPackage(String suffix) {\r
+               String prefix = getClass().getPackage().getName().replace('.', '/');\r
+               return prefix + '/' + suffix;\r
+       }\r
+\r
+       @SuppressWarnings(value = { "unchecked" })\r
+       protected <T> T loadSingleFromContext(ListableBeanFactory context,\r
+                       Class<T> clss) {\r
+               Map<String, T> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(\r
+                               context, clss, false, false);\r
+               if (beans.size() == 1) {\r
+                       return beans.values().iterator().next();\r
+               } else if (beans.size() > 1) {\r
+                       if (log.isDebugEnabled()) {\r
+                               log\r
+                                               .debug(("Found more that on bean for type " + clss\r
+                                                               + ": " + beans.keySet()));\r
+                       }\r
+                       return null;\r
+               } else {\r
+                       return null;\r
+               }\r
+       }\r
+\r
+}\r
diff --git a/org.argeo.slc.unit/src/org/argeo/slc/unit/UnitUtils.java b/org.argeo.slc.unit/src/org/argeo/slc/unit/UnitUtils.java
new file mode 100644 (file)
index 0000000..765ec70
--- /dev/null
@@ -0,0 +1,57 @@
+/*\r
+ * Copyright (C) 2007-2012 Argeo GmbH\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *         http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.argeo.slc.unit;\r
+\r
+import java.util.Calendar;\r
+import java.util.Date;\r
+import java.util.GregorianCalendar;\r
+\r
+import static junit.framework.Assert.assertEquals;\r
+import static junit.framework.Assert.assertNull;\r
+import static junit.framework.Assert.assertNotNull;\r
+\r
+public abstract class UnitUtils {\r
+       public static void assertDateSec(Date expected, Date reached) {\r
+               if (expected == null) {\r
+                       assertNull(reached);\r
+                       return;\r
+               } else {\r
+                       assertNotNull(reached);\r
+               }\r
+\r
+               Calendar expectedCal = new GregorianCalendar();\r
+               expectedCal.setTime(expected);\r
+               Calendar reachedCal = new GregorianCalendar();\r
+               reachedCal.setTime(reached);\r
+               assertEquals(expectedCal.get(Calendar.YEAR), reachedCal\r
+                               .get(Calendar.YEAR));\r
+               assertEquals(expectedCal.get(Calendar.MONTH), reachedCal\r
+                               .get(Calendar.MONTH));\r
+               assertEquals(expectedCal.get(Calendar.DATE), reachedCal\r
+                               .get(Calendar.DATE));\r
+               assertEquals(expectedCal.get(Calendar.HOUR_OF_DAY), reachedCal\r
+                               .get(Calendar.HOUR_OF_DAY));\r
+               assertEquals(expectedCal.get(Calendar.MINUTE), reachedCal\r
+                               .get(Calendar.MINUTE));\r
+               assertEquals(expectedCal.get(Calendar.SECOND), reachedCal\r
+                               .get(Calendar.SECOND));\r
+       }\r
+\r
+       private UnitUtils() {\r
+\r
+       }\r
+\r
+}\r
diff --git a/org.argeo.slc.unit/src/org/argeo/slc/unit/execution/AbstractExecutionFlowTestcase.java b/org.argeo.slc.unit/src/org/argeo/slc/unit/execution/AbstractExecutionFlowTestcase.java
new file mode 100644 (file)
index 0000000..774ce25
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.unit.execution;
+
+import org.argeo.slc.execution.ExecutionFlow;
+import org.argeo.slc.unit.AbstractSpringTestCase;
+
+public class AbstractExecutionFlowTestcase extends AbstractSpringTestCase {
+       @SuppressWarnings(value = { "unchecked" })
+       protected <T extends ExecutionFlow> T executeFlow(String flowName) {
+               ExecutionFlow flow = getBean(flowName);
+               flow.run();
+               return (T) flow;
+       }
+}
diff --git a/org.argeo.slc.unit/src/org/argeo/slc/unit/execution/ExecutionFlowDescriptorTestUtils.java b/org.argeo.slc.unit/src/org/argeo/slc/unit/execution/ExecutionFlowDescriptorTestUtils.java
new file mode 100644 (file)
index 0000000..b8619f4
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.unit.execution;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.argeo.slc.core.execution.DefaultExecutionSpec;
+import org.argeo.slc.core.execution.PrimitiveAccessor;
+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.execution.RefValueChoice;
+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");
+               flowDescriptor.setDescription("my description");
+
+               Map<String, Object> values = new HashMap<String, Object>();
+               values.put("primitiveInteger", new PrimitiveValue(
+                               PrimitiveAccessor.TYPE_INTEGER, 100));
+
+               RefValue refValue = new RefValue("002");
+               values.put("ref1", refValue);
+               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(PrimitiveAccessor.TYPE_INTEGER);
+               primitiveInteger.setValue(50);
+               attributes.put("primitiveInteger", primitiveInteger);
+
+               RefSpecAttribute ref1 = new RefSpecAttribute();
+               ref1.setTargetClass(BasicTestData.class);
+               ref1.setChoices(new ArrayList<RefValueChoice>());
+               ref1.getChoices().add(new RefValueChoice("001", "desc"));
+               ref1.getChoices().add(new RefValueChoice("002", null));
+               ref1.getChoices().add(new RefValueChoice("003", null));
+               attributes.put("ref1", ref1);
+
+               spec.setAttributes(attributes);
+
+               return spec;
+       }
+}
diff --git a/org.argeo.slc.unit/src/org/argeo/slc/unit/package.html b/org.argeo.slc.unit/src/org/argeo/slc/unit/package.html
new file mode 100644 (file)
index 0000000..907430d
--- /dev/null
@@ -0,0 +1,6 @@
+<html>\r
+<head></head>\r
+<body>\r
+Helpers for unit tests.\r
+</body>\r
+</html>
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index e474716d12860fe4f349179e2dd7ab52e587822f..91d640de574b447ee722a0cc7acd7fe3c108e3d0 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -18,6 +18,7 @@
        <modules>
                <module>org.argeo.slc.api</module>
                <module>org.argeo.slc.core</module>
+               <module>org.argeo.slc.unit</module>
 
 <!--           <module>runtime</module> -->
 <!--           <module>modules</module> -->
diff --git a/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/equinox/unit/AbstractOsgiRuntimeTestCase.java b/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/equinox/unit/AbstractOsgiRuntimeTestCase.java
deleted file mode 100644 (file)
index d17a90e..0000000
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *         http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.equinox.unit;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.slc.SlcException;
-import org.argeo.osgi.boot.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;
-
-@SuppressWarnings("restriction")
-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.unit/src/main/java/org/argeo/slc/hibernate/unit/DbModelHibernate.java b/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/hibernate/unit/DbModelHibernate.java
deleted file mode 100644 (file)
index fc572a1..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*\r
- * Copyright (C) 2007-2012 Argeo GmbH\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *         http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.hibernate.unit;\r
-\r
-import java.sql.Connection;\r
-import java.util.List;\r
-import java.util.Properties;\r
-\r
-import org.argeo.slc.support.deploy.db.DbModel;\r
-import org.hibernate.cfg.Configuration;\r
-import org.hibernate.cfg.Environment;\r
-import org.hibernate.tool.hbm2ddl.SchemaExport;\r
-\r
-/**\r
- * Creates a relational data model from Hibernate mapping files. The benefit of\r
- * this class is to be able to use Hibernate to have test data which are\r
- * independent from the type of database used.\r
- */\r
-public class DbModelHibernate implements DbModel {\r
-       private String dialect;\r
-       private List<String> mappings;\r
-\r
-       /** Sets the Hibernate dialect to use. */\r
-       public void setDialect(String dialect) {\r
-               this.dialect = dialect;\r
-       }\r
-\r
-       /** Sets the list of mappings to consider. */\r
-       public void setMappings(List<String> mappings) {\r
-               this.mappings = mappings;\r
-       }\r
-\r
-       /**\r
-        * Creates an Hibernate schema export tool, in order to create the\r
-        * underlying datamodel.\r
-        */\r
-       protected SchemaExport createSchemaExport(Connection connection) {\r
-               Configuration configuration = new Configuration();\r
-               Properties properties = new Properties();\r
-               properties.setProperty(Environment.DIALECT, dialect);\r
-               properties.setProperty(Environment.HBM2DDL_AUTO, "create");\r
-               configuration.setProperties(properties);\r
-\r
-               for (String mapping : mappings) {\r
-                       configuration.addResource(mapping.trim());\r
-               }\r
-\r
-               return new SchemaExport(configuration, connection);\r
-       }\r
-\r
-       public void createSchema(Connection connection) {\r
-               SchemaExport schemaExport = createSchemaExport(connection);\r
-               schemaExport.create(true, true);\r
-       }\r
-\r
-}\r
diff --git a/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/hibernate/unit/IndependentDbTestCase.java b/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/hibernate/unit/IndependentDbTestCase.java
deleted file mode 100644 (file)
index c1bdb1f..0000000
+++ /dev/null
@@ -1,174 +0,0 @@
-/*\r
- * Copyright (C) 2007-2012 Argeo GmbH\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *         http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.hibernate.unit;\r
-\r
-import java.io.InputStream;\r
-import java.sql.SQLException;\r
-\r
-import javax.sql.DataSource;\r
-\r
-import org.apache.commons.io.IOUtils;\r
-import org.argeo.slc.SlcException;\r
-import org.argeo.slc.unit.AbstractSpringTestCase;\r
-import org.dbunit.DataSourceDatabaseTester;\r
-import org.dbunit.DatabaseUnitException;\r
-import org.dbunit.IDatabaseTester;\r
-import org.dbunit.database.IDatabaseConnection;\r
-import org.dbunit.dataset.IDataSet;\r
-import org.dbunit.dataset.ReplacementDataSet;\r
-import org.dbunit.dataset.xml.FlatXmlDataSet;\r
-import org.dbunit.operation.DatabaseOperation;\r
-import org.hibernate.tool.hbm2ddl.SchemaExport;\r
-import org.springframework.core.io.ClassPathResource;\r
-import org.springframework.core.io.Resource;\r
-\r
-/**\r
- * Helper to make db vendor independent tests using DbUnit data sets. Based on\r
- * {@link DbModelHibernate}.\r
- */\r
-public abstract class IndependentDbTestCase extends AbstractSpringTestCase {\r
-       private IDatabaseTester databaseTester;\r
-\r
-       /** Creates the DDL of the data model and loads the data. */\r
-       @Override\r
-       protected void setUp() throws Exception {\r
-               super.setUp();\r
-\r
-               databaseTester = new DataSourceDatabaseTester(getDataSource());\r
-               databaseTester.setSetUpOperation(new DatabaseOperation() {\r
-\r
-                       @Override\r
-                       public void execute(IDatabaseConnection connection, IDataSet dataSet)\r
-                                       throws DatabaseUnitException, SQLException {\r
-                               DbModelHibernate dbModel = getDbModel();\r
-                               SchemaExport schemaExport = dbModel\r
-                                               .createSchemaExport(connection.getConnection());\r
-                               schemaExport.create(true, true);\r
-\r
-                               DatabaseOperation.INSERT.execute(connection, dataSet);\r
-                       }\r
-\r
-               });\r
-               databaseTester.setDataSet(createDataSet());\r
-               databaseTester.onSetup();\r
-       }\r
-\r
-       @Override\r
-       protected void tearDown() throws Exception {\r
-               if (databaseTester != null) {\r
-                       databaseTester.onTearDown();\r
-               }\r
-               super.tearDown();\r
-       }\r
-\r
-       /**\r
-        * The data source to use. The default implementation returns a bean named\r
-        * {@link #getDataSourceBeanName}\r
-        */\r
-       protected DataSource getDataSource() {\r
-               return getBean(DataSource.class);\r
-       }\r
-\r
-       /**\r
-        * Creates the data set to use. The default implementation creates a\r
-        * <code>FlatXmlDataSet</code> load from the resource defined in\r
-        * {@link #getDataSetResource()}\r
-        */\r
-       protected IDataSet createDataSet() {\r
-               InputStream in = null;\r
-               try {\r
-                       in = getDataSetResource().getInputStream();\r
-                       String[] replaceStrings = getReplacementStrings();\r
-                       IDataSet dataSet;\r
-                       if (replaceStrings.length == 0) {\r
-                               dataSet = new FlatXmlDataSet(in);\r
-                       } else {\r
-                               dataSet = new ReplacementDataSet(new FlatXmlDataSet(in));\r
-                               for (String str : replaceStrings) {\r
-                                       replace((ReplacementDataSet) dataSet, str);\r
-                               }\r
-                       }\r
-                       return dataSet;\r
-               } catch (Exception e) {\r
-                       throw new SlcException("Cannot create data set", e);\r
-               } finally {\r
-                       IOUtils.closeQuietly(in);\r
-               }\r
-       }\r
-\r
-       /**\r
-        * To be overridden. Return an empty array by default.\r
-        * \r
-        * @return the array of strings to replace in the dataset\r
-        */\r
-       protected String[] getReplacementStrings() {\r
-               return new String[0];\r
-       }\r
-\r
-       /**\r
-        * Set the object replacing the given string. To be overridden. Does nothing\r
-        * by default.\r
-        */\r
-       protected void replace(ReplacementDataSet dataSet, String str)\r
-                       throws Exception {\r
-\r
-       }\r
-\r
-       /**\r
-        * Replace the given string by the content of the resource with the same\r
-        * name in the same package, as a byte array.\r
-        */\r
-       protected void replaceByRessource(ReplacementDataSet dataSet, String str)\r
-                       throws Exception {\r
-               Resource zipResource = new ClassPathResource(inPackage(str));\r
-\r
-               dataSet.addReplacementObject(str, IOUtils.toByteArray(zipResource\r
-                               .getInputStream()));\r
-       }\r
-\r
-       /**\r
-        * The resource of the data set to load. The default implementation loads a\r
-        * <code>ClassPathResource</code> located at\r
-        * {@link #getDataSetResourceLocation()}.\r
-        */\r
-       protected Resource getDataSetResource() {\r
-               return new ClassPathResource(getDataSetResourceLocation());\r
-       }\r
-\r
-       /**\r
-        * The location of the data set to load. The default implementation loads\r
-        * <i>dataSet.xml</i> found in the same package as the test.\r
-        */\r
-       protected String getDataSetResourceLocation() {\r
-               return inPackage("dataSet.xml");\r
-       }\r
-\r
-       /**\r
-        * The DB model to us to create the DDL of the testes database. The default\r
-        * implementation loads a bean named after {@link #getDbModelBeanName()}.\r
-        */\r
-       protected DbModelHibernate getDbModel() {\r
-               return (DbModelHibernate) getContext().getBean(getDbModelBeanName());\r
-       }\r
-\r
-       /**\r
-        * The name of the bean to load. The default implementation returns\r
-        * <i>dbModel</i>.\r
-        */\r
-       protected String getDbModelBeanName() {\r
-               return "dbModel";\r
-       }\r
-}\r
diff --git a/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/AbstractSpringTestCase.java b/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/AbstractSpringTestCase.java
deleted file mode 100644 (file)
index 76b7fb6..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/*\r
- * Copyright (C) 2007-2012 Argeo GmbH\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *         http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.unit;\r
-\r
-import java.util.Map;\r
-\r
-import junit.framework.TestCase;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.argeo.slc.SlcException;\r
-import org.springframework.beans.factory.BeanFactoryUtils;\r
-import org.springframework.beans.factory.ListableBeanFactory;\r
-import org.springframework.context.ConfigurableApplicationContext;\r
-import org.springframework.context.support.ClassPathXmlApplicationContext;\r
-\r
-/** Helper for tests using a Spring application co,text. */\r
-public abstract class AbstractSpringTestCase extends TestCase {\r
-       protected final Log log = LogFactory.getLog(getClass());\r
-       private ConfigurableApplicationContext context;\r
-\r
-       /**\r
-        * Gets (and create if necessary) the application context to use. Default\r
-        * implementation uses a class path xml application context and calls\r
-        * {@link #getApplicationContextLocation()}.\r
-        */\r
-       protected ConfigurableApplicationContext getContext() {\r
-               if (context == null) {\r
-                       context = new ClassPathXmlApplicationContext(\r
-                                       getApplicationContextLocation());\r
-                       if (getIsStartContext())\r
-                               context.start();\r
-               }\r
-               return context;\r
-       }\r
-\r
-       @Override\r
-       protected void tearDown() throws Exception {\r
-               if (context != null && context.isActive())\r
-                       context.close();\r
-               super.tearDown();\r
-       }\r
-\r
-       /** Whether the context should be started after being created. */\r
-       protected Boolean getIsStartContext() {\r
-               return false;\r
-       }\r
-\r
-       /** Returns a bean from the underlying context */\r
-       @SuppressWarnings(value = { "unchecked" })\r
-       protected <T> T getBean(String beanId) {\r
-               return (T) getContext().getBean(beanId);\r
-       }\r
-\r
-       protected <T> T getBean(Class<? extends T> clss) {\r
-               T bean = loadSingleFromContext(getContext(), clss);\r
-               if (bean == null) {\r
-                       throw new SlcException("Cannot retrieve a unique bean of type "\r
-                                       + clss);\r
-               } else {\r
-                       return bean;\r
-               }\r
-       }\r
-\r
-       /**\r
-        * Th location of the application to load. The default implementation\r
-        * returns <i>applicationContext.xml</i> found in the same package as the\r
-        * test.\r
-        */\r
-       protected String getApplicationContextLocation() {\r
-               return inPackage("applicationContext.xml");\r
-       }\r
-\r
-       /**\r
-        * Prefixes the package of the class after converting the '.' to '/' in\r
-        * order to have a resource path.\r
-        */\r
-       protected String inPackage(String suffix) {\r
-               String prefix = getClass().getPackage().getName().replace('.', '/');\r
-               return prefix + '/' + suffix;\r
-       }\r
-\r
-       @SuppressWarnings(value = { "unchecked" })\r
-       protected <T> T loadSingleFromContext(ListableBeanFactory context,\r
-                       Class<T> clss) {\r
-               Map<String, T> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(\r
-                               context, clss, false, false);\r
-               if (beans.size() == 1) {\r
-                       return beans.values().iterator().next();\r
-               } else if (beans.size() > 1) {\r
-                       if (log.isDebugEnabled()) {\r
-                               log\r
-                                               .debug(("Found more that on bean for type " + clss\r
-                                                               + ": " + beans.keySet()));\r
-                       }\r
-                       return null;\r
-               } else {\r
-                       return null;\r
-               }\r
-       }\r
-\r
-}\r
diff --git a/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/UnitUtils.java b/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/UnitUtils.java
deleted file mode 100644 (file)
index 765ec70..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*\r
- * Copyright (C) 2007-2012 Argeo GmbH\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *         http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.unit;\r
-\r
-import java.util.Calendar;\r
-import java.util.Date;\r
-import java.util.GregorianCalendar;\r
-\r
-import static junit.framework.Assert.assertEquals;\r
-import static junit.framework.Assert.assertNull;\r
-import static junit.framework.Assert.assertNotNull;\r
-\r
-public abstract class UnitUtils {\r
-       public static void assertDateSec(Date expected, Date reached) {\r
-               if (expected == null) {\r
-                       assertNull(reached);\r
-                       return;\r
-               } else {\r
-                       assertNotNull(reached);\r
-               }\r
-\r
-               Calendar expectedCal = new GregorianCalendar();\r
-               expectedCal.setTime(expected);\r
-               Calendar reachedCal = new GregorianCalendar();\r
-               reachedCal.setTime(reached);\r
-               assertEquals(expectedCal.get(Calendar.YEAR), reachedCal\r
-                               .get(Calendar.YEAR));\r
-               assertEquals(expectedCal.get(Calendar.MONTH), reachedCal\r
-                               .get(Calendar.MONTH));\r
-               assertEquals(expectedCal.get(Calendar.DATE), reachedCal\r
-                               .get(Calendar.DATE));\r
-               assertEquals(expectedCal.get(Calendar.HOUR_OF_DAY), reachedCal\r
-                               .get(Calendar.HOUR_OF_DAY));\r
-               assertEquals(expectedCal.get(Calendar.MINUTE), reachedCal\r
-                               .get(Calendar.MINUTE));\r
-               assertEquals(expectedCal.get(Calendar.SECOND), reachedCal\r
-                               .get(Calendar.SECOND));\r
-       }\r
-\r
-       private UnitUtils() {\r
-\r
-       }\r
-\r
-}\r
diff --git a/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/UnitXmlUtils.java b/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/UnitXmlUtils.java
deleted file mode 100644 (file)
index 3371405..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*\r
- * Copyright (C) 2007-2012 Argeo GmbH\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *         http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.unit;\r
-\r
-import java.io.IOException;\r
-\r
-import javax.xml.transform.Source;\r
-\r
-import junit.framework.TestCase;\r
-\r
-import org.springframework.xml.validation.XmlValidator;\r
-import org.springframework.xml.xsd.XsdSchema;\r
-import org.xml.sax.SAXParseException;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-\r
-public abstract class UnitXmlUtils {\r
-       private final static Log log = LogFactory.getLog(UnitXmlUtils.class);\r
-\r
-       public static void assertXsdSchemaValidation(XsdSchema schema, Source source)\r
-                       throws IOException {\r
-               XmlValidator validator = schema.createValidator();\r
-               assertXmlValidation(validator, source);\r
-       }\r
-\r
-       public static void assertXmlValidation(XmlValidator validator, Source source)\r
-                       throws IOException {\r
-               SAXParseException[] exceptions = validator.validate(source);\r
-               if (exceptions.length != 0) {\r
-                       for (SAXParseException ex : exceptions) {\r
-                               log.error(ex.getMessage());\r
-                       }\r
-                       TestCase.fail("Could not validate");\r
-               }\r
-       }\r
-\r
-       private UnitXmlUtils() {\r
-\r
-       }\r
-}\r
diff --git a/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/db/DbUnitDeployment.java b/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/db/DbUnitDeployment.java
deleted file mode 100644 (file)
index 25ecb06..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-/*\r
- * Copyright (C) 2007-2012 Argeo GmbH\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *         http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.unit.db;\r
-\r
-import java.sql.SQLException;\r
-\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
-import org.argeo.slc.SlcException;\r
-import org.argeo.slc.UnsupportedException;\r
-import org.argeo.slc.build.Distribution;\r
-import org.argeo.slc.deploy.DeployedSystem;\r
-import org.argeo.slc.deploy.Deployment;\r
-import org.argeo.slc.deploy.DeploymentData;\r
-import org.argeo.slc.deploy.TargetData;\r
-import org.argeo.slc.support.deploy.db.DbModel;\r
-import org.argeo.slc.support.deploy.db.JdbcAware;\r
-import org.dbunit.DataSourceDatabaseTester;\r
-import org.dbunit.DatabaseUnitException;\r
-import org.dbunit.IDatabaseTester;\r
-import org.dbunit.database.IDatabaseConnection;\r
-import org.dbunit.dataset.IDataSet;\r
-import org.dbunit.operation.DatabaseOperation;\r
-\r
-public class DbUnitDeployment implements Deployment {\r
-       private static Log log = LogFactory.getLog(DbUnitDeployment.class);\r
-\r
-       private JdbcAware jdbcAware;\r
-       private DbUnitDeploymentData deploymentData;\r
-       private DbModel dbModel;\r
-\r
-       public void run() {\r
-               try {\r
-                       IDatabaseTester databaseTester = new DataSourceDatabaseTester(\r
-                                       jdbcAware.getDataSource());\r
-                       databaseTester.setSetUpOperation(new DatabaseOperation() {\r
-\r
-                               @Override\r
-                               public void execute(IDatabaseConnection connection,\r
-                                               IDataSet dataSet) throws DatabaseUnitException,\r
-                                               SQLException {\r
-                                       if (dbModel != null) {\r
-                                               dbModel.createSchema(connection.getConnection());\r
-                                               DatabaseOperation.INSERT.execute(connection, dataSet);\r
-                                       } else {\r
-                                               DatabaseOperation.UPDATE.execute(connection, dataSet);\r
-                                       }\r
-                               }\r
-\r
-                       });\r
-                       databaseTester.setDataSet(deploymentData.createDataSet());\r
-                       databaseTester.onSetup();\r
-                       databaseTester.onTearDown();\r
-\r
-                       log.info("Database deployed.");\r
-               } catch (Exception e) {\r
-                       throw new SlcException("Could not initialize the database", e);\r
-               }\r
-       }\r
-\r
-       public DeployedSystem getDeployedSystem() {\r
-               throw new UnsupportedOperationException();\r
-       }\r
-\r
-       public void setDbModel(DbModel dbModel) {\r
-               this.dbModel = dbModel;\r
-       }\r
-\r
-       public void setDeploymentData(DeploymentData deploymentData) {\r
-               this.deploymentData = (DbUnitDeploymentData) deploymentData;\r
-       }\r
-\r
-       public void setTargetData(TargetData targetData) {\r
-               this.jdbcAware = (JdbcAware) targetData;\r
-\r
-       }\r
-\r
-       public void setDistribution(Distribution distribution) {\r
-               throw new UnsupportedException("Method not supported");\r
-       }\r
-\r
-}\r
diff --git a/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/db/DbUnitDeploymentData.java b/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/db/DbUnitDeploymentData.java
deleted file mode 100644 (file)
index 46835c6..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*\r
- * Copyright (C) 2007-2012 Argeo GmbH\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *         http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.argeo.slc.unit.db;\r
-\r
-import java.io.InputStream;\r
-\r
-import org.argeo.slc.SlcException;\r
-import org.argeo.slc.deploy.DeploymentData;\r
-import org.dbunit.dataset.IDataSet;\r
-import org.dbunit.dataset.xml.FlatXmlDataSet;\r
-import org.springframework.core.io.Resource;\r
-\r
-public class DbUnitDeploymentData implements DeploymentData {\r
-       private Resource dataSetLocation;\r
-\r
-       public IDataSet createDataSet() {\r
-               try {\r
-                       InputStream in = dataSetLocation.getInputStream();\r
-                       IDataSet dataSet = new FlatXmlDataSet(in);\r
-                       in.close();\r
-                       return dataSet;\r
-               } catch (Exception e) {\r
-                       throw new SlcException("Cannot create data set", e);\r
-               }\r
-\r
-       }\r
-\r
-       public void setDataSetLocation(Resource dataSetLocation) {\r
-               this.dataSetLocation = dataSetLocation;\r
-       }\r
-\r
-}\r
diff --git a/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/execution/AbstractExecutionFlowTestcase.java b/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/execution/AbstractExecutionFlowTestcase.java
deleted file mode 100644 (file)
index 774ce25..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *         http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.unit.execution;
-
-import org.argeo.slc.execution.ExecutionFlow;
-import org.argeo.slc.unit.AbstractSpringTestCase;
-
-public class AbstractExecutionFlowTestcase extends AbstractSpringTestCase {
-       @SuppressWarnings(value = { "unchecked" })
-       protected <T extends ExecutionFlow> T executeFlow(String flowName) {
-               ExecutionFlow flow = getBean(flowName);
-               flow.run();
-               return (T) flow;
-       }
-}
diff --git a/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/execution/ExecutionFlowDescriptorTestUtils.java b/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/execution/ExecutionFlowDescriptorTestUtils.java
deleted file mode 100644 (file)
index b8619f4..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *         http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.slc.unit.execution;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.argeo.slc.core.execution.DefaultExecutionSpec;
-import org.argeo.slc.core.execution.PrimitiveAccessor;
-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.execution.RefValueChoice;
-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");
-               flowDescriptor.setDescription("my description");
-
-               Map<String, Object> values = new HashMap<String, Object>();
-               values.put("primitiveInteger", new PrimitiveValue(
-                               PrimitiveAccessor.TYPE_INTEGER, 100));
-
-               RefValue refValue = new RefValue("002");
-               values.put("ref1", refValue);
-               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(PrimitiveAccessor.TYPE_INTEGER);
-               primitiveInteger.setValue(50);
-               attributes.put("primitiveInteger", primitiveInteger);
-
-               RefSpecAttribute ref1 = new RefSpecAttribute();
-               ref1.setTargetClass(BasicTestData.class);
-               ref1.setChoices(new ArrayList<RefValueChoice>());
-               ref1.getChoices().add(new RefValueChoice("001", "desc"));
-               ref1.getChoices().add(new RefValueChoice("002", null));
-               ref1.getChoices().add(new RefValueChoice("003", null));
-               attributes.put("ref1", ref1);
-
-               spec.setAttributes(attributes);
-
-               return spec;
-       }
-}
diff --git a/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/package.html b/runtime/org.argeo.slc.unit/src/main/java/org/argeo/slc/unit/package.html
deleted file mode 100644 (file)
index 907430d..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<html>\r
-<head></head>\r
-<body>\r
-Helpers for unit tests.\r
-</body>\r
-</html>
\ No newline at end of file