[Lada-commits] [PATCH 2 of 4] Moved base class for tests to package 'test'

Wald Commits scm-commit at wald.intevation.org
Fri Jan 8 12:10:29 CET 2016


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1452251246 -3600
# Node ID cb1cfc8c81edc1b450fc63402e67c0dce703cb6e
# Parent  fa922101a462df6d996c9cce1472550a2e1a0a09
Moved base class for tests to package 'test'.

diff -r fa922101a462 -r cb1cfc8c81ed src/test/java/de/intevation/lada/test/ServiceTest.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/java/de/intevation/lada/test/ServiceTest.java	Fri Jan 08 12:07:26 2016 +0100
@@ -0,0 +1,363 @@
+package de.intevation.lada.test;
+
+import java.io.InputStream;
+import java.io.StringReader;
+import java.net.URL;
+import java.sql.Timestamp;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Scanner;
+
+import javax.json.Json;
+import javax.json.JsonException;
+import javax.json.JsonObject;
+import javax.json.JsonObjectBuilder;
+import javax.json.JsonReader;
+import javax.json.JsonValue;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.commons.lang.WordUtils;
+import org.junit.Assert;
+
+import de.intevation.lada.BaseTest;
+import de.intevation.lada.Protocol;
+import de.intevation.lada.test.land.ProbeTest;
+
+public class ServiceTest {
+
+    protected List<Protocol> protocol;
+
+    protected List<String> timestampAttributes;
+
+    protected URL baseUrl;
+
+    public void init(URL baseUrl, List<Protocol> protocol) {
+        this.baseUrl = baseUrl;
+        this.protocol = protocol;
+    }
+
+    /**
+     * @return The test protocol
+     */
+    public List<Protocol> getProtocol() {
+        return protocol;
+    }
+
+    protected JsonObject readJsonResource(String resource) {
+        InputStream stream =
+            ProbeTest.class.getResourceAsStream(resource);
+        Scanner scanner = new Scanner(stream, "UTF-8");
+        scanner.useDelimiter("\\A");
+        String raw = scanner.next();
+        scanner.close();
+        JsonReader reader = Json.createReader(new StringReader(raw));
+        JsonObject content = reader.readObject();
+        reader.close();
+        return content;
+    }
+
+    protected JsonObjectBuilder convertObject(JsonObject object) {
+        JsonObjectBuilder builder = Json.createObjectBuilder();
+        for (Entry<String, JsonValue> entry : object.entrySet()) {
+            String key = WordUtils.capitalize(
+                entry.getKey(), new char[]{'_'}).replaceAll("_","");
+            key = key.replaceFirst(key.substring(0, 1), key.substring(0, 1).toLowerCase());
+            if (timestampAttributes.contains(key)) {
+                Timestamp timestamp = Timestamp.valueOf(entry.getValue().toString().replaceAll("\"", ""));
+                builder.add(key, timestamp.getTime());
+            }
+            else {
+                builder.add(key, entry.getValue());
+            }
+        }
+        return builder;
+    }
+
+    public JsonObject getAll(String name, String parameter) {
+        System.out.print(".");
+        Protocol prot = new Protocol();
+        prot.setName(name + " service");
+        prot.setType("get all");
+        prot.setPassed(false);
+        protocol.add(prot);
+        /* Create a client*/
+        Client client = ClientBuilder.newClient();
+        WebTarget target = client.target(baseUrl + parameter);
+        /* Request all objects*/
+        Response response = target.request()
+            .header("X-SHIB-user", BaseTest.TEST_USER)
+            .header("X-SHIB-roles", BaseTest.TEST_ROLES)
+            .get();
+        String entity = response.readEntity(String.class);
+        try{
+            /* Try to parse the response*/
+            JsonReader reader = Json.createReader(new StringReader(entity));
+            JsonObject content = reader.readObject();
+            /* Verify the response*/
+            Assert.assertTrue(content.getBoolean("success"));
+            prot.addInfo("success", content.getBoolean("success"));
+            Assert.assertEquals("200", content.getString("message"));
+            prot.addInfo("message", content.getString("message"));
+            Assert.assertNotNull(content.getJsonArray("data"));
+            prot.addInfo("objects", content.getJsonArray("data").size());
+            prot.setPassed(true);
+            return content;
+        }
+        catch(JsonException je) {
+            prot.addInfo("exception", je.getMessage());
+            Assert.fail(je.getMessage());
+        }
+        return null;
+    }
+    /**
+     * Test the GET Service by requesting a single object by id.
+     *
+     * @param baseUrl The url pointing to the test deployment.
+     */
+    public JsonObject getById(
+        String name,
+        String parameter,
+        JsonObject expected
+    ) {
+        System.out.print(".");
+        Protocol prot = new Protocol();
+        prot.setName(name + " service");
+        prot.setType("get by Id");
+        prot.setPassed(false);
+        protocol.add(prot);
+        try {
+            /* Create a client*/
+            Client client = ClientBuilder.newClient();
+            WebTarget target = client.target(baseUrl + parameter);
+            prot.addInfo("parameter", parameter);
+            /* Request a object by id*/
+            Response response = target.request()
+                .header("X-SHIB-user", BaseTest.TEST_USER)
+                .header("X-SHIB-roles", BaseTest.TEST_ROLES)
+                .get();
+            String entity = response.readEntity(String.class);
+            /* Try to parse the response*/
+            JsonReader fromServiceReader =
+                Json.createReader(new StringReader(entity));
+            JsonObject content = fromServiceReader.readObject();
+            /* Verify the response*/
+            Assert.assertTrue(content.getBoolean("success"));
+            prot.addInfo("success", content.getBoolean("success"));
+            Assert.assertEquals("200", content.getString("message"));
+            prot.addInfo("message", content.getString("message"));
+            Assert.assertFalse(content.getJsonObject("data").isEmpty());
+            JsonObject object = content.getJsonObject("data");
+            for (Entry<String, JsonValue> entry : expected.entrySet()) {
+                if (entry.getKey().equals("parentModified") ||
+                    entry.getKey().equals("treeModified")) {
+                    continue;
+                }
+                Assert.assertEquals(entry.getValue(), object.get(entry.getKey()));
+            }
+            prot.addInfo("object", "equals");
+            prot.setPassed(true);
+            return content;
+        }
+        catch(JsonException je) {
+            prot.addInfo("exception",je.getMessage());
+            Assert.fail(je.getMessage());
+        }
+        return null;
+    }
+
+    /**
+     * Test the GET service using filters.
+     *
+     * @param baseUrl The url poining to the test deployment.
+     */
+    public JsonObject filter(String name, String parameter) {
+        System.out.print(".");
+        Protocol prot = new Protocol();
+        prot.setName(name + " service");
+        prot.setType("filter");
+        prot.setPassed(false);
+        protocol.add(prot);
+        try {
+            /* Create a client*/
+            Client client = ClientBuilder.newClient();
+            WebTarget target =
+                client.target(baseUrl + parameter);//"probe?qid=2&mst_id=11010&umw_id=N24");
+            prot.addInfo("filter", parameter);//"qid=2&mst_id=11010&umw_id=N24");
+            /* Request the objects using the filter*/
+            Response response = target.request()
+                .header("X-SHIB-user", BaseTest.TEST_USER)
+                .header("X-SHIB-roles", BaseTest.TEST_ROLES)
+                .get();
+            String entity = response.readEntity(String.class);
+            /* Try to parse the response*/
+            JsonReader reader = Json.createReader(new StringReader(entity));
+            JsonObject content = reader.readObject();
+            /* Verify the response*/
+            Assert.assertTrue(content.getBoolean("success"));
+            prot.addInfo("success", content.getBoolean("success"));
+            Assert.assertEquals("200", content.getString("message"));
+            prot.addInfo("message", content.getString("message"));
+            Assert.assertNotNull(content.getJsonArray("data"));
+            prot.addInfo("objects", content.getJsonArray("data").size());
+            prot.setPassed(true);
+            return content;
+        }
+        catch(JsonException je) {
+            prot.addInfo("exception", je.getMessage());
+            Assert.fail(je.getMessage());
+        }
+        return null;
+    }
+
+    /**
+     * Test the CREATE Service.
+     *
+     * @param baseUrl The url pointing to the test deployment.
+     */
+    public JsonObject create(String name, String parameter, JsonObject create) {
+        System.out.print(".");
+        Protocol prot = new Protocol();
+        prot.setName(name + " service");
+        prot.setType("create");
+        prot.setPassed(false);
+        protocol.add(prot);
+        try {
+            /* Create a client*/
+            Client client = ClientBuilder.newClient();
+            WebTarget target = client.target(baseUrl + parameter);
+            /* Send a post request containing a new probe*/
+            Response response = target.request()
+                .header("X-SHIB-user", BaseTest.TEST_USER)
+                .header("X-SHIB-roles", BaseTest.TEST_ROLES)
+                .post(Entity.entity(create.toString(), MediaType.APPLICATION_JSON));
+            String entity = response.readEntity(String.class);
+            /* Try to parse the response*/
+            JsonReader fromServiceReader =
+                Json.createReader(new StringReader(entity));
+            JsonObject content = fromServiceReader.readObject();
+            /* Verify the response*/
+            Assert.assertTrue(content.getBoolean("success"));
+            prot.addInfo("success", content.getBoolean("success"));
+            Assert.assertEquals("200", content.getString("message"));
+            prot.addInfo("message", content.getString("message"));
+            prot.setPassed(true);
+            return content;
+        }
+        catch(JsonException je) {
+            prot.addInfo("exception", je.getMessage());
+            Assert.fail(je.getMessage());
+        }
+        return null;
+    }
+
+    /**
+     * Test the probe update service.
+     *
+     * @param baseUrl The url pointing to the test deployment.
+     */
+    public JsonObject update(
+        String name,
+        String parameter,
+        String updateAttribute,
+        String oldValue,
+        String newValue
+    ) {
+        System.out.print(".");
+        Protocol prot = new Protocol();
+        prot.setName(name + " service");
+        prot.setType("update");
+        prot.setPassed(false);
+        protocol.add(prot);
+        try {
+            /* Create a client*/
+            Client client = ClientBuilder.newClient();
+            WebTarget target = client.target(baseUrl + parameter);
+            /* Request a with the saved id*/
+            Response response = target.request()
+                .header("X-SHIB-user", BaseTest.TEST_USER)
+                .header("X-SHIB-roles", BaseTest.TEST_ROLES)
+                .get();
+            String entity = response.readEntity(String.class);
+            /* Try to parse the response*/
+            JsonReader reader = Json.createReader(new StringReader(entity));
+            JsonObject oldObject = reader.readObject().getJsonObject("data");
+            /* Change the hauptprobenNr*/
+            String updatedEntity =
+                oldObject.toString().replace(oldValue, newValue);
+            prot.addInfo("updated datafield", updateAttribute);
+            prot.addInfo("updated value", oldValue);
+            prot.addInfo("updated to", newValue);
+            /* Send the updated probe via put request*/
+            WebTarget putTarget = client.target(baseUrl + parameter);
+            Response updated = putTarget.request()
+                .header("X-SHIB-user", BaseTest.TEST_USER)
+                .header("X-SHIB-roles", BaseTest.TEST_ROLES)
+                .put(Entity.entity(updatedEntity, MediaType.APPLICATION_JSON));
+            /* Try to parse the response*/
+            JsonReader updatedReader = Json.createReader(
+                new StringReader(updated.readEntity(String.class)));
+            JsonObject updatedObject = updatedReader.readObject();
+            /* Verify the response*/
+            Assert.assertTrue(updatedObject.getBoolean("success"));
+            prot.addInfo("success", updatedObject.getBoolean("success"));
+            Assert.assertEquals("200", updatedObject.getString("message"));
+            prot.addInfo("message", updatedObject.getString("message"));
+            Assert.assertEquals(newValue,
+                updatedObject.getJsonObject("data").getString(updateAttribute));
+            prot.setPassed(true);
+            return updatedObject;
+        }
+        catch(JsonException je) {
+            prot.addInfo("exception", je.getMessage());
+            Assert.fail(je.getMessage());
+        }
+        return null;
+    }
+
+    /**
+     * Test the DELETE Service.
+     *
+     * @param baseUrl The url pointing to the test deployment.
+     */
+    public JsonObject delete(String name, String parameter) {
+        System.out.print(".");
+        Protocol prot = new Protocol();
+        prot.setName(name + " service");
+        prot.setType("delete");
+        prot.setPassed(false);
+        protocol.add(prot);
+        try {
+            /* Create a client*/
+            Client client = ClientBuilder.newClient();
+            WebTarget target =
+                client.target(baseUrl + parameter);
+            prot.addInfo("parameter", parameter);
+            /* Delete a probe with the id saved when created a probe*/
+            Response response = target.request()
+                .header("X-SHIB-user", BaseTest.TEST_USER)
+                .header("X-SHIB-roles", BaseTest.TEST_ROLES)
+                .delete();
+            String entity = response.readEntity(String.class);
+            /* Try to parse the response*/
+            JsonReader reader = Json.createReader(new StringReader(entity));
+            JsonObject content = reader.readObject();
+            /* Verify the response*/
+            Assert.assertTrue(content.getBoolean("success"));
+            prot.addInfo("success", content.getBoolean("success"));
+            Assert.assertEquals("200", content.getString("message"));
+            prot.addInfo("message", content.getString("message"));
+            prot.setPassed(true);
+            return content;
+        }
+        catch(JsonException je) {
+            prot.addInfo("exception", je.getMessage());
+            Assert.fail(je.getMessage());
+        }
+        return null;
+    }
+}
diff -r fa922101a462 -r cb1cfc8c81ed src/test/java/de/intevation/lada/test/land/KommentarMTest.java
--- a/src/test/java/de/intevation/lada/test/land/KommentarMTest.java	Fri Jan 08 12:05:26 2016 +0100
+++ b/src/test/java/de/intevation/lada/test/land/KommentarMTest.java	Fri Jan 08 12:07:26 2016 +0100
@@ -11,6 +11,7 @@
 import org.junit.Assert;
 
 import de.intevation.lada.Protocol;
