annotate src/test/java/de/intevation/lada/RestEasyClient.java @ 282:b99a129a659a

Fixed package name.
author Torsten Irländer <torsten.irlaender@intevation.de>
date Fri, 09 Aug 2013 11:34:26 +0200
parents cba1e9bef7c2
children
rev   line source
282
b99a129a659a Fixed package name.
Torsten Irländer <torsten.irlaender@intevation.de>
parents: 281
diff changeset
1 package de.intevation.lada;
273
cd78ec2f7d76 Add "get" tests for L*Service.
Ludwig Reiter <ludwig@intevation.de>
parents:
diff changeset
2
cd78ec2f7d76 Add "get" tests for L*Service.
Ludwig Reiter <ludwig@intevation.de>
parents:
diff changeset
3 import junit.framework.Assert;
cd78ec2f7d76 Add "get" tests for L*Service.
Ludwig Reiter <ludwig@intevation.de>
parents:
diff changeset
4 import org.junit.Test;
cd78ec2f7d76 Add "get" tests for L*Service.
Ludwig Reiter <ludwig@intevation.de>
parents:
diff changeset
5
cd78ec2f7d76 Add "get" tests for L*Service.
Ludwig Reiter <ludwig@intevation.de>
parents:
diff changeset
6 import org.jboss.resteasy.client.ClientRequest;
cd78ec2f7d76 Add "get" tests for L*Service.
Ludwig Reiter <ludwig@intevation.de>
parents:
diff changeset
7 import org.jboss.resteasy.client.ClientResponse;
cd78ec2f7d76 Add "get" tests for L*Service.
Ludwig Reiter <ludwig@intevation.de>
parents:
diff changeset
8
cd78ec2f7d76 Add "get" tests for L*Service.
Ludwig Reiter <ludwig@intevation.de>
parents:
diff changeset
9 public class RestEasyClient {
cd78ec2f7d76 Add "get" tests for L*Service.
Ludwig Reiter <ludwig@intevation.de>
parents:
diff changeset
10
280
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
11 public static String baseURL = "https://bfs-lada.intevation.de/lada/server/rest/";
274
2a8d816610c4 REST get test, check if the right (message 200) answer is given.
Ludwig Reiter <ludwig@intevation.de>
parents: 273
diff changeset
12
280
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
13 public ClientResponse<String> getResponse(String url, boolean header){
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
14 ClientRequest request = new ClientRequest(url);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
15 if(header)
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
16 request.header("Authorization", "Basic dGVzdGVpbnM6TjVKOENmSm5iOA==");
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
17 ClientResponse<String> response = null;
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
18 try {
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
19 response = request.get(String.class);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
20 }
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
21 catch(Exception e) {
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
22 e.printStackTrace();
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
23 }
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
24 return response;
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
25 }
273
cd78ec2f7d76 Add "get" tests for L*Service.
Ludwig Reiter <ludwig@intevation.de>
parents:
diff changeset
26
280
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
27 public void checkResponse(ClientResponse<String> response){
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
28 Assert.assertEquals(true, response.getEntity().contains("\"message\":\"200\""));
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
29 }
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
30
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
31 public void testHttpOK(String url) {
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
32 ClientResponse<String> response = getResponse(url, true);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
33 Assert.assertNotNull("Response shouldnot be null", response);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
34 Assert.assertEquals(200, response.getStatus());
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
35 checkResponse(response);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
36 }
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
37
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
38 public void testHttpForbidden(String url) {
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
39 ClientResponse<String> response = getResponse(url, false);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
40 Assert.assertNotNull("Response shouldnot be null", response);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
41 Assert.assertEquals(401, response.getStatus());
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
42 }
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
43
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
44 @Test
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
45 public void testLOrtService(){
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
46 testHttpOK(baseURL + "ort?probeId=000007587685X");
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
47 testHttpForbidden(baseURL + "ort");
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
48 ClientResponse<String> response = getResponse(baseURL + "ort/000007587685X", true);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
49 Assert.assertNotNull(response);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
50 Assert.assertEquals(404, response.getStatus());
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
51 }
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
52 @Test
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
53 public void testLMessKommentarService() {
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
54 testHttpOK(baseURL + "messkommentare?probeId=000007587685X&messungsId=1");
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
55 testHttpForbidden(baseURL + "messkommentare");
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
56 ClientResponse<String> response = getResponse(baseURL + "messkommentare/000007587685X", true);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
57 Assert.assertNotNull(response);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
58 Assert.assertEquals(404, response.getStatus());
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
59 }
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
60 @Test
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
61 public void testLKommentarService() {
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
62 testHttpOK(baseURL + "kommentare?probeId=000007587685X");
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
63 testHttpForbidden(baseURL + "kommentare");
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
64 ClientResponse<String> response = getResponse(baseURL + "kommentare/000007587685X", true);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
65 Assert.assertNotNull(response);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
66 Assert.assertEquals(404, response.getStatus());
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
67 }
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
68 @Test
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
69 public void testMessungService() {
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
70 testHttpOK(baseURL + "messung?probeId=000007587685X");
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
71 testHttpForbidden(baseURL + "messung");
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
72 ClientResponse<String> response = getResponse(baseURL + "messung/000007587685X", true);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
73 Assert.assertNotNull(response);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
74 Assert.assertEquals(404, response.getStatus());
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
75 }
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
76 @Test
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
77 public void testLMesswertService() {
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
78 testHttpOK(baseURL + "messwert?probeId=000007587685X&messungsId=1");
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
79 testHttpForbidden(baseURL + "messwert");
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
80 ClientResponse<String> response = getResponse(baseURL + "messungwert/000007587685X", true);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
81 Assert.assertNotNull(response);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
82 Assert.assertEquals(404, response.getStatus());
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
83 }
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
84 @Test
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
85 public void testLProbenService() {
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
86 testHttpOK(baseURL + "proben?mstId=06010&umwId=N24");
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
87 testHttpForbidden(baseURL + "proben?mstId=06010&umwId=N24");
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
88 ClientResponse<String> response = getResponse(baseURL + "proben/000007587685X", true);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
89 Assert.assertNotNull(response);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
90 Assert.assertEquals(200, response.getStatus());
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
91 checkResponse(response);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
92 }
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
93 @Test
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
94 public void testLStatusService() {
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
95 testHttpOK(baseURL + "status?probeId=000007587685X&messungsId=1");
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
96 testHttpForbidden(baseURL + "status");
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
97 ClientResponse<String> response = getResponse(baseURL + "status/000007587685X", true);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
98 Assert.assertNotNull(response);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
99 Assert.assertEquals(404, response.getStatus());
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
100 }
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
101 @Test
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
102 public void testLZusatzwertService() {
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
103 testHttpOK(baseURL + "zusatzwert?probeId=000007587685X");
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
104 testHttpForbidden(baseURL + "zusatzwert");
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
105 ClientResponse<String> response = getResponse(baseURL + "zusatzwert/000007587685X", true);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
106 Assert.assertNotNull(response);
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
107 Assert.assertEquals(404, response.getStatus());
0701c6b6182d Fixed indention
torsten
parents: 275
diff changeset
108 }
273
cd78ec2f7d76 Add "get" tests for L*Service.
Ludwig Reiter <ludwig@intevation.de>
parents:
diff changeset
109 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)