You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by GitBox <gi...@apache.org> on 2019/01/11 16:46:28 UTC

[GitHub] amarkevich closed pull request #497: org.apache.cxf.osgi.itests: improve test stability

amarkevich closed pull request #497: org.apache.cxf.osgi.itests: improve test stability
URL: https://github.com/apache/cxf/pull/497
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/AbstractServerActivator.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/AbstractServerActivator.java
new file mode 100644
index 00000000000..66a6e8fea33
--- /dev/null
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/AbstractServerActivator.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.cxf.osgi.itests;
+
+import org.apache.cxf.endpoint.Server;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.util.tracker.ServiceTracker;
+
+public abstract class AbstractServerActivator implements BundleActivator {
+
+    private Server server;
+
+    public static void awaitService(BundleContext bundleContext, String filter, long timeout)
+            throws InvalidSyntaxException, InterruptedException {
+        Filter serviceFilter = bundleContext.createFilter(filter);
+        ServiceTracker<Object, ?> tracker = new ServiceTracker<>(bundleContext, serviceFilter, null);
+        tracker.open();
+        Object service = tracker.waitForService(timeout);
+        tracker.close();
+        if (service == null) {
+            throw new IllegalStateException("Expected service with filter " + filter + " was not found");
+        }
+    }
+
+    private static void awaitCxfServlet(BundleContext bundleContext)
+            throws InvalidSyntaxException, InterruptedException {
+        awaitService(bundleContext, "(" + Constants.OBJECTCLASS + "=javax.servlet.ServletContext)", 60000L);
+    }
+
+    @Override
+    public void start(BundleContext bundleContext) throws Exception {
+        awaitCxfServlet(bundleContext);
+        server = createServer();
+    }
+
+    protected abstract Server createServer();
+
+    @Override
+    public void stop(BundleContext bundleContext) throws Exception {
+        server.destroy();
+    }
+
+}
diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/BundlesAndNamespacesTest.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/BundlesAndNamespacesTest.java
index 5640197648a..05b70256d26 100644
--- a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/BundlesAndNamespacesTest.java
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/BundlesAndNamespacesTest.java
@@ -38,23 +38,23 @@
     @Test
     public void test() throws Exception {
         assertBundleStarted("org.apache.cxf.cxf-core");
-        assertBlueprintNamespacePublished("http://cxf.apache.org/blueprint/core", 1000);
-        assertBlueprintNamespacePublished("http://cxf.apache.org/configuration/beans", 1000);
-        assertBlueprintNamespacePublished("http://cxf.apache.org/configuration/parameterized-types", 1000);
-        assertBlueprintNamespacePublished("http://cxf.apache.org/configuration/security", 1000);
-        assertBlueprintNamespacePublished("http://schemas.xmlsoap.org/wsdl/", 1000);
+        assertBlueprintNamespacePublished("http://cxf.apache.org/blueprint/core", 1000L);
+        assertBlueprintNamespacePublished("http://cxf.apache.org/configuration/beans", 1000L);
+        assertBlueprintNamespacePublished("http://cxf.apache.org/configuration/parameterized-types", 1000L);
+        assertBlueprintNamespacePublished("http://cxf.apache.org/configuration/security", 1000L);
+        assertBlueprintNamespacePublished("http://schemas.xmlsoap.org/wsdl/", 1000L);
 
         assertBundleStarted("org.apache.cxf.cxf-rt-frontend-jaxws");
-        assertBlueprintNamespacePublished("http://cxf.apache.org/blueprint/jaxws", 1000);
-        assertBlueprintNamespacePublished("http://cxf.apache.org/blueprint/simple", 1000);
+        assertBlueprintNamespacePublished("http://cxf.apache.org/blueprint/jaxws", 1000L);
+        assertBlueprintNamespacePublished("http://cxf.apache.org/blueprint/simple", 1000L);
     }
 
     @Configuration
     public Option[] config() {
         return new Option[]{
                 cxfBaseConfig(),
-
-                features(cxfUrl, "aries-blueprint", "cxf-core", "cxf-jaxws"),
+                features(karafUrl, "aries-blueprint"),
+                features(cxfUrl, "cxf-core", "cxf-jaxws"),
                 logLevel(LogLevel.INFO)};
     }
 }
diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/CXFOSGiTestSupport.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/CXFOSGiTestSupport.java
index 42246711b07..cffd4d633d7 100644
--- a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/CXFOSGiTestSupport.java
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/CXFOSGiTestSupport.java
@@ -22,27 +22,22 @@
 
 
 import java.io.File;
-import java.io.IOException;
-import java.net.DatagramSocket;
-import java.net.ServerSocket;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
+import java.net.URISyntaxException;
 
 import javax.inject.Inject;
 
-import org.apache.karaf.features.FeaturesService;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.Filter;
-import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.framework.InvalidSyntaxException;
 
-import org.junit.Assert;
 import org.ops4j.pax.exam.MavenUtils;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.karaf.container.internal.JavaVersionUtil;
 import org.ops4j.pax.exam.options.MavenUrlReference;
 import org.ops4j.pax.exam.options.extra.VMOption;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.ops4j.pax.exam.CoreOptions.composite;
 import static org.ops4j.pax.exam.CoreOptions.maven;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
@@ -60,11 +55,6 @@
     @Inject
     protected BundleContext bundleContext;
 
-    @Inject
-    protected FeaturesService featureService;
-
-    protected ExecutorService executor = Executors.newCachedThreadPool();
-
     protected MavenUrlReference cxfUrl;
     protected MavenUrlReference karafUrl;
     protected MavenUrlReference amqUrl;
