comparison src/test/java/de/intevation/lada/test/ServiceTest.java @ 1241:95d04f56266d

Cleanup comments.
author Tom Gottfried <tom@intevation.de>
date Thu, 15 Dec 2016 12:42:20 +0100
parents 59bdb52bac1c
children b652f4c9b75c
comparison
equal deleted inserted replaced
1240:961d50dde3c2 1241:95d04f56266d
157 return null; 157 return null;
158 } 158 }
159 /** 159 /**
160 * Test the GET Service by requesting a single object by id. 160 * Test the GET Service by requesting a single object by id.
161 * 161 *
162 * @param baseUrl The url pointing to the test deployment.
163 */ 162 */
164 public JsonObject getById( 163 public JsonObject getById(
165 String name, 164 String name,
166 String parameter, 165 String parameter,
167 JsonObject expected 166 JsonObject expected
216 } 215 }
217 216
218 /** 217 /**
219 * Test the GET service using filters. 218 * Test the GET service using filters.
220 * 219 *
221 * @param baseUrl The url poining to the test deployment.
222 */ 220 */
223 public JsonObject filter(String name, String parameter) { 221 public JsonObject filter(String name, String parameter) {
224 System.out.print("."); 222 System.out.print(".");
225 Protocol prot = new Protocol(); 223 Protocol prot = new Protocol();
226 prot.setName(name + " service"); 224 prot.setName(name + " service");
228 prot.setPassed(false); 226 prot.setPassed(false);
229 protocol.add(prot); 227 protocol.add(prot);
230 /* Create a client*/ 228 /* Create a client*/
231 Client client = ClientBuilder.newClient(); 229 Client client = ClientBuilder.newClient();
232 WebTarget target = 230 WebTarget target =
233 client.target(baseUrl + parameter);//"probe?qid=2&mst_id=11010&umw_id=N24"); 231 client.target(baseUrl + parameter);
234 prot.addInfo("filter", parameter);//"qid=2&mst_id=11010&umw_id=N24"); 232 prot.addInfo("filter", parameter);
235 /* Request the objects using the filter*/ 233 /* Request the objects using the filter*/
236 Response response = target.request() 234 Response response = target.request()
237 .header("X-SHIB-user", BaseTest.TEST_USER) 235 .header("X-SHIB-user", BaseTest.TEST_USER)
238 .header("X-SHIB-roles", BaseTest.TEST_ROLES) 236 .header("X-SHIB-roles", BaseTest.TEST_ROLES)
239 .get(); 237 .get();
262 } 260 }
263 261
264 /** 262 /**
265 * Test the CREATE Service. 263 * Test the CREATE Service.
266 * 264 *
267 * @param baseUrl The url pointing to the test deployment.
268 */ 265 */
269 public JsonObject create(String name, String parameter, JsonObject create) { 266 public JsonObject create(String name, String parameter, JsonObject create) {
270 System.out.print("."); 267 System.out.print(".");
271 Protocol prot = new Protocol(); 268 Protocol prot = new Protocol();
272 prot.setName(name + " service"); 269 prot.setName(name + " service");
274 prot.setPassed(false); 271 prot.setPassed(false);
275 protocol.add(prot); 272 protocol.add(prot);
276 /* Create a client*/ 273 /* Create a client*/
277 Client client = ClientBuilder.newClient(); 274 Client client = ClientBuilder.newClient();
278 WebTarget target = client.target(baseUrl + parameter); 275 WebTarget target = client.target(baseUrl + parameter);
279 /* Send a post request containing a new probe*/ 276 /* Send a post request containing a new object*/
280 Response response = target.request() 277 Response response = target.request()
281 .header("X-SHIB-user", BaseTest.TEST_USER) 278 .header("X-SHIB-user", BaseTest.TEST_USER)
282 .header("X-SHIB-roles", BaseTest.TEST_ROLES) 279 .header("X-SHIB-roles", BaseTest.TEST_ROLES)
283 .post(Entity.entity(create.toString(), MediaType.APPLICATION_JSON)); 280 .post(Entity.entity(create.toString(), MediaType.APPLICATION_JSON));
284 String entity = response.readEntity(String.class); 281 String entity = response.readEntity(String.class);
303 } 300 }
304 return null; 301 return null;
305 } 302 }
306 303
307 /** 304 /**
308 * Test the probe update service. 305 * Test an update service.
309 * 306 *
310 * @param baseUrl The url pointing to the test deployment.
311 */ 307 */
312 public JsonObject update( 308 public JsonObject update(
313 String name, 309 String name,
314 String parameter, 310 String parameter,
315 String updateAttribute, 311 String updateAttribute,
324 protocol.add(prot); 320 protocol.add(prot);
325 try { 321 try {
326 /* Create a client*/ 322 /* Create a client*/
327 Client client = ClientBuilder.newClient(); 323 Client client = ClientBuilder.newClient();
328 WebTarget target = client.target(baseUrl + parameter); 324 WebTarget target = client.target(baseUrl + parameter);
329 /* Request a with the saved id*/ 325 /* Request object corresponding to id in URL */
330 Response response = target.request() 326 Response response = target.request()
331 .header("X-SHIB-user", BaseTest.TEST_USER) 327 .header("X-SHIB-user", BaseTest.TEST_USER)
332 .header("X-SHIB-roles", BaseTest.TEST_ROLES) 328 .header("X-SHIB-roles", BaseTest.TEST_ROLES)
333 .get(); 329 .get();
334 String entity = response.readEntity(String.class); 330 String entity = response.readEntity(String.class);
335 /* Try to parse the response*/ 331 /* Try to parse the response*/
336 JsonReader reader = Json.createReader(new StringReader(entity)); 332 JsonReader reader = Json.createReader(new StringReader(entity));
337 JsonObject oldObject = reader.readObject().getJsonObject("data"); 333 JsonObject oldObject = reader.readObject().getJsonObject("data");
338 /* Change the hauptprobenNr*/ 334
335 /* Value replacement */
339 String updatedEntity = 336 String updatedEntity =
340 oldObject.toString().replace(oldValue, newValue); 337 oldObject.toString().replace(oldValue, newValue);
341 prot.addInfo("updated datafield", updateAttribute); 338 prot.addInfo("updated datafield", updateAttribute);
342 prot.addInfo("updated value", oldValue); 339 prot.addInfo("updated value", oldValue);
343 prot.addInfo("updated to", newValue); 340 prot.addInfo("updated to", newValue);
344 /* Send the updated probe via put request*/ 341
342 /* Send modified object via put request*/
345 WebTarget putTarget = client.target(baseUrl + parameter); 343 WebTarget putTarget = client.target(baseUrl + parameter);
346 Response updated = putTarget.request() 344 Response updated = putTarget.request()
347 .header("X-SHIB-user", BaseTest.TEST_USER) 345 .header("X-SHIB-user", BaseTest.TEST_USER)
348 .header("X-SHIB-roles", BaseTest.TEST_ROLES) 346 .header("X-SHIB-roles", BaseTest.TEST_ROLES)
349 .put(Entity.entity(updatedEntity, MediaType.APPLICATION_JSON)); 347 .put(Entity.entity(updatedEntity, MediaType.APPLICATION_JSON));
348
350 /* Try to parse the response*/ 349 /* Try to parse the response*/
351 JsonReader updatedReader = Json.createReader( 350 JsonReader updatedReader = Json.createReader(
352 new StringReader(updated.readEntity(String.class))); 351 new StringReader(updated.readEntity(String.class)));
353 JsonObject updatedObject = updatedReader.readObject(); 352 JsonObject updatedObject = updatedReader.readObject();
354 /* Verify the response*/ 353 /* Verify the response*/
371 } 370 }
372 371
373 /** 372 /**
374 * Test the DELETE Service. 373 * Test the DELETE Service.
375 * 374 *
376 * @param baseUrl The url pointing to the test deployment.
377 */ 375 */
378 public JsonObject delete(String name, String parameter) { 376 public JsonObject delete(String name, String parameter) {
379 System.out.print("."); 377 System.out.print(".");
380 Protocol prot = new Protocol(); 378 Protocol prot = new Protocol();
381 prot.setName(name + " service"); 379 prot.setName(name + " service");
385 /* Create a client*/ 383 /* Create a client*/
386 Client client = ClientBuilder.newClient(); 384 Client client = ClientBuilder.newClient();
387 WebTarget target = 385 WebTarget target =
388 client.target(baseUrl + parameter); 386 client.target(baseUrl + parameter);
389 prot.addInfo("parameter", parameter); 387 prot.addInfo("parameter", parameter);
390 /* Delete a probe with the id saved when created a probe*/ 388 /* Delete object with ID given in URL */
391 Response response = target.request() 389 Response response = target.request()
392 .header("X-SHIB-user", BaseTest.TEST_USER) 390 .header("X-SHIB-user", BaseTest.TEST_USER)
393 .header("X-SHIB-roles", BaseTest.TEST_ROLES) 391 .header("X-SHIB-roles", BaseTest.TEST_ROLES)
394 .delete(); 392 .delete();
395 String entity = response.readEntity(String.class); 393 String entity = response.readEntity(String.class);
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)