cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject cxf git commit: Refactored OSGi tests
Date Fri, 28 Apr 2017 13:46:16 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 02fd70cd6 -> c1ba5d90e


Refactored OSGi tests


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/c1ba5d90
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/c1ba5d90
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/c1ba5d90

Branch: refs/heads/master
Commit: c1ba5d90e34993d737f0944dbb69ccda7c4bcfd1
Parents: 02fd70c
Author: Christian Schneider <chris@die-schneider.net>
Authored: Fri Apr 28 15:46:07 2017 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Fri Apr 28 15:46:07 2017 +0200

----------------------------------------------------------------------
 .../cxf/osgi/itests/CXFOSGiTestSupport.java     | 20 ++++------
 .../cxf/osgi/itests/jaxrs/JaxRsServiceTest.java | 39 +++++++++-----------
 .../osgi/itests/jaxrs/JaxRsTestActivator.java   |  2 -
 .../cxf/osgi/itests/soap/HttpTestActivator.java | 17 ++++-----
 .../cxf/osgi/itests/soap/JmsServiceTest.java    | 12 +-----
 5 files changed, 35 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/c1ba5d90/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/CXFOSGiTestSupport.java
----------------------------------------------------------------------
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 4a5d107..c0c6a8a 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
@@ -34,6 +34,7 @@ import org.apache.karaf.features.FeaturesService;
 import org.junit.Assert;
 import org.ops4j.pax.exam.MavenUtils;
 import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
 import org.ops4j.pax.exam.options.MavenUrlReference;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -46,6 +47,7 @@ import static org.ops4j.pax.exam.CoreOptions.systemProperty;
 import static org.ops4j.pax.exam.CoreOptions.when;
 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
