changeset 273:cd78ec2f7d76

Add "get" tests for L*Service. Requires a running test server and the unit-tests profile.
author Ludwig Reiter <ludwig@intevation.de>
date Thu, 25 Jul 2013 15:50:42 +0200
parents 0ddcc6240d47
children 2a8d816610c4
files pom.xml src/main/java/de/intevation/lada/test/RestEasyClient.java
diffstat 2 files changed, 121 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/pom.xml	Thu Jul 25 14:23:44 2013 +0200
+++ b/pom.xml	Thu Jul 25 15:50:42 2013 +0200
@@ -161,7 +161,6 @@
             <artifactId>arquillian-protocol-servlet</artifactId>
             <scope>test</scope>
         </dependency>
-
     </dependencies>
 
     <build>
@@ -274,6 +273,26 @@
                 </plugins>
             </build>
         </profile>
-
+        <profile>
+        	<id>unit-tests</id>
+        	<dependencies>
+                <dependency>
+                   <groupId>junit</groupId>
+                   <artifactId>junit</artifactId>
+                   <version>4.10</version>
+                   <scope>test</scope>
+            </dependency>
+            <dependency>
+                   <groupId>org.jboss.resteasy</groupId>
+                   <artifactId>resteasy-jaxrs</artifactId>
+                   <version>2.2.2.GA</version>
+            </dependency>
+            <dependency>
+                 <groupId>org.apache.httpcomponents</groupId>
+                 <artifactId>httpcore</artifactId>
+                 <version>4.1.4</version>
+            </dependency>
+            </dependencies>
+        </profile>  
     </profiles>
 </project>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/test/RestEasyClient.java	Thu Jul 25 15:50:42 2013 +0200
@@ -0,0 +1,100 @@
+package de.intevation.lada.test;
+
+import junit.framework.Assert;
+import org.junit.Test;
+
+import org.jboss.resteasy.client.ClientRequest;
+import org.jboss.resteasy.client.ClientResponse;
+
+public class RestEasyClient {
+
+	public static String baseURL = "https://bfs-lada.intevation.de/lada/server/rest/";
+/*	
+	@Test
+	public void test2() {
+		String url = "https://bfs-lada.intevation.de/lada/server/rest/proben?mstId=06010&umwId=N24";
+		ClientRequest request = new ClientRequest(url);
+		request.header("Authorization", "Basic dGVzdGVpbnM6TjVKOENmSm5iOA==");
+		request.accept(MediaType.WILDCARD_TYPE);
+		
+		ClientResponse<String> response;
+		boolean get_error = false;
+		try {
+			response = request.get(String.class);
+			Assert.assertEquals(200,response.getStatus());
+			System.out.println(response.getEntity(String.class));
+		} catch (Exception e) {
+			get_error = true;
+			e.printStackTrace();
+		}
+		Assert.assertEquals(false, get_error);
+	}
+*/
+public ClientResponse<String> getResponse(String url, boolean header){
+	ClientRequest request = new ClientRequest(url);
+	if(header)
+		request.header("Authorization", "Basic dGVzdGVpbnM6TjVKOENmSm5iOA==");
+	ClientResponse<String> response = null;
+	try {
+		response = request.get(String.class);
+	}
+	catch(Exception e) {
+		e.printStackTrace();
+	}
+	return response;
+}
+
+public void testHttpOK(String url) {
+	ClientResponse<String> response = getResponse(url, true);
+	Assert.assertNotNull("Response shouldnot be null", response);
+	Assert.assertEquals(200, response.getStatus());
+}
+
+public void testHttpForbidden(String url) {
+	ClientResponse<String> response = getResponse(url, false);
+	Assert.assertNotNull("Response shouldnot be null", response);
+	Assert.assertEquals(401, response.getStatus());
+}
+
+@Test
+public void testLOrtService(){
+	testHttpOK(baseURL + "ort");
+	testHttpForbidden(baseURL + "ort");
+}
+@Test
+public void testLMessKommentarService() {
+	testHttpOK(baseURL + "messkommentare");
+	testHttpForbidden(baseURL + "messkommentare");
+}
+@Test
+public void testLKommentarService() {
+	testHttpOK(baseURL + "kommentare");
+	testHttpForbidden(baseURL + "kommentare");
+}
+@Test
+public void testMessungService() {
+	testHttpOK(baseURL + "messung");
+	testHttpForbidden(baseURL + "messung");
+}
+@Test
+public void testLMesswertService() {
+	testHttpOK(baseURL + "messwert");
+	testHttpForbidden(baseURL + "messwert");
+}
+@Test
+public void testLProbenService() {
+	testHttpOK(baseURL + "proben?mstId=06010&umwId=N24");
+	testHttpForbidden(baseURL + "proben?mstId=06010&umwId=N24");
+}
+@Test
+public void testLStatusService() {
+	testHttpOK(baseURL + "status");
+	testHttpForbidden(baseURL + "status");
+}
+@Test
+public void testLZusatzwertService() {
+	testHttpOK(baseURL + "zusatzwert");
+	testHttpForbidden(baseURL + "zusatzwert");
+}
+
+}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)