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