[jboss-cvs] JBossAS SVN: r110695 - in trunk/resteasy-int/test/cdi-test-2: src/main/java/org/jboss/resteasy/cdi/test/basic and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Feb 17 08:31:55 EST 2011
Author: jharting
Date: 2011-02-17 08:31:54 -0500 (Thu, 17 Feb 2011)
New Revision: 110695
Added:
trunk/resteasy-int/test/cdi-test-2/src/main/java/org/jboss/resteasy/cdi/test/interceptor/resteasy/
trunk/resteasy-int/test/cdi-test-2/src/main/java/org/jboss/resteasy/cdi/test/interceptor/resteasy/ResteasyInterceptor.java
trunk/resteasy-int/test/cdi-test-2/src/test/java/org/jboss/resteasy/cdi/test/ResteasyInterceptorTest.java
Modified:
trunk/resteasy-int/test/cdi-test-2/pom.xml
trunk/resteasy-int/test/cdi-test-2/src/main/java/org/jboss/resteasy/cdi/test/basic/TestProvider.java
trunk/resteasy-int/test/cdi-test-2/src/main/java/org/jboss/resteasy/cdi/test/basic/TestResource.java
trunk/resteasy-int/test/cdi-test-2/src/test/java/org/jboss/resteasy/cdi/test/AbstractProviderTest.java
trunk/resteasy-int/test/cdi-test-2/src/test/java/org/jboss/resteasy/cdi/test/BeanClassLocalViewEjbProviderTest.java
trunk/resteasy-int/test/cdi-test-2/src/test/java/org/jboss/resteasy/cdi/test/ProviderTest.java
trunk/resteasy-int/test/cdi-test-2/src/test/java/org/jboss/resteasy/cdi/test/SingletonProviderTest.java
Log:
Added tests for RESTEasy interceptors.
Modified: trunk/resteasy-int/test/cdi-test-2/pom.xml
===================================================================
--- trunk/resteasy-int/test/cdi-test-2/pom.xml 2011-02-17 09:33:12 UTC (rev 110694)
+++ trunk/resteasy-int/test/cdi-test-2/pom.xml 2011-02-17 13:31:54 UTC (rev 110695)
@@ -5,7 +5,7 @@
<parent>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-as-parent</artifactId>
- <version>6.1.0-SNAPSHOT</version>
+ <version>6.0.0.Final</version>
</parent>
<artifactId>resteasy-cdi-test</artifactId>
Modified: trunk/resteasy-int/test/cdi-test-2/src/main/java/org/jboss/resteasy/cdi/test/basic/TestProvider.java
===================================================================
--- trunk/resteasy-int/test/cdi-test-2/src/main/java/org/jboss/resteasy/cdi/test/basic/TestProvider.java 2011-02-17 09:33:12 UTC (rev 110694)
+++ trunk/resteasy-int/test/cdi-test-2/src/main/java/org/jboss/resteasy/cdi/test/basic/TestProvider.java 2011-02-17 13:31:54 UTC (rev 110695)
@@ -8,6 +8,7 @@
import java.lang.reflect.Type;
import javax.inject.Inject;
+import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
@@ -31,7 +32,7 @@
private Cat initializerCat;
@Context
private Providers providers;
-
+
public TestProvider()
{
}
@@ -41,13 +42,13 @@
{
constructorCat = cat;
}
-
+
@Inject
public void init(Cat cat)
{
initializerCat = cat;
}
-
+
public long getSize(Dog t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType)
{
return -1;
@@ -61,11 +62,33 @@
public void writeTo(Dog t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException
{
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(entityStream));
- bw.write("CDI field injection: " + (cat != null));
- bw.write("\nCDI constructor injection: " + (constructorCat != null));
- bw.write("\nCDI initializer injection: " + (initializerCat != null));
- bw.write("\nJAX-RS field injection: " + (providers != null));
- bw.write("\nProvider toString(): " + toString());
+
+ if (printProviderInjectionInformation(annotations))
+ {
+ bw.write("CDI-enabled Provider");
+ bw.write("\nCDI field injection: " + (cat != null));
+ bw.write("\nCDI constructor injection: " + (constructorCat != null));
+ bw.write("\nCDI initializer injection: " + (initializerCat != null));
+ bw.write("\nJAX-RS field injection: " + (providers != null));
+ bw.write("\nProvider toString(): " + toString());
+ }
+
bw.flush();
}
+
+ private boolean printProviderInjectionInformation(Annotation[] annotations)
+ {
+ for (Annotation annotation : annotations)
+ {
+ if (Path.class.isAssignableFrom(annotation.annotationType()))
+ {
+ Path path = (Path) annotation;
+ if ("/resteasyInterceptor".equals(path.value()))
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
}
Modified: trunk/resteasy-int/test/cdi-test-2/src/main/java/org/jboss/resteasy/cdi/test/basic/TestResource.java
===================================================================
--- trunk/resteasy-int/test/cdi-test-2/src/main/java/org/jboss/resteasy/cdi/test/basic/TestResource.java 2011-02-17 09:33:12 UTC (rev 110694)
+++ trunk/resteasy-int/test/cdi-test-2/src/main/java/org/jboss/resteasy/cdi/test/basic/TestResource.java 2011-02-17 13:31:54 UTC (rev 110695)
@@ -118,6 +118,13 @@
return new Dog();
}
+ @GET
+ @Path("/resteasyInterceptor")
+ public Dog testResteasyInterceptor()
+ {
+ return new Dog();
+ }
+
@Context
public void setSetterUriInfo(UriInfo setterUriInfo)
{
Added: trunk/resteasy-int/test/cdi-test-2/src/main/java/org/jboss/resteasy/cdi/test/interceptor/resteasy/ResteasyInterceptor.java
===================================================================
--- trunk/resteasy-int/test/cdi-test-2/src/main/java/org/jboss/resteasy/cdi/test/interceptor/resteasy/ResteasyInterceptor.java (rev 0)
+++ trunk/resteasy-int/test/cdi-test-2/src/main/java/org/jboss/resteasy/cdi/test/interceptor/resteasy/ResteasyInterceptor.java 2011-02-17 13:31:54 UTC (rev 110695)
@@ -0,0 +1,81 @@
+package org.jboss.resteasy.cdi.test.interceptor.resteasy;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.lang.annotation.Annotation;
+
+import javax.inject.Inject;
+import javax.ws.rs.Path;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.Providers;
+
+import org.jboss.resteasy.annotations.interception.ServerInterceptor;
+import org.jboss.resteasy.cdi.test.Cat;
+import org.jboss.resteasy.spi.interception.MessageBodyWriterContext;
+import org.jboss.resteasy.spi.interception.MessageBodyWriterInterceptor;
+
+ at Provider
+ at ServerInterceptor
+public class ResteasyInterceptor implements MessageBodyWriterInterceptor
+{
+
+ @Inject
+ private Cat cat;
+ private Cat constructorCat;
+ private Cat initializerCat;
+ @Context
+ private Providers providers;
+
+ public ResteasyInterceptor()
+ {
+ }
+
+ @Inject
+ public ResteasyInterceptor(Cat cat)
+ {
+ constructorCat = cat;
+ }
+
+ @Inject
+ public void init(Cat cat)
+ {
+ initializerCat = cat;
+ }
+
+ public void write(MessageBodyWriterContext context) throws IOException, WebApplicationException
+ {
+ context.proceed();
+
+ if (!printProviderInjectionInformation(context.getAnnotations()))
+ {
+
+ BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(context.getOutputStream()));
+ bw.write("CDI-enabled RESTEasy Interceptor");
+ bw.write("\nCDI field injection: " + (cat != null));
+ bw.write("\nCDI constructor injection: " + (constructorCat != null));
+ bw.write("\nCDI initializer injection: " + (initializerCat != null));
+ bw.write("\nJAX-RS field injection: " + (providers != null));
+ bw.write("\nProvider toString(): " + toString());
+ bw.flush();
+ }
+ }
+
+ private boolean printProviderInjectionInformation(Annotation[] annotations)
+ {
+ for (Annotation annotation : annotations)
+ {
+ if (Path.class.isAssignableFrom(annotation.annotationType()))
+ {
+ Path path = (Path) annotation;
+ if ("/resteasyInterceptor".equals(path.value()))
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+}
Modified: trunk/resteasy-int/test/cdi-test-2/src/test/java/org/jboss/resteasy/cdi/test/AbstractProviderTest.java
===================================================================
--- trunk/resteasy-int/test/cdi-test-2/src/test/java/org/jboss/resteasy/cdi/test/AbstractProviderTest.java 2011-02-17 09:33:12 UTC (rev 110694)
+++ trunk/resteasy-int/test/cdi-test-2/src/test/java/org/jboss/resteasy/cdi/test/AbstractProviderTest.java 2011-02-17 13:31:54 UTC (rev 110695)
@@ -15,18 +15,18 @@
@Test
public void testCdiFieldInjection()
{
- testPlainTextReadonlyResource(BASE_URI + getTestPrefix() + "providers", "CDI field injection: true");
+ testPlainTextReadonlyResource(BASE_URI + getTestPrefix(), "CDI field injection: true");
}
@Test
public void testCdiInitializerInjection()
{
- testPlainTextReadonlyResource(BASE_URI + getTestPrefix() + "providers", "CDI initializer injection: true");
+ testPlainTextReadonlyResource(BASE_URI + getTestPrefix(), "CDI initializer injection: true");
}
@Test
public void testJaxrsFieldInjection()
{
- testPlainTextReadonlyResource(BASE_URI + getTestPrefix() + "providers", "JAX-RS field injection: true");
+ testPlainTextReadonlyResource(BASE_URI + getTestPrefix(), "JAX-RS field injection: true");
}
}
Modified: trunk/resteasy-int/test/cdi-test-2/src/test/java/org/jboss/resteasy/cdi/test/BeanClassLocalViewEjbProviderTest.java
===================================================================
--- trunk/resteasy-int/test/cdi-test-2/src/test/java/org/jboss/resteasy/cdi/test/BeanClassLocalViewEjbProviderTest.java 2011-02-17 09:33:12 UTC (rev 110694)
+++ trunk/resteasy-int/test/cdi-test-2/src/test/java/org/jboss/resteasy/cdi/test/BeanClassLocalViewEjbProviderTest.java 2011-02-17 13:31:54 UTC (rev 110695)
@@ -7,12 +7,12 @@
@Override
protected String getTestPrefix()
{
- return "beanClassLocalViewEjb/";
+ return "beanClassLocalViewEjb/providers";
}
@Test
public void testEjbInjection()
{
- testPlainTextReadonlyResource(BASE_URI + getTestPrefix() + "providers", "EJB injection: true");
+ testPlainTextReadonlyResource(BASE_URI + getTestPrefix(), "EJB injection: true");
}
}
Modified: trunk/resteasy-int/test/cdi-test-2/src/test/java/org/jboss/resteasy/cdi/test/ProviderTest.java
===================================================================
--- trunk/resteasy-int/test/cdi-test-2/src/test/java/org/jboss/resteasy/cdi/test/ProviderTest.java 2011-02-17 09:33:12 UTC (rev 110694)
+++ trunk/resteasy-int/test/cdi-test-2/src/test/java/org/jboss/resteasy/cdi/test/ProviderTest.java 2011-02-17 13:31:54 UTC (rev 110695)
@@ -7,12 +7,12 @@
@Override
protected String getTestPrefix()
{
- return "resource/";
+ return "resource/providers";
}
@Test
public void testCdiConstructorInjection()
{
- testPlainTextReadonlyResource(BASE_URI + getTestPrefix() + "providers", "CDI constructor injection: true");
+ testPlainTextReadonlyResource(BASE_URI + getTestPrefix(), "CDI constructor injection: true");
}
}
Added: trunk/resteasy-int/test/cdi-test-2/src/test/java/org/jboss/resteasy/cdi/test/ResteasyInterceptorTest.java
===================================================================
--- trunk/resteasy-int/test/cdi-test-2/src/test/java/org/jboss/resteasy/cdi/test/ResteasyInterceptorTest.java (rev 0)
+++ trunk/resteasy-int/test/cdi-test-2/src/test/java/org/jboss/resteasy/cdi/test/ResteasyInterceptorTest.java 2011-02-17 13:31:54 UTC (rev 110695)
@@ -0,0 +1,10 @@
+package org.jboss.resteasy.cdi.test;
+
+public class ResteasyInterceptorTest extends ProviderTest
+{
+ @Override
+ protected String getTestPrefix()
+ {
+ return "resource/resteasyInterceptor";
+ }
+}
Modified: trunk/resteasy-int/test/cdi-test-2/src/test/java/org/jboss/resteasy/cdi/test/SingletonProviderTest.java
===================================================================
--- trunk/resteasy-int/test/cdi-test-2/src/test/java/org/jboss/resteasy/cdi/test/SingletonProviderTest.java 2011-02-17 09:33:12 UTC (rev 110694)
+++ trunk/resteasy-int/test/cdi-test-2/src/test/java/org/jboss/resteasy/cdi/test/SingletonProviderTest.java 2011-02-17 13:31:54 UTC (rev 110695)
@@ -5,6 +5,6 @@
@Override
protected String getTestPrefix()
{
- return "singleton/";
+ return "singleton/providers";
}
}
More information about the jboss-cvs-commits
mailing list