Author: cschneider
Date: Tue Nov 20 10:43:40 2012
New Revision: 1411614
URL: http://svn.apache.org/viewvc?rev=1411614&view=rev
Log:
Improve test structure
Modified:
cxf/dosgi/trunk/systests2/common/src/main/java/org/apache/cxf/dosgi/systests2/common/AbstractTestImportService.java
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/MultiBundleTools.java
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestDiscoveryExport.java
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestImportService.java
Modified:
cxf/dosgi/trunk/systests2/common/src/main/java/org/apache/cxf/dosgi/systests2/common/AbstractTestImportService.java
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/common/src/main/java/org/apache/cxf/dosgi/systests2/common/AbstractTestImportService.java?rev=1411614&r1=1411613&r2=1411614&view=diff
==============================================================================
---
cxf/dosgi/trunk/systests2/common/src/main/java/org/apache/cxf/dosgi/systests2/common/AbstractTestImportService.java
(original)
+++
cxf/dosgi/trunk/systests2/common/src/main/java/org/apache/cxf/dosgi/systests2/common/AbstractTestImportService.java
Tue Nov 20 10:43:40 2012
@@ -88,9 +88,6 @@ public abstract class AbstractTestImport
Thread.currentThread().setContextClassLoader(ServerFactoryBean.class.getClassLoader());
server = factory.create();
- System.out.println("Give the system a few seconds to breathe...");
- Thread.sleep(3000);
-
Hashtable<String, Object> props = new Hashtable<String, Object>();
props.put("testName", "test1");
getBundleContext().registerService(Object.class.getName(), new
Object(), props);
Modified:
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/MultiBundleTools.java
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/MultiBundleTools.java?rev=1411614&r1=1411613&r2=1411614&view=diff
==============================================================================
---
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/MultiBundleTools.java
(original)
+++
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/MultiBundleTools.java
Tue Nov 20 10:43:40 2012
@@ -21,12 +21,17 @@ package org.apache.cxf.dosgi.systests2.m
import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.TreeMap;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -35,7 +40,7 @@ import org.w3c.dom.NodeList;
public class MultiBundleTools {
private MultiBundleTools() {}
- static int getDistroBundles(Map<Integer, String> bundles, boolean
discovery) throws Exception {
+ private static int getDistroBundles(Map<Integer, String> bundles, boolean
discovery) throws Exception {
File root = getRootDirectory();
File mdRoot = new File(root, "distribution/multi-bundle");
String pomVersion = getPomVersion(mdRoot);
@@ -102,4 +107,23 @@ public class MultiBundleTools {
}
return pomVersion;
}
+
+ private static Option[] getDistroBundleOptions(boolean b) throws Exception
{
+ Map<Integer, String> bundles = new TreeMap<Integer, String>();
+ MultiBundleTools.getDistroBundles(bundles, true);
+ List<Option> opts = new ArrayList<Option>();
+ for (Map.Entry<Integer, String> entry : bundles.entrySet()) {
+ String bundleUri = entry.getValue();
+ opts.add(CoreOptions.bundle(bundleUri));
+ }
+ return opts.toArray(new Option[opts.size()]);
+ }
+
+ public static Option getDistroWithDiscovery() throws Exception {
+ return CoreOptions.composite(getDistroBundleOptions(true));
+ }
+
+ public static Option getDistro() throws Exception {
+ return CoreOptions.composite(getDistroBundleOptions(true));
+ }
}
Modified:
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestDiscoveryExport.java
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestDiscoveryExport.java?rev=1411614&r1=1411613&r2=1411614&view=diff
==============================================================================
---
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestDiscoveryExport.java
(original)
+++
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestDiscoveryExport.java
Tue Nov 20 10:43:40 2012
@@ -18,14 +18,12 @@
*/
package org.apache.cxf.dosgi.systests2.multi;
+import static org.ops4j.pax.exam.CoreOptions.frameworkStartLevel;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
import java.io.IOException;
import java.net.ServerSocket;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
import javax.inject.Inject;
@@ -36,7 +34,6 @@ import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.CoreOptions;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.Configuration;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
@@ -54,40 +51,40 @@ public class TestDiscoveryExport extends
@Configuration
public static Option[] configure() throws Exception {
- Map<Integer, String> bundles = new TreeMap<Integer, String>();
- MultiBundleTools.getDistroBundles(bundles, true);
-
- List<Option> opts = new ArrayList<Option>();
-
- for (Map.Entry<Integer, String> entry : bundles.entrySet()) {
- String bundleUri = entry.getValue();
- opts.add(CoreOptions.bundle(bundleUri));
- }
-
opts.add(CoreOptions.mavenBundle().groupId("org.apache.servicemix.bundles")
-
.artifactId("org.apache.servicemix.bundles.junit").version("4.9_2"));
-
opts.add(CoreOptions.mavenBundle().groupId("org.apache.cxf.dosgi.samples")
-
.artifactId("cxf-dosgi-ri-samples-greeter-interface").versionAsInProject());
-
opts.add(CoreOptions.mavenBundle().groupId("org.apache.cxf.dosgi.samples")
-
.artifactId("cxf-dosgi-ri-samples-greeter-impl").versionAsInProject());
-
opts.add(mavenBundle().groupId("org.apache.cxf.dosgi.systests").artifactId("cxf-dosgi-ri-systests2-common")
- .versionAsInProject());
-
- return CoreOptions.options(opts.toArray(new Option[opts.size()]));
+ return new Option[] {
+ MultiBundleTools.getDistroWithDiscovery(),
+
systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
+
mavenBundle().groupId("org.apache.servicemix.bundles").artifactId("org.apache.servicemix.bundles.junit").version("4.9_2"),
+
mavenBundle().groupId("org.apache.cxf.dosgi.samples").artifactId("cxf-dosgi-ri-samples-greeter-interface").versionAsInProject(),
+
mavenBundle().groupId("org.apache.cxf.dosgi.samples").artifactId("cxf-dosgi-ri-samples-greeter-impl").versionAsInProject(),
+
mavenBundle().groupId("org.apache.cxf.dosgi.systests").artifactId("cxf-dosgi-ri-systests2-common").versionAsInProject(),
+ frameworkStartLevel(100)
+ };
}
@Test
public void testDiscoveryExport() throws Exception {
final int zkPort = getFreePort();
configureZookeeper(configAdmin, zkPort);
- Thread.sleep(3000);
ZooKeeper zk = new ZooKeeper("localhost:" + zkPort, 1000, null);
- Stat stat = zk.exists(
-
"/osgi/service_registry/org/apache/cxf/dosgi/samples/greeter/GreeterService/localhost#9090##greeter",
- null);
- Assert.assertNotNull("Node for GreeterService endpoint not found in
zookeeper", stat);
+ assertExists(zk,
"/osgi/service_registry/org/apache/cxf/dosgi/samples/greeter/GreeterService/localhost#9090##greeter",
4000);
zk.close();
}
+ private void assertExists(ZooKeeper zk, String zNode, int timeout) {
+ long endTime = System.currentTimeMillis() + timeout;
+ Stat stat = null;
+ while (stat == null && System.currentTimeMillis() < endTime) {
+ try {
+ stat = zk.exists(zNode, null);
+ Thread.sleep(200);
+ } catch (Exception e) {
+ // Ignore
+ }
+ }
+ Assert.assertNotNull("Zookeeper node " + zNode + " was not found",
stat);
+ }
+
private int getFreePort() throws IOException {
ServerSocket socket = new ServerSocket(0);
try {
Modified:
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java?rev=1411614&r1=1411613&r2=1411614&view=diff
==============================================================================
---
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java
(original)
+++
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestExportService.java
Tue Nov 20 10:43:40 2012
@@ -18,17 +18,15 @@
*/
package org.apache.cxf.dosgi.systests2.multi;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
+import static org.ops4j.pax.exam.CoreOptions.frameworkStartLevel;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
import javax.inject.Inject;
import org.apache.cxf.dosgi.systests2.common.AbstractTestExportService;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.CoreOptions;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.Configuration;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
@@ -41,29 +39,15 @@ public class TestExportService extends A
@Configuration
public static Option[] configure() throws Exception {
- Map<Integer, String> bundles = new TreeMap<Integer, String>();
- int startLevel = MultiBundleTools.getDistroBundles(bundles, false);
-
- List<Option> opts = new ArrayList<Option>();
-
- for(Map.Entry<Integer, String> entry : bundles.entrySet()) {
- String bundleUri = entry.getValue();
- if (!bundleUri.contains("pax-logging")) {
- opts.add(CoreOptions.bundle(bundleUri));
- }
- }
-
opts.add(CoreOptions.mavenBundle().groupId("org.apache.servicemix.bundles"
).artifactId("org.apache.servicemix.bundles.junit").version("4.9_2"));
-
opts.add(CoreOptions.mavenBundle().groupId("org.apache.cxf.dosgi.samples").artifactId("cxf-dosgi-ri-samples-greeter-interface").versionAsInProject());
-
opts.add(CoreOptions.mavenBundle().groupId("org.apache.cxf.dosgi.samples").artifactId("cxf-dosgi-ri-samples-greeter-impl").versionAsInProject());
-
opts.add(CoreOptions.mavenBundle().groupId("org.apache.cxf.dosgi.systests").artifactId("cxf-dosgi-ri-systests2-common").versionAsInProject());
-
opts.add(CoreOptions.systemProperty("org.osgi.framework.startlevel.beginning").value(""
+ startLevel));
-
- // For debugging...
- // opts.add(PaxRunnerOptions.vmOption(
"-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=6006" ));
- // opts.add(CoreOptions.waitForFrameworkStartup());
- // end debugging section.
-
- return CoreOptions.options(opts.toArray(new Option[opts.size()]));
+ return new Option[] {
+ MultiBundleTools.getDistroWithDiscovery(),
+
systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
+ mavenBundle().groupId("org.apache.servicemix.bundles"
).artifactId("org.apache.servicemix.bundles.junit").version("4.9_2"),
+
mavenBundle().groupId("org.apache.cxf.dosgi.samples").artifactId("cxf-dosgi-ri-samples-greeter-interface").versionAsInProject(),
+
mavenBundle().groupId("org.apache.cxf.dosgi.samples").artifactId("cxf-dosgi-ri-samples-greeter-impl").versionAsInProject(),
+
mavenBundle().groupId("org.apache.cxf.dosgi.systests").artifactId("cxf-dosgi-ri-systests2-common").versionAsInProject(),
+ frameworkStartLevel(100)
+ };
}
Modified:
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestImportService.java
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestImportService.java?rev=1411614&r1=1411613&r2=1411614&view=diff
==============================================================================
---
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestImportService.java
(original)
+++
cxf/dosgi/trunk/systests2/multi-bundle/src/test/java/org/apache/cxf/dosgi/systests2/multi/TestImportService.java
Tue Nov 20 10:43:40 2012
@@ -18,17 +18,16 @@
*/
package org.apache.cxf.dosgi.systests2.multi;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
+import static org.ops4j.pax.exam.CoreOptions.frameworkStartLevel;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
import javax.inject.Inject;
import org.apache.cxf.dosgi.systests2.common.AbstractTestImportService;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.CoreOptions;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.Configuration;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
@@ -41,25 +40,18 @@ public class TestImportService extends A
@Configuration
public static Option[] configure() throws Exception {
- Map<Integer, String> bundles = new TreeMap<Integer, String>();
- MultiBundleTools.getDistroBundles(bundles, false);
-
- List<Option> opts = new ArrayList<Option>();
- for(Map.Entry<Integer, String> entry : bundles.entrySet()) {
- String bundleUri = entry.getValue();
- if (!bundleUri.contains("pax-logging")) {
- opts.add(CoreOptions.bundle(bundleUri));
- }
- }
-
opts.add(CoreOptions.mavenBundle().groupId("org.apache.cxf.dosgi.samples").artifactId("cxf-dosgi-ri-samples-greeter-interface").versionAsInProject());
-
opts.add(CoreOptions.mavenBundle().groupId("org.apache.servicemix.bundles"
).artifactId("org.apache.servicemix.bundles.junit").version("4.9_2"));
-
opts.add(CoreOptions.mavenBundle().groupId("org.apache.cxf.dosgi.systests").artifactId("cxf-dosgi-ri-systests2-common").versionAsInProject());
- opts.add(CoreOptions.provision(getTestClientBundle()));
-
- // service wait timeout (this should also be increased for
debugging)...
-
opts.add(CoreOptions.systemProperty("org.apache.cxf.dosgi.test.serviceWaitTimeout").value(System.getProperty("org.apache.cxf.dosgi.test.serviceWaitTimeout",
"20")));
-
- return CoreOptions.options(opts.toArray(new Option[opts.size()]));
+ return new Option[] {
+ MultiBundleTools.getDistroWithDiscovery(),
+
systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
+
mavenBundle().groupId("org.apache.cxf.dosgi.samples").artifactId("cxf-dosgi-ri-samples-greeter-interface").versionAsInProject(),
+
mavenBundle().groupId("org.apache.servicemix.bundles").artifactId("org.apache.servicemix.bundles.junit").version("4.9_2"),
+
mavenBundle().groupId("org.apache.cxf.dosgi.systests").artifactId("cxf-dosgi-ri-systests2-common").versionAsInProject(),
+ provision(getTestClientBundle()),
+ // increase for debugging
+
systemProperty("org.apache.cxf.dosgi.test.serviceWaitTimeout").value(
+
System.getProperty("org.apache.cxf.dosgi.test.serviceWaitTimeout", "20")),
+ frameworkStartLevel(100)
+ };
}
protected BundleContext getBundleContext() {