Mercurial > lada > lada-server
changeset 492:164b30723f11
Restructured tests.
* Introduced new base class for tests.
* Added new test class for stammdaten.
* Moved test classes for 'land' services into new package.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 18 Feb 2015 15:33:46 +0100 |
parents | 6fdbda6c5448 |
children | 58ce14fbfdaa |
files | src/test/java/de/intevation/lada/BaseTest.java src/test/java/de/intevation/lada/LadaLandTest.java src/test/java/de/intevation/lada/LadaStammTest.java src/test/java/de/intevation/lada/LadaTest.java src/test/java/de/intevation/lada/test/KommentarM.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/Messwert.java src/test/java/de/intevation/lada/test/Ort.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/Status.java src/test/java/de/intevation/lada/test/Zusatzwert.java src/test/java/de/intevation/lada/test/land/KommentarM.java src/test/java/de/intevation/lada/test/land/KommentarP.java src/test/java/de/intevation/lada/test/land/Messung.java src/test/java/de/intevation/lada/test/land/Messwert.java src/test/java/de/intevation/lada/test/land/Ort.java src/test/java/de/intevation/lada/test/land/Probe.java src/test/java/de/intevation/lada/test/land/Query.java src/test/java/de/intevation/lada/test/land/Status.java src/test/java/de/intevation/lada/test/land/Zusatzwert.java |
diffstat | 22 files changed, 3202 insertions(+), 3143 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/BaseTest.java Wed Feb 18 15:33:46 2015 +0100 @@ -0,0 +1,55 @@ +/* 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; + +import java.util.List; + +import org.apache.log4j.Logger; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.After; + +/** + * Class to test the Lada server. + * + * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> + */ +public class BaseTest { + + private static String ARCHIVE_NAME = "lada-basis-test.war"; + + private static Logger logger = Logger.getLogger(BaseTest.class); + + protected static List<Protocol> testProtocol; + + protected static boolean verboseLogging = false; + + /** + * Create a deployable WAR archive. + */ + @Deployment(testable=true) + public static WebArchive createDeployment() throws Exception { + WebArchive archive = ShrinkWrap.create(WebArchive.class, ARCHIVE_NAME) + .addPackages(true, Package.getPackage("de.intevation.lada")) + .addAsResource("log4j.properties", "log4j.properties") + .addAsResource("queryconf.json", "queryconf.json") + .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") + .addAsResource("META-INF/test-persistence.xml", + "META-INF/persistence.xml"); + return archive; + } + + @After + public final void printLogs() { + for (Protocol p : testProtocol) { + logger.info(p.toString(verboseLogging)); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/LadaLandTest.java Wed Feb 18 15:33:46 2015 +0100 @@ -0,0 +1,465 @@ +/* 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; + +import java.net.URL; +import java.util.ArrayList; + +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.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; + +import de.intevation.lada.test.land.KommentarM; +import de.intevation.lada.test.land.KommentarP; +import de.intevation.lada.test.land.Messung; +import de.intevation.lada.test.land.Messwert; +import de.intevation.lada.test.land.Ort; +import de.intevation.lada.test.land.Probe; +import de.intevation.lada.test.land.Query; +import de.intevation.lada.test.land.Status; +import de.intevation.lada.test.land.Zusatzwert; + + +/** + * Class to test the Lada server. + * + * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> + */ +@RunWith(Arquillian.class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class LadaLandTest extends BaseTest { + + private static Logger logger = Logger.getLogger(LadaLandTest.class); + + private Probe probeTest; + private Query queryTest; + private Messung messungTest; + private KommentarP kommentarPTest; + private KommentarM kommentarMTest; + private Messwert messwertTest; + private Ort ortTest; + private Status statusTest; + private Zusatzwert zusatzwertTest; + + public LadaLandTest() { + probeTest = new Probe(); + queryTest = new Query(); + messungTest = new Messung(); + kommentarPTest = new KommentarP(); + kommentarMTest = new KommentarM(); + messwertTest = new Messwert(); + ortTest = new Ort(); + statusTest = new Status(); + zusatzwertTest = new Zusatzwert(); + testProtocol = new ArrayList<Protocol>(); + verboseLogging = false; + } + + @BeforeClass + public static void beforeTests() { + logger.info("---------- Testing Lada Land Services ----------"); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_ProbeGetAllServices(@ArquillianResource URL baseUrl) + throws Exception { + 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); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_KommentarPGetFilterServices(@ArquillianResource URL baseUrl) + throws Exception { + this.kommentarPTest.filterService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_KommentarMGetAllServices(@ArquillianResource URL baseUrl) + throws Exception { + this.kommentarMTest.getAllService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_KommentarMGetByIdServices(@ArquillianResource URL baseUrl) + throws Exception { + this.kommentarMTest.getByIdService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_KommentarMGetFilterServices(@ArquillianResource URL baseUrl) + throws Exception { + this.kommentarMTest.filterService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_MesswertGetAllServices(@ArquillianResource URL baseUrl) + throws Exception { + this.messwertTest.getAllService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_MesswertGetByIdServices(@ArquillianResource URL baseUrl) + throws Exception { + this.messwertTest.getByIdService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_MesswertGetFilterServices(@ArquillianResource URL baseUrl) + throws Exception { + this.messwertTest.filterService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_OrtGetAllServices(@ArquillianResource URL baseUrl) + throws Exception { + this.ortTest.getAllService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_OrtGetByIdServices(@ArquillianResource URL baseUrl) + throws Exception { + this.ortTest.getByIdService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_OrtGetFilterServices(@ArquillianResource URL baseUrl) + throws Exception { + this.ortTest.filterService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_StatusGetAllServices(@ArquillianResource URL baseUrl) + throws Exception { + this.statusTest.getAllService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_StatusGetByIdServices(@ArquillianResource URL baseUrl) + throws Exception { + this.statusTest.getByIdService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_StatusGetFilterServices(@ArquillianResource URL baseUrl) + throws Exception { + this.statusTest.filterService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_ZusatzwertGetAllServices(@ArquillianResource URL baseUrl) + throws Exception { + this.zusatzwertTest.getAllService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_ZusatzwertGetByIdServices(@ArquillianResource URL baseUrl) + throws Exception { + this.zusatzwertTest.getByIdService(baseUrl, testProtocol); + } + + /** + * Testing GET Services. + */ + @Test + @RunAsClient + public final void testA_ZusatzwertGetFilterServices(@ArquillianResource URL baseUrl) + throws Exception { + this.zusatzwertTest.filterService(baseUrl, testProtocol); + } + /** + * Testing CREATE services. + */ + @Test + @RunAsClient + public final void testB_CreateServices(@ArquillianResource URL baseUrl) + throws Exception { + this.probeTest.createService(baseUrl, testProtocol); + Assert.assertNotNull(this.probeTest.getCreatedProbeId()); + this.messungTest.createService( + baseUrl, + testProtocol, + this.probeTest.getCreatedProbeId()); + this.kommentarPTest.createService( + baseUrl, + testProtocol, + this.probeTest.getCreatedProbeId()); + this.ortTest.createService( + baseUrl, + testProtocol, + this.probeTest.getCreatedProbeId()); + this.zusatzwertTest.createService( + baseUrl, + testProtocol, + this.probeTest.getCreatedProbeId()); + Assert.assertNotNull(this.messungTest.getCreatedMessungId()); + this.kommentarMTest.createService( + baseUrl, + testProtocol, + this.messungTest.getCreatedMessungId()); + this.messwertTest.createService( + baseUrl, + testProtocol, + this.messungTest.getCreatedMessungId()); + this.statusTest.createService( + baseUrl, + testProtocol, + this.messungTest.getCreatedMessungId()); + } + + /** + * Testing UPDATE services. + */ + @Test + @RunAsClient + public final void testC_probeUpdateService(@ArquillianResource URL baseUrl) + throws Exception { + 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); + } + + /** + * Testing UPDATE services. + */ + @Test + @RunAsClient + public final void testC_kommentarPUpdateService(@ArquillianResource URL baseUrl) + throws Exception { + Assert.assertNotNull(this.kommentarPTest.getCreatedKommentarId()); + this.kommentarPTest.updateService(baseUrl, testProtocol); + } + + /** + * Testing UPDATE services. + */ + @Test + @RunAsClient + public final void testC_kommentarMUpdateService(@ArquillianResource URL baseUrl) + throws Exception { + Assert.assertNotNull(this.kommentarMTest.getCreatedKommentarId()); + this.kommentarMTest.updateService(baseUrl, testProtocol); + } + + /** + * Testing UPDATE services. + */ + @Test + @RunAsClient + public final void testC_messwertUpdateService(@ArquillianResource URL baseUrl) + throws Exception { + Assert.assertNotNull(this.messwertTest.getCreatedMesswertId()); + this.messwertTest.updateService(baseUrl, testProtocol); + } + + /** + * Testing UPDATE services. + */ + @Test + @RunAsClient + public final void testC_ortUpdateService(@ArquillianResource URL baseUrl) + throws Exception { + Assert.assertNotNull(this.ortTest.getCreatedId()); + this.ortTest.updateService(baseUrl, testProtocol); + } + + /** + * Testing UPDATE services. + */ + @Test + @RunAsClient + public final void testC_statusUpdateService(@ArquillianResource URL baseUrl) + throws Exception { + Assert.assertNotNull(this.ortTest.getCreatedId()); + this.statusTest.updateService(baseUrl, testProtocol); + } + + /** + * Testing DELETE services. + */ + @Test + @RunAsClient + public final void testD_DeleteServices(@ArquillianResource URL baseUrl) + throws Exception { + Assert.assertNotNull(this.zusatzwertTest.getCreatedId()); + this.zusatzwertTest.deleteService(baseUrl, testProtocol); + Assert.assertNotNull(this.statusTest.getCreatedId()); + this.statusTest.deleteService(baseUrl, testProtocol); + Assert.assertNotNull(this.ortTest.getCreatedId()); + this.ortTest.deleteService(baseUrl, testProtocol); + Assert.assertNotNull(this.messwertTest.getCreatedMesswertId()); + this.messwertTest.deleteService(baseUrl, testProtocol); + Assert.assertNotNull(this.kommentarMTest.getCreatedKommentarId()); + this.kommentarMTest.deleteService(baseUrl, testProtocol); + Assert.assertNotNull(this.kommentarPTest.getCreatedKommentarId()); + this.kommentarPTest.deleteService(baseUrl, testProtocol); + Assert.assertNotNull(this.messungTest.getCreatedMessungId()); + this.messungTest.deleteService(baseUrl, testProtocol); + Assert.assertNotNull(this.probeTest.getCreatedProbeId()); + this.probeTest.deleteService(baseUrl, testProtocol); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/LadaStammTest.java Wed Feb 18 15:33:46 2015 +0100 @@ -0,0 +1,33 @@ +package de.intevation.lada; + +import java.net.URL; +import java.util.ArrayList; + +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.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; + +import de.intevation.lada.test.stamm.Stammdaten; + +@RunWith(Arquillian.class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class LadaStammTest extends BaseTest { + + private static Logger logger = Logger.getLogger(LadaStammTest.class); + + public LadaStammTest () { + testProtocol = new ArrayList<Protocol>(); + verboseLogging = true; + } + + @BeforeClass + public static void beforeTests() { + logger.info("---------- Testing Lada Stamm Services ----------"); + } +}
--- a/src/test/java/de/intevation/lada/LadaTest.java Wed Feb 18 14:42:54 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,494 +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; - -import java.net.URL; -import java.util.ArrayList; -import java.util.List; - -import org.apache.log4j.Logger; -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.container.test.api.RunAsClient; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; -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.KommentarM; -import de.intevation.lada.test.KommentarP; -import de.intevation.lada.test.Messung; -import de.intevation.lada.test.Messwert; -import de.intevation.lada.test.Ort; -import de.intevation.lada.test.Probe; -import de.intevation.lada.test.Query; -import de.intevation.lada.test.Status; -import de.intevation.lada.test.Zusatzwert; - - -/** - * Class to test the Lada server. - * - * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> - */ -@RunWith(Arquillian.class) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class LadaTest { - - private static String ARCHIVE_NAME = "lada-basis-test.war"; - - private static Logger logger = Logger.getLogger(LadaTest.class); - - private static boolean verboseLogging = true; - - private Probe probeTest; - private Query queryTest; - private Messung messungTest; - private KommentarP kommentarPTest; - private KommentarM kommentarMTest; - private Messwert messwertTest; - private Ort ortTest; - private Status statusTest; - private Zusatzwert zusatzwertTest; - - private static List<Protocol> testProtocol; - - public LadaTest() { - probeTest = new Probe(); - queryTest = new Query(); - messungTest = new Messung(); - kommentarPTest = new KommentarP(); - kommentarMTest = new KommentarM(); - messwertTest = new Messwert(); - ortTest = new Ort(); - statusTest = new Status(); - zusatzwertTest = new Zusatzwert(); - testProtocol = new ArrayList<Protocol>(); - } - - /** - * Create a deployable WAR archive. - */ - @Deployment(testable=true) - public static WebArchive createDeployment() throws Exception { - logger.info("\n\n---------- Test Protocol ----------"); - logger.info("Create and deploy: " + ARCHIVE_NAME); - WebArchive archive = ShrinkWrap.create(WebArchive.class, ARCHIVE_NAME) - .addPackages(true, Package.getPackage("de.intevation.lada")) - .addAsResource("log4j.properties", "log4j.properties") - .addAsResource("queryconf.json", "queryconf.json") - .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") - .addAsResource("META-INF/test-persistence.xml", - "META-INF/persistence.xml"); - 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_ProbeGetAllServices(@ArquillianResource URL baseUrl) - throws Exception { - 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); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_KommentarPGetFilterServices(@ArquillianResource URL baseUrl) - throws Exception { - this.kommentarPTest.filterService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_KommentarMGetAllServices(@ArquillianResource URL baseUrl) - throws Exception { - this.kommentarMTest.getAllService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_KommentarMGetByIdServices(@ArquillianResource URL baseUrl) - throws Exception { - this.kommentarMTest.getByIdService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_KommentarMGetFilterServices(@ArquillianResource URL baseUrl) - throws Exception { - this.kommentarMTest.filterService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_MesswertGetAllServices(@ArquillianResource URL baseUrl) - throws Exception { - this.messwertTest.getAllService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_MesswertGetByIdServices(@ArquillianResource URL baseUrl) - throws Exception { - this.messwertTest.getByIdService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_MesswertGetFilterServices(@ArquillianResource URL baseUrl) - throws Exception { - this.messwertTest.filterService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_OrtGetAllServices(@ArquillianResource URL baseUrl) - throws Exception { - this.ortTest.getAllService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_OrtGetByIdServices(@ArquillianResource URL baseUrl) - throws Exception { - this.ortTest.getByIdService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_OrtGetFilterServices(@ArquillianResource URL baseUrl) - throws Exception { - this.ortTest.filterService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_StatusGetAllServices(@ArquillianResource URL baseUrl) - throws Exception { - this.statusTest.getAllService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_StatusGetByIdServices(@ArquillianResource URL baseUrl) - throws Exception { - this.statusTest.getByIdService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_StatusGetFilterServices(@ArquillianResource URL baseUrl) - throws Exception { - this.statusTest.filterService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_ZusatzwertGetAllServices(@ArquillianResource URL baseUrl) - throws Exception { - this.zusatzwertTest.getAllService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_ZusatzwertGetByIdServices(@ArquillianResource URL baseUrl) - throws Exception { - this.zusatzwertTest.getByIdService(baseUrl, testProtocol); - } - - /** - * Testing GET Services. - */ - @Test - @RunAsClient - public final void testA_ZusatzwertGetFilterServices(@ArquillianResource URL baseUrl) - throws Exception { - this.zusatzwertTest.filterService(baseUrl, testProtocol); - } - /** - * Testing CREATE services. - */ - @Test - @RunAsClient - public final void testB_CreateServices(@ArquillianResource URL baseUrl) - throws Exception { - this.probeTest.createService(baseUrl, testProtocol); - Assert.assertNotNull(this.probeTest.getCreatedProbeId()); - this.messungTest.createService( - baseUrl, - testProtocol, - this.probeTest.getCreatedProbeId()); - this.kommentarPTest.createService( - baseUrl, - testProtocol, - this.probeTest.getCreatedProbeId()); - this.ortTest.createService( - baseUrl, - testProtocol, - this.probeTest.getCreatedProbeId()); - this.zusatzwertTest.createService( - baseUrl, - testProtocol, - this.probeTest.getCreatedProbeId()); - Assert.assertNotNull(this.messungTest.getCreatedMessungId()); - this.kommentarMTest.createService( - baseUrl, - testProtocol, - this.messungTest.getCreatedMessungId()); - this.messwertTest.createService( - baseUrl, - testProtocol, - this.messungTest.getCreatedMessungId()); - this.statusTest.createService( - baseUrl, - testProtocol, - this.messungTest.getCreatedMessungId()); - } - - /** - * Testing UPDATE services. - */ - @Test - @RunAsClient - public final void testC_probeUpdateService(@ArquillianResource URL baseUrl) - throws Exception { - 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); - } - - /** - * Testing UPDATE services. - */ - @Test - @RunAsClient - public final void testC_kommentarPUpdateService(@ArquillianResource URL baseUrl) - throws Exception { - Assert.assertNotNull(this.kommentarPTest.getCreatedKommentarId()); - this.kommentarPTest.updateService(baseUrl, testProtocol); - } - - /** - * Testing UPDATE services. - */ - @Test - @RunAsClient - public final void testC_kommentarMUpdateService(@ArquillianResource URL baseUrl) - throws Exception { - Assert.assertNotNull(this.kommentarMTest.getCreatedKommentarId()); - this.kommentarMTest.updateService(baseUrl, testProtocol); - } - - /** - * Testing UPDATE services. - */ - @Test - @RunAsClient - public final void testC_messwertUpdateService(@ArquillianResource URL baseUrl) - throws Exception { - Assert.assertNotNull(this.messwertTest.getCreatedMesswertId()); - this.messwertTest.updateService(baseUrl, testProtocol); - } - - /** - * Testing UPDATE services. - */ - @Test - @RunAsClient - public final void testC_ortUpdateService(@ArquillianResource URL baseUrl) - throws Exception { - Assert.assertNotNull(this.ortTest.getCreatedId()); - this.ortTest.updateService(baseUrl, testProtocol); - } - - /** - * Testing UPDATE services. - */ - @Test - @RunAsClient - public final void testC_statusUpdateService(@ArquillianResource URL baseUrl) - throws Exception { - Assert.assertNotNull(this.ortTest.getCreatedId()); - this.statusTest.updateService(baseUrl, testProtocol); - } - - /** - * Testing DELETE services. - */ - @Test - @RunAsClient - public final void testD_DeleteServices(@ArquillianResource URL baseUrl) - throws Exception { - Assert.assertNotNull(this.zusatzwertTest.getCreatedId()); - this.zusatzwertTest.deleteService(baseUrl, testProtocol); - Assert.assertNotNull(this.statusTest.getCreatedId()); - this.statusTest.deleteService(baseUrl, testProtocol); - Assert.assertNotNull(this.ortTest.getCreatedId()); - this.ortTest.deleteService(baseUrl, testProtocol); - Assert.assertNotNull(this.messwertTest.getCreatedMesswertId()); - this.messwertTest.deleteService(baseUrl, testProtocol); - Assert.assertNotNull(this.kommentarMTest.getCreatedKommentarId()); - this.kommentarMTest.deleteService(baseUrl, testProtocol); - Assert.assertNotNull(this.kommentarPTest.getCreatedKommentarId()); - this.kommentarPTest.deleteService(baseUrl, testProtocol); - 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/KommentarM.java Wed Feb 18 14:42:54 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,321 +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.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 containing test cases for messung kommentar objects. - * - * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> - */ -public class KommentarM { - - private static final String COMPARE_KOMMENTARM = - "{\"messungId\":5,\"datum\":1336627500000,\"erzeuger\":\"12010\"," + - "\"id\":478,\"text\":\"Hofladen Lenzen geschlossen\"}"; - - private static final String CREATE_KOMMENTARM = - "{\"messungId\":\"MID\",\"erzeuger\":\"11010\",\"text\":" + - "\"test\",\"datum\":\"2015-02-09T10:58:36\"}"; - - private List<Protocol> protocol; - - private static Integer createdKommentarId; - - /** - * @return The test protocol - */ - public List<Protocol> getProtocol() { - return protocol; - } - - /** - * @return The created KommentarId - */ - public Integer getCreatedKommentarId() { - return createdKommentarId; - } - - /** - * Test the GET Service by requesting all 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("MessungKommentarService"); - prot.setType("get all"); - prot.setPassed(false); - protocol.add(prot); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "mkommentar"); - /* Request all 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 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("MessungKommentarService"); - 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_KOMMENTARM)); - JsonObject staticKommentar = fromStringRreader.readObject(); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "mkommentar/478"); - prot.addInfo("kommentarId", 478); - /* 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); - } - - /** - * Test the GET 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("MessungKommentarService"); - prot.setType("get by filter"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "mkommentar?messungId=988"); - prot.addInfo("filter", "messungId=988"); - /* Request the 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, - Integer messungId) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MessungKommentarService"); - prot.setType("create"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "mkommentar"); - /* Send a post request containing a new kommentar*/ - String mess = CREATE_KOMMENTARM.replace("MID", messungId.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 id*/ - createdKommentarId = - content.getJsonObject("data").getJsonNumber("id").intValue(); - prot.addInfo("kommentarId", createdKommentarId); - /* 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. - */ - public final void updateService(URL baseUrl, List<Protocol> protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MessungKommentarService"); - prot.setType("update"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "mkommentar/" + createdKommentarId); - prot.addInfo("kommentarId", createdKommentarId); - /* 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 oldKommentar = reader.readObject().getJsonObject("data"); - /* Change the text*/ - String updatedEntity = - oldKommentar.toString().replace("test", "neu"); - prot.addInfo("updated field", "text"); - prot.addInfo("updated value", "test"); - prot.addInfo("updated to", "neu"); - /* Send the updated kommentar via put reauest*/ - WebTarget putTarget = client.target(baseUrl + "mkommentar"); - 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("neu", - updatedMessung.getJsonObject("data").getString("text")); - } - 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("MessungKommentarService"); - prot.setType("delete"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "mkommentar/" + createdKommentarId); - prot.addInfo("kommentarId", createdKommentarId); - /* Delete a kommentar 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); - } -}
--- a/src/test/java/de/intevation/lada/test/KommentarP.java Wed Feb 18 14:42:54 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,322 +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.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 containing test cases for probekommentar objects. - * - * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> - */ -public class KommentarP { - - 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}"; - - private static final String CREATE_KOMMENTARP = - "{\"probeId\":\"PID\",\"erzeuger\":\"11010\",\"text\":" + - "\"test\",\"datum\":\"2015-02-09T10:58:36\"}"; - - private List<Protocol> protocol; - - private static Integer createdKommentarId; - - /** - * @return The test protocol - */ - public List<Protocol> getProtocol() { - return protocol; - } - - /** - * @return The created KommentarId - */ - public Integer getCreatedKommentarId() { - return createdKommentarId; - } - - /** - * Test the GET Service by requesting all 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 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 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); - } - - /** - * Test the GET 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("ProbeKommentarService"); - prot.setType("get by filter"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "pkommentar?probeId=400"); - prot.addInfo("filter", "probeId=400"); - /* Request the 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, - Integer probeId) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeKommentarService"); - prot.setType("create"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "pkommentar"); - /* Send a post request containing a new kommentar*/ - String mess = CREATE_KOMMENTARP.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 id*/ - createdKommentarId = - content.getJsonObject("data").getJsonNumber("id").intValue(); - prot.addInfo("kommentarId", createdKommentarId); - /* 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. - */ - public final void updateService(URL baseUrl, List<Protocol> protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ProbeKommentarService"); - prot.setType("update"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "pkommentar/" + createdKommentarId); - prot.addInfo("kommentarId", createdKommentarId); - /* 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 oldKommentar = reader.readObject().getJsonObject("data"); - /* Change the text*/ - String updatedEntity = - oldKommentar.toString().replace("test", "neu"); - prot.addInfo("updated field", "text"); - prot.addInfo("updated value", "test"); - prot.addInfo("updated to", "neu"); - /* Send the updated kommentar via put reauest*/ - WebTarget putTarget = client.target(baseUrl + "pkommentar"); - 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("neu", - updatedMessung.getJsonObject("data").getString("text")); - } - 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("ProbeKommentarService"); - prot.setType("delete"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "pkommentar/" + createdKommentarId); - prot.addInfo("kommentarId", createdKommentarId); - /* Delete a kommentar 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); - } -}
--- a/src/test/java/de/intevation/lada/test/Messung.java Wed Feb 18 14:42:54 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,320 +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.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 containing test cases for messung objects. - * - * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> - */ -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 test protocol - */ - public List<Protocol> getProtocol() { - return protocol; - } - - /** - * Test the GET Service by requesting all 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 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 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 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 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 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, - 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 object*/ - 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 id*/ - 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("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. - */ - public final void updateService(URL baseUrl, List<Protocol> protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MessungService"); - 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 messung with the saved id*/ - 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 mmtId*/ - 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 messung via put request*/ - 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 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 messung 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); - } -}
--- a/src/test/java/de/intevation/lada/test/Messwert.java Wed Feb 18 14:42:54 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,321 +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.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 containing test cases for messwert objects. - * - * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> - */ -public class Messwert { - - private static final String COMPARE_MESSWERT = - "{\"id\":1,\"grenzwertueberschreitung\":null,\"letzteAenderung\":" + - "1327305368000,\"mehId\":69,\"messfehler\":1.1,\"messgroesseId\":28," + - "\"messungsId\":749,\"messwert\":97.0,\"messwertNwg\":null," + - "\"nwgZuMesswert\":null}"; - - private static final String CREATE_MESSWERT = - "{\"messungsId\":MID,\"messgroesseId\":242,\"messwert\":1," + - "\"messwertNwg\":\"\",\"messfehler\":1,\"nwgZuMesswert\":3," + - "\"mehId\":207,\"grenzwertueberschreitung\":false," + - "\"letzteAenderung\":null}"; - - private List<Protocol> protocol; - - private static Integer createdMesswertId; - - public Integer getCreatedMesswertId() { - return createdMesswertId; - } - - /** - * @return The test protocol - */ - public List<Protocol> getProtocol() { - return protocol; - } - - /** - * Test the GET Service by requesting all 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("MesswertService"); - prot.setType("get all"); - prot.setPassed(false); - protocol.add(prot); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "messwert"); - /* Request all 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 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("MesswertService"); - prot.setType("get by Id"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a json object from static messwert string*/ - JsonReader fromStringRreader = - Json.createReader(new StringReader(COMPARE_MESSWERT)); - JsonObject staticMessung = fromStringRreader.readObject(); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "messwert/1"); - prot.addInfo("messwertId", 1); - /* Request a 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 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("MesswertService"); - prot.setType("get by filter"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "messwert?messungId=1"); - prot.addInfo("filter", "messungId=1"); - /* Request the 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, - Integer messungId) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MesswertService"); - prot.setType("create"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "messwert"); - /* Send a post request containing a new object*/ - String mess = CREATE_MESSWERT.replace("MID", messungId.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 id*/ - createdMesswertId = - content.getJsonObject("data").getJsonNumber("id").intValue(); - prot.addInfo("messwertId", createdMesswertId); - /* 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. - */ - public final void updateService(URL baseUrl, List<Protocol> protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("MesswertService"); - prot.setType("update"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "messwert/" + createdMesswertId); - prot.addInfo("messwertId", createdMesswertId); - /* Request a messwert with the saved id*/ - Response response = target.request().get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject oldMesswert = reader.readObject().getJsonObject("data"); - /* Change the mmtId*/ - String updatedEntity = - oldMesswert.toString().replace("207", "69"); - prot.addInfo("updated field", "mehId"); - prot.addInfo("updated value", "207"); - prot.addInfo("updated to", "69"); - /* Send the updated messwert via put request*/ - WebTarget putTarget = client.target(baseUrl + "messwert"); - 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(69, - updatedMessung.getJsonObject("data").getInt("mehId")); - } - 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("MesswertService"); - prot.setType("delete"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "messwert/" + createdMesswertId); - prot.addInfo("messwertId", createdMesswertId); - /* Delete a messwert 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); - } -}
--- a/src/test/java/de/intevation/lada/test/Ort.java Wed Feb 18 14:42:54 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,317 +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.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 containing test cases for ort objects. - * - * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> - */ -public class Ort { - - private static final String COMPARE = - "{\"id\":1,\"letzteAenderung\":1376287046510,\"ortsTyp\":\"Z\"," + - "\"ortszusatztext\":null,\"probeId\":96,\"ort\":213}"; - - private static final String CREATE = - "{\"letzteAenderung\":1376287046510,\"ortsTyp\":\"Z\"," + - "\"ortszusatztext\":\"textzusatz\",\"probeId\":PID,\"ort\":213}"; - - private List<Protocol> protocol; - - private static Integer createdId; - - public Integer getCreatedId() { - return createdId; - } - - /** - * @return The test protocol - */ - public List<Protocol> getProtocol() { - return protocol; - } - - /** - * Test the GET Service by requesting all 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("OrtService"); - prot.setType("get all"); - prot.setPassed(false); - protocol.add(prot); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "ort"); - /* Request all 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 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("OrtService"); - prot.setType("get by Id"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a json object from static messwert string*/ - JsonReader fromStringRreader = - Json.createReader(new StringReader(COMPARE)); - JsonObject staticMessung = fromStringRreader.readObject(); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "ort/1"); - prot.addInfo("ortId", 1); - /* Request a 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 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("OrtService"); - prot.setType("get by filter"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "ort?probeId=1"); - prot.addInfo("filter", "probeId=1"); - /* Request the 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, - Integer probeId) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("OrtService"); - prot.setType("create"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "ort"); - /* Send a post request containing a new object*/ - String mess = CREATE.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 id*/ - createdId = - content.getJsonObject("data").getJsonNumber("id").intValue(); - prot.addInfo("ortId", createdId); - /* 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. - */ - public final void updateService(URL baseUrl, List<Protocol> protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("OrtService"); - prot.setType("update"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "ort/" + createdId); - prot.addInfo("ortId", createdId); - /* Request an object with the saved id*/ - Response response = target.request().get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject old = reader.readObject().getJsonObject("data"); - /* Change the mmtId*/ - String updatedEntity = - old.toString().replace("textzusatz", "changedzusatz"); - prot.addInfo("updated field", "ortszusatztext"); - prot.addInfo("updated value", "text"); - prot.addInfo("updated to", "zusatz"); - /* Send the updated messwert via put request*/ - WebTarget putTarget = client.target(baseUrl + "ort"); - 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("changedzusatz", - updatedObj.getJsonObject("data").getString("ortszusatztext")); - } - 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("OrtService"); - prot.setType("delete"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "ort/" + createdId); - prot.addInfo("ortId", createdId); - /* 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); - } -}
--- a/src/test/java/de/intevation/lada/test/Probe.java Wed Feb 18 14:42:54 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,331 +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.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 containing test cases for probe objects. - * - * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> - */ -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 test protocol - */ - public List<Protocol> getProtocol() { - return protocol; - } - - /** - * Test the GET Service by requesting all 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 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 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 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 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 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 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 id*/ - 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("message", 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 with the saved id*/ - 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", "2345678901"); - /* 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"); - } -}
--- a/src/test/java/de/intevation/lada/test/Query.java Wed Feb 18 14:42:54 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +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.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 containing test cases for query config. - * - * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> - */ -public class Query { - - private List<Protocol> protocol; - - /** - * @return The test 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/Status.java Wed Feb 18 14:42:54 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,317 +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.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 containing test cases for status objects. - * - * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> - */ -public class Status { - - private static final String COMPARE = - "{\"id\":1,\"erzeuger\":\"06010\",\"messungsId\":440,\"status\":3," + - "\"sdatum\":1373846400000,\"skommentar\":\"test\"}"; - - private static final String CREATE = - "{\"erzeuger\":\"06010\",\"messungsId\":MID,\"status\":3," + - "\"sdatum\":1373846400000,\"skommentar\":\"status3\"}"; - - private List<Protocol> protocol; - - private static Integer createdId; - - public Integer getCreatedId() { - return createdId; - } - - /** - * @return The test protocol - */ - public List<Protocol> getProtocol() { - return protocol; - } - - /** - * Test the GET Service by requesting all 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("StatusService"); - prot.setType("get all"); - prot.setPassed(false); - protocol.add(prot); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "status"); - /* Request all 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 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("StatusService"); - prot.setType("get by Id"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a json object from static messwert string*/ - JsonReader fromStringRreader = - Json.createReader(new StringReader(COMPARE)); - JsonObject staticMessung = fromStringRreader.readObject(); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "status/1"); - prot.addInfo("statusId", 1); - /* Request a 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 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("StatusService"); - prot.setType("get by filter"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "status?messungId=1"); - prot.addInfo("filter", "messungId=1"); - /* Request the 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, - Integer messungId) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("StatusService"); - prot.setType("create"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "status"); - /* Send a post request containing a new object*/ - String stat = CREATE.replace("MID", messungId.toString()); - Response response = target.request().post( - Entity.entity(stat, 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*/ - createdId = - content.getJsonObject("data").getJsonNumber("id").intValue(); - prot.addInfo("statusId", createdId); - /* 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. - */ - public final void updateService(URL baseUrl, List<Protocol> protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("StatusService"); - prot.setType("update"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "status/" + createdId); - prot.addInfo("statusId", createdId); - /* Request an object with the saved id*/ - Response response = target.request().get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject old = reader.readObject().getJsonObject("data"); - /* Change the mmtId*/ - String updatedEntity = - old.toString().replace("status3", "status3updated"); - prot.addInfo("updated field", "skommentar"); - prot.addInfo("updated value", "status3"); - prot.addInfo("updated to", "status3updated"); - /* Send the updated messwert via put request*/ - WebTarget putTarget = client.target(baseUrl + "status"); - 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("status3updated", - updatedObj.getJsonObject("data").getString("skommentar")); - } - 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("StatusService"); - prot.setType("delete"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "status/" + createdId); - prot.addInfo("statusId", createdId); - /* 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); - } -}
--- a/src/test/java/de/intevation/lada/test/Zusatzwert.java Wed Feb 18 14:42:54 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,319 +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.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 containing test cases for zusatzwert objects. - * - * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> - */ -public class Zusatzwert { - - private static final String COMPARE = - "{\"id\":1,\"letzteAenderung\":1335177176000,\"messfehler\":48.0," + - "\"messwertPzs\":7.5,\"nwgZuMesswert\":null,\"probeId\":84," + - "\"pzsId\":\"A76\"}"; - - private static final String CREATE = - "{\"letzteAenderung\":1335177176000,\"messfehler\":18.0," + - "\"messwertPzs\":3.5,\"nwgZuMesswert\":null,\"probeId\":PID," + - "\"pzsId\":\"A76\"}"; - - private List<Protocol> protocol; - - private static Integer createdId; - - public Integer getCreatedId() { - return createdId; - } - - /** - * @return The test protocol - */ - public List<Protocol> getProtocol() { - return protocol; - } - - /** - * Test the GET Service by requesting all 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("ZusatzwertService"); - prot.setType("get all"); - prot.setPassed(false); - protocol.add(prot); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "zusatzwert"); - /* Request all 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 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("ZusatzwertService"); - 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)); - JsonObject staticMessung = fromStringRreader.readObject(); - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "zusatzwert/1"); - prot.addInfo("zustzwertId", 1); - /* Request a 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 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("ZusatzwertService"); - prot.setType("get by filter"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "zusatzwert?probeIdId=1"); - prot.addInfo("filter", "probeId=1"); - /* Request the 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, - Integer probeId) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ZusatzwertService"); - prot.setType("create"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = client.target(baseUrl + "zusatzwert"); - /* Send a post request containing a new object*/ - String zus = CREATE.replace("PID", probeId.toString()); - Response response = target.request().post( - Entity.entity(zus, 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*/ - createdId = - content.getJsonObject("data").getJsonNumber("id").intValue(); - prot.addInfo("zusatzwertId", createdId); - /* 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. - */ - public final void updateService(URL baseUrl, List<Protocol> protocol) - throws Exception { - System.out.print("."); - Protocol prot = new Protocol(); - prot.setName("ZusatzwertService"); - prot.setType("update"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "zusatzwert/" + createdId); - prot.addInfo("zusatzwertId", createdId); - /* Request an object with the saved id*/ - Response response = target.request().get(); - String entity = response.readEntity(String.class); - /* Try to parse the response*/ - JsonReader reader = Json.createReader(new StringReader(entity)); - JsonObject old = reader.readObject().getJsonObject("data"); - /* Change the mmtId*/ - String updatedEntity = - old.toString().replace("3.5", "14"); - prot.addInfo("updated field", "messwertPzs"); - prot.addInfo("updated value", "3.5"); - prot.addInfo("updated to", "14"); - /* Send the updated messwert via put request*/ - WebTarget putTarget = client.target(baseUrl + "zusatzwert"); - 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(14, - updatedObj.getJsonObject("data").getJsonNumber("messwertPzs")); - } - 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("ZusatzwertService"); - prot.setType("delete"); - prot.setPassed(false); - protocol.add(prot); - try { - /* Create a client*/ - Client client = ClientBuilder.newClient(); - WebTarget target = - client.target(baseUrl + "zusatzwert/" + createdId); - prot.addInfo("zusatzwertId", createdId); - /* 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); - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/land/KommentarM.java Wed Feb 18 15:33:46 2015 +0100 @@ -0,0 +1,321 @@ +/* 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.land; + +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; + + +/** + * Class containing test cases for messung kommentar objects. + * + * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> + */ +public class KommentarM { + + private static final String COMPARE_KOMMENTARM = + "{\"messungId\":5,\"datum\":1336627500000,\"erzeuger\":\"12010\"," + + "\"id\":478,\"text\":\"Hofladen Lenzen geschlossen\"}"; + + private static final String CREATE_KOMMENTARM = + "{\"messungId\":\"MID\",\"erzeuger\":\"11010\",\"text\":" + + "\"test\",\"datum\":\"2015-02-09T10:58:36\"}"; + + private List<Protocol> protocol; + + private static Integer createdKommentarId; + + /** + * @return The test protocol + */ + public List<Protocol> getProtocol() { + return protocol; + } + + /** + * @return The created KommentarId + */ + public Integer getCreatedKommentarId() { + return createdKommentarId; + } + + /** + * Test the GET Service by requesting all 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("MessungKommentarService"); + prot.setType("get all"); + prot.setPassed(false); + protocol.add(prot); + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "mkommentar"); + /* Request all 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 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("MessungKommentarService"); + 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_KOMMENTARM)); + JsonObject staticKommentar = fromStringRreader.readObject(); + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "mkommentar/478"); + prot.addInfo("kommentarId", 478); + /* 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); + } + + /** + * Test the GET 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("MessungKommentarService"); + prot.setType("get by filter"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "mkommentar?messungId=988"); + prot.addInfo("filter", "messungId=988"); + /* Request the 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, + Integer messungId) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("MessungKommentarService"); + prot.setType("create"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "mkommentar"); + /* Send a post request containing a new kommentar*/ + String mess = CREATE_KOMMENTARM.replace("MID", messungId.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 id*/ + createdKommentarId = + content.getJsonObject("data").getJsonNumber("id").intValue(); + prot.addInfo("kommentarId", createdKommentarId); + /* 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. + */ + public final void updateService(URL baseUrl, List<Protocol> protocol) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("MessungKommentarService"); + prot.setType("update"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "mkommentar/" + createdKommentarId); + prot.addInfo("kommentarId", createdKommentarId); + /* 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 oldKommentar = reader.readObject().getJsonObject("data"); + /* Change the text*/ + String updatedEntity = + oldKommentar.toString().replace("test", "neu"); + prot.addInfo("updated field", "text"); + prot.addInfo("updated value", "test"); + prot.addInfo("updated to", "neu"); + /* Send the updated kommentar via put reauest*/ + WebTarget putTarget = client.target(baseUrl + "mkommentar"); + 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("neu", + updatedMessung.getJsonObject("data").getString("text")); + } + 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("MessungKommentarService"); + prot.setType("delete"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "mkommentar/" + createdKommentarId); + prot.addInfo("kommentarId", createdKommentarId); + /* Delete a kommentar 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); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/land/KommentarP.java Wed Feb 18 15:33:46 2015 +0100 @@ -0,0 +1,322 @@ +/* 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.land; + +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; + + +/** + * Class containing test cases for probekommentar objects. + * + * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> + */ +public class KommentarP { + + 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}"; + + private static final String CREATE_KOMMENTARP = + "{\"probeId\":\"PID\",\"erzeuger\":\"11010\",\"text\":" + + "\"test\",\"datum\":\"2015-02-09T10:58:36\"}"; + + private List<Protocol> protocol; + + private static Integer createdKommentarId; + + /** + * @return The test protocol + */ + public List<Protocol> getProtocol() { + return protocol; + } + + /** + * @return The created KommentarId + */ + public Integer getCreatedKommentarId() { + return createdKommentarId; + } + + /** + * Test the GET Service by requesting all 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 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 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); + } + + /** + * Test the GET 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("ProbeKommentarService"); + prot.setType("get by filter"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "pkommentar?probeId=400"); + prot.addInfo("filter", "probeId=400"); + /* Request the 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, + Integer probeId) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("ProbeKommentarService"); + prot.setType("create"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "pkommentar"); + /* Send a post request containing a new kommentar*/ + String mess = CREATE_KOMMENTARP.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 id*/ + createdKommentarId = + content.getJsonObject("data").getJsonNumber("id").intValue(); + prot.addInfo("kommentarId", createdKommentarId); + /* 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. + */ + public final void updateService(URL baseUrl, List<Protocol> protocol) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("ProbeKommentarService"); + prot.setType("update"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "pkommentar/" + createdKommentarId); + prot.addInfo("kommentarId", createdKommentarId); + /* 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 oldKommentar = reader.readObject().getJsonObject("data"); + /* Change the text*/ + String updatedEntity = + oldKommentar.toString().replace("test", "neu"); + prot.addInfo("updated field", "text"); + prot.addInfo("updated value", "test"); + prot.addInfo("updated to", "neu"); + /* Send the updated kommentar via put reauest*/ + WebTarget putTarget = client.target(baseUrl + "pkommentar"); + 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("neu", + updatedMessung.getJsonObject("data").getString("text")); + } + 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("ProbeKommentarService"); + prot.setType("delete"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "pkommentar/" + createdKommentarId); + prot.addInfo("kommentarId", createdKommentarId); + /* Delete a kommentar 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); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/land/Messung.java Wed Feb 18 15:33:46 2015 +0100 @@ -0,0 +1,320 @@ +/* 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.land; + +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; + +/** + * Class containing test cases for messung objects. + * + * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> + */ +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 test protocol + */ + public List<Protocol> getProtocol() { + return protocol; + } + + /** + * Test the GET Service by requesting all 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 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 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 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 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 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, + 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 object*/ + 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 id*/ + 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("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. + */ + public final void updateService(URL baseUrl, List<Protocol> protocol) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("MessungService"); + 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 messung with the saved id*/ + 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 mmtId*/ + 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 messung via put request*/ + 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 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 messung 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); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/land/Messwert.java Wed Feb 18 15:33:46 2015 +0100 @@ -0,0 +1,321 @@ +/* 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.land; + +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; + +/** + * Class containing test cases for messwert objects. + * + * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> + */ +public class Messwert { + + private static final String COMPARE_MESSWERT = + "{\"id\":1,\"grenzwertueberschreitung\":null,\"letzteAenderung\":" + + "1327305368000,\"mehId\":69,\"messfehler\":1.1,\"messgroesseId\":28," + + "\"messungsId\":749,\"messwert\":97.0,\"messwertNwg\":null," + + "\"nwgZuMesswert\":null}"; + + private static final String CREATE_MESSWERT = + "{\"messungsId\":MID,\"messgroesseId\":242,\"messwert\":1," + + "\"messwertNwg\":\"\",\"messfehler\":1,\"nwgZuMesswert\":3," + + "\"mehId\":207,\"grenzwertueberschreitung\":false," + + "\"letzteAenderung\":null}"; + + private List<Protocol> protocol; + + private static Integer createdMesswertId; + + public Integer getCreatedMesswertId() { + return createdMesswertId; + } + + /** + * @return The test protocol + */ + public List<Protocol> getProtocol() { + return protocol; + } + + /** + * Test the GET Service by requesting all 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("MesswertService"); + prot.setType("get all"); + prot.setPassed(false); + protocol.add(prot); + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "messwert"); + /* Request all 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 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("MesswertService"); + prot.setType("get by Id"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a json object from static messwert string*/ + JsonReader fromStringRreader = + Json.createReader(new StringReader(COMPARE_MESSWERT)); + JsonObject staticMessung = fromStringRreader.readObject(); + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "messwert/1"); + prot.addInfo("messwertId", 1); + /* Request a 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 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("MesswertService"); + prot.setType("get by filter"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "messwert?messungId=1"); + prot.addInfo("filter", "messungId=1"); + /* Request the 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, + Integer messungId) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("MesswertService"); + prot.setType("create"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "messwert"); + /* Send a post request containing a new object*/ + String mess = CREATE_MESSWERT.replace("MID", messungId.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 id*/ + createdMesswertId = + content.getJsonObject("data").getJsonNumber("id").intValue(); + prot.addInfo("messwertId", createdMesswertId); + /* 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. + */ + public final void updateService(URL baseUrl, List<Protocol> protocol) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("MesswertService"); + prot.setType("update"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "messwert/" + createdMesswertId); + prot.addInfo("messwertId", createdMesswertId); + /* Request a messwert with the saved id*/ + Response response = target.request().get(); + String entity = response.readEntity(String.class); + /* Try to parse the response*/ + JsonReader reader = Json.createReader(new StringReader(entity)); + JsonObject oldMesswert = reader.readObject().getJsonObject("data"); + /* Change the mmtId*/ + String updatedEntity = + oldMesswert.toString().replace("207", "69"); + prot.addInfo("updated field", "mehId"); + prot.addInfo("updated value", "207"); + prot.addInfo("updated to", "69"); + /* Send the updated messwert via put request*/ + WebTarget putTarget = client.target(baseUrl + "messwert"); + 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(69, + updatedMessung.getJsonObject("data").getInt("mehId")); + } + 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("MesswertService"); + prot.setType("delete"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "messwert/" + createdMesswertId); + prot.addInfo("messwertId", createdMesswertId); + /* Delete a messwert 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); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/land/Ort.java Wed Feb 18 15:33:46 2015 +0100 @@ -0,0 +1,317 @@ +/* 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.land; + +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; + +/** + * Class containing test cases for ort objects. + * + * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> + */ +public class Ort { + + private static final String COMPARE = + "{\"id\":1,\"letzteAenderung\":1376287046510,\"ortsTyp\":\"Z\"," + + "\"ortszusatztext\":null,\"probeId\":96,\"ort\":213}"; + + private static final String CREATE = + "{\"letzteAenderung\":1376287046510,\"ortsTyp\":\"Z\"," + + "\"ortszusatztext\":\"textzusatz\",\"probeId\":PID,\"ort\":213}"; + + private List<Protocol> protocol; + + private static Integer createdId; + + public Integer getCreatedId() { + return createdId; + } + + /** + * @return The test protocol + */ + public List<Protocol> getProtocol() { + return protocol; + } + + /** + * Test the GET Service by requesting all 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("OrtService"); + prot.setType("get all"); + prot.setPassed(false); + protocol.add(prot); + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "ort"); + /* Request all 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 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("OrtService"); + prot.setType("get by Id"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a json object from static messwert string*/ + JsonReader fromStringRreader = + Json.createReader(new StringReader(COMPARE)); + JsonObject staticMessung = fromStringRreader.readObject(); + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "ort/1"); + prot.addInfo("ortId", 1); + /* Request a 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 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("OrtService"); + prot.setType("get by filter"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "ort?probeId=1"); + prot.addInfo("filter", "probeId=1"); + /* Request the 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, + Integer probeId) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("OrtService"); + prot.setType("create"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "ort"); + /* Send a post request containing a new object*/ + String mess = CREATE.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 id*/ + createdId = + content.getJsonObject("data").getJsonNumber("id").intValue(); + prot.addInfo("ortId", createdId); + /* 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. + */ + public final void updateService(URL baseUrl, List<Protocol> protocol) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("OrtService"); + prot.setType("update"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "ort/" + createdId); + prot.addInfo("ortId", createdId); + /* Request an object with the saved id*/ + Response response = target.request().get(); + String entity = response.readEntity(String.class); + /* Try to parse the response*/ + JsonReader reader = Json.createReader(new StringReader(entity)); + JsonObject old = reader.readObject().getJsonObject("data"); + /* Change the mmtId*/ + String updatedEntity = + old.toString().replace("textzusatz", "changedzusatz"); + prot.addInfo("updated field", "ortszusatztext"); + prot.addInfo("updated value", "text"); + prot.addInfo("updated to", "zusatz"); + /* Send the updated messwert via put request*/ + WebTarget putTarget = client.target(baseUrl + "ort"); + 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("changedzusatz", + updatedObj.getJsonObject("data").getString("ortszusatztext")); + } + 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("OrtService"); + prot.setType("delete"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "ort/" + createdId); + prot.addInfo("ortId", createdId); + /* 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); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/land/Probe.java Wed Feb 18 15:33:46 2015 +0100 @@ -0,0 +1,331 @@ +/* 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.land; + +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; + + +/** + * Class containing test cases for probe objects. + * + * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> + */ +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 test protocol + */ + public List<Protocol> getProtocol() { + return protocol; + } + + /** + * Test the GET Service by requesting all 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 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 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 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 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 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 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 id*/ + 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("message", 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 with the saved id*/ + 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", "2345678901"); + /* 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/land/Query.java Wed Feb 18 15:33:46 2015 +0100 @@ -0,0 +1,81 @@ +/* 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.land; + +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; + + +/** + * Class containing test cases for query config. + * + * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> + */ +public class Query { + + private List<Protocol> protocol; + + /** + * @return The test 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); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/land/Status.java Wed Feb 18 15:33:46 2015 +0100 @@ -0,0 +1,317 @@ +/* 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.land; + +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; + +/** + * Class containing test cases for status objects. + * + * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> + */ +public class Status { + + private static final String COMPARE = + "{\"id\":1,\"erzeuger\":\"06010\",\"messungsId\":440,\"status\":3," + + "\"sdatum\":1373846400000,\"skommentar\":\"test\"}"; + + private static final String CREATE = + "{\"erzeuger\":\"06010\",\"messungsId\":MID,\"status\":3," + + "\"sdatum\":1373846400000,\"skommentar\":\"status3\"}"; + + private List<Protocol> protocol; + + private static Integer createdId; + + public Integer getCreatedId() { + return createdId; + } + + /** + * @return The test protocol + */ + public List<Protocol> getProtocol() { + return protocol; + } + + /** + * Test the GET Service by requesting all 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("StatusService"); + prot.setType("get all"); + prot.setPassed(false); + protocol.add(prot); + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "status"); + /* Request all 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 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("StatusService"); + prot.setType("get by Id"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a json object from static messwert string*/ + JsonReader fromStringRreader = + Json.createReader(new StringReader(COMPARE)); + JsonObject staticMessung = fromStringRreader.readObject(); + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "status/1"); + prot.addInfo("statusId", 1); + /* Request a 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 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("StatusService"); + prot.setType("get by filter"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "status?messungId=1"); + prot.addInfo("filter", "messungId=1"); + /* Request the 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, + Integer messungId) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("StatusService"); + prot.setType("create"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "status"); + /* Send a post request containing a new object*/ + String stat = CREATE.replace("MID", messungId.toString()); + Response response = target.request().post( + Entity.entity(stat, 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*/ + createdId = + content.getJsonObject("data").getJsonNumber("id").intValue(); + prot.addInfo("statusId", createdId); + /* 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. + */ + public final void updateService(URL baseUrl, List<Protocol> protocol) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("StatusService"); + prot.setType("update"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "status/" + createdId); + prot.addInfo("statusId", createdId); + /* Request an object with the saved id*/ + Response response = target.request().get(); + String entity = response.readEntity(String.class); + /* Try to parse the response*/ + JsonReader reader = Json.createReader(new StringReader(entity)); + JsonObject old = reader.readObject().getJsonObject("data"); + /* Change the mmtId*/ + String updatedEntity = + old.toString().replace("status3", "status3updated"); + prot.addInfo("updated field", "skommentar"); + prot.addInfo("updated value", "status3"); + prot.addInfo("updated to", "status3updated"); + /* Send the updated messwert via put request*/ + WebTarget putTarget = client.target(baseUrl + "status"); + 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("status3updated", + updatedObj.getJsonObject("data").getString("skommentar")); + } + 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("StatusService"); + prot.setType("delete"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "status/" + createdId); + prot.addInfo("statusId", createdId); + /* 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); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/de/intevation/lada/test/land/Zusatzwert.java Wed Feb 18 15:33:46 2015 +0100 @@ -0,0 +1,319 @@ +/* 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.land; + +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; + +/** + * Class containing test cases for zusatzwert objects. + * + * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> + */ +public class Zusatzwert { + + private static final String COMPARE = + "{\"id\":1,\"letzteAenderung\":1335177176000,\"messfehler\":48.0," + + "\"messwertPzs\":7.5,\"nwgZuMesswert\":null,\"probeId\":84," + + "\"pzsId\":\"A76\"}"; + + private static final String CREATE = + "{\"letzteAenderung\":1335177176000,\"messfehler\":18.0," + + "\"messwertPzs\":3.5,\"nwgZuMesswert\":null,\"probeId\":PID," + + "\"pzsId\":\"A76\"}"; + + private List<Protocol> protocol; + + private static Integer createdId; + + public Integer getCreatedId() { + return createdId; + } + + /** + * @return The test protocol + */ + public List<Protocol> getProtocol() { + return protocol; + } + + /** + * Test the GET Service by requesting all 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("ZusatzwertService"); + prot.setType("get all"); + prot.setPassed(false); + protocol.add(prot); + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "zusatzwert"); + /* Request all 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 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("ZusatzwertService"); + 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)); + JsonObject staticMessung = fromStringRreader.readObject(); + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "zusatzwert/1"); + prot.addInfo("zustzwertId", 1); + /* Request a 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 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("ZusatzwertService"); + prot.setType("get by filter"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "zusatzwert?probeIdId=1"); + prot.addInfo("filter", "probeId=1"); + /* Request the 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, + Integer probeId) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("ZusatzwertService"); + prot.setType("create"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = client.target(baseUrl + "zusatzwert"); + /* Send a post request containing a new object*/ + String zus = CREATE.replace("PID", probeId.toString()); + Response response = target.request().post( + Entity.entity(zus, 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*/ + createdId = + content.getJsonObject("data").getJsonNumber("id").intValue(); + prot.addInfo("zusatzwertId", createdId); + /* 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. + */ + public final void updateService(URL baseUrl, List<Protocol> protocol) + throws Exception { + System.out.print("."); + Protocol prot = new Protocol(); + prot.setName("ZusatzwertService"); + prot.setType("update"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "zusatzwert/" + createdId); + prot.addInfo("zusatzwertId", createdId); + /* Request an object with the saved id*/ + Response response = target.request().get(); + String entity = response.readEntity(String.class); + /* Try to parse the response*/ + JsonReader reader = Json.createReader(new StringReader(entity)); + JsonObject old = reader.readObject().getJsonObject("data"); + /* Change the mmtId*/ + String updatedEntity = + old.toString().replace("3.5", "14"); + prot.addInfo("updated field", "messwertPzs"); + prot.addInfo("updated value", "3.5"); + prot.addInfo("updated to", "14"); + /* Send the updated messwert via put request*/ + WebTarget putTarget = client.target(baseUrl + "zusatzwert"); + 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(14, + updatedObj.getJsonObject("data").getJsonNumber("messwertPzs")); + } + 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("ZusatzwertService"); + prot.setType("delete"); + prot.setPassed(false); + protocol.add(prot); + try { + /* Create a client*/ + Client client = ClientBuilder.newClient(); + WebTarget target = + client.target(baseUrl + "zusatzwert/" + createdId); + prot.addInfo("zusatzwertId", createdId); + /* 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); + } +}