changeset 448:4986ef8bff19

Updated query service tests. Running as client now.
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 11 Feb 2015 12:53:57 +0100
parents 76c0cc6d2d85
children ee5c7309e4b9
files src/test/java/de/intevation/lada/LadaTest.java src/test/java/de/intevation/lada/test/QueryServiceTest.java
diffstat 2 files changed, 63 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- 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);
     }
 
     /**
--- 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@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");
     }
 
 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)