@@ -81,16 +71,21 @@ private static String getKarafVersion() {
      */
     protected Option cxfBaseConfig() {
         karafUrl = maven().groupId("org.apache.karaf").artifactId("apache-karaf-minimal").version(getKarafVersion())
-            .type("tar.gz");
+                .type("tar.gz");
         cxfUrl = maven().groupId("org.apache.cxf.karaf").artifactId("apache-cxf").versionAsInProject()
-            .type("xml").classifier("features");
+                .type("xml").classifier("features");
         amqUrl = maven().groupId("org.apache.activemq")
-        .artifactId("activemq-karaf").type("xml").classifier("features").versionAsInProject();
-        springLegacyUrl = maven().groupId("org.apache.karaf.features").
-            artifactId("spring-legacy").version(getKarafVersion())
-            .type("xml").classifier("features");
+                .artifactId("activemq-karaf").type("xml").classifier("features").versionAsInProject();
+        springLegacyUrl = maven().groupId("org.apache.karaf.features").artifactId("spring-legacy")
+                .version(getKarafVersion()).type("xml").classifier("features");
         String localRepo = System.getProperty("localRepository");
         Object urp = System.getProperty("cxf.useRandomFirstPort");
+        final File loggingCfg;
+        try {
+            loggingCfg = new File(getClass().getResource("/etc/org.ops4j.pax.logging.cfg").toURI());
+        } catch (URISyntaxException e) {
+            throw new RuntimeException(e);
+        }
         if (JavaVersionUtil.getMajorVersion() >= 9) {
             return composite(karafDistributionConfiguration()
                              .frameworkUrl(karafUrl)
@@ -103,8 +98,7 @@ protected Option cxfBaseConfig() {
                          //debugConfiguration(), // nor this
                          systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
                          systemProperty("java.awt.headless").value("true"),
-                         replaceConfigurationFile("etc/org.ops4j.pax.logging.cfg",
-                                                  new File("src/test/resources/etc/org.ops4j.pax.logging.cfg")),
+                         replaceConfigurationFile("etc/org.ops4j.pax.logging.cfg", loggingCfg),
                          when(localRepo != null)
                              .useOptions(editConfigurationFilePut("etc/org.ops4j.pax.url.mvn.cfg",
                                                                   "org.ops4j.pax.url.mvn.localRepository",
@@ -149,8 +143,7 @@ protected Option cxfBaseConfig() {
                          //debugConfiguration(), // nor this
                          systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
                          systemProperty("java.awt.headless").value("true"),
-                         replaceConfigurationFile("etc/org.ops4j.pax.logging.cfg",
-                                                  new File("src/test/resources/etc/org.ops4j.pax.logging.cfg")),
+                         replaceConfigurationFile("etc/org.ops4j.pax.logging.cfg", loggingCfg),
                          when(localRepo != null)
                              .useOptions(editConfigurationFilePut("etc/org.ops4j.pax.url.mvn.cfg",
                                                                   "org.ops4j.pax.url.mvn.localRepository",
@@ -159,66 +152,14 @@ protected Option cxfBaseConfig() {
         }
     }
 
-    protected Option testUtils() {
+    protected static Option testUtils() {
         return mavenBundle().groupId("org.apache.cxf").artifactId("cxf-testutils").versionAsInProject();
     }
 
-    protected Bundle getInstalledBundle(String symbolicName) {
-        for (Bundle b : bundleContext.getBundles()) {
-            if (b.getSymbolicName().equals(symbolicName)) {
-                return b;
-            }
-        }
-        for (Bundle b : bundleContext.getBundles()) {
-            System.err.println("Bundle: " + b.getSymbolicName());
-        }
-        throw new RuntimeException("Bundle " + symbolicName + " does not exist");
-    }
-
-    /**
-     * Finds a free port starting from the give port numner.
-     *
-     * @return
-     */
-    protected int getFreePort(int port) {
-        while (!isPortAvailable(port)) {
-            port++;
-        }
-        return port;
-    }
-
-    /**
-     * Returns true if port is available for use.
-     *
-     * @param port
-     * @return
-     */
-    public static boolean isPortAvailable(int port) {
-        ServerSocket ss = null;
-        try (DatagramSocket ds = new DatagramSocket(port)) {
-            ss = new ServerSocket(port);
-            ss.setReuseAddress(true);
-            ds.setReuseAddress(true);
-            return true;
-        } catch (IOException e) {
-            // ignore
-        } finally {
-            if (ss != null) {
-                try {
-                    ss.close();
-                } catch (IOException e) {
-                    /* should not be thrown */
-                }
-            }
-        }
-
-        return false;
-    }
-
     protected void assertBundleStarted(String name) {
         Bundle bundle = findBundleByName(name);
-        Assert.assertNotNull("Bundle " + name + " should be installed", bundle);
-        Assert.assertEquals("Bundle " + name + " should be started", Bundle.ACTIVE, bundle.getState());
+        assertNotNull("Bundle " + name + " should be installed", bundle);
+        assertEquals("Bundle " + name + " should be started", Bundle.ACTIVE, bundle.getState());
     }
 
     protected Bundle findBundleByName(String symbolicName) {
@@ -230,24 +171,12 @@ protected Bundle findBundleByName(String symbolicName) {
         return null;
     }
 
-    public void assertServicePublished(String filter, int timeout) {
-        try {
-            Filter serviceFilter = bundleContext.createFilter(filter);
-            ServiceTracker<Object, ?> tracker = new ServiceTracker<>(bundleContext, serviceFilter, null);
-            tracker.open();
-            Object service = tracker.waitForService(timeout);
-            tracker.close();
-            if (service == null) {
-                throw new IllegalStateException("Expected service with filter " + filter + " was not found");
-            }
-        } catch (Exception e) {
-            throw new RuntimeException("Unexpected exception occured", e);
-        }
-    }
-
-    public void assertBlueprintNamespacePublished(String namespace, int timeout) {
-        assertServicePublished(String.format("(&(objectClass=org.apache.aries.blueprint.NamespaceHandler)"
-                                             + "(osgi.service.blueprint.namespace=%s))", namespace), timeout);
+    protected void assertBlueprintNamespacePublished(String namespace, long timeout)
+            throws InvalidSyntaxException, InterruptedException {
+        AbstractServerActivator.awaitService(bundleContext,
+                String.format("(&(objectClass=org.apache.aries.blueprint.NamespaceHandler)"
+                        + "(osgi.service.blueprint.namespace=%s))", namespace),
+                timeout);
     }
 
 }
diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java
index 05a1847b84f..b59f96cda6c 100644
--- a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java
@@ -20,17 +20,16 @@
 
 import java.io.InputStream;
 
-import javax.ws.rs.client.Client;
 import javax.ws.rs.client.ClientBuilder;
 import javax.ws.rs.client.Entity;
 import javax.ws.rs.client.WebTarget;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status;
 
+import org.apache.cxf.osgi.itests.AbstractServerActivator;
 import org.apache.cxf.osgi.itests.CXFOSGiTestSupport;
 import org.osgi.framework.Constants;
 
-import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Configuration;
@@ -41,7 +40,8 @@
 import org.ops4j.pax.exam.spi.reactors.PerClass;
 import org.ops4j.pax.tinybundles.core.TinyBundles;
 
-
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.ops4j.pax.exam.CoreOptions.provision;
 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
@@ -53,17 +53,12 @@
 
     private static final String BASE_URL = "http://localhost:8181/cxf/jaxrs/bookstore";
 
-    private final WebTarget wt;
-
-    public JaxRsServiceTest() {
-        Client client = ClientBuilder.newClient();
-        wt = client.target(BASE_URL);
-    }
+    private final WebTarget wt = ClientBuilder.newClient().target(BASE_URL);
 
     @Test
     public void testJaxRsGet() throws Exception {
         Book book = wt.path("/books/123").request("application/xml").get(Book.class);
-        Assert.assertNotNull(book);
+        assertNotNull(book);
     }
 
     @Test
@@ -71,7 +66,7 @@ public void testJaxRsPost() throws Exception {
         Book book = new Book("New Book", 321);
         Response response = wt.path("/books/").request("application/xml").post(Entity.xml(book));
         assertStatus(Status.CREATED, response);
-        Assert.assertNotNull(response.getLocation());
+        assertNotNull(response.getLocation());
     }
     
     @Test
@@ -86,7 +81,7 @@ public void postWithValidation() throws Exception {
         Book book = new Book("A Book", 3212);
         Response response = wt.path("/books-validate/").request("application/xml").post(Entity.xml(book));
         assertStatus(Status.CREATED, response);
-        Assert.assertNotNull(response.getLocation());
+        assertNotNull(response.getLocation());
     }
 
     @Test
@@ -102,25 +97,24 @@ public void testJaxRsPut() throws Exception {
         assertStatus(Status.OK, response);
     }
 
+    private static void assertStatus(Status expectedStatus, Response response) {
+        assertEquals(expectedStatus.getStatusCode(), response.getStatus());
+    }
+
     @Configuration
     public Option[] config() {
         return new Option[] {
             cxfBaseConfig(),
-            features(cxfUrl, "aries-blueprint", "cxf-core", "cxf-wsdl", "cxf-jaxrs", "http",
-                    "cxf-bean-validation-core",
-                    "cxf-bean-validation"),
-            testUtils(),
+            features(karafUrl, "aries-blueprint", "http"),
+            features(cxfUrl, "cxf-core", "cxf-wsdl", "cxf-jaxrs", "cxf-bean-validation-core", "cxf-bean-validation"),
             logLevel(LogLevel.INFO),
             provision(serviceBundle())
         };
     }
 
-    private void assertStatus(Status expectedStatus, Response response) {
-        Assert.assertEquals(expectedStatus.getStatusCode(), response.getStatus());
-    }
-
-    private InputStream serviceBundle() {
+    private static InputStream serviceBundle() {
         return TinyBundles.bundle()
+                  .add(AbstractServerActivator.class)
                   .add(JaxRsTestActivator.class)
                   .add(Book.class)
                   .add(BookStore.class)
diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsTestActivator.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsTestActivator.java
index 6a73a29f96b..8f4b2868f9d 100644
--- a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsTestActivator.java
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsTestActivator.java
@@ -18,31 +18,21 @@
  */
 package org.apache.cxf.osgi.itests.jaxrs;
 
-import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
+import org.apache.cxf.osgi.itests.AbstractServerActivator;
 
-public class JaxRsTestActivator implements BundleActivator {
-//    public static final String PORT = TestUtil.getPortNumber(JaxRsTestActivator.class);
-    private Server server;
+public class JaxRsTestActivator extends AbstractServerActivator {
 
     @Override
-    public void start(BundleContext arg0) throws Exception {
-        Bus bus = BusFactory.newInstance().createBus();
-        bus.setExtension(JaxRsTestActivator.class.getClassLoader(), ClassLoader.class);
+    protected Server createServer() {
+//        Bus bus = BusFactory.newInstance().createBus();
+//        bus.setExtension(JaxRsTestActivator.class.getClassLoader(), ClassLoader.class);
         JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
-        sf.setBus(bus);
+//        sf.setBus(bus);
         sf.setResourceClasses(BookStore.class);
         sf.setAddress("/jaxrs");
-        server = sf.create();
-    }
-
-    @Override
-    public void stop(BundleContext arg0) throws Exception {
-        server.destroy();
+        return sf.create();
     }
 
 }
diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/soap/HttpServiceTest.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/soap/HttpServiceTest.java
index c2894d0c82b..307d1f893dd 100644
--- a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/soap/HttpServiceTest.java
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/soap/HttpServiceTest.java
@@ -21,10 +21,10 @@
 import java.io.InputStream;
 
 import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+import org.apache.cxf.osgi.itests.AbstractServerActivator;
 import org.apache.cxf.osgi.itests.CXFOSGiTestSupport;
 import org.osgi.framework.Constants;
 
-import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Configuration;
@@ -35,6 +35,7 @@
 import org.ops4j.pax.exam.spi.reactors.PerClass;
 import org.ops4j.pax.tinybundles.core.TinyBundles;
 
+import static org.junit.Assert.assertEquals;
 import static org.ops4j.pax.exam.CoreOptions.provision;
 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
@@ -47,14 +48,14 @@
     public void testHttpEndpoint() throws Exception {
         Greeter greeter = greeterHttpProxy("8181");
         String res = greeter.greetMe("Chris");
-        Assert.assertEquals("Hi Chris", res);
+        assertEquals("Hi Chris", res);
     }
 
     @Test
     public void testHttpEndpointJetty() throws Exception {
         Greeter greeter = greeterHttpProxy(HttpTestActivator.PORT);
         String res = greeter.greetMe("Chris");
-        Assert.assertEquals("Hi Chris", res);
+        assertEquals("Hi Chris", res);
     }
 
     private Greeter greeterHttpProxy(String port) {
@@ -68,15 +69,17 @@ private Greeter greeterHttpProxy(String port) {
     public Option[] config() {
         return new Option[] {
             cxfBaseConfig(),
-            features(cxfUrl, "cxf-jaxws", "cxf-http-jetty", "http"),
+            features(karafUrl, "http"),
+            features(cxfUrl, "cxf-jaxws", "cxf-http-jetty"),
             testUtils(),
             logLevel(LogLevel.INFO),
             provision(serviceBundle())
         };
     }
 
-    private InputStream serviceBundle() {
+    private static InputStream serviceBundle() {
         return TinyBundles.bundle()
+                  .add(AbstractServerActivator.class)
                   .add(HttpTestActivator.class)
                   .add(Greeter.class)
                   .add(GreeterImpl.class)
diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/soap/HttpTestActivator.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/soap/HttpTestActivator.java
index 8d46c1a3580..56b8b79b294 100644
--- a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/soap/HttpTestActivator.java
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/soap/HttpTestActivator.java
@@ -20,19 +20,18 @@
 
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
+import org.apache.cxf.osgi.itests.AbstractServerActivator;
 import org.apache.cxf.testutil.common.TestUtil;
-import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 
-public class HttpTestActivator implements BundleActivator {
+public class HttpTestActivator extends AbstractServerActivator {
     public static final String PORT = TestUtil.getPortNumber(HttpTestActivator.class);
-    private Server server;
     private Server serverJetty;
 
     @Override
-    public void start(BundleContext arg0) throws Exception {
-        server = createTestServer("/greeter");
+    protected Server createServer() {
         serverJetty = createTestServer("http://localhost:" + PORT + "/cxf/greeter");
+        return createTestServer("/greeter");
     }
 
     private Server createTestServer(String url) {
@@ -44,8 +43,8 @@ private Server createTestServer(String url) {
     }
 
     @Override
-    public void stop(BundleContext arg0) throws Exception {
-        server.destroy();
+    public void stop(BundleContext bundleContext) throws Exception {
+        super.stop(bundleContext);
         serverJetty.destroy();
     }
 
diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/soap/JmsServiceTest.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/soap/JmsServiceTest.java
index a97fbccc3b4..dcde114986e 100644
--- a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/soap/JmsServiceTest.java
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/soap/JmsServiceTest.java
@@ -29,7 +29,6 @@
 import org.apache.cxf.transport.jms.ConnectionFactoryFeature;
 import org.osgi.framework.Constants;
 
-import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Configuration;
@@ -39,6 +38,7 @@
 import org.ops4j.pax.exam.spi.reactors.PerClass;
 import org.ops4j.pax.tinybundles.core.TinyBundles;
 
+import static org.junit.Assert.assertEquals;
 import static org.ops4j.pax.exam.CoreOptions.provision;
 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
 
@@ -50,10 +50,10 @@
     public void testJmsEndpoint() throws Exception {
         Greeter greeter = greeterJms();
         String res = greeter.greetMe("Chris");
-        Assert.assertEquals("Hi Chris", res);
+        assertEquals("Hi Chris", res);
     }
 
-    private Greeter greeterJms() {
+    private static Greeter greeterJms() {
         JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
         factory.setServiceClass(Greeter.class);
         factory.setAddress("jms:queue:greeter");
@@ -62,7 +62,7 @@ private Greeter greeterJms() {
         return factory.create(Greeter.class);
     }
 
-    private ActiveMQConnectionFactory createConnectionFactory() {
+    private static ActiveMQConnectionFactory createConnectionFactory() {
         ActiveMQConnectionFactory connectionFactory
             = new ActiveMQConnectionFactory("vm://JmsServiceTest");
         connectionFactory.setUserName("karaf");
@@ -74,17 +74,21 @@ private ActiveMQConnectionFactory createConnectionFactory() {
     public Option[] config() {
         return new Option[] {
             cxfBaseConfig(),
-            testUtils(),
-            features(springLegacyUrl, "spring/4.3.18.RELEASE_1"),
+            features(karafUrl, "aries-blueprint", "shell-compat"),
             features(cxfUrl, "cxf-core", "cxf-jaxws", "cxf-transports-jms"),
-            features(amqUrl, "aries-blueprint", "shell-compat", "activemq-broker-noweb"),
+            features(springLegacyUrl, "spring/4.3.18.RELEASE_1"),
+            features(amqUrl, "activemq-broker-noweb"),
             provision(serviceBundle())
         };
     }
 
-    private InputStream serviceBundle() {
-        return TinyBundles.bundle().add(JmsTestActivator.class).add(Greeter.class).add(GreeterImpl.class)
-            .set(Constants.BUNDLE_ACTIVATOR, JmsTestActivator.class.getName()).build(TinyBundles.withBnd());
+    private static InputStream serviceBundle() {
+        return TinyBundles.bundle()
+                .add(JmsTestActivator.class)
+                .add(Greeter.class)
+                .add(GreeterImpl.class)
+                .set(Constants.BUNDLE_ACTIVATOR, JmsTestActivator.class.getName())
+                .build(TinyBundles.withBnd());
     }
 
 }
diff --git a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/soap/JmsTestActivator.java b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/soap/JmsTestActivator.java
index 44fc44f510c..e9a97ce3b9e 100644
--- a/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/soap/JmsTestActivator.java
+++ b/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/soap/JmsTestActivator.java
@@ -25,13 +25,11 @@
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
-import org.apache.cxf.testutil.common.TestUtil;
 import org.apache.cxf.transport.jms.ConnectionFactoryFeature;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 
 public class JmsTestActivator implements BundleActivator {
-    public static final String PORT = TestUtil.getPortNumber(JmsTestActivator.class);
     private Server server;
 
     @Override


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services