annotate src/test/java/de/intevation/lada/test/ServiceTest.java @ 840:2fe625c91ab3

Merged branches.
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 21 Jan 2016 09:01:57 +0100
parents cb1cfc8c81ed
children d0a591b3eade
rev   line source
834
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
1 package de.intevation.lada.test;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
2
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
3 import java.io.InputStream;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
4 import java.io.StringReader;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
5 import java.net.URL;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
6 import java.sql.Timestamp;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
7 import java.util.List;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
8 import java.util.Map.Entry;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
9 import java.util.Scanner;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
10
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
11 import javax.json.Json;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
12 import javax.json.JsonException;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
13 import javax.json.JsonObject;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
14 import javax.json.JsonObjectBuilder;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
15 import javax.json.JsonReader;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16 import javax.json.JsonValue;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
17 import javax.ws.rs.client.Client;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18 import javax.ws.rs.client.ClientBuilder;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
19 import javax.ws.rs.client.Entity;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
20 import javax.ws.rs.client.WebTarget;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
21 import javax.ws.rs.core.MediaType;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
22 import javax.ws.rs.core.Response;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24 import org.apache.commons.lang.WordUtils;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25 import org.junit.Assert;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
26
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
27 import de.intevation.lada.BaseTest;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
28 import de.intevation.lada.Protocol;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
29 import de.intevation.lada.test.land.ProbeTest;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
30
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
31 public class ServiceTest {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
33 protected List<Protocol> protocol;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
34
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
35 protected List<String> timestampAttributes;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
36
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
37 protected URL baseUrl;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
38
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
39 public void init(URL baseUrl, List<Protocol> protocol) {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
40 this.baseUrl = baseUrl;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
41 this.protocol = protocol;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
42 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
43
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
44 /**
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45 * @return The test protocol
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
46 */
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
47 public List<Protocol> getProtocol() {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
48 return protocol;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
49 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
50
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
51 protected JsonObject readJsonResource(String resource) {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
52 InputStream stream =
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
53 ProbeTest.class.getResourceAsStream(resource);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
54 Scanner scanner = new Scanner(stream, "UTF-8");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
55 scanner.useDelimiter("\\A");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
56 String raw = scanner.next();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
57 scanner.close();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
58 JsonReader reader = Json.createReader(new StringReader(raw));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
59 JsonObject content = reader.readObject();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
60 reader.close();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
61 return content;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
62 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
63
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
64 protected JsonObjectBuilder convertObject(JsonObject object) {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
65 JsonObjectBuilder builder = Json.createObjectBuilder();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
66 for (Entry<String, JsonValue> entry : object.entrySet()) {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
67 String key = WordUtils.capitalize(
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
68 entry.getKey(), new char[]{'_'}).replaceAll("_","");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
69 key = key.replaceFirst(key.substring(0, 1), key.substring(0, 1).toLowerCase());
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
70 if (timestampAttributes.contains(key)) {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
71 Timestamp timestamp = Timestamp.valueOf(entry.getValue().toString().replaceAll("\"", ""));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
72 builder.add(key, timestamp.getTime());
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
73 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
74 else {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
75 builder.add(key, entry.getValue());
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
76 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
77 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
78 return builder;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
79 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
80
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
81 public JsonObject getAll(String name, String parameter) {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
82 System.out.print(".");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
83 Protocol prot = new Protocol();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
84 prot.setName(name + " service");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
85 prot.setType("get all");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
86 prot.setPassed(false);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
87 protocol.add(prot);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
88 /* Create a client*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
89 Client client = ClientBuilder.newClient();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
90 WebTarget target = client.target(baseUrl + parameter);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
91 /* Request all objects*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
92 Response response = target.request()
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
93 .header("X-SHIB-user", BaseTest.TEST_USER)
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
94 .header("X-SHIB-roles", BaseTest.TEST_ROLES)
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
95 .get();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
96 String entity = response.readEntity(String.class);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
97 try{
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
98 /* Try to parse the response*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
99 JsonReader reader = Json.createReader(new StringReader(entity));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
100 JsonObject content = reader.readObject();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
101 /* Verify the response*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
102 Assert.assertTrue(content.getBoolean("success"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
103 prot.addInfo("success", content.getBoolean("success"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
104 Assert.assertEquals("200", content.getString("message"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
105 prot.addInfo("message", content.getString("message"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
106 Assert.assertNotNull(content.getJsonArray("data"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
107 prot.addInfo("objects", content.getJsonArray("data").size());
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
108 prot.setPassed(true);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
109 return content;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
110 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
111 catch(JsonException je) {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
112 prot.addInfo("exception", je.getMessage());
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
113 Assert.fail(je.getMessage());
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
114 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
115 return null;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
116 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
117 /**
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
118 * Test the GET Service by requesting a single object by id.
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
119 *
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
120 * @param baseUrl The url pointing to the test deployment.
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
121 */
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
122 public JsonObject getById(
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
123 String name,
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
124 String parameter,
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
125 JsonObject expected
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
126 ) {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
127 System.out.print(".");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
128 Protocol prot = new Protocol();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
129 prot.setName(name + " service");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
130 prot.setType("get by Id");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
131 prot.setPassed(false);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
132 protocol.add(prot);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
133 try {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
134 /* Create a client*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
135 Client client = ClientBuilder.newClient();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
136 WebTarget target = client.target(baseUrl + parameter);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
137 prot.addInfo("parameter", parameter);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
138 /* Request a object by id*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
139 Response response = target.request()
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
140 .header("X-SHIB-user", BaseTest.TEST_USER)
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
141 .header("X-SHIB-roles", BaseTest.TEST_ROLES)
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
142 .get();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
143 String entity = response.readEntity(String.class);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
144 /* Try to parse the response*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
145 JsonReader fromServiceReader =
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
146 Json.createReader(new StringReader(entity));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
147 JsonObject content = fromServiceReader.readObject();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
148 /* Verify the response*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
149 Assert.assertTrue(content.getBoolean("success"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
150 prot.addInfo("success", content.getBoolean("success"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
151 Assert.assertEquals("200", content.getString("message"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
152 prot.addInfo("message", content.getString("message"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
153 Assert.assertFalse(content.getJsonObject("data").isEmpty());
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
154 JsonObject object = content.getJsonObject("data");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
155 for (Entry<String, JsonValue> entry : expected.entrySet()) {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
156 if (entry.getKey().equals("parentModified") ||
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
157 entry.getKey().equals("treeModified")) {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
158 continue;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
159 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
160 Assert.assertEquals(entry.getValue(), object.get(entry.getKey()));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
161 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
162 prot.addInfo("object", "equals");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
163 prot.setPassed(true);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
164 return content;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
165 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
166 catch(JsonException je) {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
167 prot.addInfo("exception",je.getMessage());
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
168 Assert.fail(je.getMessage());
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
169 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
170 return null;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
171 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
172
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
173 /**
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
174 * Test the GET service using filters.
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
175 *
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
176 * @param baseUrl The url poining to the test deployment.
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
177 */
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
178 public JsonObject filter(String name, String parameter) {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
179 System.out.print(".");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
180 Protocol prot = new Protocol();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
181 prot.setName(name + " service");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
182 prot.setType("filter");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
183 prot.setPassed(false);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
184 protocol.add(prot);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
185 try {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
186 /* Create a client*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
187 Client client = ClientBuilder.newClient();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
188 WebTarget target =
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
189 client.target(baseUrl + parameter);//"probe?qid=2&mst_id=11010&umw_id=N24");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
190 prot.addInfo("filter", parameter);//"qid=2&mst_id=11010&umw_id=N24");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
191 /* Request the objects using the filter*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
192 Response response = target.request()
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
193 .header("X-SHIB-user", BaseTest.TEST_USER)
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
194 .header("X-SHIB-roles", BaseTest.TEST_ROLES)
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
195 .get();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
196 String entity = response.readEntity(String.class);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
197 /* Try to parse the response*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
198 JsonReader reader = Json.createReader(new StringReader(entity));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
199 JsonObject content = reader.readObject();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
200 /* Verify the response*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
201 Assert.assertTrue(content.getBoolean("success"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
202 prot.addInfo("success", content.getBoolean("success"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
203 Assert.assertEquals("200", content.getString("message"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
204 prot.addInfo("message", content.getString("message"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
205 Assert.assertNotNull(content.getJsonArray("data"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
206 prot.addInfo("objects", content.getJsonArray("data").size());
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
207 prot.setPassed(true);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
208 return content;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
209 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
210 catch(JsonException je) {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
211 prot.addInfo("exception", je.getMessage());
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
212 Assert.fail(je.getMessage());
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
213 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
214 return null;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
215 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
216
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
217 /**
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
218 * Test the CREATE Service.
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
219 *
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
220 * @param baseUrl The url pointing to the test deployment.
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
221 */
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
222 public JsonObject create(String name, String parameter, JsonObject create) {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
223 System.out.print(".");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
224 Protocol prot = new Protocol();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
225 prot.setName(name + " service");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
226 prot.setType("create");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
227 prot.setPassed(false);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
228 protocol.add(prot);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
229 try {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
230 /* Create a client*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
231 Client client = ClientBuilder.newClient();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
232 WebTarget target = client.target(baseUrl + parameter);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
233 /* Send a post request containing a new probe*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
234 Response response = target.request()
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
235 .header("X-SHIB-user", BaseTest.TEST_USER)
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
236 .header("X-SHIB-roles", BaseTest.TEST_ROLES)
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
237 .post(Entity.entity(create.toString(), MediaType.APPLICATION_JSON));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
238 String entity = response.readEntity(String.class);
840
2fe625c91ab3 Merged branches.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 834
diff changeset
239 System.out.println(entity);
834
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
240 /* Try to parse the response*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
241 JsonReader fromServiceReader =
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
242 Json.createReader(new StringReader(entity));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
243 JsonObject content = fromServiceReader.readObject();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
244 /* Verify the response*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
245 Assert.assertTrue(content.getBoolean("success"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
246 prot.addInfo("success", content.getBoolean("success"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
247 Assert.assertEquals("200", content.getString("message"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
248 prot.addInfo("message", content.getString("message"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
249 prot.setPassed(true);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
250 return content;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
251 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
252 catch(JsonException je) {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
253 prot.addInfo("exception", je.getMessage());
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
254 Assert.fail(je.getMessage());
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
255 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
256 return null;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
257 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
258
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
259 /**
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
260 * Test the probe update service.
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
261 *
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
262 * @param baseUrl The url pointing to the test deployment.
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
263 */
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
264 public JsonObject update(
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
265 String name,
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
266 String parameter,
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
267 String updateAttribute,
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
268 String oldValue,
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
269 String newValue
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
270 ) {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
271 System.out.print(".");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
272 Protocol prot = new Protocol();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
273 prot.setName(name + " service");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
274 prot.setType("update");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
275 prot.setPassed(false);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
276 protocol.add(prot);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
277 try {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
278 /* Create a client*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
279 Client client = ClientBuilder.newClient();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
280 WebTarget target = client.target(baseUrl + parameter);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
281 /* Request a with the saved id*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
282 Response response = target.request()
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
283 .header("X-SHIB-user", BaseTest.TEST_USER)
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
284 .header("X-SHIB-roles", BaseTest.TEST_ROLES)
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
285 .get();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
286 String entity = response.readEntity(String.class);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
287 /* Try to parse the response*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
288 JsonReader reader = Json.createReader(new StringReader(entity));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
289 JsonObject oldObject = reader.readObject().getJsonObject("data");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
290 /* Change the hauptprobenNr*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
291 String updatedEntity =
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
292 oldObject.toString().replace(oldValue, newValue);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
293 prot.addInfo("updated datafield", updateAttribute);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
294 prot.addInfo("updated value", oldValue);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
295 prot.addInfo("updated to", newValue);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
296 /* Send the updated probe via put request*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
297 WebTarget putTarget = client.target(baseUrl + parameter);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
298 Response updated = putTarget.request()
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
299 .header("X-SHIB-user", BaseTest.TEST_USER)
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
300 .header("X-SHIB-roles", BaseTest.TEST_ROLES)
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
301 .put(Entity.entity(updatedEntity, MediaType.APPLICATION_JSON));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
302 /* Try to parse the response*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
303 JsonReader updatedReader = Json.createReader(
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
304 new StringReader(updated.readEntity(String.class)));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
305 JsonObject updatedObject = updatedReader.readObject();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
306 /* Verify the response*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
307 Assert.assertTrue(updatedObject.getBoolean("success"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
308 prot.addInfo("success", updatedObject.getBoolean("success"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
309 Assert.assertEquals("200", updatedObject.getString("message"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
310 prot.addInfo("message", updatedObject.getString("message"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
311 Assert.assertEquals(newValue,
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
312 updatedObject.getJsonObject("data").getString(updateAttribute));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
313 prot.setPassed(true);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
314 return updatedObject;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
315 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
316 catch(JsonException je) {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
317 prot.addInfo("exception", je.getMessage());
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
318 Assert.fail(je.getMessage());
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
319 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
320 return null;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
321 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
322
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
323 /**
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
324 * Test the DELETE Service.
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
325 *
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
326 * @param baseUrl The url pointing to the test deployment.
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
327 */
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
328 public JsonObject delete(String name, String parameter) {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
329 System.out.print(".");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
330 Protocol prot = new Protocol();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
331 prot.setName(name + " service");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
332 prot.setType("delete");
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
333 prot.setPassed(false);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
334 protocol.add(prot);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
335 try {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
336 /* Create a client*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
337 Client client = ClientBuilder.newClient();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
338 WebTarget target =
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
339 client.target(baseUrl + parameter);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
340 prot.addInfo("parameter", parameter);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
341 /* Delete a probe with the id saved when created a probe*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
342 Response response = target.request()
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
343 .header("X-SHIB-user", BaseTest.TEST_USER)
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
344 .header("X-SHIB-roles", BaseTest.TEST_ROLES)
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
345 .delete();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
346 String entity = response.readEntity(String.class);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
347 /* Try to parse the response*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
348 JsonReader reader = Json.createReader(new StringReader(entity));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
349 JsonObject content = reader.readObject();
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
350 /* Verify the response*/
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
351 Assert.assertTrue(content.getBoolean("success"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
352 prot.addInfo("success", content.getBoolean("success"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
353 Assert.assertEquals("200", content.getString("message"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
354 prot.addInfo("message", content.getString("message"));
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
355 prot.setPassed(true);
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
356 return content;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
357 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
358 catch(JsonException je) {
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
359 prot.addInfo("exception", je.getMessage());
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
360 Assert.fail(je.getMessage());
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
361 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
362 return null;
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
363 }
cb1cfc8c81ed Moved base class for tests to package 'test'.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
364 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)