[jboss-cvs] JBossAS SVN: r105683 - in trunk/resteasy-int/test/application-war/src: test/java/org/jboss/resteasy/test/jboss and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jun 3 18:36:09 EDT 2010
Author: bill.burke at jboss.com
Date: 2010-06-03 18:36:08 -0400 (Thu, 03 Jun 2010)
New Revision: 105683
Modified:
trunk/resteasy-int/test/application-war/src/main/java/org/jboss/resteasy/test/smoke/AppConfig.java
trunk/resteasy-int/test/application-war/src/main/java/org/jboss/resteasy/test/smoke/MyApplicationConfig.java
trunk/resteasy-int/test/application-war/src/test/java/org/jboss/resteasy/test/jboss/AppConfigTest.java
Log:
Modified: trunk/resteasy-int/test/application-war/src/main/java/org/jboss/resteasy/test/smoke/AppConfig.java
===================================================================
--- trunk/resteasy-int/test/application-war/src/main/java/org/jboss/resteasy/test/smoke/AppConfig.java 2010-06-03 22:35:51 UTC (rev 105682)
+++ trunk/resteasy-int/test/application-war/src/main/java/org/jboss/resteasy/test/smoke/AppConfig.java 2010-06-03 22:36:08 UTC (rev 105683)
@@ -6,16 +6,14 @@
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
/**
* @author <a href="mailto:bill at burkecentral.com">Bill Burke</a>
@@ -32,12 +30,54 @@
{
return "hello";
}
+
+ @GET
+ @Path("exception")
+ public String getException()
+ {
+ throw new FooException();
+ }
+
+ @GET
+ @Path("exception/count")
+ @Produces("text/plain")
+ public String getCount()
+ {
+ return Integer.toString(FooExceptionMapper.num_instantiations);
+ }
}
+ public static class FooException extends RuntimeException
+ {
+ }
+
@Provider
+ public static class FooExceptionMapper implements ExceptionMapper<FooException>
+ {
+ public static int num_instantiations = 0;
+
+ public FooExceptionMapper()
+ {
+ num_instantiations++;
+ }
+
+ public Response toResponse(FooException exception)
+ {
+ return Response.status(412).build();
+ }
+ }
+
+ @Provider
@Produces("text/quoted")
public static class QuotedTextWriter implements MessageBodyWriter<String>
{
+ public static int num_instantiations = 0;
+
+ public QuotedTextWriter()
+ {
+ num_instantiations++;
+ }
+
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType)
{
return type.equals(String.class);
Modified: trunk/resteasy-int/test/application-war/src/main/java/org/jboss/resteasy/test/smoke/MyApplicationConfig.java
===================================================================
--- trunk/resteasy-int/test/application-war/src/main/java/org/jboss/resteasy/test/smoke/MyApplicationConfig.java 2010-06-03 22:35:51 UTC (rev 105682)
+++ trunk/resteasy-int/test/application-war/src/main/java/org/jboss/resteasy/test/smoke/MyApplicationConfig.java 2010-06-03 22:36:08 UTC (rev 105683)
@@ -1,20 +1,7 @@
package org.jboss.resteasy.test.smoke;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Application;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.ext.MessageBodyWriter;
-import javax.ws.rs.ext.Provider;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.HashMap;
import java.util.HashSet;
-import java.util.Map;
import java.util.Set;
/**
@@ -30,6 +17,7 @@
{
classes.add(AppConfig.MyResource.class);
singletons.add(new AppConfig.QuotedTextWriter());
+ singletons.add(new AppConfig.FooExceptionMapper());
}
public Set<Class<?>> getClasses()
Modified: trunk/resteasy-int/test/application-war/src/test/java/org/jboss/resteasy/test/jboss/AppConfigTest.java
===================================================================
--- trunk/resteasy-int/test/application-war/src/test/java/org/jboss/resteasy/test/jboss/AppConfigTest.java 2010-06-03 22:35:51 UTC (rev 105682)
+++ trunk/resteasy-int/test/application-war/src/test/java/org/jboss/resteasy/test/jboss/AppConfigTest.java 2010-06-03 22:36:08 UTC (rev 105683)
@@ -1,28 +1,14 @@
package org.jboss.resteasy.test.jboss;
-import org.junit.BeforeClass;
-import org.junit.AfterClass;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.jboss.resteasy.client.ClientRequest;
+import org.jboss.resteasy.client.ClientResponse;
+import org.jboss.resteasy.util.HttpResponseCodes;
import org.junit.Assert;
import org.junit.Test;
-import org.jboss.resteasy.util.HttpResponseCodes;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.methods.GetMethod;
-import javax.ws.rs.Path;
-import javax.ws.rs.GET;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.ext.Provider;
-import javax.ws.rs.ext.MessageBodyWriter;
-import java.lang.reflect.Type;
-import java.lang.annotation.Annotation;
-import java.io.OutputStream;
import java.io.IOException;
-import java.util.Set;
-import java.util.Map;
-import java.util.HashSet;
-import java.util.HashMap;
/**
* @author <a href="mailto:bill at burkecentral.com">Bill Burke</a>
@@ -56,4 +42,24 @@
HttpClient client = new HttpClient();
_test(client, "http://localhost:8080/application-config-test/my", "\"hello\"");
}
+
+ @Test
+ public void testSingletons() throws Exception
+ {
+ ClientRequest request = new ClientRequest("http://localhost:8080/application-config-test/my/exception");
+ ClientResponse response = request.get();
+ Assert.assertEquals(412, response.getStatus());
+
+ ClientRequest countRequest = new ClientRequest("http://localhost:8080/application-config-test/my/exception/count");
+ String res = countRequest.getTarget(String.class);
+ Assert.assertEquals("1", res);
+
+ request.clear();
+ response = request.get();
+ Assert.assertEquals(412, response.getStatus());
+
+ countRequest.clear();
+ res = countRequest.getTarget(String.class);
+ Assert.assertEquals("1", res);
+ }
}
More information about the jboss-cvs-commits
mailing list