Repository: aries-jax-rs-whiteboard
Updated Branches:
  refs/heads/master d934b9204 -> 77e9bf3e4


[jaxrs] cleanup unused JSON deps, restructure test code, fix & test JAXB

Signed-off-by: Raymond Auge <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/commit/34f36639
Tree: 
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/34f36639
Diff: 
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/34f36639

Branch: refs/heads/master
Commit: 34f366399207991d38f520a283e8b449e67f8231
Parents: d934b92
Author: Raymond Auge <[email protected]>
Authored: Mon May 7 13:04:20 2018 -0400
Committer: Carlos Sierra <[email protected]>
Committed: Tue May 8 08:32:27 2018 +0200

----------------------------------------------------------------------
 jax-rs.example/example.bndrun                   |   1 -
 jax-rs.example/pom.xml                          |   5 -
 jax-rs.itests/bnd.bnd                           |   1 +
 jax-rs.itests/itest.bndrun                      |   1 -
 jax-rs.itests/pom.xml                           |  22 ++
 .../src/main/java/jaxb/types/Product.java       |  38 +++
 jax-rs.itests/src/main/java/test/JaxBTest.java  |  90 ++++++
 jax-rs.itests/src/main/java/test/JaxrsTest.java | 315 +-----------------
 .../src/main/java/test/types/TestHelper.java    | 320 ++++++++++++++++++-
 .../src/main/java/test/types/TestJAXBAddon.java |  52 +++
 jax-rs.whiteboard/bnd.bnd                       |   6 +-
 jax-rs.whiteboard/pom.xml                       |  30 +-
 12 files changed, 531 insertions(+), 350 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/34f36639/jax-rs.example/example.bndrun
----------------------------------------------------------------------
diff --git a/jax-rs.example/example.bndrun b/jax-rs.example/example.bndrun
index f0a9396..613f885 100644
--- a/jax-rs.example/example.bndrun
+++ b/jax-rs.example/example.bndrun
@@ -25,7 +25,6 @@
 -runbundles: \
        ch.qos.logback.classic;version='[1.2.3,1.2.4)',\
        ch.qos.logback.core;version='[1.2.3,1.2.4)',\
-       javax.json-api;version='[1.0.0,1.0.1)',\
        org.apache.aries.javax.annotation-api;version='[0.0.1,0.0.2)',\
        org.apache.aries.javax.jax.rs-api;version='[0.0.1,0.0.2)',\
        org.apache.aries.jax.rs.example;version='[0.0.1,0.0.2)',\

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/34f36639/jax-rs.example/pom.xml
----------------------------------------------------------------------
diff --git a/jax-rs.example/pom.xml b/jax-rs.example/pom.xml
index b8af2c9..1304d40 100644
--- a/jax-rs.example/pom.xml
+++ b/jax-rs.example/pom.xml
@@ -88,11 +88,6 @@
             <version>6.0.0</version>
         </dependency>
         <dependency>
-            <groupId>javax.json</groupId>
-            <artifactId>javax.json-api</artifactId>
-            <version>1.0</version>
-        </dependency>
-        <dependency>
             <groupId>org.apache.aries.jax.rs</groupId>
             <artifactId>org.apache.aries.jax.rs.whiteboard</artifactId>
             <version>0.0.1-SNAPSHOT</version>

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/34f36639/jax-rs.itests/bnd.bnd
----------------------------------------------------------------------
diff --git a/jax-rs.itests/bnd.bnd b/jax-rs.itests/bnd.bnd
index 7b2adb9..f5b7187 100644
--- a/jax-rs.itests/bnd.bnd
+++ b/jax-rs.itests/bnd.bnd
@@ -5,5 +5,6 @@ Test-Cases: \
        ${classes;CONCRETE;ANNOTATED;org.junit.Test}
 
 -contract: JavaJAXRS
+-includeresource: target/generated-resources/schemagen/
 
 Require-Capability: 
osgi.service;filter:="(objectClass=org.osgi.service.cm.ConfigurationAdmin)"

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/34f36639/jax-rs.itests/itest.bndrun
----------------------------------------------------------------------
diff --git a/jax-rs.itests/itest.bndrun b/jax-rs.itests/itest.bndrun
index 34e61a2..13969fd 100644
--- a/jax-rs.itests/itest.bndrun
+++ b/jax-rs.itests/itest.bndrun
@@ -25,7 +25,6 @@
 -runbundles: \
        ch.qos.logback.classic;version='[1.2.3,1.2.4)',\
        ch.qos.logback.core;version='[1.2.3,1.2.4)',\
