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 83F9B200CF2 for ; Fri, 18 Aug 2017 16:01:56 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 82ACC16C2D0; Fri, 18 Aug 2017 14:01:56 +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 A98BC16BC8D for ; Fri, 18 Aug 2017 16:01:55 +0200 (CEST) Received: (qmail 72029 invoked by uid 500); 18 Aug 2017 14:01:52 -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 71999 invoked by uid 99); 18 Aug 2017 14:01:52 -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; Fri, 18 Aug 2017 14:01:52 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 50024DFC28; Fri, 18 Aug 2017 14:01:50 +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: Fri, 18 Aug 2017 14:02:01 -0000 Message-Id: <532c04ec23594b5cb622be46decc5088@git.apache.org> In-Reply-To: <1aa0ad14e7a848b396707345cb3d9ca7@git.apache.org> References: <1aa0ad14e7a848b396707345cb3d9ca7@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [12/14] aries-jax-rs-whiteboard git commit: Add basic tests for ApplicationDTO archived-at: Fri, 18 Aug 2017 14:01:56 -0000 Add basic tests for ApplicationDTO 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/d369a6a9 Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/d369a6a9 Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/d369a6a9 Branch: refs/heads/master Commit: d369a6a9ddb178feda6f4d0351b2ad2d7b66f030 Parents: bf5454a Author: Carlos Sierra Authored: Thu Aug 17 12:46:39 2017 +0200 Committer: Carlos Sierra Committed: Fri Aug 18 15:59:21 2017 +0200 ---------------------------------------------------------------------- jax-rs.itests/src/main/java/test/JaxrsTest.java | 65 +++++++++++++++++--- 1 file changed, 58 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/d369a6a9/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 dbea7c0..c36f0df 100644 --- a/jax-rs.itests/src/main/java/test/JaxrsTest.java +++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java @@ -17,17 +17,21 @@ package test; +import static org.junit.Assert.assertNotNull; import static org.osgi.service.jaxrs.whiteboard.JaxRSWhiteboardConstants.*; import java.util.Dictionary; import java.util.Hashtable; +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.jaxrs.runtime.JaxRSServiceRuntime; +import org.osgi.util.tracker.ServiceTracker; import test.types.TestAddon; import test.types.TestAddonConflict; import test.types.TestAddonConflict2; @@ -48,14 +52,24 @@ import static org.junit.Assert.assertNull; public class JaxrsTest extends TestHelper { + private ServiceTracker _runtimeTracker; + @Test - public void testApplication() { + public void testApplication() throws InterruptedException { ServiceRegistration serviceRegistration = null; try { + JaxRSServiceRuntime runtime = getJaxRSServiceRuntime(); + + assertEquals(0, runtime.getRuntimeDTO().applicationDTOs.length); + + assertNotNull(runtime); + serviceRegistration = registerApplication( new TestApplication()); + assertEquals(1, runtime.getRuntimeDTO().applicationDTOs.length); + Client client = createClient(); WebTarget webTarget = client. @@ -74,6 +88,15 @@ public class JaxrsTest extends TestHelper { } } + private JaxRSServiceRuntime getJaxRSServiceRuntime() throws InterruptedException { + _runtimeTracker = new ServiceTracker<>( + bundleContext, JaxRSServiceRuntime.class, null); + + _runtimeTracker.open(); + + return _runtimeTracker.waitForService(5000); + } + @Test public void testApplicationConflict() { Client client = createClient(); @@ -121,20 +144,27 @@ public class JaxrsTest extends TestHelper { } @Test - public void testApplicationOverride() { + public void testApplicationOverride() throws InterruptedException { Client client = createClient(); WebTarget webTarget = client. target("http://localhost:8080"). path("test-application"); + JaxRSServiceRuntime runtime = getJaxRSServiceRuntime(); ServiceRegistration serviceRegistration = null; ServiceRegistration serviceRegistration2; try { + assertEquals(0, runtime.getRuntimeDTO().applicationDTOs.length); + assertEquals(0, runtime.getRuntimeDTO().failedApplicationDTOs.length); + serviceRegistration = registerApplication(new TestApplication()); + assertEquals(1, runtime.getRuntimeDTO().applicationDTOs.length); + assertEquals(0, runtime.getRuntimeDTO().failedApplicationDTOs.length); + Response response = webTarget.request().get(); assertEquals( @@ -144,6 +174,9 @@ public class JaxrsTest extends TestHelper { serviceRegistration2 = registerApplication( new TestApplicationConflict(), "service.ranking", 1); + assertEquals(1, runtime.getRuntimeDTO().applicationDTOs.length); + assertEquals(1, runtime.getRuntimeDTO().failedApplicationDTOs.length); + response = webTarget.request().get(); assertEquals( @@ -156,6 +189,9 @@ public class JaxrsTest extends TestHelper { serviceRegistration2.unregister(); + assertEquals(1, runtime.getRuntimeDTO().applicationDTOs.length); + assertEquals(0, runtime.getRuntimeDTO().failedApplicationDTOs.length); + response = webTarget.request().get(); assertEquals( @@ -169,14 +205,18 @@ public class JaxrsTest extends TestHelper { } @Test - public void testApplicationReadd() { + public void testApplicationReadd() throws InterruptedException { Client client = createClient(); WebTarget webTarget = client. target("http://localhost:8080"). path("/test-application"); + JaxRSServiceRuntime runtime = getJaxRSServiceRuntime(); + Runnable testCase = () -> { + assertEquals(0, runtime.getRuntimeDTO().applicationDTOs.length); + assertEquals(404, webTarget.request().get().getStatus()); ServiceRegistration serviceRegistration = null; @@ -190,6 +230,8 @@ public class JaxrsTest extends TestHelper { request(). get(). readEntity(String.class)); + + assertEquals(1, runtime.getRuntimeDTO().applicationDTOs.length); } finally { if (serviceRegistration != null) { @@ -239,7 +281,7 @@ public class JaxrsTest extends TestHelper { } @Test - public void testApplicationEndpointExtensionReadd() { + public void testApplicationEndpointExtensionReadd() throws InterruptedException { Client client = createClient(); WebTarget webTarget = client. @@ -249,7 +291,11 @@ public class JaxrsTest extends TestHelper { ServiceRegistration applicationRegistration = null; + JaxRSServiceRuntime jaxRSServiceRuntime = getJaxRSServiceRuntime(); + try { + + applicationRegistration = registerApplication( new TestApplication()); @@ -312,9 +358,7 @@ public class JaxrsTest extends TestHelper { "Hello application", response.readEntity(String.class)); - assertEquals( - "true", - response.getHeaders().getFirst("Filtered")); + assertEquals("true", response.getHeaders().getFirst("Filtered")); } finally { if (applicationRegistration != null) { @@ -789,4 +833,11 @@ public class JaxrsTest extends TestHelper { Object.class, testFilter, properties); } + @After + public void tearDown() { + if (_runtimeTracker != null) { + _runtimeTracker.close(); + } + } + }