+import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel;
 
 /**
  *
@@ -62,20 +64,10 @@ public class CXFOSGiTestSupport {
 
     protected MavenUrlReference cxfUrl;
     protected MavenUrlReference karafUrl;
+    protected MavenUrlReference amqUrl;
 
     private static String getKarafVersion() {
-        String karafVersion = MavenUtils.getArtifactVersion("org.apache.karaf", "apache-karaf");
-        if (karafVersion == null) {
-            karafVersion = System.getProperty("cxf.karaf.version");
-        }
-        if (karafVersion == null) {
-            karafVersion = System.getProperty("karaf.version");
-        }
-        if (karafVersion == null) {
-            // setup the default version of it
-            karafVersion = "4.0.5";
-        }
-        return karafVersion;
+        return MavenUtils.getArtifactVersion("org.apache.karaf", "apache-karaf");
     }
 
     /**
@@ -88,6 +80,8 @@ public class CXFOSGiTestSupport {
             .type("tar.gz");
         cxfUrl = maven().groupId("org.apache.cxf.karaf").artifactId("apache-cxf").versionAsInProject()
             .type("xml").classifier("features");
+        amqUrl = maven().groupId("org.apache.activemq")
+        .artifactId("activemq-karaf").type("xml").classifier("features").versionAsInProject();
         String localRepo = System.getProperty("localRepository");
         Object urp = System.getProperty("cxf.useRandomFirstPort");
         return composite(karafDistributionConfiguration()
@@ -101,6 +95,7 @@ public class CXFOSGiTestSupport {
                          //debugConfiguration(), // nor this
                          systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
                          systemProperty("java.awt.headless").value("true"),
+                         logLevel(LogLevel.INFO),
                          when(localRepo != null)
                              .useOptions(editConfigurationFilePut("etc/org.ops4j.pax.url.mvn.cfg",
                                                                   "org.ops4j.pax.url.mvn.localRepository",
@@ -198,4 +193,5 @@ public class CXFOSGiTestSupport {
         assertServicePublished(String.format("(&(objectClass=org.apache.aries.blueprint.NamespaceHandler)"
                                              + "(osgi.service.blueprint.namespace=%s))",
namespace), timeout);
     }
+
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/c1ba5d90/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsServiceTest.java
----------------------------------------------------------------------
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 4e01a17..4ae7b09 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
@@ -65,46 +65,40 @@ public class JaxRsServiceTest extends CXFOSGiTestSupport {
 
     @Test
     public void testJaxRsPost() throws Exception {
-        Book book = new Book();
-        book.setId(321);
-        book.setName("New Book");
+        Book book = new Book("New Book", 321);
         Response response = wt.path("/books/").request("application/xml").post(Entity.xml(book));
-        Assert.assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
+        assertStatus(Status.CREATED, response);
         Assert.assertNotNull(response.getLocation());
     }
+    
+    @Test
+    public void postWithValidationError() throws Exception {
+        Book book = new Book(null, -1);
+        Response response = wt.path("/books-validate/").request("application/xml").post(Entity.xml(book));
+        assertStatus(Status.BAD_REQUEST, response);
+    }
 
     @Test
     public void postWithValidation() throws Exception {
-        Book book = new Book();
-        book.setId(-1);
-        book.setName(null);
+        Book book = new Book("A Book", 3212);
         Response response = wt.path("/books-validate/").request("application/xml").post(Entity.xml(book));
-        Assert.assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
-
-        book = new Book();
-        book.setId(3212);
-        book.setName("A Book");
-        response = wt.path("/books-validate/").request("application/xml").post(Entity.xml(book));
-        Assert.assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
+        assertStatus(Status.CREATED, response);
         Assert.assertNotNull(response.getLocation());
     }
 
     @Test
     public void testJaxRsDelete() throws Exception {
         Response response = wt.path("/books/123").request("application/xml").delete();
-        Assert.assertEquals(Status.OK.getStatusCode(), response.getStatus());
+        assertStatus(Status.OK, response);
     }
 
     @Test
     public void testJaxRsPut() throws Exception {
-        Book book = new Book();
-        book.setId(123);
-        book.setName("Updated Book");
+        Book book = new Book("Updated Book", 123);
         Response response = wt.path("/books/123").request("application/xml").put(Entity.xml(book));
-        Assert.assertEquals(Status.OK.getStatusCode(), response.getStatus());
+        assertStatus(Status.OK, response);
     }
 
-
     @Configuration
     public Option[] config() {
         return new Option[] {
@@ -118,9 +112,12 @@ public class JaxRsServiceTest extends CXFOSGiTestSupport {
         };
     }
 
+    private void assertStatus(Status expectedStatus, Response response) {
+        Assert.assertEquals(expectedStatus.getStatusCode(), response.getStatus());
+    }
+
     private InputStream serviceBundle() {
         return TinyBundles.bundle()
-                  .set(Constants.DYNAMICIMPORT_PACKAGE, "*")
                   .add(JaxRsTestActivator.class)
                   .add(Book.class)
                   .add(BookStore.class)

http://git-wip-us.apache.org/repos/asf/cxf/blob/c1ba5d90/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/jaxrs/JaxRsTestActivator.java
----------------------------------------------------------------------
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 15349be..ac358a3 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
@@ -32,7 +32,6 @@ public class JaxRsTestActivator implements BundleActivator {
     @Override
     public void start(BundleContext arg0) throws Exception {
         Bus bus = BusFactory.newInstance().createBus();
-        bus.setExtension(JaxRsTestActivator.class.getClassLoader(), ClassLoader.class);
         JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
         sf.setBus(bus);
         sf.setResourceClasses(BookStore.class);
@@ -42,7 +41,6 @@ public class JaxRsTestActivator implements BundleActivator {
 
     @Override
     public void stop(BundleContext arg0) throws Exception {
-        server.stop();
         server.destroy();
     }
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/c1ba5d90/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/soap/HttpTestActivator.java
----------------------------------------------------------------------
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 06ae938..8d46c1a 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
@@ -31,24 +31,21 @@ public class HttpTestActivator implements BundleActivator {
 
     @Override
     public void start(BundleContext arg0) throws Exception {
-        JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
-        factory.setServiceClass(Greeter.class);
-        factory.setAddress("/greeter");
-        factory.setServiceBean(new GreeterImpl());
-        server = factory.create();
+        server = createTestServer("/greeter");
+        serverJetty = createTestServer("http://localhost:" + PORT + "/cxf/greeter");
+    }
 
-        factory = new JaxWsServerFactoryBean();
+    private Server createTestServer(String url) {
+        JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
         factory.setServiceClass(Greeter.class);
-        factory.setAddress("http://localhost:" + PORT + "/cxf/greeter");
+        factory.setAddress(url);
         factory.setServiceBean(new GreeterImpl());
-        serverJetty = factory.create();
+        return factory.create();
     }
 
     @Override
     public void stop(BundleContext arg0) throws Exception {
-        server.stop();
         server.destroy();
-        serverJetty.stop();
         serverJetty.destroy();
     }
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/c1ba5d90/osgi/itests/src/test/java/org/apache/cxf/osgi/itests/soap/JmsServiceTest.java
----------------------------------------------------------------------
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 6363b28..3d6e7b3 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
@@ -33,17 +33,13 @@ import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.karaf.options.KarafDistributionOption;
-import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
-import org.ops4j.pax.exam.options.MavenUrlReference;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
 import org.ops4j.pax.tinybundles.core.TinyBundles;
 import org.osgi.framework.Constants;
-import static org.ops4j.pax.exam.CoreOptions.maven;
+
 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;
 
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
@@ -75,15 +71,11 @@ public class JmsServiceTest extends CXFOSGiTestSupport {
 
     @Configuration
     public Option[] config() {
-        MavenUrlReference activeMQFeature = maven().groupId("org.apache.activemq")
-            .artifactId("activemq-karaf").type("xml").classifier("features").versionAsInProject();
         return new Option[] {
             cxfBaseConfig(),
             testUtils(),
             features(cxfUrl, "cxf-core", "cxf-jaxws", "cxf-transports-jms"),
-            KarafDistributionOption.keepRuntimeFolder(),
-            logLevel(LogLevel.INFO),
-            features(activeMQFeature, "activemq-broker-noweb"),
+            features(amqUrl, "activemq-broker-noweb"),
             provision(serviceBundle())
         };
     }


Mime
View raw message