-       javax.json-api;version='[1.0.0,1.0.1)',\
        org.apache.aries.javax.annotation-api;version='[0.0.1,0.0.2)',\
        org.apache.aries.javax.jax.rs-api;version='[0.0.1,0.0.2)',\
        org.apache.aries.jax.rs.itests-fragment;version='[0.0.1,0.0.2)',\

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/34f36639/jax-rs.itests/pom.xml
----------------------------------------------------------------------
diff --git a/jax-rs.itests/pom.xml b/jax-rs.itests/pom.xml
index ec9d633..8a1b33e 100644
--- a/jax-rs.itests/pom.xml
+++ b/jax-rs.itests/pom.xml
@@ -40,6 +40,28 @@
     <build>
         <plugins>
             <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>jaxb2-maven-plugin</artifactId>
+                <version>2.2</version>
+                <configuration>
+                    <schemaSourceExcludeFilters>
+                        <filter 
implementation="org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter">
+                            <patterns>
+                                <pattern>test</pattern>
+                            </patterns>
+                        </filter>
+                    </schemaSourceExcludeFilters>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>schemagen</id>
+                        <goals>
+                            <goal>schemagen</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
                 <groupId>biz.aQute.bnd</groupId>
                 <artifactId>bnd-indexer-maven-plugin</artifactId>
                 <configuration>

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/34f36639/jax-rs.itests/src/main/java/jaxb/types/Product.java
----------------------------------------------------------------------
diff --git a/jax-rs.itests/src/main/java/jaxb/types/Product.java 
b/jax-rs.itests/src/main/java/jaxb/types/Product.java
new file mode 100644
index 0000000..03a67a1
--- /dev/null
+++ b/jax-rs.itests/src/main/java/jaxb/types/Product.java
@@ -0,0 +1,38 @@
+/*
+ * 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 jaxb.types;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name="product")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class Product {
+
+    @XmlElement(required=true)
+    public int id;
+    @XmlElement(required=true)
+    public String name;
+    @XmlElement(required=true)
+    public String description;
+    @XmlElement(required=true)
+    public int price;
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/34f36639/jax-rs.itests/src/main/java/test/JaxBTest.java
----------------------------------------------------------------------
diff --git a/jax-rs.itests/src/main/java/test/JaxBTest.java 
b/jax-rs.itests/src/main/java/test/JaxBTest.java
new file mode 100644
index 0000000..880de75
--- /dev/null
+++ b/jax-rs.itests/src/main/java/test/JaxBTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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 test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.junit.Test;
+
+import jaxb.types.Product;
+import test.types.TestHelper;
+import test.types.TestJAXBAddon;
+
+public class JaxBTest extends TestHelper {
+
+    @Test
+    public void testJAXBEndPoint() throws InterruptedException {
+        WebTarget webTarget = createDefaultTarget().path("test");
+
+        getRuntimeDTO();
+
+        registerAddon(new TestJAXBAddon());
+
+        Response response = webTarget.request(MediaType.APPLICATION_XML).get();
+
+        String result = response.readEntity(String.class);
+
+        assertTrue(
+            "This should contain XML with <name>test</name>", 
result.contains("<name>test</name>"));
+    }
+
+    @Test
+    public void testJAXBClientConversion() throws InterruptedException {
+        WebTarget webTarget = createDefaultTarget().path("test");
+
+        getRuntimeDTO();
+
+        registerAddon(new TestJAXBAddon());
+
+        Product product = 
webTarget.request(MediaType.APPLICATION_XML).get(Product.class);
+
+        assertEquals("Description: test", product.description);
+        assertEquals(25, product.id);
+        assertEquals("test", product.name);
+        assertEquals(100, product.price);
+    }
+
+    @Test
+    public void testJAXBClientPut() throws InterruptedException {
+        WebTarget webTarget = createDefaultTarget().path("create");
+
+        getRuntimeDTO();
+
+        registerAddon(new TestJAXBAddon());
+
+        Product p = new Product();
+        p.description = "Description: BAR";
+        p.id = 10023;
+        p.name = "BAR";
+        p.price = 100;
+
+        Entity<Product> entity = Entity.entity(p, 
MediaType.APPLICATION_XML_TYPE);
+
+        Response response = 
webTarget.request(MediaType.APPLICATION_XML).put(entity);
+
+        assertEquals(200, response.getStatus());
+        assertEquals(p.id + "", response.readEntity(String.class));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/34f36639/jax-rs.itests/src/main/java/test/JaxrsTest.java
----------------------------------------------------------------------
diff --git a/jax-rs.itests/src/main/java/test/JaxrsTest.java 
b/jax-rs.itests/src/main/java/test/JaxrsTest.java
index eaf9889..752c923 100644
--- a/jax-rs.itests/src/main/java/test/JaxrsTest.java
+++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java
@@ -29,12 +29,10 @@ import java.lang.reflect.InvocationTargetException;
 import java.net.MalformedURLException;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.Dictionary;
 import java.util.HashSet;
 import java.util.Hashtable;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.CountDownLatch;
@@ -44,16 +42,11 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.Function;
-import java.util.function.Predicate;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.jaxrs.ext.ContextProvider;
 import org.apache.cxf.message.Message;
-import org.junit.After;
 import org.junit.Test;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.PrototypeServiceFactory;
-import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceRegistration;
 
 import org.osgi.service.http.context.ServletContextHelper;
@@ -67,7 +60,7 @@ import org.osgi.service.jaxrs.runtime.dto.ResourceDTO;
 import org.osgi.service.jaxrs.runtime.dto.ResourceMethodInfoDTO;
 import org.osgi.service.jaxrs.runtime.dto.RuntimeDTO;
 import org.osgi.util.promise.Promise;
-import org.osgi.util.tracker.ServiceTracker;
+
 import test.types.ConfigurationAwareResource;
 import test.types.CxfExtensionTestAddon;
 import test.types.ExtensionA;
@@ -75,14 +68,12 @@ import test.types.ExtensionB;
 import test.types.TestAddon;
 import test.types.TestAddonConflict;
 import test.types.TestAddonConflict2;
-import test.types.TestAddonLifecycle;
 import test.types.TestApplication;
 import test.types.TestApplicationConflict;
 import test.types.TestApplicationWithException;
 import test.types.TestAsyncResource;
 import test.types.TestCxfExtension;
 import test.types.TestFilter;
-import test.types.TestFilterAndExceptionMapper;
 import test.types.TestHelper;
 import test.types.TestSSEApplication;
 
@@ -106,28 +97,6 @@ import static org.junit.Assert.assertNull;
 
 public class JaxrsTest extends TestHelper {
 
-    @After
-    public void tearDown() {
-        Iterator<ServiceRegistration<?>> iterator = _registrations.iterator();
-
-        while (iterator.hasNext()) {
-            ServiceRegistration<?> registration =  iterator.next();
-
-            try {
-                registration.unregister();
-            }
-            catch(Exception e) {
-            }
-            finally {
-                iterator.remove();
-            }
-        }
-
-        if (_runtimeTracker != null) {
-            _runtimeTracker.close();
-        }
-    }
-
     @Test
     public void testApplication() throws InterruptedException {
         assertEquals(0, getRuntimeDTO().applicationDTOs.length);
@@ -464,7 +433,7 @@ public class JaxrsTest extends TestHelper {
     }
 
     @SuppressWarnings("serial")
-       @Test
+    @Test
     public void testApplicationRebase() {
         assertEquals(0, getRuntimeDTO().applicationDTOs.length);
 
@@ -954,7 +923,7 @@ public class JaxrsTest extends TestHelper {
 
     @Test
     /**
-     * Propietary extension... not in the spec
+     * Proprietary extension... not in the spec
      * breaks application isolation if several applications are forced to
      * use the same ServletContext
      */
