Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 84A56200BD4 for ; Thu, 1 Dec 2016 12:32:04 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 832BC160B0B; Thu, 1 Dec 2016 11:32:04 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7F0DB160B0F for ; Thu, 1 Dec 2016 12:32:03 +0100 (CET) Received: (qmail 96825 invoked by uid 500); 1 Dec 2016 11:32:02 -0000 Mailing-List: contact commits-help@aries.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@aries.apache.org Delivered-To: mailing list commits@aries.apache.org Received: (qmail 96805 invoked by uid 99); 1 Dec 2016 11:32:02 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Dec 2016 11:32:02 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 48D27E69B1; Thu, 1 Dec 2016 11:32:02 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: csierra@apache.org To: commits@aries.apache.org Date: Thu, 01 Dec 2016 11:32:03 -0000 Message-Id: In-Reply-To: <622de8e88d604a75b9f16ead0e7d27f2@git.apache.org> References: <622de8e88d604a75b9f16ead0e7d27f2@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] aries-jax-rs-whiteboard git commit: Added test variants to test deregistration archived-at: Thu, 01 Dec 2016 11:32:04 -0000 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 Authored: Thu Dec 1 12:31:29 2016 +0100 Committer: Carlos Sierra 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 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 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 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 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 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 properties = new Hashtable<>(); + + properties.put(key, value); + + return bundleContext.registerService( + Object.class, testFilter, properties); + } + }