Mercurial > lada > lada-server
comparison src/test/java/de/intevation/lada/LadaStammTest.java @ 517:e5a8b3c7721c
Added test for s_ort (location) services.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Thu, 19 Feb 2015 14:14:31 +0100 |
parents | 6774e6aa350d |
children | 688d91792c63 |
comparison
equal
deleted
inserted
replaced
516:f921a0db3729 | 517:e5a8b3c7721c |
---|---|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out | 5 * and comes with ABSOLUTELY NO WARRANTY! Check out |
6 * the documentation coming with IMIS-Labordaten-Application for details. | 6 * the documentation coming with IMIS-Labordaten-Application for details. |
7 */ | 7 */ |
8 package de.intevation.lada; | 8 package de.intevation.lada; |
9 | 9 |
10 import java.io.StringReader; | |
10 import java.net.URL; | 11 import java.net.URL; |
11 import java.util.ArrayList; | 12 import java.util.ArrayList; |
13 | |
14 import javax.json.Json; | |
15 import javax.json.JsonException; | |
16 import javax.json.JsonObject; | |
17 import javax.json.JsonReader; | |
18 import javax.ws.rs.client.Client; | |
19 import javax.ws.rs.client.ClientBuilder; | |
20 import javax.ws.rs.client.Entity; | |
21 import javax.ws.rs.client.WebTarget; | |
22 import javax.ws.rs.core.MediaType; | |
23 import javax.ws.rs.core.Response; | |
12 | 24 |
13 import org.apache.log4j.Logger; | 25 import org.apache.log4j.Logger; |
14 import org.jboss.arquillian.container.test.api.RunAsClient; | 26 import org.jboss.arquillian.container.test.api.RunAsClient; |
15 import org.jboss.arquillian.junit.Arquillian; | 27 import org.jboss.arquillian.junit.Arquillian; |
16 import org.jboss.arquillian.test.api.ArquillianResource; | 28 import org.jboss.arquillian.test.api.ArquillianResource; |
29 import org.junit.Assert; | |
17 import org.junit.BeforeClass; | 30 import org.junit.BeforeClass; |
18 import org.junit.FixMethodOrder; | 31 import org.junit.FixMethodOrder; |
32 import org.junit.Ignore; | |
19 import org.junit.Test; | 33 import org.junit.Test; |
20 import org.junit.runner.RunWith; | 34 import org.junit.runner.RunWith; |
21 import org.junit.runners.MethodSorters; | 35 import org.junit.runners.MethodSorters; |
22 | 36 |
23 import de.intevation.lada.test.stamm.Stammdaten; | 37 import de.intevation.lada.test.stamm.Stammdaten; |
32 @FixMethodOrder(MethodSorters.NAME_ASCENDING) | 46 @FixMethodOrder(MethodSorters.NAME_ASCENDING) |
33 public class LadaStammTest extends BaseTest { | 47 public class LadaStammTest extends BaseTest { |
34 | 48 |
35 private static Logger logger = Logger.getLogger(LadaStammTest.class); | 49 private static Logger logger = Logger.getLogger(LadaStammTest.class); |
36 | 50 |
51 private static Integer createdOrtId; | |
52 | |
37 private Stammdaten stammdatenTest; | 53 private Stammdaten stammdatenTest; |
38 | 54 |
39 public LadaStammTest () { | 55 public LadaStammTest () { |
40 stammdatenTest = new Stammdaten(); | 56 stammdatenTest = new Stammdaten(); |
41 testProtocol = new ArrayList<Protocol>(); | 57 testProtocol = new ArrayList<Protocol>(); |
152 @Test | 168 @Test |
153 @RunAsClient | 169 @RunAsClient |
154 public final void testProbenzusatzById(@ArquillianResource URL baseUrl) { | 170 public final void testProbenzusatzById(@ArquillianResource URL baseUrl) { |
155 stammdatenTest.getById(baseUrl, "probenzusatz", "A74", testProtocol); | 171 stammdatenTest.getById(baseUrl, "probenzusatz", "A74", testProtocol); |
156 } | 172 } |
173 | |
174 @Test | |
175 @RunAsClient | |
176 public final void testLocationAll(@ArquillianResource URL baseUrl) { | |
177 stammdatenTest.getAll(baseUrl, "location", testProtocol); | |
178 } | |
179 | |
180 @Test | |
181 @RunAsClient | |
182 public final void testLocationById(@ArquillianResource URL baseUrl) { | |
183 stammdatenTest.getById(baseUrl, "location", "19", testProtocol); | |
184 } | |
185 | |
186 @Test | |
187 @RunAsClient | |
188 public final void testLocation1CreateService(@ArquillianResource URL baseUrl) | |
189 throws Exception { | |
190 System.out.print("."); | |
191 Protocol prot = new Protocol(); | |
192 prot.setName("locationService"); | |
193 prot.setType("create"); | |
194 prot.setPassed(false); | |
195 testProtocol.add(prot); | |
196 try { | |
197 /* Create a client*/ | |
198 Client client = ClientBuilder.newClient(); | |
199 WebTarget target = client.target(baseUrl + "location"); | |
200 /* Send a post request containing a new kommentar*/ | |
201 String newObj = "{\"beschreibung\":\"Neuer Ort\"," + | |
202 "\"bezeichnung\":\"T123456\",\"hoeheLand\":null," + | |
203 "\"koordXExtern\":\"32531152\",\"koordYExtern\":\"5684269\"," + | |
204 "\"latitude\":51.30888,\"letzteAenderung\":1376287046332," + | |
205 "\"longitude\":9.44693,\"nutsCode\":\"DE731\",\"unscharf\":" + | |
206 "\"0\",\"netzbetreiberId\":null,\"staatId\":0," + | |
207 "\"verwaltungseinheitId\":\"06611000\",\"otyp\":\"Z\"," + | |
208 "\"koordinatenartId\":5}"; | |
209 | |
210 Response response = target.request().post( | |
211 Entity.entity(newObj, MediaType.APPLICATION_JSON)); | |
212 String entity = response.readEntity(String.class); | |
213 /* Try to parse the response*/ | |
214 JsonReader fromServiceReader = | |
215 Json.createReader(new StringReader(entity)); | |
216 JsonObject content = fromServiceReader.readObject(); | |
217 /* Save the id*/ | |
218 createdOrtId = | |
219 content.getJsonObject("data").getJsonNumber("id").intValue(); | |
220 prot.addInfo("ortId", createdOrtId); | |
221 /* Verify the response*/ | |
222 Assert.assertTrue(content.getBoolean("success")); | |
223 prot.addInfo("success", content.getBoolean("success")); | |
224 Assert.assertEquals("200", content.getString("message")); | |
225 prot.addInfo("message", content.getString("message")); | |
226 } | |
227 catch(JsonException je) { | |
228 prot.addInfo("exception", je.getMessage()); | |
229 Assert.fail(je.getMessage()); | |
230 } | |
231 prot.setPassed(true); | |
232 } | |
233 | |
234 /** | |
235 * Test the UPDATE Service. | |
236 * | |
237 * @param baseUrl The url pointing to the test deployment. | |
238 */ | |
239 @Test | |
240 @RunAsClient | |
241 public final void testLocation2UpdateService(@ArquillianResource URL baseUrl) | |
242 throws Exception { | |
243 System.out.print("."); | |
244 Protocol prot = new Protocol(); | |
245 prot.setName("locationService"); | |
246 prot.setType("update"); | |
247 prot.setPassed(false); | |
248 testProtocol.add(prot); | |
249 try { | |
250 /* Create a client*/ | |
251 Client client = ClientBuilder.newClient(); | |
252 WebTarget target = | |
253 client.target(baseUrl + "location/" + createdOrtId); | |
254 prot.addInfo("locationId", createdOrtId); | |
255 /* Request a kommentar with the id saved when created a kommentar*/ | |
256 Response response = target.request().get(); | |
257 String entity = response.readEntity(String.class); | |
258 /* Try to parse the response*/ | |
259 JsonReader reader = Json.createReader(new StringReader(entity)); | |
260 JsonObject oldObj = reader.readObject().getJsonObject("data"); | |
261 /* Change the text*/ | |
262 String updatedEntity = | |
263 oldObj.toString().replace("Neuer Ort", "Neuerer Ort"); | |
264 prot.addInfo("updated field", "beschreibung"); | |
265 prot.addInfo("updated value", "Neuer Ort"); | |
266 prot.addInfo("updated to", "Neuerer Ort"); | |
267 /* Send the updated kommentar via put reauest*/ | |
268 WebTarget putTarget = client.target(baseUrl + "location"); | |
269 Response updated = putTarget.request().put( | |
270 Entity.entity(updatedEntity, MediaType.APPLICATION_JSON)); | |
271 /* Try to parse the response*/ | |
272 JsonReader updatedReader = Json.createReader( | |
273 new StringReader(updated.readEntity(String.class))); | |
274 JsonObject updatedObj = updatedReader.readObject(); | |
275 /* Verify the response*/ | |
276 Assert.assertTrue(updatedObj.getBoolean("success")); | |
277 prot.addInfo("success", updatedObj.getBoolean("success")); | |
278 Assert.assertEquals("200", updatedObj.getString("message")); | |
279 prot.addInfo("message", updatedObj.getString("message")); | |
280 Assert.assertEquals("Neuerer Ort", | |
281 updatedObj.getJsonObject("data").getString("beschreibung")); | |
282 } | |
283 catch(JsonException je) { | |
284 prot.addInfo("exception", je.getMessage()); | |
285 Assert.fail(je.getMessage()); | |
286 } | |
287 prot.setPassed(true); | |
288 } | |
289 | |
290 @Test | |
291 @RunAsClient | |
292 public final void testLocation3DeleteService(@ArquillianResource URL baseUrl) | |
293 throws Exception { | |
294 System.out.print("."); | |
295 Protocol prot = new Protocol(); | |
296 prot.setName("locationService"); | |
297 prot.setType("delete"); | |
298 prot.setPassed(false); | |
299 testProtocol.add(prot); | |
300 try { | |
301 /* Create a client*/ | |
302 Client client = ClientBuilder.newClient(); | |
303 WebTarget target = | |
304 client.target(baseUrl + "location/" + createdOrtId); | |
305 prot.addInfo("locationId", createdOrtId); | |
306 /* Delete the object with the saved id*/ | |
307 Response response = target.request().delete(); | |
308 String entity = response.readEntity(String.class); | |
309 /* Try to parse the response*/ | |
310 JsonReader reader = Json.createReader(new StringReader(entity)); | |
311 JsonObject respObj = reader.readObject(); | |
312 /* Verify the response*/ | |
313 Assert.assertTrue(respObj.getBoolean("success")); | |
314 prot.addInfo("success", respObj.getBoolean("success")); | |
315 Assert.assertEquals("200", respObj.getString("message")); | |
316 prot.addInfo("message", respObj.getString("message")); | |
317 } | |
318 catch(JsonException je) { | |
319 prot.addInfo("exception", je.getMessage()); | |
320 Assert.fail(je.getMessage()); | |
321 } | |
322 prot.setPassed(true); | |
323 } | |
157 } | 324 } |