[Lada-commits] [PATCH 6 of 9] Updated query service tests. Running as client now

Wald Commits scm-commit at wald.intevation.org
Wed Feb 11 13:02:44 CET 2015


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1423655637 -3600
# Node ID 4986ef8bff19ca0fbea3065a4942b5e74bdf13ab
# Parent  76c0cc6d2d852fd5431595bbbf8fcb40210a5b03
Updated query service tests. Running as client now.

diff -r 76c0cc6d2d85 -r 4986ef8bff19 src/test/java/de/intevation/lada/LadaTest.java
--- a/src/test/java/de/intevation/lada/LadaTest.java	Wed Feb 11 12:51:42 2015 +0100
+++ b/src/test/java/de/intevation/lada/LadaTest.java	Wed Feb 11 12:53:57 2015 +0100
@@ -2,8 +2,6 @@
 
 import java.net.URL;
 
-import javax.inject.Inject;
-
 import org.jboss.arquillian.container.test.api.Deployment;
 import org.jboss.arquillian.container.test.api.RunAsClient;
 import org.jboss.arquillian.junit.Arquillian;
@@ -14,16 +12,12 @@
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
-import de.intevation.lada.rest.QueryService;
 import de.intevation.lada.test.ProbeServiceTest;
 import de.intevation.lada.test.QueryServiceTest;
 
 @RunWith(Arquillian.class)
 public class LadaTest {
 
-    @Inject
-    private QueryService queryService;
-
     @Deployment
     public static WebArchive createDeployment() throws Exception {
         return ShrinkWrap.create(WebArchive.class, "lada-basis-test.war")
@@ -39,9 +33,12 @@
      * Testing the QueryService.
      */
     @Test
-    public final void testQueryService() throws Exception {
+    @RunAsClient
+    public final void testQueryService(@ArquillianResource URL baseUrl)
+    throws Exception {
+        Assert.assertNotNull(baseUrl);
         QueryServiceTest queryServiceTest = new QueryServiceTest();
-        queryServiceTest.test(queryService);
+        queryServiceTest.test(baseUrl);
     }
 
     /**
diff -r 76c0cc6d2d85 -r 4986ef8bff19 src/test/java/de/intevation/lada/test/QueryServiceTest.java
--- a/src/test/java/de/intevation/lada/test/QueryServiceTest.java	Wed Feb 11 12:51:42 2015 +0100
+++ b/src/test/java/de/intevation/lada/test/QueryServiceTest.java	Wed Feb 11 12:53:57 2015 +0100
@@ -1,23 +1,70 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3) 
+ * and comes with ABSOLUTELY NO WARRANTY! Check out 
+ * the documentation coming with IMIS-Labordaten-Application for details. 
+ */
 package de.intevation.lada.test;
 
+import java.io.StringReader;
+import java.net.URL;
+
+import javax.json.Json;
+import javax.json.JsonException;
+import javax.json.JsonObject;
+import javax.json.JsonReader;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
 import org.junit.Assert;
 
-import de.intevation.lada.rest.QueryService;
-import de.intevation.lada.util.rest.Response;
-
-
+/**
+ * Class to test the Lada query REST service.
+ *
+ * @author <a href="mailto:rrenkert at intevation.de">Raimund Renkert</a>
+ */
 public class QueryServiceTest {
 
-    public final void test(QueryService queryService) throws Exception {
-        queryService(queryService);
+    /**
+     * Main entry point in this class to start the tests.
+     *
+     * @param baseUrl The url pointing to the test deployment.
+     */
+    public final void test(URL baseUrl) throws Exception {
+        queryService(baseUrl);
     }
 
-    private final void queryService(QueryService queryService)
+    /**
+     * Test the GET Service by requesting all queries.
+     *
+     * @param baseUrl The url pointing to the test deployment.
+     */
+    private final void queryService(URL baseUrl)
     throws Exception {
-        Response response = queryService.get();
-        Assert.assertEquals("200", response.getMessage());
-        Assert.assertTrue(response.getSuccess());
-        Assert.assertNotNull(response.getData());
+        System.out.println("Starting test (1) on Query-Service:");
+        System.out.println("Testing get: ");
+        /* Create a client*/
+        Client client = ClientBuilder.newClient();
+        WebTarget target = client.target(baseUrl + "query");
+        /* Request all queries*/
+        Response response = target.request().get();
+        String entity = response.readEntity(String.class);
+        try{
+            /* Try to parse the response*/
+            JsonReader reader = Json.createReader(new StringReader(entity));
+            JsonObject content = reader.readObject();
+            /* Verfiy the response*/
+            Assert.assertTrue(content.getBoolean("success"));
+            Assert.assertEquals("200", content.getString("message"));
+            Assert.assertNotNull(content.getJsonArray("data"));
+        }
+        catch(JsonException je) {
+            Assert.fail(je.getMessage());
+        }
+        System.out.println("passed");
     }
 
 }


More information about the Lada-commits mailing list