+import de.intevation.lada.test.ServiceTest;
 
 public class KommentarMTest extends ServiceTest {
 
diff -r fa922101a462 -r cb1cfc8c81ed src/test/java/de/intevation/lada/test/land/KommentarPTest.java
--- a/src/test/java/de/intevation/lada/test/land/KommentarPTest.java	Fri Jan 08 12:05:26 2016 +0100
+++ b/src/test/java/de/intevation/lada/test/land/KommentarPTest.java	Fri Jan 08 12:07:26 2016 +0100
@@ -11,6 +11,7 @@
 import org.junit.Assert;
 
 import de.intevation.lada.Protocol;
+import de.intevation.lada.test.ServiceTest;
 
 public class KommentarPTest extends ServiceTest {
 
diff -r fa922101a462 -r cb1cfc8c81ed src/test/java/de/intevation/lada/test/land/MessprogrammTest.java
--- a/src/test/java/de/intevation/lada/test/land/MessprogrammTest.java	Fri Jan 08 12:05:26 2016 +0100
+++ b/src/test/java/de/intevation/lada/test/land/MessprogrammTest.java	Fri Jan 08 12:07:26 2016 +0100
@@ -11,6 +11,7 @@
 import org.junit.Assert;
 
 import de.intevation.lada.Protocol;
+import de.intevation.lada.test.ServiceTest;
 
 public class MessprogrammTest extends ServiceTest {
     private JsonObject expectedById;
diff -r fa922101a462 -r cb1cfc8c81ed src/test/java/de/intevation/lada/test/land/MessungTest.java
--- a/src/test/java/de/intevation/lada/test/land/MessungTest.java	Fri Jan 08 12:05:26 2016 +0100
+++ b/src/test/java/de/intevation/lada/test/land/MessungTest.java	Fri Jan 08 12:07:26 2016 +0100
@@ -11,6 +11,7 @@
 import org.junit.Assert;
 
 import de.intevation.lada.Protocol;
+import de.intevation.lada.test.ServiceTest;
 
 public class MessungTest extends ServiceTest {
 
diff -r fa922101a462 -r cb1cfc8c81ed src/test/java/de/intevation/lada/test/land/MesswertTest.java
--- a/src/test/java/de/intevation/lada/test/land/MesswertTest.java	Fri Jan 08 12:05:26 2016 +0100
+++ b/src/test/java/de/intevation/lada/test/land/MesswertTest.java	Fri Jan 08 12:07:26 2016 +0100
@@ -11,6 +11,7 @@
 import org.junit.Assert;
 
 import de.intevation.lada.Protocol;
+import de.intevation.lada.test.ServiceTest;
 
 public class MesswertTest extends ServiceTest {
 
diff -r fa922101a462 -r cb1cfc8c81ed src/test/java/de/intevation/lada/test/land/OrtszuordnungTest.java
--- a/src/test/java/de/intevation/lada/test/land/OrtszuordnungTest.java	Fri Jan 08 12:05:26 2016 +0100
+++ b/src/test/java/de/intevation/lada/test/land/OrtszuordnungTest.java	Fri Jan 08 12:07:26 2016 +0100
@@ -11,6 +11,7 @@
 import org.junit.Assert;
 
 import de.intevation.lada.Protocol;
+import de.intevation.lada.test.ServiceTest;
 
 public class OrtszuordnungTest extends ServiceTest {
 
diff -r fa922101a462 -r cb1cfc8c81ed src/test/java/de/intevation/lada/test/land/ProbeTest.java
--- a/src/test/java/de/intevation/lada/test/land/ProbeTest.java	Fri Jan 08 12:05:26 2016 +0100
+++ b/src/test/java/de/intevation/lada/test/land/ProbeTest.java	Fri Jan 08 12:07:26 2016 +0100
@@ -11,6 +11,7 @@
 import org.junit.Assert;
 
 import de.intevation.lada.Protocol;
+import de.intevation.lada.test.ServiceTest;
 
 public class ProbeTest extends ServiceTest {
 
diff -r fa922101a462 -r cb1cfc8c81ed src/test/java/de/intevation/lada/test/land/QueryTest.java
--- a/src/test/java/de/intevation/lada/test/land/QueryTest.java	Fri Jan 08 12:05:26 2016 +0100
+++ b/src/test/java/de/intevation/lada/test/land/QueryTest.java	Fri Jan 08 12:07:26 2016 +0100
@@ -4,6 +4,7 @@
 import java.util.List;
 
 import de.intevation.lada.Protocol;
+import de.intevation.lada.test.ServiceTest;
 
 public class QueryTest extends ServiceTest {
 
diff -r fa922101a462 -r cb1cfc8c81ed src/test/java/de/intevation/lada/test/land/ServiceTest.java
--- a/src/test/java/de/intevation/lada/test/land/ServiceTest.java	Fri Jan 08 12:05:26 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,362 +0,0 @@
-package de.intevation.lada.test.land;
-
-import java.io.InputStream;
-import java.io.StringReader;
-import java.net.URL;
-import java.sql.Timestamp;
-import java.util.List;
-import java.util.Map.Entry;
-import java.util.Scanner;
-
-import javax.json.Json;
-import javax.json.JsonException;
-import javax.json.JsonObject;
-import javax.json.JsonObjectBuilder;
-import javax.json.JsonReader;
-import javax.json.JsonValue;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-import org.apache.commons.lang.WordUtils;
-import org.junit.Assert;
-
-import de.intevation.lada.BaseTest;
-import de.intevation.lada.Protocol;
-
-public class ServiceTest {
-
-    protected List<Protocol> protocol;
-
-    protected List<String> timestampAttributes;
-
-    protected URL baseUrl;
-
-    public void init(URL baseUrl, List<Protocol> protocol) {
-        this.baseUrl = baseUrl;
-        this.protocol = protocol;
-    }
-
-    /**
-     * @return The test protocol
-     */
-    public List<Protocol> getProtocol() {
-        return protocol;
-    }
-
-    protected JsonObject readJsonResource(String resource) {
-        InputStream stream =
-            ProbeTest.class.getResourceAsStream(resource);
-        Scanner scanner = new Scanner(stream, "UTF-8");
-        scanner.useDelimiter("\\A");
-        String raw = scanner.next();
-        scanner.close();
-        JsonReader reader = Json.createReader(new StringReader(raw));
-        JsonObject content = reader.readObject();
-        reader.close();
-        return content;
-    }
-
-    protected JsonObjectBuilder convertObject(JsonObject object) {
-        JsonObjectBuilder builder = Json.createObjectBuilder();
-        for (Entry<String, JsonValue> entry : object.entrySet()) {
-            String key = WordUtils.capitalize(
-                entry.getKey(), new char[]{'_'}).replaceAll("_","");
-            key = key.replaceFirst(key.substring(0, 1), key.substring(0, 1).toLowerCase());
-            if (timestampAttributes.contains(key)) {
-                Timestamp timestamp = Timestamp.valueOf(entry.getValue().toString().replaceAll("\"", ""));
-                builder.add(key, timestamp.getTime());
-            }
-            else {
-                builder.add(key, entry.getValue());
-            }
-        }
-        return builder;
-    }
-
-    public JsonObject getAll(String name, String parameter) {
-        System.out.print(".");
-        Protocol prot = new Protocol();
-        prot.setName(name + " service");
-        prot.setType("get all");
-        prot.setPassed(false);
-        protocol.add(prot);
-        /* Create a client*/
-        Client client = ClientBuilder.newClient();
-        WebTarget target = client.target(baseUrl + parameter);
-        /* Request all objects*/
-        Response response = target.request()
-            .header("X-SHIB-user", BaseTest.TEST_USER)
-            .header("X-SHIB-roles", BaseTest.TEST_ROLES)
-            .get();
-        String entity = response.readEntity(String.class);
-        try{
-            /* Try to parse the response*/
-            JsonReader reader = Json.createReader(new StringReader(entity));
-            JsonObject content = reader.readObject();
-            /* Verify the response*/
-            Assert.assertTrue(content.getBoolean("success"));
-            prot.addInfo("success", content.getBoolean("success"));
-            Assert.assertEquals("200", content.getString("message"));
-            prot.addInfo("message", content.getString("message"));
-            Assert.assertNotNull(content.getJsonArray("data"));
-            prot.addInfo("objects", content.getJsonArray("data").size());
-            prot.setPassed(true);
-            return content;
-        }
-        catch(JsonException je) {
-            prot.addInfo("exception", je.getMessage());
-            Assert.fail(je.getMessage());
-        }
-        return null;
-    }
-    /**
-     * Test the GET Service by requesting a single object by id.
-     *
-     * @param baseUrl The url pointing to the test deployment.
-     */
-    public JsonObject getById(
-        String name,
-        String parameter,
-        JsonObject expected
-    ) {
-        System.out.print(".");
-        Protocol prot = new Protocol();
-        prot.setName(name + " service");
-        prot.setType("get by Id");
-        prot.setPassed(false);
-        protocol.add(prot);
-        try {
-            /* Create a client*/
-            Client client = ClientBuilder.newClient();
-            WebTarget target = client.target(baseUrl + parameter);
-            prot.addInfo("parameter", parameter);
-            /* Request a object by id*/
-            Response response = target.request()
-                .header("X-SHIB-user", BaseTest.TEST_USER)
-                .header("X-SHIB-roles", BaseTest.TEST_ROLES)
-                .get();
-            String entity = response.readEntity(String.class);
-            /* Try to parse the response*/
-            JsonReader fromServiceReader =
-                Json.createReader(new StringReader(entity));
-            JsonObject content = fromServiceReader.readObject();
-            /* Verify the response*/
-            Assert.assertTrue(content.getBoolean("success"));
-            prot.addInfo("success", content.getBoolean("success"));
-            Assert.assertEquals("200", content.getString("message"));
-            prot.addInfo("message", content.getString("message"));
-            Assert.assertFalse(content.getJsonObject("data").isEmpty());
-            JsonObject object = content.getJsonObject("data");
-            for (Entry<String, JsonValue> entry : expected.entrySet()) {
-                if (entry.getKey().equals("parentModified") ||
-                    entry.getKey().equals("treeModified")) {
-                    continue;
-                }
-                Assert.assertEquals(entry.getValue(), object.get(entry.getKey()));
-            }
-            prot.addInfo("object", "equals");
-            prot.setPassed(true);
-            return content;
-        }
-        catch(JsonException je) {
-            prot.addInfo("exception",je.getMessage());
-            Assert.fail(je.getMessage());
-        }
-        return null;
-    }
-
-    /**
-     * Test the GET service using filters.
-     *
-     * @param baseUrl The url poining to the test deployment.
-     */
-    public JsonObject filter(String name, String parameter) {
-        System.out.print(".");
-        Protocol prot = new Protocol();
-        prot.setName(name + " service");
-        prot.setType("filter");
-        prot.setPassed(false);
-        protocol.add(prot);
-        try {
-            /* Create a client*/
-            Client client = ClientBuilder.newClient();
-            WebTarget target =
-                client.target(baseUrl + parameter);//"probe?qid=2&mst_id=11010&umw_id=N24");
-            prot.addInfo("filter", parameter);//"qid=2&mst_id=11010&umw_id=N24");
-            /* Request the objects using the filter*/
-            Response response = target.request()
-                .header("X-SHIB-user", BaseTest.TEST_USER)
-                .header("X-SHIB-roles", BaseTest.TEST_ROLES)
-                .get();
-            String entity = response.readEntity(String.class);
-            /* Try to parse the response*/
-            JsonReader reader = Json.createReader(new StringReader(entity));
-            JsonObject content = reader.readObject();
-            /* Verify the response*/
-            Assert.assertTrue(content.getBoolean("success"));
-            prot.addInfo("success", content.getBoolean("success"));
-            Assert.assertEquals("200", content.getString("message"));
-            prot.addInfo("message", content.getString("message"));
-            Assert.assertNotNull(content.getJsonArray("data"));
-            prot.addInfo("objects", content.getJsonArray("data").size());
-            prot.setPassed(true);
-            return content;
-        }
-        catch(JsonException je) {
-            prot.addInfo("exception", je.getMessage());
-            Assert.fail(je.getMessage());
-        }
-        return null;
-    }
-
-    /**
-     * Test the CREATE Service.
-     *
-     * @param baseUrl The url pointing to the test deployment.
-     */
-    public JsonObject create(String name, String parameter, JsonObject create) {
-        System.out.print(".");
-        Protocol prot = new Protocol();
-        prot.setName(name + " service");
-        prot.setType("create");
-        prot.setPassed(false);
-        protocol.add(prot);
-        try {
-            /* Create a client*/
-            Client client = ClientBuilder.newClient();
-            WebTarget target = client.target(baseUrl + parameter);
-            /* Send a post request containing a new probe*/
-            Response response = target.request()
-                .header("X-SHIB-user", BaseTest.TEST_USER)
-                .header("X-SHIB-roles", BaseTest.TEST_ROLES)
-                .post(Entity.entity(create.toString(), MediaType.APPLICATION_JSON));
-            String entity = response.readEntity(String.class);
-            /* Try to parse the response*/
-            JsonReader fromServiceReader =
-                Json.createReader(new StringReader(entity));
-            JsonObject content = fromServiceReader.readObject();
-            /* Verify the response*/
-            Assert.assertTrue(content.getBoolean("success"));
-            prot.addInfo("success", content.getBoolean("success"));
-            Assert.assertEquals("200", content.getString("message"));
-            prot.addInfo("message", content.getString("message"));
-            prot.setPassed(true);
-            return content;
-        }
-        catch(JsonException je) {
-            prot.addInfo("exception", je.getMessage());
-            Assert.fail(je.getMessage());
-        }
-        return null;
-    }
-
-    /**
-     * Test the probe update service.
-     *
-     * @param baseUrl The url pointing to the test deployment.
-     */
-    public JsonObject update(
-        String name,
-        String parameter,
-        String updateAttribute,
-        String oldValue,
-        String newValue
-    ) {
-        System.out.print(".");
-        Protocol prot = new Protocol();
-        prot.setName(name + " service");
-        prot.setType("update");
-        prot.setPassed(false);
-        protocol.add(prot);
-        try {
-            /* Create a client*/
-            Client client = ClientBuilder.newClient();
-            WebTarget target = client.target(baseUrl + parameter);
-            /* Request a with the saved id*/
-            Response response = target.request()
-                .header("X-SHIB-user", BaseTest.TEST_USER)
-                .header("X-SHIB-roles", BaseTest.TEST_ROLES)
-                .get();
-            String entity = response.readEntity(String.class);
-            /* Try to parse the response*/
-            JsonReader reader = Json.createReader(new StringReader(entity));
-            JsonObject oldObject = reader.readObject().getJsonObject("data");
-            /* Change the hauptprobenNr*/
-            String updatedEntity =
-                oldObject.toString().replace(oldValue, newValue);
-            prot.addInfo("updated datafield", updateAttribute);
-            prot.addInfo("updated value", oldValue);
-            prot.addInfo("updated to", newValue);
-            /* Send the updated probe via put request*/
-            WebTarget putTarget = client.target(baseUrl + parameter);
-            Response updated = putTarget.request()
-                .header("X-SHIB-user", BaseTest.TEST_USER)
-                .header("X-SHIB-roles", BaseTest.TEST_ROLES)
-                .put(Entity.entity(updatedEntity, MediaType.APPLICATION_JSON));
-            /* Try to parse the response*/
-            JsonReader updatedReader = Json.createReader(
-                new StringReader(updated.readEntity(String.class)));
-            JsonObject updatedObject = updatedReader.readObject();
-            /* Verify the response*/
-            Assert.assertTrue(updatedObject.getBoolean("success"));
-            prot.addInfo("success", updatedObject.getBoolean("success"));
-            Assert.assertEquals("200", updatedObject.getString("message"));
-            prot.addInfo("message", updatedObject.getString("message"));
-            Assert.assertEquals(newValue,
-                updatedObject.getJsonObject("data").getString(updateAttribute));
-            prot.setPassed(true);
-            return updatedObject;
-        }
-        catch(JsonException je) {
-            prot.addInfo("exception", je.getMessage());
-            Assert.fail(je.getMessage());
-        }
-        return null;
-    }
-
-    /**
-     * Test the DELETE Service.
-     *
-     * @param baseUrl The url pointing to the test deployment.
-     */
-    public JsonObject delete(String name, String parameter) {
-        System.out.print(".");
-        Protocol prot = new Protocol();
-        prot.setName(name + " service");
-        prot.setType("delete");
-        prot.setPassed(false);
-        protocol.add(prot);
-        try {
-            /* Create a client*/
-            Client client = ClientBuilder.newClient();
-            WebTarget target =
-                client.target(baseUrl + parameter);
-            prot.addInfo("parameter", parameter);
-            /* Delete a probe with the id saved when created a probe*/
-            Response response = target.request()
-                .header("X-SHIB-user", BaseTest.TEST_USER)
-                .header("X-SHIB-roles", BaseTest.TEST_ROLES)
-                .delete();
-            String entity = response.readEntity(String.class);
-            /* Try to parse the response*/
-            JsonReader reader = Json.createReader(new StringReader(entity));
-            JsonObject content = reader.readObject();
-            /* Verify the response*/
-            Assert.assertTrue(content.getBoolean("success"));
-            prot.addInfo("success", content.getBoolean("success"));
-            Assert.assertEquals("200", content.getString("message"));
-            prot.addInfo("message", content.getString("message"));
-            prot.setPassed(true);
-            return content;
-        }
-        catch(JsonException je) {
-            prot.addInfo("exception", je.getMessage());
-            Assert.fail(je.getMessage());
-        }
-        return null;
-    }
-}
diff -r fa922101a462 -r cb1cfc8c81ed src/test/java/de/intevation/lada/test/land/StatusTest.java
--- a/src/test/java/de/intevation/lada/test/land/StatusTest.java	Fri Jan 08 12:05:26 2016 +0100
+++ b/src/test/java/de/intevation/lada/test/land/StatusTest.java	Fri Jan 08 12:07:26 2016 +0100
@@ -11,6 +11,7 @@
 import org.junit.Assert;
 
 import de.intevation.lada.Protocol;
+import de.intevation.lada.test.ServiceTest;
 
 public class StatusTest extends ServiceTest {
 
diff -r fa922101a462 -r cb1cfc8c81ed src/test/java/de/intevation/lada/test/land/ZusatzwertTest.java
--- a/src/test/java/de/intevation/lada/test/land/ZusatzwertTest.java	Fri Jan 08 12:05:26 2016 +0100
+++ b/src/test/java/de/intevation/lada/test/land/ZusatzwertTest.java	Fri Jan 08 12:07:26 2016 +0100
@@ -11,6 +11,7 @@
 import org.junit.Assert;
 
 import de.intevation.lada.Protocol;
+import de.intevation.lada.test.ServiceTest;
 
 public class ZusatzwertTest extends ServiceTest {
 


More information about the Lada-commits mailing list