aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From csie...@apache.org
Subject [2/2] aries-jax-rs-whiteboard git commit: Added test variants to test deregistration
Date Thu, 01 Dec 2016 11:32:03 GMT
Added test variants to test deregistration


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

Branch: refs/heads/master
Commit: 29a02c70400bd4136da6e54d507ed06e57b6be0e
Parents: ee7b13c
Author: Carlos Sierra <csierra@apache.org>
Authored: Thu Dec 1 12:31:29 2016 +0100
Committer: Carlos Sierra <csierra@apache.org>
Committed: Thu Dec 1 12:31:29 2016 +0100

----------------------------------------------------------------------
 jax-rs.itests/src/main/java/test/JaxrsTest.java | 359 ++++++++++++++-----
 1 file changed, 267 insertions(+), 92 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/29a02c70/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 1c8e41a..d5f3ec5 100644
--- a/jax-rs.itests/src/main/java/test/JaxrsTest.java
+++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java
@@ -36,7 +36,7 @@ import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Response;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNull;
 
 
 public class JaxrsTest {
@@ -71,43 +71,67 @@ public class JaxrsTest {
 
     @Test
     public void testApplicationReadd() {
-        ServiceRegistration<?> serviceRegistration = null;
-
         Client client = createClient();
 
         WebTarget webTarget = client.
             target("http://localhost:8080").
             path("/test-application");
 
-        assertTrue(webTarget.request().get().getStatus() == 404);
+        Runnable testCase = () -> {
+            assertEquals(webTarget.request().get().getStatus(), 404);
 
-        try {
-            serviceRegistration = registerApplication();
+            ServiceRegistration<?> serviceRegistration = null;
 
-            assertEquals(
-                "Hello application",
-                webTarget.
-                    request().
-                    get().
-                    readEntity(String.class));
-        }
-        finally {
-            if (serviceRegistration != null) {
-                serviceRegistration.unregister();
+            try {
+                serviceRegistration = registerApplication();
+
+                assertEquals(
+                    "Hello application",
+                    webTarget.
+                        request().
+                        get().
+                        readEntity(String.class));
             }
-        }
+            finally {
+                if (serviceRegistration != null) {
+                    serviceRegistration.unregister();
+                }
+            }
+        };
+
+        testCase.run();
 
-        assertTrue(webTarget.request().get().getStatus() == 404);
+        testCase.run();
+    }
+
+    @Test
+    public void testApplicationEndpointExtension() {
+        Client client = createClient();
+
+        WebTarget webTarget = client.
+            target("http://localhost:8080").
+            path("/test-application").
+            path("extended");
+
+        ServiceRegistration<?> applicationRegistration = null;
+
+        ServiceRegistration<?> serviceRegistration = null;
 
         try {
-            serviceRegistration = registerApplication();
+            applicationRegistration = registerApplication();
 
-            assertEquals("Hello application",
-                webTarget.
-                    request().
-                    get().readEntity(String.class));
+            serviceRegistration = registerAddon(
+                "jaxrs.application.select",
+                "(osgi.jaxrs.application.base=/test-application)");
+
+            assertEquals(
+                "Hello extended",
+                webTarget.request().get().readEntity(String.class));
         }
         finally {
+            if (applicationRegistration != null) {
+                applicationRegistration.unregister();
+            }
             if (serviceRegistration != null) {
                 serviceRegistration.unregister();
             }
@@ -115,49 +139,60 @@ public class JaxrsTest {
     }
 
     @Test
-    public void testApplicationEndpointExtension() {
-        ServiceRegistration<?> applicationRegistration = null;
+    public void testApplicationEndpointExtensionReadd() {
+        Client client = createClient();
 
-        ServiceRegistration<?> serviceRegistration = null;
+        WebTarget webTarget = client.
+            target("http://localhost:8080").
+            path("/test-application").
+            path("extended");
+
+        ServiceRegistration<?> applicationRegistration = null;
 
         try {
             applicationRegistration = registerApplication();
 
-            TestAddon testAddon = new TestAddon();
-
-            Dictionary<String, Object> properties = new Hashtable<>();
+            Runnable testCase = () -> {
+                assertEquals(webTarget.request().get().getStatus(), 404);
 
-            properties.put(
-                "jaxrs.application.select",
-                "(osgi.jaxrs.application.base=/test-application)");
-
-            serviceRegistration = bundleContext.registerService(
-                Object.class, testAddon, properties);
+                ServiceRegistration<?> serviceRegistration = null;
 
-            Client client = createClient();
+                try {
+                    serviceRegistration = registerAddon(
+                        "jaxrs.application.select",
+                        "(osgi.jaxrs.application.base=/test-application)");
 
-            WebTarget webTarget = client.
-                target("http://localhost:8080").
-                path("/test-application").
-                path("extended");
+                    assertEquals(
+                        "Hello extended",
+                        webTarget.request().get().readEntity(String.class));
+                }
+                finally {
+                    if (serviceRegistration != null) {
+                        serviceRegistration.unregister();
+                    }
+                }
+            };
 
-            Response response = webTarget.request().get();
+            testCase.run();
 
-            assertEquals("Hello extended",
-                response.readEntity(String.class));
+            testCase.run();
         }
         finally {
             if (applicationRegistration != null) {
                 applicationRegistration.unregister();
             }
-            if (serviceRegistration != null) {
-                serviceRegistration.unregister();
-            }
+
         }
     }
 
     @Test
     public void testApplicationProviderExtension() {
+        Client client = createClient();
+
+        WebTarget webTarget = client.
+            target("http://localhost:8080").
+            path("/test-application");
+
         ServiceRegistration<?> applicationRegistration = null;
 
         ServiceRegistration<?> filterRegistration = null;
@@ -165,28 +200,19 @@ public class JaxrsTest {
         try {
             applicationRegistration = registerApplication();
 
-            TestFilter testFilter = new TestFilter();
-
-            Dictionary<String, Object> properties = new Hashtable<>();
-
-            properties.put(
+            filterRegistration = registerFilter(
                 "jaxrs.application.select",
                 "(osgi.jaxrs.application.base=/test-application)");
 
-            filterRegistration = bundleContext.registerService(
-                Object.class, testFilter, properties);
-
-            Client client = createClient();
-
-            WebTarget webTarget = client.
-                target("http://localhost:8080").
-                path("/test-application");
             Response response = webTarget.request().get();
 
             assertEquals(
-                "Hello application", response.readEntity(String.class));
+                "Hello application",
+                response.readEntity(String.class));
 
-            assertEquals(response.getHeaders().getFirst("Filtered"), "true");
+            assertEquals(
+                response.getHeaders().getFirst("Filtered"),
+                "true");
         }
         finally {
             if (applicationRegistration != null) {
@@ -199,25 +225,73 @@ public class JaxrsTest {
     }
 
     @Test
-    public void testStandaloneEndPoint() {
-        ServiceRegistration<?> serviceRegistration = null;
+    public void testApplicationProviderExtensionReadd() {
+        Client client = createClient();
+
+        WebTarget webTarget = client.
+            target("http://localhost:8080").
+            path("/test-application");
+
+        ServiceRegistration<?> applicationRegistration = null;
 
         try {
-            TestAddon testAddon = new TestAddon();
+            applicationRegistration = registerApplication();
 
-            Dictionary<String, Object> properties = new Hashtable<>();
+            assertEquals(
+                "Hello application",
+                webTarget.request().get().readEntity(String.class));
 
-            properties.put("osgi.jaxrs.resource.base", "/test-addon");
+            Runnable testCase = () ->  {
+                Response response = webTarget.request().get();
 
-            serviceRegistration = bundleContext.registerService(
-                Object.class, testAddon, properties);
+                assertNull(response.getHeaders().getFirst("Filtered"));
 
-            Client client = createClient();
+                ServiceRegistration<?> filterRegistration = null;
 
-            WebTarget webTarget = client.
-                target("http://localhost:8080").
-                path("/test-addon").
-                path("test");
+                try {
+                    filterRegistration = registerFilter(
+                        "jaxrs.application.select",
+                        "(osgi.jaxrs.application.base=/test-application)");
+
+                    response = webTarget.request().get();
+
+                    assertEquals(
+                        response.getHeaders().getFirst("Filtered"),
+                        "true");
+                }
+                finally {
+                    if (filterRegistration != null) {
+                        filterRegistration.unregister();
+                    }
+                }
+            };
+
+            testCase.run();
+
+            testCase.run();
+
+        }
+        finally {
+            if (applicationRegistration != null) {
+                applicationRegistration.unregister();
+            }
+        }
+    }
+
+    @Test
+    public void testStandaloneEndPoint() {
+        Client client = createClient();
+
+        WebTarget webTarget = client.
+            target("http://localhost:8080").
+            path("/test-addon").
+            path("test");
+
+        ServiceRegistration<?> serviceRegistration = null;
+
+        try {
+            serviceRegistration = registerAddon(
+                "osgi.jaxrs.resource.base", "/test-addon");
 
             Response response = webTarget.request().get();
 
@@ -232,37 +306,60 @@ public class JaxrsTest {
         }
     }
 
+
     @Test
-    public void testStandaloneFilter() {
-        ServiceRegistration<?> filterRegistration = null;
+    public void testStandaloneEndPointReadd() {
+        Client client = createClient();
 
-        ServiceRegistration<?> serviceRegistration = null;
+        WebTarget webTarget = client.
+            target("http://localhost:8080").
+            path("/test-addon").
+            path("test");
 
-        try {
-            TestAddon testAddon = new TestAddon();
+        Runnable testCase = () -> {
+            assertEquals(webTarget.request().get().getStatus(), 404);
 
-            Dictionary<String, Object> properties = new Hashtable<>();
+            ServiceRegistration<?> serviceRegistration = null;
 
-            properties.put("osgi.jaxrs.resource.base", "/test-addon");
+            try {
+                serviceRegistration = registerAddon(
+                    "osgi.jaxrs.resource.base", "/test-addon");
 
-            serviceRegistration = bundleContext.registerService(
-                Object.class, testAddon, properties);
+                assertEquals(
+                    "Hello test",
+                    webTarget.request().get().readEntity(String.class));
+            }
+            finally {
+                if (serviceRegistration != null) {
+                    serviceRegistration.unregister();
+                }
+            }
+        };
 
-            TestFilter testFilter = new TestFilter();
+        testCase.run();
 
-            properties = new Hashtable<>();
+        testCase.run();
+    }
 
-            properties.put("osgi.jaxrs.filter.base", "/test-addon");
+    @Test
+    public void testStandaloneFilter() {
+        Client client = createClient();
 
-            filterRegistration = bundleContext.registerService(
-                Object.class, testFilter, properties);
+        WebTarget webTarget = client.
+            target("http://localhost:8080").
+            path("/test-addon").
+            path("test");
 
-            Client client = createClient();
+        ServiceRegistration<?> filterRegistration = null;
 
-            WebTarget webTarget = client.
-                target("http://localhost:8080").
-                path("/test-addon").
-                path("test");
+        ServiceRegistration<?> serviceRegistration = null;
+
+        try {
+            serviceRegistration = registerAddon(
+                "osgi.jaxrs.resource.base", "/test-addon");
+
+            filterRegistration = registerFilter(
+                "osgi.jaxrs.filter.base", "/test-addon");
 
             Response response = webTarget.request().get();
 
@@ -282,6 +379,62 @@ public class JaxrsTest {
         }
     }
 
+    @Test
+    public void testStandaloneFilterReadd() {
+        Client client = createClient();
+
+        WebTarget webTarget = client.
+            target("http://localhost:8080").
+            path("/test-addon").
+            path("test");
+
+        ServiceRegistration<?> serviceRegistration = null;
+
+        try {
+            serviceRegistration = registerAddon(
+                "osgi.jaxrs.resource.base", "/test-addon");
+
+            assertEquals("Hello test",
+                webTarget.request().get().readEntity(String.class));
+
+            Runnable testCase = () -> {
+                ServiceRegistration<?> filterRegistration = null;
+
+                try {
+                    Response response = webTarget.request().get();
+
+                    assertNull(response.getHeaders().getFirst("Filtered"));
+
+                    filterRegistration = registerFilter(
+                        "osgi.jaxrs.filter.base", "/test-addon");
+
+                    response = webTarget.request().get();
+
+                    assertEquals(
+                        "Hello test", response.readEntity(String.class));
+
+                    assertEquals(
+                        response.getHeaders().getFirst("Filtered"), "true");
+                }
+                finally {
+                    if (filterRegistration != null) {
+                        filterRegistration.unregister();
+                    }
+                }
+            };
+
+            testCase.run();
+
+            testCase.run();
+        }
+        finally {
+            if (serviceRegistration != null) {
+                serviceRegistration.unregister();
+            }
+
+        }
+    }
+
     private Client createClient() {
         Thread thread = Thread.currentThread();
 
@@ -298,6 +451,17 @@ public class JaxrsTest {
         }
     }
 
+    private ServiceRegistration<?> registerAddon(String key, String value) {
+        TestAddon testAddon = new TestAddon();
+
+        Dictionary<String, Object> properties = new Hashtable<>();
+
+        properties.put(key, value);
+
+        return bundleContext.registerService(
+            Object.class, testAddon, properties);
+    }
+
 
     private ServiceRegistration<?> registerApplication() {
         TestApplication testApplication = new TestApplication();
@@ -311,4 +475,15 @@ public class JaxrsTest {
             Application.class, testApplication, properties);
     }
 
+    private ServiceRegistration<?> registerFilter(String key, String value) {
+        TestFilter testFilter = new TestFilter();
+
+        Dictionary<String, Object> properties = new Hashtable<>();
+
+        properties.put(key, value);
+
+        return bundleContext.registerService(
+            Object.class, testFilter, properties);
+    }
+
 }


Mime
View raw message