Mercurial > lada > lada-server
changeset 468:b4e6c5648644
Improved testing.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Tue, 17 Feb 2015 15:27:52 +0100 |
parents | e147de48162a |
children | d416f0a8277c |
files | src/test/java/de/intevation/lada/LadaTest.java src/test/java/de/intevation/lada/test/CreateTests.java src/test/java/de/intevation/lada/test/DeleteTests.java src/test/java/de/intevation/lada/test/GetTests.java src/test/java/de/intevation/lada/test/KommentarP.java src/test/java/de/intevation/lada/test/Messung.java src/test/java/de/intevation/lada/test/Probe.java src/test/java/de/intevation/lada/test/Query.java src/test/java/de/intevation/lada/test/UpdateTests.java |
diffstat | 9 files changed, 940 insertions(+), 978 deletions(-) [+] |
line wrap: on
line diff
--- a/src/test/java/de/intevation/lada/LadaTest.java Tue Feb 17 13:45:41 2015 +0100 +++ b/src/test/java/de/intevation/lada/LadaTest.java Tue Feb 17 15:27:52 2015 +0100 @@ -19,16 +19,17 @@ import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.EmptyAsset; import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.After; import org.junit.Assert; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; -import de.intevation.lada.test.CreateTests; -import de.intevation.lada.test.DeleteTests; -import de.intevation.lada.test.GetTests; -import de.intevation.lada.test.UpdateTests; +import de.intevation.lada.test.KommentarP; +import de.intevation.lada.test.Messung; +import de.intevation.lada.test.Probe; +import de.intevation.lada.test.Query; /** @@ -44,23 +45,20 @@ private static Logger logger = Logger.getLogger(LadaTest.class); - private boolean verboseLogging = false; - - private GetTests get; + private static boolean verboseLogging = true; - private CreateTests create; + private Probe probeTest; + private Query queryTest; + private Messung messungTest; + private KommentarP kommentarPTest; - private UpdateTests update; - - private DeleteTests delete; - - private List<Protocol> testProtocol; + private static List<Protocol> testProtocol; public LadaTest() { - get = new GetTests(); - create = new CreateTests(); - update = new UpdateTests(); - delete = new DeleteTests(); + probeTest = new Probe(); + queryTest = new Query(); + messungTest = new Messung(); + kommentarPTest = new KommentarP(); testProtocol = new ArrayList<Protocol>(); } @@ -80,19 +78,101 @@ return archive; } + @After + public final void printLogs() { + for (Protocol p : testProtocol) { + logger.info(p.toString(verboseLogging)); + } + } + /** * Testing GET Services. */ @Test @RunAsClient - public final void testA_GetServices(@ArquillianResource URL baseUrl) + public final void testA_ProbeGetAllServices(@ArquillianResource URL baseUrl) throws Exception { - this.get.test(baseUrl); - logger.info("---------- Testprotocol -----------"); - testProtocol.addAll(this.get.getProtocol()); - for (Protocol p : testProtocol) { - logger.info(p.toString(verboseLogging)); - } + this.probeTest.getAllService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_ProbeGetByIdServices(@ArquillianResource URL baseUrl) + throws Exception { + this.probeTest.getByIdService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_ProbeGetByFilterServices(@ArquillianResource URL baseUrl) + throws Exception { + this.probeTest.filterService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_GetQueryServices(@ArquillianResource URL baseUrl) + throws Exception { + this.queryTest.getAllService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_MessungGetAllServices(@ArquillianResource URL baseUrl) + throws Exception { + this.messungTest.getAllService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_MessungGetByIdServices(@ArquillianResource URL baseUrl) + throws Exception { + this.messungTest.getByIdService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_MessungGetFilterServices(@ArquillianResource URL baseUrl) + throws Exception { + this.messungTest.filterService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_KommentarPGetAllServices(@ArquillianResource URL baseUrl) + throws Exception { + this.kommentarPTest.getAllService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_KommentarPGetByIdServices(@ArquillianResource URL baseUrl) + throws Exception { + this.kommentarPTest.getByIdService(baseUrl, testProtocol); } /** @@ -102,11 +182,12 @@ @RunAsClient public final void testB_CreateServices(@ArquillianResource URL baseUrl) throws Exception { - this.create.test(baseUrl); - testProtocol.addAll(this.create.getProtocol()); - for (Protocol p : testProtocol) { - logger.info(p.toString(verboseLogging)); - } + this.probeTest.createService(baseUrl, testProtocol); + Assert.assertNotNull(this.probeTest.getCreatedProbeId()); + this.messungTest.createService( + baseUrl, + testProtocol, + this.probeTest.getCreatedProbeId()); } /** @@ -114,17 +195,21 @@ */ @Test @RunAsClient - public final void testC_UpdateServices(@ArquillianResource URL baseUrl) + public final void testC_probeUpdateService(@ArquillianResource URL baseUrl) throws Exception { - Assert.assertNotNull(this.create.getCreatedProbeId()); - this.update.test( - baseUrl, - this.create.getCreatedProbeId(), - this.create.getCreatedMessungId()); - testProtocol.addAll(this.update.getProtocol()); - for (Protocol p : testProtocol) { - logger.info(p.toString(verboseLogging)); - } + Assert.assertNotNull(this.probeTest.getCreatedProbeId()); + this.probeTest.updateService(baseUrl, testProtocol); + } + + /** + * Testing UPDATE services. + */ + @Test + @RunAsClient + public final void testC_messungUpdateService(@ArquillianResource URL baseUrl) + throws Exception { + Assert.assertNotNull(this.messungTest.getCreatedMessungId()); + this.messungTest.updateService(baseUrl, testProtocol); } /** @@ -134,14 +219,9 @@ @RunAsClient public final void testD_DeleteServices(@ArquillianResource URL baseUrl) throws Exception { - Assert.assertNotNull(this.create.getCreatedProbeId()); - this.delete.test( - baseUrl, - this.create.getCreatedProbeId(), - this.create.getCreatedMessungId()); - testProtocol.addAll(this.delete.getProtocol()); - for (Protocol p : testProtocol) { - logger.info(p.toString(verboseLogging)); - } + Assert.assertNotNull(this.messungTest.getCreatedMessungId()); + this.messungTest.deleteService(baseUrl, testProtocol); + Assert.assertNotNull(this.probeTest.getCreatedProbeId()); + this.probeTest.deleteService(baseUrl, testProtocol); } }
--- a/src/test/java/de/intevation/lada/test/CreateTests.java Tue Feb 17 13:45:41 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,169 +0,0 @@ -/* 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 java.util.ArrayList; -import java.util.List; - -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.junit.Assert; - -import de.intevation.lada.Protocol; - -/** - * Class to test all CREATE services. - * - * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> - */ -public class CreateTests { - - private static final String CREATE_PROBE = - "{\"baId\":\"1\",\"datenbasisId\":2,\"erzeugerId\":\"\"," + - "\"hauptprobenNr\":\"1234567890\",\"media\":\"\",\"mediaDesk\":" + - "\"\",\"mittelungsdauer\":\"\",\"mpKat\":\"\",\"mplId\":\"\"," + - "\"mprId\":\"\",\"mstId\":\"11010\",\"netzbetreiberId\":\"11\"," + - "\"probeNehmerId\":3,\"probenartId\":1,\"test\":true,\"umwId\":" + - "\"A1\",\"letzteAenderung\":\"2015-02-09T10:58:36\"" + - ",\"probeentnahmeBeginn\":\"2015-02-08T10:58:36\"," + - "\"probeentnahmeEnde\":\"2015-02-09T10:58:36\",\"solldatumBeginn\":" + - "\"2015-02-09T10:58:36\",\"solldatumEnde\":\"2015-02-09T10:58:36\"}"; - - private static final String CREATE_MESSUNG = - "{\"probeId\":\"PID\",\"mmtId\":\"A4\",\"nebenprobenNr\":\"10R1\"," + - "\"messdauer\":10,\"fertig\":false,\"letzteAenderung\":null," + - "\"geplant\":true,\"messzeitpunkt\":\"2015-02-09T10:58:36\"}"; - - - private static Integer createdProbeId; - private static Integer createdMessungId; - - private List<Protocol> protocol; - - public Integer getCreatedProbeId() { - return createdProbeId; - } - - public Integer getCreatedMessungId() { - return createdMessungId; - } - - /** - * @return the protocol - */ - public List<Protocol> getProtocol() { - return protocol; - } - - /** - * 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 { - protocol = new ArrayList<Protocol>(); - probeCreateService(baseUrl); - messungCreateService(baseUrl); - } - - /** - * Test the CREATE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - private final void probeCreateService(URL baseUrl) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeService"); - prot.setType("create"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "probe"); - /* Send a post request containing a new probe*/ - Response response = target.request().post( - Entity.entity(CREATE_PROBE, 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 probeid*/ - createdProbeId = - content.getJsonObject("data").getJsonNumber("id").intValue(); - prot.addInfo("probeId", createdProbeId); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("messung", content.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the messung CREATE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - private final void messungCreateService(URL baseUrl) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MessungService"); - prot.setType("create"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "messung"); - /* Send a post request containing a new probe*/ - String mess = CREATE_MESSUNG.replace("PID", createdProbeId.toString()); - Response response = target.request().post( - Entity.entity(mess, 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 probeid*/ - createdMessungId = - content.getJsonObject("data").getJsonNumber("id").intValue(); - prot.addInfo("messungId", createdMessungId); - /* Verify the response*/ - Assert.assertTrue(content.getBoolean("success")); - prot.addInfo("success", content.getBoolean("success")); - Assert.assertEquals("200", content.getString("message")); - prot.addInfo("messung", content.getString("message")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } -}
--- a/src/test/java/de/intevation/lada/test/DeleteTests.java Tue Feb 17 13:45:41 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,140 +0,0 @@ -/* 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 java.util.ArrayList; -import java.util.List; - -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.Protocol; - -/** - * Class to test all DELETE services. - * - * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> - */ -public class DeleteTests { - - private static List<Protocol> protocol; - - private Integer probeId; - - private Integer messungId; - - /** - * @return the protocol - */ - public static List<Protocol> getProtocol() { - return protocol; - } - - /** - * 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, - Integer probeId, - Integer messungId) - throws Exception { - protocol = new ArrayList<Protocol>(); - this.probeId = probeId; - this.messungId = messungId; - messungDeleteService(baseUrl); - probeDeleteService(baseUrl); - } - - /** - * Test the DELETE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - private final void probeDeleteService(URL baseUrl) { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeService"); - prot.setType("delete"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "probe/" + this.probeId); - prot.addInfo("probeId", this.probeId); - /* Delete a probe with the id saved when created a probe*/ - 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); - System.out.print("\n"); - } - - /** - * Test the messung DELETE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - private final void messungDeleteService(URL baseUrl) { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MessungService"); - prot.setType("delete"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "messung/" + this.messungId); - prot.addInfo("messungId", this.messungId); - /* Delete a probe with the id saved when created a probe*/ - 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); - } - -}
--- a/src/test/java/de/intevation/lada/test/GetTests.java Tue Feb 17 13:45:41 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,449 +0,0 @@ -/* 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 java.util.ArrayList; -import java.util.List; - -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.Protocol; - -/** - * Class to test all GET services. - * - * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> - */ -public class GetTests { - - private static List<Protocol> protocol; - - private static final String COMPARE_PROBE = - "{\"id\":1,\"baId\":\"1\",\"datenbasisId\":2," + - "\"letzteAenderung\":1339570306000,\"media\":\"Trinkwasser " + - "Zentralversorgung Oberflächenwasser aufbereitet\",\"mediaDesk\":" + - "\"D: 59 04 01 00 05 05 01 02 00 00 00 00\",\"mittelungsdauer\":" + - "null,\"mstId\":\"06010\",\"netzbetreiberId\":\"06\"," + - "\"probeentnahmeBeginn\":1336467600000,\"probeentnahmeEnde\":" + - "null,\"probenartId\":1,\"test\":false,\"umwId\":\"N72\"," + - "\"erzeugerId\":null,\"mpKat\":\"1\",\"mplId\":null,\"mprId\":3749," + - "\"probeNehmerId\":726,\"solldatumBeginn\":1336341600000," + - "\"solldatumEnde\":1336939199000,\"probeIdAlt\":\"000007581034X\"," + - "\"hauptprobenNr\":\"120510002\"}"; - - private static final String COMPARE_MESSUNG = - "{\"id\":1,\"fertig\":true,\"letzteAenderung\":1331536340000," + - "\"messdauer\":73929,\"messzeitpunkt\":1329139620000,\"mmtId\":" + - "\"G1\",\"probeId\":575,\"nebenprobenNr\":\"01G1\",\"geplant\":true," + - "\"messungsIdAlt\":1}"; - - private static final String COMPARE_KOMMENTARP = ""; - - /** - * @return the protocol - */ - public static List<Protocol> getProtocol() { - return protocol; - } - - /** - * 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 { - protocol = new ArrayList<Protocol>(); - queryGetService(baseUrl); - probeGetAllService(baseUrl); - probeGetByIdService(baseUrl); - probeFilterService(baseUrl); - messungGetAllService(baseUrl); - messungGetByIdService(baseUrl); - messungFilterService(baseUrl); - pkommentarGetAllService(baseUrl); - //pkommentarGetByIdService(baseUrl); - } - - /** - * Test the GET Service by requesting all queries. - * - * @param baseUrl The url pointing to the test deployment. - */ - private final void queryGetService(URL baseUrl) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("QueryService"); - prot.setType("get all"); - prot.setPassed(false); - protocol.add(prot); - /* 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")); - 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()); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET Service by requesting all probe objects. - * - * @param baseUrl The url pointing to the test deployment. - */ - private final void probeGetAllService(URL baseUrl) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeService"); - prot.setType("get all"); - prot.setPassed(false); - protocol.add(prot); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "probe"); - /* Request all probe objects*/ - 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(); - /* 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()); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET Service by requesting a single probe object by id. - * - * @param baseUrl The url pointing to the test deployment. - */ - private final void probeGetByIdService(URL baseUrl) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeService"); - prot.setType("get by Id"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a json object from static probe string*/ - JsonReader fromStringRreader = - Json.createReader(new StringReader(COMPARE_PROBE)); - JsonObject staticProbe = fromStringRreader.readObject(); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "probe/1"); - prot.addInfo("probeId", 1); - /* Request a probe object by id*/ - Response response = target.request().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.assertEquals(staticProbe, - content.getJsonObject("data")); - prot.addInfo("object", "equals"); - } - catch(JsonException je) { - prot.addInfo("exception",je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET probe service using filters. - * - * @param baseUrl The url poining to the test deployment. - */ - private final void probeFilterService(URL baseUrl) { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeService"); - prot.setType("get by filter"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "probe?qid=2&mst_id=11010&umw_id=N24"); - prot.addInfo("filter", "qid=2&mst_id=11010&umw_id=N24"); - /* Request the probe objects using the filter*/ - Response response = target.request().get(); - 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")); - Assert.assertNotNull(respObj.getJsonArray("data")); - prot.addInfo("objects", respObj.getJsonArray("data").size()); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - - /** - * Test the GET Service by requesting all messung objects. - * - * @param baseUrl The url pointing to the test deployment. - */ - private final void messungGetAllService(URL baseUrl) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MessungService"); - prot.setType("get all"); - prot.setPassed(false); - protocol.add(prot); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "messung"); - /* Request all probe objects*/ - 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(); - /* 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()); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET Service by requesting a single messung object by id. - * - * @param baseUrl The url pointing to the test deployment. - */ - private final void messungGetByIdService(URL baseUrl) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MessungService"); - prot.setType("get by Id"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a json object from static messung string*/ - JsonReader fromStringRreader = - Json.createReader(new StringReader(COMPARE_MESSUNG)); - JsonObject staticMessung = fromStringRreader.readObject(); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "messung/1"); - prot.addInfo("messungId", 1); - /* Request a probe object by id*/ - Response response = target.request().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.assertEquals(staticMessung, - content.getJsonObject("data")); - prot.addInfo("object", "equals"); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET messung service using filters. - * - * @param baseUrl The url poining to the test deployment. - */ - private final void messungFilterService(URL baseUrl) { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MessungService"); - prot.setType("get by filter"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "messung?probeId=1"); - prot.addInfo("filter", "probeId=1"); - /* Request the probe objects using the filter*/ - Response response = target.request().get(); - 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")); - Assert.assertNotNull(respObj.getJsonArray("data")); - prot.addInfo("objects", respObj.getJsonArray("data").size()); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET Service by requesting all KommentarP objects. - * - * @param baseUrl The url pointing to the test deployment. - */ - private final void pkommentarGetAllService(URL baseUrl) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeKommentarService"); - prot.setType("get all"); - prot.setPassed(false); - protocol.add(prot); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "pkommentar"); - /* Request all probe objects*/ - 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(); - /* 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()); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the GET Service by requesting a single KommentarP object by id. - * - * @param baseUrl The url pointing to the test deployment. - */ - private final void pkommentarGetByIdService(URL baseUrl) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeKommentarService"); - prot.setType("get by Id"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a json object from static messung string*/ - JsonReader fromStringRreader = - Json.createReader(new StringReader(COMPARE_KOMMENTARP)); - JsonObject staticKommentar = fromStringRreader.readObject(); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "pkommentar/1"); - prot.addInfo("kommentarId", 1); - /* Request a probe object by id*/ - Response response = target.request().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.assertEquals(staticKommentar, - content.getJsonObject("data")); - prot.addInfo("object", "equals"); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/KommentarP.java Tue Feb 17 15:27:52 2015 +0100 @@ -0,0 +1,118 @@ +package de.intevation.lada.test; + +import java.io.StringReader; +import java.net.URL; +import java.util.List; + +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.Protocol; + +public class KommentarP { + + private List<Protocol> protocol; + + private static final String COMPARE_KOMMENTARP = + "{\"datum\":1321002077000,\"erzeuger\":\"06010\",\"id\":1,\"text\":" + + "\"Die Probe wurde in Darmstadt gammaspektrometrisch gemessen und " + + "fĂĽr die Sr-Bestimmung verascht. \",\"probeId\":361}"; + + /** + * @return the protocol + */ + public List<Protocol> getProtocol() { + return protocol; + } + + /** + * Test the GET Service by requesting all KommentarP objects. + * + * @param baseUrl The url pointing to the test deployment. + */ + public final void getAllService(URL baseUrl, List<Protocol> protocol) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("ProbeKommentarService"); + prot.setType("get all"); + prot.setPassed(false); + protocol.add(prot); + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "pkommentar"); + /* Request all probe objects*/ + 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(); + /* 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()); + } + catch(JsonException je) { + prot.addInfo("exception", je.getMessage()); + Assert.fail(je.getMessage()); + } + prot.setPassed(true); + } + + /** + * Test the GET Service by requesting a single KommentarP object by id. + * + * @param baseUrl The url pointing to the test deployment. + */ + public final void getByIdService(URL baseUrl, List<Protocol> protocol) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("ProbeKommentarService"); + prot.setType("get by Id"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a json object from static string*/ + JsonReader fromStringRreader = + Json.createReader(new StringReader(COMPARE_KOMMENTARP)); + JsonObject staticKommentar = fromStringRreader.readObject(); + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "pkommentar/1"); + prot.addInfo("kommentarId", 1); + /* Request an object by id*/ + Response response = target.request().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.assertEquals(staticKommentar, + content.getJsonObject("data")); + prot.addInfo("object", "equals"); + } + catch(JsonException je) { + prot.addInfo("exception", je.getMessage()); + Assert.fail(je.getMessage()); + } + prot.setPassed(true); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/Messung.java Tue Feb 17 15:27:52 2015 +0100 @@ -0,0 +1,308 @@ +package de.intevation.lada.test; + +import java.io.StringReader; +import java.net.URL; +import java.util.List; + +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.junit.Assert; + +import de.intevation.lada.Protocol; + +public class Messung { + + private static final String COMPARE_MESSUNG = + "{\"id\":1,\"fertig\":true,\"letzteAenderung\":1331536340000," + + "\"messdauer\":73929,\"messzeitpunkt\":1329139620000,\"mmtId\":" + + "\"G1\",\"probeId\":575,\"nebenprobenNr\":\"01G1\",\"geplant\":true," + + "\"messungsIdAlt\":1}"; + + private static final String CREATE_MESSUNG = + "{\"probeId\":\"PID\",\"mmtId\":\"A4\",\"nebenprobenNr\":\"10R1\"," + + "\"messdauer\":10,\"fertig\":false,\"letzteAenderung\":null," + + "\"geplant\":true,\"messzeitpunkt\":\"2015-02-09T10:58:36\"}"; + + private List<Protocol> protocol; + + private static Integer createdMessungId; + + public Integer getCreatedMessungId() { + return createdMessungId; + } + + /** + * @return the protocol + */ + public List<Protocol> getProtocol() { + return protocol; + } + + /** + * Test the GET Service by requesting all messung objects. + * + * @param baseUrl The url pointing to the test deployment. + */ + public final void getAllService(URL baseUrl, List<Protocol> protocol) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("MessungService"); + prot.setType("get all"); + prot.setPassed(false); + protocol.add(prot); + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "messung"); + /* Request all probe objects*/ + 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(); + /* 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()); + } + catch(JsonException je) { + prot.addInfo("exception", je.getMessage()); + Assert.fail(je.getMessage()); + } + prot.setPassed(true); + } + + /** + * Test the GET Service by requesting a single messung object by id. + * + * @param baseUrl The url pointing to the test deployment. + */ + public final void getByIdService(URL baseUrl, List<Protocol> protocol) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("MessungService"); + prot.setType("get by Id"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a json object from static messung string*/ + JsonReader fromStringRreader = + Json.createReader(new StringReader(COMPARE_MESSUNG)); + JsonObject staticMessung = fromStringRreader.readObject(); + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "messung/1"); + prot.addInfo("messungId", 1); + /* Request a probe object by id*/ + Response response = target.request().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.assertEquals(staticMessung, + content.getJsonObject("data")); + prot.addInfo("object", "equals"); + } + catch(JsonException je) { + prot.addInfo("exception", je.getMessage()); + Assert.fail(je.getMessage()); + } + prot.setPassed(true); + } + + /** + * Test the GET messung service using filters. + * + * @param baseUrl The url poining to the test deployment. + */ + public final void filterService(URL baseUrl, List<Protocol> protocol) { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("MessungService"); + prot.setType("get by filter"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "messung?probeId=1"); + prot.addInfo("filter", "probeId=1"); + /* Request the probe objects using the filter*/ + Response response = target.request().get(); + 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")); + Assert.assertNotNull(respObj.getJsonArray("data")); + prot.addInfo("objects", respObj.getJsonArray("data").size()); + } + catch(JsonException je) { + prot.addInfo("exception", je.getMessage()); + Assert.fail(je.getMessage()); + } + prot.setPassed(true); + } + + /** + * Test the messung CREATE Service. + * + * @param baseUrl The url pointing to the test deployment. + */ + public final void createService( + URL baseUrl, + List<Protocol> protocol, + Integer probeId) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("MessungService"); + prot.setType("create"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "messung"); + /* Send a post request containing a new probe*/ + String mess = CREATE_MESSUNG.replace("PID", probeId.toString()); + Response response = target.request().post( + Entity.entity(mess, 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 probeid*/ + createdMessungId = + content.getJsonObject("data").getJsonNumber("id").intValue(); + prot.addInfo("messungId", createdMessungId); + /* Verify the response*/ + Assert.assertTrue(content.getBoolean("success")); + prot.addInfo("success", content.getBoolean("success")); + Assert.assertEquals("200", content.getString("message")); + prot.addInfo("messung", content.getString("message")); + } + catch(JsonException je) { + prot.addInfo("exception", je.getMessage()); + Assert.fail(je.getMessage()); + } + prot.setPassed(true); + } + + /** + * Test the messung UPDATE Service. + * + * @param baseUrl The url pointing to the test deployment. + */ + public final void updateService(URL baseUrl, List<Protocol> protocol) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("ProbeService"); + prot.setType("update"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "messung/" + createdMessungId); + prot.addInfo("messungId", createdMessungId); + /* Request a probe with the id saved when created a probe*/ + Response response = target.request().get(); + String entity = response.readEntity(String.class); + /* Try to parse the response*/ + JsonReader reader = Json.createReader(new StringReader(entity)); + JsonObject oldMessung = reader.readObject().getJsonObject("data"); + /* Change the hauptprobenNr*/ + String updatedEntity = + oldMessung.toString().replace("A4", "G1"); + prot.addInfo("updated field", "mmtId"); + prot.addInfo("updated value", "A4"); + prot.addInfo("updated to", "G1"); + /* Send the updated probe via put reauest*/ + WebTarget putTarget = client.target(baseUrl + "messung"); + 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 updatedMessung = updatedReader.readObject(); + /* Verify the response*/ + Assert.assertTrue(updatedMessung.getBoolean("success")); + prot.addInfo("success", updatedMessung.getBoolean("success")); + Assert.assertEquals("200", updatedMessung.getString("message")); + prot.addInfo("message", updatedMessung.getString("message")); + Assert.assertEquals("G1", + updatedMessung.getJsonObject("data").getString("mmtId")); + } + catch(JsonException je) { + prot.addInfo("exception", je.getMessage()); + Assert.fail(je.getMessage()); + } + prot.setPassed(true); + } + + /** + * Test the messung DELETE Service. + * + * @param baseUrl The url pointing to the test deployment. + */ + public final void deleteService(URL baseUrl, List<Protocol> protocol) { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("MessungService"); + prot.setType("delete"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "messung/" + createdMessungId); + prot.addInfo("messungId", createdMessungId); + /* Delete a probe with the id saved when created a probe*/ + 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); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/Probe.java Tue Feb 17 15:27:52 2015 +0100 @@ -0,0 +1,318 @@ +package de.intevation.lada.test; + +import java.io.StringReader; +import java.net.URL; +import java.util.List; + +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.junit.Assert; + +import de.intevation.lada.Protocol; + +public class Probe { + + private static final String COMPARE_PROBE = + "{\"id\":1,\"baId\":\"1\",\"datenbasisId\":2," + + "\"letzteAenderung\":1339570306000,\"media\":\"Trinkwasser " + + "Zentralversorgung Oberflächenwasser aufbereitet\",\"mediaDesk\":" + + "\"D: 59 04 01 00 05 05 01 02 00 00 00 00\",\"mittelungsdauer\":" + + "null,\"mstId\":\"06010\",\"netzbetreiberId\":\"06\"," + + "\"probeentnahmeBeginn\":1336467600000,\"probeentnahmeEnde\":" + + "null,\"probenartId\":1,\"test\":false,\"umwId\":\"N72\"," + + "\"erzeugerId\":null,\"mpKat\":\"1\",\"mplId\":null,\"mprId\":3749," + + "\"probeNehmerId\":726,\"solldatumBeginn\":1336341600000," + + "\"solldatumEnde\":1336939199000,\"probeIdAlt\":\"000007581034X\"," + + "\"hauptprobenNr\":\"120510002\"}"; + + private static final String CREATE_PROBE = + "{\"baId\":\"1\",\"datenbasisId\":2,\"erzeugerId\":\"\"," + + "\"hauptprobenNr\":\"1234567890\",\"media\":\"\",\"mediaDesk\":" + + "\"\",\"mittelungsdauer\":\"\",\"mpKat\":\"\",\"mplId\":\"\"," + + "\"mprId\":\"\",\"mstId\":\"11010\",\"netzbetreiberId\":\"11\"," + + "\"probeNehmerId\":3,\"probenartId\":1,\"test\":true,\"umwId\":" + + "\"A1\",\"letzteAenderung\":\"2015-02-09T10:58:36\"" + + ",\"probeentnahmeBeginn\":\"2015-02-08T10:58:36\"," + + "\"probeentnahmeEnde\":\"2015-02-09T10:58:36\",\"solldatumBeginn\":" + + "\"2015-02-09T10:58:36\",\"solldatumEnde\":\"2015-02-09T10:58:36\"}"; + + private List<Protocol> protocol; + + private static Integer createdProbeId; + + public Integer getCreatedProbeId() { + return createdProbeId; + } + + /** + * @return the protocol + */ + public List<Protocol> getProtocol() { + return protocol; + } + + /** + * Test the GET Service by requesting all probe objects. + * + * @param baseUrl The url pointing to the test deployment. + */ + public final void getAllService(URL baseUrl, List<Protocol> protocol) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("ProbeService"); + prot.setType("get all"); + prot.setPassed(false); + protocol.add(prot); + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "probe"); + /* Request all probe objects*/ + 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(); + /* 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()); + } + catch(JsonException je) { + prot.addInfo("exception", je.getMessage()); + Assert.fail(je.getMessage()); + } + prot.setPassed(true); + } + + /** + * Test the GET Service by requesting a single probe object by id. + * + * @param baseUrl The url pointing to the test deployment. + */ + public final void getByIdService(URL baseUrl, List<Protocol> protocol) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("ProbeService"); + prot.setType("get by Id"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a json object from static probe string*/ + JsonReader fromStringRreader = + Json.createReader(new StringReader(COMPARE_PROBE)); + JsonObject staticProbe = fromStringRreader.readObject(); + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "probe/1"); + prot.addInfo("probeId", 1); + /* Request a probe object by id*/ + Response response = target.request().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.assertEquals(staticProbe, + content.getJsonObject("data")); + prot.addInfo("object", "equals"); + } + catch(JsonException je) { + prot.addInfo("exception",je.getMessage()); + Assert.fail(je.getMessage()); + } + prot.setPassed(true); + } + + /** + * Test the GET probe service using filters. + * + * @param baseUrl The url poining to the test deployment. + */ + public final void filterService(URL baseUrl, List<Protocol> protocol) { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("ProbeService"); + prot.setType("get by filter"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "probe?qid=2&mst_id=11010&umw_id=N24"); + prot.addInfo("filter", "qid=2&mst_id=11010&umw_id=N24"); + /* Request the probe objects using the filter*/ + Response response = target.request().get(); + 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")); + Assert.assertNotNull(respObj.getJsonArray("data")); + prot.addInfo("objects", respObj.getJsonArray("data").size()); + } + catch(JsonException je) { + prot.addInfo("exception", je.getMessage()); + Assert.fail(je.getMessage()); + } + prot.setPassed(true); + } + + /** + * Test the CREATE Service. + * + * @param baseUrl The url pointing to the test deployment. + */ + public final void createService(URL baseUrl, List<Protocol> protocol) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("ProbeService"); + prot.setType("create"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "probe"); + /* Send a post request containing a new probe*/ + Response response = target.request().post( + Entity.entity(CREATE_PROBE, 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 probeid*/ + createdProbeId = + content.getJsonObject("data").getJsonNumber("id").intValue(); + prot.addInfo("probeId", createdProbeId); + /* Verify the response*/ + Assert.assertTrue(content.getBoolean("success")); + prot.addInfo("success", content.getBoolean("success")); + Assert.assertEquals("200", content.getString("message")); + prot.addInfo("messung", content.getString("message")); + } + catch(JsonException je) { + prot.addInfo("exception", je.getMessage()); + Assert.fail(je.getMessage()); + } + prot.setPassed(true); + } + + /** + * Test the probe update service. + * + * @param baseUrl The url pointing to the test deployment. + */ + public final void updateService(URL baseUrl, List<Protocol> protocol) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("ProbeService"); + prot.setType("update"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "probe/" + createdProbeId); + prot.addInfo("probeId", createdProbeId); + /* Request a probe with the id saved when created a probe*/ + Response response = target.request().get(); + String entity = response.readEntity(String.class); + /* Try to parse the response*/ + JsonReader reader = Json.createReader(new StringReader(entity)); + JsonObject oldProbe = reader.readObject().getJsonObject("data"); + /* Change the hauptprobenNr*/ + String updatedEntity = + oldProbe.toString().replace("1234567890", "2345678901"); + prot.addInfo("updated datafield", "hauptprobenNr"); + prot.addInfo("updated value", "1234567890"); + prot.addInfo("updated to", "1234567890"); + /* Send the updated probe via put reauest*/ + WebTarget putTarget = client.target(baseUrl + "probe"); + 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 updatedProbe = updatedReader.readObject(); + /* Verify the response*/ + Assert.assertTrue(updatedProbe.getBoolean("success")); + prot.addInfo("success", updatedProbe.getBoolean("success")); + Assert.assertEquals("200", updatedProbe.getString("message")); + prot.addInfo("message", updatedProbe.getString("message")); + Assert.assertEquals("2345678901", + updatedProbe.getJsonObject("data").getString("hauptprobenNr")); + } + catch(JsonException je) { + prot.addInfo("exception", je.getMessage()); + Assert.fail(je.getMessage()); + } + prot.setPassed(true); + } + + /** + * Test the DELETE Service. + * + * @param baseUrl The url pointing to the test deployment. + */ + public final void deleteService(URL baseUrl, List<Protocol> protocol) { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("ProbeService"); + prot.setType("delete"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "probe/" + createdProbeId); + prot.addInfo("probeId", createdProbeId); + /* Delete a probe with the id saved when created a probe*/ + 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); + System.out.print("\n"); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/Query.java Tue Feb 17 15:27:52 2015 +0100 @@ -0,0 +1,68 @@ +package de.intevation.lada.test; + +import java.io.StringReader; +import java.net.URL; +import java.util.List; + +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.Protocol; + +public class Query { + + private List<Protocol> protocol; + + /** + * @return the protocol + */ + public List<Protocol> getProtocol() { + return protocol; + } + + /** + * Test the GET Service by requesting all queries. + * + * @param baseUrl The url pointing to the test deployment. + */ + public final void getAllService(URL baseUrl, List<Protocol> protocol) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("QueryService"); + prot.setType("get all"); + prot.setPassed(false); + protocol.add(prot); + /* 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")); + 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()); + } + catch(JsonException je) { + prot.addInfo("exception", je.getMessage()); + Assert.fail(je.getMessage()); + } + prot.setPassed(true); + } +}
--- a/src/test/java/de/intevation/lada/test/UpdateTests.java Tue Feb 17 13:45:41 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,172 +0,0 @@ -/* 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 java.util.ArrayList; -import java.util.List; - -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.junit.Assert; - -import de.intevation.lada.Protocol; - -/** - * Class to test all UPDATE services. - * - * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> - */ -public class UpdateTests { - - private static List<Protocol> protocol; - - private Integer probeId; - - private Integer messungId; - - /** - * @return the protocol - */ - public static List<Protocol> getProtocol() { - return protocol; - } - - /** - * 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, Integer probeId, Integer messungId) - throws Exception { - protocol = new ArrayList<Protocol>(); - this.probeId = probeId; - this.messungId = messungId; - probeUpdateService(baseUrl); - messungUpdate(baseUrl); - } - - /** - * Test the probe update service. - * - * @param baseUrl The url pointing to the test deployment. - */ - private final void probeUpdateService(URL baseUrl) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeService"); - prot.setType("update"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "probe/" + this.probeId); - prot.addInfo("probeId", this.probeId); - /* Request a probe with the id saved when created a probe*/ - Response response = target.request().get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject oldProbe = reader.readObject().getJsonObject("data"); - /* Change the hauptprobenNr*/ - String updatedEntity = - oldProbe.toString().replace("1234567890", "2345678901"); - prot.addInfo("updated datafield", "hauptprobenNr"); - prot.addInfo("updated value", "1234567890"); - prot.addInfo("updated to", "1234567890"); - /* Send the updated probe via put reauest*/ - WebTarget putTarget = client.target(baseUrl + "probe"); - 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 updatedProbe = updatedReader.readObject(); - /* Verify the response*/ - Assert.assertTrue(updatedProbe.getBoolean("success")); - prot.addInfo("success", updatedProbe.getBoolean("success")); - Assert.assertEquals("200", updatedProbe.getString("message")); - prot.addInfo("message", updatedProbe.getString("message")); - Assert.assertEquals("2345678901", - updatedProbe.getJsonObject("data").getString("hauptprobenNr")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - - /** - * Test the messung UPDATE Service. - * - * @param baseUrl The url pointing to the test deployment. - */ - private final void messungUpdate(URL baseUrl) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeService"); - prot.setType("update"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "messung/" + this.messungId); - prot.addInfo("messungId", this.messungId); - /* Request a probe with the id saved when created a probe*/ - Response response = target.request().get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject oldMessung = reader.readObject().getJsonObject("data"); - /* Change the hauptprobenNr*/ - String updatedEntity = - oldMessung.toString().replace("A4", "G1"); - prot.addInfo("updated field", "mmtId"); - prot.addInfo("updated value", "A4"); - prot.addInfo("updated to", "G1"); - /* Send the updated probe via put reauest*/ - WebTarget putTarget = client.target(baseUrl + "messung"); - 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 updatedMessung = updatedReader.readObject(); - /* Verify the response*/ - Assert.assertTrue(updatedMessung.getBoolean("success")); - prot.addInfo("success", updatedMessung.getBoolean("success")); - Assert.assertEquals("200", updatedMessung.getString("message")); - prot.addInfo("message", updatedMessung.getString("message")); - Assert.assertEquals("G1", - updatedMessung.getJsonObject("data").getString("mmtId")); - } - catch(JsonException je) { - prot.addInfo("exception", je.getMessage()); - Assert.fail(je.getMessage()); - } - prot.setPassed(true); - } - -}