@@ -2028,286 +1997,8 @@ public class JaxrsTest extends TestHelper {
 
     }
 
-
     private static Function<RuntimeDTO, FailedApplicationDTO[]>
         FAILED_APPLICATIONS = r -> r.failedApplicationDTOs;
-    private Collection<ServiceRegistration<?>> _registrations =
-        new ArrayList<>();
-
-    private static long getServiceId(ServiceRegistration<?> propertyHolder) {
-        return (long)propertyHolder.getReference().getProperty("service.id");
-    }
-
-    private <T> void assertThatInRuntime(
-        Function<RuntimeDTO, T[]> getter, Predicate<T> predicate) {
-
-        assertTrue(
-            Arrays.stream(getter.apply(getRuntimeDTO())).anyMatch(predicate));
-    }
-
-    private JaxrsServiceRuntime getJaxrsServiceRuntime()
-        throws InterruptedException {
-
-        _runtimeTracker = new ServiceTracker<>(
-            bundleContext, JaxrsServiceRuntime.class, null);
-
-        _runtimeTracker.open();
-
-        return _runtimeTracker.waitForService(15000L);
-    }
-
-    private RuntimeDTO getRuntimeDTO() {
-        return _runtime.getRuntimeDTO();
-    }
-
-    private ServiceRegistration<?> registerAddon(
-        Object instance, Object... keyValues) {
-
-        Dictionary<String, Object> properties = new Hashtable<>();
-
-        properties.put(JAX_RS_RESOURCE, "true");
-
-        for (int i = 0; i < keyValues.length; i = i + 2) {
-            properties.put(keyValues[i].toString(), keyValues[i + 1]);
-        }
-
-        ServiceRegistration<Object> serviceRegistration =
-            bundleContext.registerService(Object.class, instance, properties);
-
-        _registrations.add(serviceRegistration);
-
-        return serviceRegistration;
-    }
-
-    private ServiceRegistration<?> registerAddonLifecycle(
-        boolean singleton, Object... keyValues) {
-
-        Dictionary<String, Object> properties = new Hashtable<>();
-
-        for (int i = 0; i < keyValues.length; i = i + 2) {
-            properties.put(keyValues[i].toString(), keyValues[i + 1]);
-        }
-
-        if (singleton) {
-            return bundleContext.registerService(
-                Object.class, new TestAddonLifecycle(), properties);
-        } else {
-            PrototypeServiceFactory<Object> prototypeServiceFactory =
-                new PrototypeServiceFactory<Object>() {
-                    @Override
-                    public Object getService(
-                        Bundle bundle,
-                        ServiceRegistration<Object> registration) {
-
-                        return new TestAddonLifecycle();
-                    }
-
-                    @Override
-                    public void ungetService(
-                        Bundle bundle, ServiceRegistration<Object> 
registration,
-                        Object service) {
-
-                    }
-                };
-
-            ServiceRegistration<Object> serviceRegistration =
-                bundleContext.registerService(
-                    Object.class, (ServiceFactory<?>) prototypeServiceFactory,
-                    properties);
-
-            _registrations.add(serviceRegistration);
-
-            return serviceRegistration;
-        }
-    }
-
-    private ServiceRegistration<Application> registerApplication(
-        Application application, Object... keyValues) {
-
-        Dictionary<String, Object> properties = new Hashtable<>();
-
-        for (int i = 0; i < keyValues.length; i = i + 2) {
-            properties.put(keyValues[i].toString(), keyValues[i + 1]);
-        }
-
-        if (properties.get(JAX_RS_APPLICATION_BASE) == null) {
-            properties.put(JAX_RS_APPLICATION_BASE, "/test-application");
-        }
-
-        ServiceRegistration<Application> serviceRegistration =
-            bundleContext.registerService(
-                Application.class, application, properties);
-
-        _registrations.add(serviceRegistration);
-
-        return serviceRegistration;
-    }
-
-    private ServiceRegistration<Application> registerApplication(
-        ServiceFactory<Application> serviceFactory, Object... keyValues) {
-
-        Dictionary<String, Object> properties = new Hashtable<>();
-
-        properties.put(JAX_RS_APPLICATION_BASE, "/test-application");
-
-        for (int i = 0; i < keyValues.length; i = i + 2) {
-            properties.put(keyValues[i].toString(), keyValues[i + 1]);
-        }
-
-        ServiceRegistration<Application> serviceRegistration =
-            bundleContext.registerService(
-                Application.class, serviceFactory, properties);
-
-        _registrations.add(serviceRegistration);
-
-        return serviceRegistration;
-    }
-
-    private ServiceRegistration<?> registerExtension(
-        String name, Object... keyValues) {
-
-        TestFilter testFilter = new TestFilter();
-
-        Dictionary<String, Object> properties = new Hashtable<>();
-
-        properties.put(JAX_RS_EXTENSION, true);
-        properties.put(JAX_RS_NAME, name);
-
-        for (int i = 0; i < keyValues.length; i = i + 2) {
-            properties.put(keyValues[i].toString(), keyValues[i + 1]);
-        }
-
-        ServiceRegistration<ContainerResponseFilter> serviceRegistration =
-            bundleContext.registerService(
-                ContainerResponseFilter.class, testFilter, properties);
-
-        _registrations.add(serviceRegistration);
-
-        return serviceRegistration;
-    }
-
-    private <T> ServiceRegistration<T> registerExtension(
-        Class<T> clazz, T extension, String name, Object... keyValues) {
-
-        Dictionary<String, Object> properties = new Hashtable<>();
-
-        properties.put(JAX_RS_EXTENSION, true);
-        properties.put(JAX_RS_NAME, name);
-
-        for (int i = 0; i < keyValues.length; i = i + 2) {
-            properties.put(keyValues[i].toString(), keyValues[i + 1]);
-        }
-
-        ServiceRegistration<T> serviceRegistration =
-            bundleContext.registerService(clazz, extension, properties);
-
-        _registrations.add(serviceRegistration);
-
-        return serviceRegistration;
-    }
-
-    private ServiceRegistration<?> registerInvalidExtension(
-        String name, Object... keyValues) {
-
-        TestFilter testFilter = new TestFilter();
-
-        Dictionary<String, Object> properties = new Hashtable<>();
-
-        properties.put(JAX_RS_EXTENSION, true);
-        properties.put(JAX_RS_NAME, name);
-
-        for (int i = 0; i < keyValues.length; i = i + 2) {
-            properties.put(keyValues[i].toString(), keyValues[i + 1]);
-        }
-
-        ServiceRegistration<Object> serviceRegistration =
-            bundleContext.registerService(
-                Object.class, testFilter, properties);
-
-        _registrations.add(serviceRegistration);
-
-        return serviceRegistration;
-    }
-
-    private ServiceRegistration<?> registerMultiExtension(
-        String name, String... classes) {
-
-        Dictionary<String, Object> properties = new Hashtable<>();
-
-        properties.put(JAX_RS_EXTENSION, true);
-        properties.put(JAX_RS_NAME, name);
-
-        ServiceRegistration<?> serviceRegistration =
-            bundleContext.registerService(
-                classes, new TestFilterAndExceptionMapper(), properties);
-
-        _registrations.add(serviceRegistration);
-
-        return serviceRegistration;
-    }
-
-    private ServiceRegistration<Application> registerUngettableApplication(
-        Object... keyValues) {
-
-        return registerApplication(
-            new ServiceFactory<Application>() {
-                @Override
-                public Application getService(
-                    Bundle bundle,
-                    ServiceRegistration<Application> serviceRegistration) {
-
-                    return null;
-                }
-
-                @Override
-                public void ungetService(
-                    Bundle bundle,
-                    ServiceRegistration<Application> serviceRegistration,
-                    Application application) {
-
-                }
-            }, keyValues);
-    }
-
-    private ServiceRegistration<?> registerUngettableExtension(
-        String name, Object... keyValues) {
-
-        Dictionary<String, Object> properties = new Hashtable<>();
-
-        properties.put(JAX_RS_EXTENSION, true);
-        properties.put(JAX_RS_NAME, name);
-
-        for (int i = 0; i < keyValues.length; i = i + 2) {
-            properties.put(keyValues[i].toString(), keyValues[i + 1]);
-        }
-
-        ServiceRegistration<ContainerResponseFilter> serviceRegistration =
-            bundleContext.registerService(
-                ContainerResponseFilter.class,
-                new ServiceFactory<ContainerResponseFilter>() {
-                    @Override
-                    public ContainerResponseFilter getService(
-                        Bundle bundle,
-                        ServiceRegistration<ContainerResponseFilter>
-                            serviceRegistration) {
-
-                        return null;
-                    }
-
-                    @Override
-                    public void ungetService(
-                        Bundle bundle,
-                        ServiceRegistration<ContainerResponseFilter>
-                            serviceRegistration,
-                        ContainerResponseFilter containerResponseFilter) {
-
-                    }
-                }, properties);
-
-        _registrations.add(serviceRegistration);
-
-        return serviceRegistration;
-    }
 
     @Provider
     private static class BusContextProvider implements ContextProvider<Bus> {

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/34f36639/jax-rs.itests/src/main/java/test/types/TestHelper.java
----------------------------------------------------------------------
diff --git a/jax-rs.itests/src/main/java/test/types/TestHelper.java 
b/jax-rs.itests/src/main/java/test/types/TestHelper.java
index a5c5869..d5c8014 100644
--- a/jax-rs.itests/src/main/java/test/types/TestHelper.java
+++ b/jax-rs.itests/src/main/java/test/types/TestHelper.java
@@ -20,17 +20,37 @@ package test.types;
 import javax.ws.rs.client.Client;
 import javax.ws.rs.client.ClientBuilder;
 import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.core.Application;
 
 import org.junit.After;
 import org.junit.Before;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.PrototypeServiceFactory;
+import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.jaxrs.client.SseEventSourceFactory;
 import org.osgi.service.jaxrs.runtime.JaxrsServiceRuntime;
+import org.osgi.service.jaxrs.runtime.dto.RuntimeDTO;
 import org.osgi.util.tracker.ServiceTracker;
 
+import static org.junit.Assert.assertTrue;
+import static 
org.osgi.service.jaxrs.whiteboard.JaxrsWhiteboardConstants.JAX_RS_APPLICATION_BASE;
+import static 
org.osgi.service.jaxrs.whiteboard.JaxrsWhiteboardConstants.JAX_RS_EXTENSION;
+import static 
org.osgi.service.jaxrs.whiteboard.JaxrsWhiteboardConstants.JAX_RS_NAME;
+import static 
org.osgi.service.jaxrs.whiteboard.JaxrsWhiteboardConstants.JAX_RS_RESOURCE;
+
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.function.Function;
+import java.util.function.Predicate;
 
 public class TestHelper {
 
@@ -39,6 +59,8 @@ public class TestHelper {
             getBundle(TestHelper.class).
             getBundleContext();
 
+    protected Collection<ServiceRegistration<?>> _registrations =
+        new ArrayList<>();
     protected ServiceTracker<JaxrsServiceRuntime, JaxrsServiceRuntime>
         _runtimeTracker;
     protected ServiceTracker<ClientBuilder, ClientBuilder>
@@ -47,8 +69,25 @@ public class TestHelper {
     protected ServiceReference<JaxrsServiceRuntime> _runtimeServiceReference;
 
     @After
-    public void after() {
-        _runtimeTracker.close();
+    public void tearDown() {
+        Iterator<ServiceRegistration<?>> iterator = _registrations.iterator();
+
+        while (iterator.hasNext()) {
+            ServiceRegistration<?> registration =  iterator.next();
+
+            try {
+                registration.unregister();
+            }
+            catch(Exception e) {
+            }
+            finally {
+                iterator.remove();
+            }
+        }
+
+        if (_runtimeTracker != null) {
+            _runtimeTracker.close();
+        }
 
         _clientBuilderTracker.close();
     }
@@ -84,7 +123,7 @@ public class TestHelper {
         _sseEventSourceFactoryTracker;
 
     @SuppressWarnings("unchecked")
-       private static String[] canonicalize(Object propertyValue) {
+    private static String[] canonicalize(Object propertyValue) {
         if (propertyValue == null) {
             return new String[0];
         }
@@ -137,4 +176,279 @@ public class TestHelper {
         return client.target(runtime);
     }
 
+    protected static long getServiceId(ServiceRegistration<?> propertyHolder) {
+        return (long)propertyHolder.getReference().getProperty("service.id");
+    }
+
+    protected <T> void assertThatInRuntime(
+        Function<RuntimeDTO, T[]> getter, Predicate<T> predicate) {
+
+        assertTrue(
+            Arrays.stream(getter.apply(getRuntimeDTO())).anyMatch(predicate));
+    }
+
+    protected JaxrsServiceRuntime getJaxrsServiceRuntime()
+        throws InterruptedException {
+
+        _runtimeTracker = new ServiceTracker<>(
+            bundleContext, JaxrsServiceRuntime.class, null);
+
+        _runtimeTracker.open();
+
+        return _runtimeTracker.waitForService(15000L);
+    }
+
+    protected RuntimeDTO getRuntimeDTO() {
+        return _runtime.getRuntimeDTO();
+    }
+
+    protected ServiceRegistration<?> registerAddon(
+        Object instance, Object... keyValues) {
+
+        Dictionary<String, Object> properties = new Hashtable<>();
+
+        properties.put(JAX_RS_RESOURCE, "true");
+
+        for (int i = 0; i < keyValues.length; i = i + 2) {
+            properties.put(keyValues[i].toString(), keyValues[i + 1]);
+        }
+
+        ServiceRegistration<Object> serviceRegistration =
+            bundleContext.registerService(Object.class, instance, properties);
+
+        _registrations.add(serviceRegistration);
+
+        return serviceRegistration;
+    }
+
+    protected ServiceRegistration<?> registerAddonLifecycle(
+        boolean singleton, Object... keyValues) {
+
+        Dictionary<String, Object> properties = new Hashtable<>();
+
+        for (int i = 0; i < keyValues.length; i = i + 2) {
+            properties.put(keyValues[i].toString(), keyValues[i + 1]);
+        }
+
+        if (singleton) {
+            return bundleContext.registerService(
+                Object.class, new TestAddonLifecycle(), properties);
+        } else {
+            PrototypeServiceFactory<Object> prototypeServiceFactory =
+                new PrototypeServiceFactory<Object>() {
+                    @Override
+                    public Object getService(
+                        Bundle bundle,
+                        ServiceRegistration<Object> registration) {
+
+                        return new TestAddonLifecycle();
+                    }
+
+                    @Override
+                    public void ungetService(
+                        Bundle bundle, ServiceRegistration<Object> 
registration,
+                        Object service) {
+
+                    }
+                };
+
+            ServiceRegistration<Object> serviceRegistration =
+                bundleContext.registerService(
+                    Object.class, (ServiceFactory<?>) prototypeServiceFactory,
+                    properties);
+
+            _registrations.add(serviceRegistration);
+
+            return serviceRegistration;
+        }
+    }
+
+    protected ServiceRegistration<Application> registerApplication(
+        Application application, Object... keyValues) {
+
+        Dictionary<String, Object> properties = new Hashtable<>();
+
+        for (int i = 0; i < keyValues.length; i = i + 2) {
+            properties.put(keyValues[i].toString(), keyValues[i + 1]);
+        }
+
+        if (properties.get(JAX_RS_APPLICATION_BASE) == null) {
+            properties.put(JAX_RS_APPLICATION_BASE, "/test-application");
+        }
+
+        ServiceRegistration<Application> serviceRegistration =
+            bundleContext.registerService(
+                Application.class, application, properties);
+
+        _registrations.add(serviceRegistration);
+
+        return serviceRegistration;
+    }
+
+    protected ServiceRegistration<Application> registerApplication(
+        ServiceFactory<Application> serviceFactory, Object... keyValues) {
+
+        Dictionary<String, Object> properties = new Hashtable<>();
+
+        properties.put(JAX_RS_APPLICATION_BASE, "/test-application");
+
+        for (int i = 0; i < keyValues.length; i = i + 2) {
+            properties.put(keyValues[i].toString(), keyValues[i + 1]);
+        }
+
+        ServiceRegistration<Application> serviceRegistration =
+            bundleContext.registerService(
+                Application.class, serviceFactory, properties);
+
+        _registrations.add(serviceRegistration);
+
+        return serviceRegistration;
+    }
+
+    protected ServiceRegistration<?> registerExtension(
+        String name, Object... keyValues) {
+
+        TestFilter testFilter = new TestFilter();
+
+        Dictionary<String, Object> properties = new Hashtable<>();
+
+        properties.put(JAX_RS_EXTENSION, true);
+        properties.put(JAX_RS_NAME, name);
+
+        for (int i = 0; i < keyValues.length; i = i + 2) {
+            properties.put(keyValues[i].toString(), keyValues[i + 1]);
+        }
+
+        ServiceRegistration<ContainerResponseFilter> serviceRegistration =
+            bundleContext.registerService(
+                ContainerResponseFilter.class, testFilter, properties);
+
+        _registrations.add(serviceRegistration);
+
+        return serviceRegistration;
+    }
+
+    protected <T> ServiceRegistration<T> registerExtension(
+        Class<T> clazz, T extension, String name, Object... keyValues) {
+
+        Dictionary<String, Object> properties = new Hashtable<>();
+
+        properties.put(JAX_RS_EXTENSION, true);
+        properties.put(JAX_RS_NAME, name);
+
+        for (int i = 0; i < keyValues.length; i = i + 2) {
+            properties.put(keyValues[i].toString(), keyValues[i + 1]);
+        }
+
+        ServiceRegistration<T> serviceRegistration =
+            bundleContext.registerService(clazz, extension, properties);
+
+        _registrations.add(serviceRegistration);
+
+        return serviceRegistration;
+    }
+
+    protected ServiceRegistration<?> registerInvalidExtension(
+        String name, Object... keyValues) {
+
+        TestFilter testFilter = new TestFilter();
+
+        Dictionary<String, Object> properties = new Hashtable<>();
+
+        properties.put(JAX_RS_EXTENSION, true);
+        properties.put(JAX_RS_NAME, name);
+
+        for (int i = 0; i < keyValues.length; i = i + 2) {
+            properties.put(keyValues[i].toString(), keyValues[i + 1]);
+        }
+
+        ServiceRegistration<Object> serviceRegistration =
+            bundleContext.registerService(
+                Object.class, testFilter, properties);
+
+        _registrations.add(serviceRegistration);
+
+        return serviceRegistration;
+    }
+
+    protected ServiceRegistration<?> registerMultiExtension(
+        String name, String... classes) {
+
+        Dictionary<String, Object> properties = new Hashtable<>();
+
+        properties.put(JAX_RS_EXTENSION, true);
+        properties.put(JAX_RS_NAME, name);
+
+        ServiceRegistration<?> serviceRegistration =
+            bundleContext.registerService(
+                classes, new TestFilterAndExceptionMapper(), properties);
+
+        _registrations.add(serviceRegistration);
+
+        return serviceRegistration;
+    }
+
+    protected ServiceRegistration<Application> registerUngettableApplication(
+        Object... keyValues) {
+
+        return registerApplication(
+            new ServiceFactory<Application>() {
+                @Override
+                public Application getService(
+                    Bundle bundle,
+                    ServiceRegistration<Application> serviceRegistration) {
+
+                    return null;
+                }
+
+                @Override
+                public void ungetService(
+                    Bundle bundle,
+                    ServiceRegistration<Application> serviceRegistration,
+                    Application application) {
+
+                }
+            }, keyValues);
+    }
+
+    protected ServiceRegistration<?> registerUngettableExtension(
+        String name, Object... keyValues) {
+
+        Dictionary<String, Object> properties = new Hashtable<>();
+
+        properties.put(JAX_RS_EXTENSION, true);
+        properties.put(JAX_RS_NAME, name);
+
+        for (int i = 0; i < keyValues.length; i = i + 2) {
+            properties.put(keyValues[i].toString(), keyValues[i + 1]);
+        }
+
+        ServiceRegistration<ContainerResponseFilter> serviceRegistration =
+            bundleContext.registerService(
+                ContainerResponseFilter.class,
+                new ServiceFactory<ContainerResponseFilter>() {
+                    @Override
+                    public ContainerResponseFilter getService(
+                        Bundle bundle,
+                        ServiceRegistration<ContainerResponseFilter>
+                            serviceRegistration) {
+
+                        return null;
+                    }
+
+                    @Override
+                    public void ungetService(
+                        Bundle bundle,
+                        ServiceRegistration<ContainerResponseFilter>
+                            serviceRegistration,
+                        ContainerResponseFilter containerResponseFilter) {
+
+                    }
+                }, properties);
+
+        _registrations.add(serviceRegistration);
+
+        return serviceRegistration;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/34f36639/jax-rs.itests/src/main/java/test/types/TestJAXBAddon.java
----------------------------------------------------------------------
diff --git a/jax-rs.itests/src/main/java/test/types/TestJAXBAddon.java 
b/jax-rs.itests/src/main/java/test/types/TestJAXBAddon.java
new file mode 100644
index 0000000..d82da2d
--- /dev/null
+++ b/jax-rs.itests/src/main/java/test/types/TestJAXBAddon.java
@@ -0,0 +1,52 @@
+/*
+ * 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 test.types;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import jaxb.types.Product;
+
+public class TestJAXBAddon {
+
+    @GET
+    @Path("/{name}")
+    @Produces(MediaType.APPLICATION_XML)
+    public Product product(@PathParam("name") String name) {
+        Product p = new Product();
+        p.description = "Description: " + name;
+        p.id = 25;
+        p.name = name;
+        p.price = 100;
+        return p;
+    }
+
+    @PUT
+    @Path("/create")
+    @Consumes(MediaType.APPLICATION_XML)
+    public Response product(Product p) {
+        return Response.ok(p.id + "").build();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/34f36639/jax-rs.whiteboard/bnd.bnd
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/bnd.bnd b/jax-rs.whiteboard/bnd.bnd
index c39d068..54e3ba6 100644
--- a/jax-rs.whiteboard/bnd.bnd
+++ b/jax-rs.whiteboard/bnd.bnd
@@ -22,7 +22,6 @@ Require-Capability: \
         filter:='(&(osgi.implementation=osgi.http)(version>=1)(!(version>=2)))'
 Import-Package:\
     !com.sun.*,\
-    !com.ctc.wstx.*,\
     !javax.cache.*,\
     !javax.imageio.*,\
     !javax.jws.*,\
@@ -41,7 +40,6 @@ Import-Package:\
     !org.apache.xml.resolver.*,\
     !org.apache.xmlbeans.*,\
     !org.atmosphere.*,\
-    !org.codehaus.stax2.*,\
     !org.dom4j.*,\
     !org.junit.*,\
     !org.jvnet.fastinfoset.*,\
@@ -65,9 +63,9 @@ Import-Package:\
     lib/cxf-rt-databinding-jaxb.jar=cxf-rt-databinding-jaxb-*.jar;lib:=true,\
     lib/cxf-rt-frontend-jaxrs.jar=cxf-rt-frontend-jaxrs-*.jar;lib:=true,\
     lib/cxf-rt-rs-client.jar=cxf-rt-rs-client-*.jar;lib:=true,\
-    
lib/cxf-rt-rs-extension-providers.jar=cxf-rt-rs-extension-providers-*.jar;lib:=true,\
     lib/cxf-rt-rs-sse.jar=cxf-rt-rs-sse-*.jar;lib:=true,\
     lib/cxf-rt-transports-http.jar=cxf-rt-transports-http-*.jar;lib:=true,\
     lib/cxf-tools-common.jar=cxf-tools-common-*.jar;lib:=true,\
-    lib/jettison.jar=jettison-*.jar;lib:=true,\
+    lib/stax2-api.jar=stax2-api-*.jar;lib:=true,\
+    lib/woodstox-core.jar=woodstox-core-*.jar;lib:=true,\
     lib/xmlschema-core.jar=xmlschema-core-*.jar;lib:=true

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/34f36639/jax-rs.whiteboard/pom.xml
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/pom.xml b/jax-rs.whiteboard/pom.xml
index 6c2cf4d..652da42 100644
--- a/jax-rs.whiteboard/pom.xml
+++ b/jax-rs.whiteboard/pom.xml
@@ -35,7 +35,7 @@
         <dependency>
             <groupId>org.apache.aries.component-dsl</groupId>
             
<artifactId>org.apache.aries.component-dsl.component-dsl</artifactId>
-            <version>0.0.1-SNAPSHOT</version>
+            <version>1.0.0</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
@@ -74,12 +74,6 @@
         </dependency>
         <dependency>
             <groupId>org.apache.cxf</groupId>
-            <artifactId>cxf-rt-rs-extension-providers</artifactId>
-            <version>${cxf.version}</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.cxf</groupId>
             <artifactId>cxf-rt-frontend-jaxrs</artifactId>
             <version>${cxf.version}</version>
             <scope>provided</scope>
@@ -108,12 +102,6 @@
             <version>1.1.2</version>
         </dependency>
         <dependency>
-            <groupId>org.codehaus.jettison</groupId>
-            <artifactId>jettison</artifactId>
-            <version>1.3.8</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>osgi.annotation</artifactId>
             <version>6.0.1</version>
@@ -146,18 +134,12 @@
             <version>1.7.2</version>
         </dependency>
         <dependency>
-            <groupId>javax.json</groupId>
-            <artifactId>javax.json-api</artifactId>
-            <version>1.0</version>
-            <scope>runtime</scope>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.12</version>
+            <scope>test</scope>
         </dependency>
-               <dependency>
-                       <groupId>junit</groupId>
-                       <artifactId>junit</artifactId>
-                       <version>4.12</version>
-                       <scope>test</scope>
-               </dependency>
-       </dependencies>
+    </dependencies>
 
     <build>
         <pluginManagement>

Reply via email to