aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From csie...@apache.org
Subject [12/14] aries-jax-rs-whiteboard git commit: Add basic tests for ApplicationDTO
Date Fri, 18 Aug 2017 14:02:01 GMT
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 <csierra@apache.org>
Authored: Thu Aug 17 12:46:39 2017 +0200
Committer: Carlos Sierra <csierra@apache.org>
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<JaxRSServiceRuntime, JaxRSServiceRuntime> _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();
+        }
+    }
+
 }


Mime
View raw message