[Lada-commits] [PATCH 4 of 8] Added test for s_ort (location) services
Wald Commits
scm-commit at wald.intevation.org
Thu Feb 19 14:20:54 CET 2015
# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1424351671 -3600
# Node ID e5a8b3c7721c5013a4f539d5ec817d55254e1cb1
# Parent f921a0db372930feab8b6da3da4071164f3ddde4
Added test for s_ort (location) services.
diff -r f921a0db3729 -r e5a8b3c7721c src/test/java/de/intevation/lada/LadaStammTest.java
--- a/src/test/java/de/intevation/lada/LadaStammTest.java Thu Feb 19 14:13:22 2015 +0100
+++ b/src/test/java/de/intevation/lada/LadaStammTest.java Thu Feb 19 14:14:31 2015 +0100
@@ -7,15 +7,29 @@
*/
package de.intevation.lada;
+import java.io.StringReader;
import java.net.URL;
import java.util.ArrayList;
+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.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
import org.apache.log4j.Logger;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
+import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
@@ -34,6 +48,8 @@
private static Logger logger = Logger.getLogger(LadaStammTest.class);
+ private static Integer createdOrtId;
+
private Stammdaten stammdatenTest;
public LadaStammTest () {
@@ -154,4 +170,155 @@
public final void testProbenzusatzById(@ArquillianResource URL baseUrl) {
stammdatenTest.getById(baseUrl, "probenzusatz", "A74", testProtocol);
}
+
+ @Test
+ @RunAsClient
+ public final void testLocationAll(@ArquillianResource URL baseUrl) {
+ stammdatenTest.getAll(baseUrl, "location", testProtocol);
+ }
+
+ @Test
+ @RunAsClient
+ public final void testLocationById(@ArquillianResource URL baseUrl) {
+ stammdatenTest.getById(baseUrl, "location", "19", testProtocol);
+ }
+
+ @Test
+ @RunAsClient
+ public final void testLocation1CreateService(@ArquillianResource URL baseUrl)
+ throws Exception {
+ System.out.print(".");
+ Protocol prot = new Protocol();
+ prot.setName("locationService");
+ prot.setType("create");
+ prot.setPassed(false);
+ testProtocol.add(prot);
+ try {
+ /* Create a client*/
+ Client client = ClientBuilder.newClient();
+ WebTarget target = client.target(baseUrl + "location");
+ /* Send a post request containing a new kommentar*/
+ String newObj = "{\"beschreibung\":\"Neuer Ort\"," +
+ "\"bezeichnung\":\"T123456\",\"hoeheLand\":null," +
+ "\"koordXExtern\":\"32531152\",\"koordYExtern\":\"5684269\"," +
+ "\"latitude\":51.30888,\"letzteAenderung\":1376287046332," +
+ "\"longitude\":9.44693,\"nutsCode\":\"DE731\",\"unscharf\":" +
+ "\"0\",\"netzbetreiberId\":null,\"staatId\":0," +
+ "\"verwaltungseinheitId\":\"06611000\",\"otyp\":\"Z\"," +
+ "\"koordinatenartId\":5}";
+
+ Response response = target.request().post(
+ Entity.entity(newObj, 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();
+ /* Save the id*/
+ createdOrtId =
+ content.getJsonObject("data").getJsonNumber("id").intValue();
+ prot.addInfo("ortId", createdOrtId);
+ /* 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"));
+ }
+ catch(JsonException je) {
+ prot.addInfo("exception", je.getMessage());
+ Assert.fail(je.getMessage());
+ }
+ prot.setPassed(true);
+ }
+
+ /**
+ * Test the UPDATE Service.
+ *
+ * @param baseUrl The url pointing to the test deployment.
+ */
+ @Test
+ @RunAsClient
+ public final void testLocation2UpdateService(@ArquillianResource URL baseUrl)
+ throws Exception {
+ System.out.print(".");
+ Protocol prot = new Protocol();
+ prot.setName("locationService");
+ prot.setType("update");
+ prot.setPassed(false);
+ testProtocol.add(prot);
+ try {
+ /* Create a client*/
+ Client client = ClientBuilder.newClient();
+ WebTarget target =
+ client.target(baseUrl + "location/" + createdOrtId);
+ prot.addInfo("locationId", createdOrtId);
+ /* Request a kommentar with the id saved when created a kommentar*/
+ Response response = target.request().get();
+ String entity = response.readEntity(String.class);
+ /* Try to parse the response*/
+ JsonReader reader = Json.createReader(new StringReader(entity));
+ JsonObject oldObj = reader.readObject().getJsonObject("data");
+ /* Change the text*/
+ String updatedEntity =
+ oldObj.toString().replace("Neuer Ort", "Neuerer Ort");
+ prot.addInfo("updated field", "beschreibung");
+ prot.addInfo("updated value", "Neuer Ort");
+ prot.addInfo("updated to", "Neuerer Ort");
+ /* Send the updated kommentar via put reauest*/
+ WebTarget putTarget = client.target(baseUrl + "location");
+ Response updated = putTarget.request().put(
+ Entity.entity(updatedEntity, MediaType.APPLICATION_JSON));
+ /* Try to parse the response*/
+ JsonReader updatedReader = Json.createReader(
+ new StringReader(updated.readEntity(String.class)));
+ JsonObject updatedObj = updatedReader.readObject();
+ /* Verify the response*/
+ Assert.assertTrue(updatedObj.getBoolean("success"));
+ prot.addInfo("success", updatedObj.getBoolean("success"));
+ Assert.assertEquals("200", updatedObj.getString("message"));
+ prot.addInfo("message", updatedObj.getString("message"));
+ Assert.assertEquals("Neuerer Ort",
+ updatedObj.getJsonObject("data").getString("beschreibung"));
+ }
+ catch(JsonException je) {
+ prot.addInfo("exception", je.getMessage());
+ Assert.fail(je.getMessage());
+ }
+ prot.setPassed(true);
+ }
+
+ @Test
+ @RunAsClient
+ public final void testLocation3DeleteService(@ArquillianResource URL baseUrl)
+ throws Exception {
+ System.out.print(".");
+ Protocol prot = new Protocol();
+ prot.setName("locationService");
+ prot.setType("delete");
+ prot.setPassed(false);
+ testProtocol.add(prot);
+ try {
+ /* Create a client*/
+ Client client = ClientBuilder.newClient();
+ WebTarget target =
+ client.target(baseUrl + "location/" + createdOrtId);
+ prot.addInfo("locationId", createdOrtId);
+ /* Delete the object with the saved id*/
+ Response response = target.request().delete();
+ String entity = response.readEntity(String.class);
+ /* Try to parse the response*/
+ JsonReader reader = Json.createReader(new StringReader(entity));
+ JsonObject respObj = reader.readObject();
+ /* Verify the response*/
+ Assert.assertTrue(respObj.getBoolean("success"));
+ prot.addInfo("success", respObj.getBoolean("success"));
+ Assert.assertEquals("200", respObj.getString("message"));
+ prot.addInfo("message", respObj.getString("message"));
+ }
+ catch(JsonException je) {
+ prot.addInfo("exception", je.getMessage());
+ Assert.fail(je.getMessage());
+ }
+ prot.setPassed(true);
+ }
}
diff -r f921a0db3729 -r e5a8b3c7721c src/test/java/de/intevation/lada/test/stamm/Stammdaten.java
--- a/src/test/java/de/intevation/lada/test/stamm/Stammdaten.java Thu Feb 19 14:13:22 2015 +0100
+++ b/src/test/java/de/intevation/lada/test/stamm/Stammdaten.java Thu Feb 19 14:14:31 2015 +0100
@@ -57,6 +57,14 @@
compare.put("probenzusatz",
"{\"id\":\"A74\",\"beschreibung\":\"Volumenstrom\"," +
"\"eudfKeyword\":null,\"zusatzwert\":\"VOLSTR\",\"mehId\":32}");
+ compare.put("location",
+ "{\"id\":19,\"beschreibung\":\"WW Kassel\",\"bezeichnung\":" +
+ "\"T060014\",\"hoeheLand\":null,\"koordXExtern\":\"32531152\"," +
+ "\"koordYExtern\":\"5684269\",\"latitude\":51.30888," +
+ "\"letzteAenderung\":1376287046332,\"longitude\":9.44693," +
+ "\"nutsCode\":\"DE731\",\"unscharf\":\"0\",\"netzbetreiberId\":" +
+ "null,\"staatId\":0,\"verwaltungseinheitId\":\"06611000\"," +
+ "\"otyp\":\"Z\",\"koordinatenartId\":5}");
}
/**
More information about the Lada-commits
mailing list