You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2017/06/19 15:34:12 UTC

[08/11] aries-jax-rs-whiteboard git commit: Add tests for application override and conflict resolution

Add tests for application override and conflict resolution


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/1a1c2b70
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/1a1c2b70
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/1a1c2b70

Branch: refs/heads/master
Commit: 1a1c2b708e457f851ce588f9871584e26b47f707
Parents: ec283e3
Author: Carlos Sierra <cs...@apache.org>
Authored: Thu Jun 15 17:20:33 2017 +0200
Committer: Carlos Sierra <cs...@apache.org>
Committed: Mon Jun 19 17:31:56 2017 +0200

----------------------------------------------------------------------
 jax-rs.itests/src/main/java/test/JaxrsTest.java | 126 +++++++++++++++++++
 .../test/types/TestApplicationConflict.java     |  47 +++++++
 2 files changed, 173 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/1a1c2b70/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 3b6e411..5fd2b3d 100644
--- a/jax-rs.itests/src/main/java/test/JaxrsTest.java
+++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java
@@ -17,6 +17,7 @@
 
 package test;
 
+import static org.junit.Assert.assertNotNull;
 import static org.osgi.service.jaxrs.whiteboard.JaxRSWhiteboardConstants.*;
 
 import java.util.Dictionary;
@@ -30,9 +31,12 @@ import org.osgi.framework.PrototypeServiceFactory;
 import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceRegistration;
 
+import org.osgi.service.jaxrs.runtime.dto.FailedApplicationDTO;
+import org.osgi.util.tracker.ServiceTracker;
 import test.types.TestAddon;
 import test.types.TestAddonLifecycle;
 import test.types.TestApplication;
+import test.types.TestApplicationConflict;
 import test.types.TestFilter;
 
 import javax.ws.rs.client.Client;
@@ -75,6 +79,128 @@ public class JaxrsTest {
     }
 
     @Test
+    public void testApplicationConflict() {
+        Client client = createClient();
+
+        WebTarget webTarget = client.
+            target("http://localhost:8080").
+            path("test-application");
+
+        ServiceTracker serviceTracker = new ServiceTracker<>(
+            bundleContext, FailedApplicationDTO.class, null);
+
+        serviceTracker.open();
+
+        ServiceRegistration<?> serviceRegistration = null;
+        ServiceRegistration<?> serviceRegistration2;
+
+        try {
+            serviceRegistration = registerApplication(new TestApplication());
+
+            Response response = webTarget.request().get();
+
+            assertEquals(
+                "Hello application",
+                response.readEntity(String.class));
+
+            assertNull(serviceTracker.getService());
+
+            serviceRegistration2 = registerApplication(
+                new TestApplicationConflict(), "service.ranking", -1);
+
+            response = webTarget.request().get();
+
+            assertEquals(
+                "Hello application", response.readEntity(String.class));
+
+            assertNotNull(serviceTracker.getService());
+
+            assertEquals(
+                Response.Status.NOT_FOUND.getStatusCode(),
+                webTarget.path("conflict").request().get().getStatus());
+
+            serviceRegistration2.unregister();
+
+            assertNull(serviceTracker.getService());
+
+            response = webTarget.request().get();
+
+            assertEquals(
+                "Hello application", response.readEntity(String.class));
+        }
+        finally {
+            if (serviceRegistration != null) {
+                serviceRegistration.unregister();
+            }
+
+            serviceTracker.close();
+        }
+    }
+
+    @Test
+    public void testApplicationOverride() {
+        Client client = createClient();
+
+        WebTarget webTarget = client.
+            target("http://localhost:8080").
+            path("test-application");
+
+        ServiceTracker serviceTracker = new ServiceTracker<>(
+            bundleContext, FailedApplicationDTO.class, null);
+
+        serviceTracker.open();
+
+        ServiceRegistration<?> serviceRegistration = null;
+        ServiceRegistration<?> serviceRegistration2;
+
+        try {
+            serviceRegistration = registerApplication(new TestApplication());
+
+            Response response = webTarget.request().get();
+
+            assertEquals(
+                "Hello application",
+                response.readEntity(String.class));
+
+            assertNull(serviceTracker.getService());
+
+            serviceRegistration2 = registerApplication(
+                new TestApplicationConflict(), "service.ranking", 1);
+
+            response = webTarget.request().get();
+
+            assertEquals(
+                "Hello application conflict",
+                response.readEntity(String.class));
+
+            assertNotNull(serviceTracker.getService());
+
+            assertEquals(
+                "conflict",
+                webTarget.path("conflict").request().get(String.class));
+
+            serviceRegistration2.unregister();
+
+            assertNull(serviceTracker.getService());
+
+            response = webTarget.request().get();
+
+            assertEquals(
+                "Hello application", response.readEntity(String.class));
+        }
+        finally {
+            if (serviceRegistration != null) {
+                serviceRegistration.unregister();
+            }
+
+            serviceTracker.close();
+        }
+    }
+
+    static BundleContext bundleContext = FrameworkUtil.getBundle(
+        JaxrsTest.class).getBundleContext();
+
+    @Test
     public void testApplicationReadd() {
         Client client = createClient();
 

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/1a1c2b70/jax-rs.itests/src/main/java/test/types/TestApplicationConflict.java
----------------------------------------------------------------------
diff --git a/jax-rs.itests/src/main/java/test/types/TestApplicationConflict.java b/jax-rs.itests/src/main/java/test/types/TestApplicationConflict.java
new file mode 100644
index 0000000..3f8594d
--- /dev/null
+++ b/jax-rs.itests/src/main/java/test/types/TestApplicationConflict.java
@@ -0,0 +1,47 @@
+/*
+ * 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.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Application;
+import java.util.Collections;
+import java.util.Set;
+
+public class TestApplicationConflict extends Application {
+
+    @Override
+    public Set<Object> getSingletons() {
+        return Collections.<Object>singleton(this);
+    }
+
+    @GET
+    @Produces("text/plain")
+    public String sayHello() {
+        return "Hello application conflict";
+    }
+
+    @Path("/conflict")
+    @GET
+    @Produces("text/plain")
+    public String conflict() {
+        return "conflict";
+    }
+
+}