Index: resteasy-cdi-war/src/test/java/org/jboss/resteasy/cdi/test/ResteasyCdiTest.java =================================================================== --- resteasy-cdi-war/src/test/java/org/jboss/resteasy/cdi/test/ResteasyCdiTest.java (revision 0) +++ resteasy-cdi-war/src/test/java/org/jboss/resteasy/cdi/test/ResteasyCdiTest.java (revision 0) @@ -0,0 +1,34 @@ +package org.jboss.resteasy.cdi.test; + + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.GetMethod; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +public class ResteasyCdiTest +{ + private HttpClient client = new HttpClient(); + public static final String BASE_URI = "http://localhost:8080/resteasy-cdi/"; + + public void testPlainTextReadonlyResource(String uri, String body) + { + GetMethod get = new GetMethod(uri); + get.addRequestHeader("Accept", "text/plain"); + try + { + int status = client.executeMethod(get); + assertEquals(status, 200); + assertTrue(get.getResponseBodyAsString().contains(body)); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + } + + public void testPlainTextReadonlyResource(String uri, boolean body) + { + testPlainTextReadonlyResource(uri, String.valueOf(body)); + } +} Index: resteasy-cdi-war/src/test/java/org/jboss/resteasy/cdi/test/ResourceTest.java =================================================================== --- resteasy-cdi-war/src/test/java/org/jboss/resteasy/cdi/test/ResourceTest.java (revision 0) +++ resteasy-cdi-war/src/test/java/org/jboss/resteasy/cdi/test/ResourceTest.java (revision 0) @@ -0,0 +1,53 @@ +package org.jboss.resteasy.cdi.test; + +import org.testng.annotations.Test; + +public class ResourceTest extends ResteasyCdiTest +{ + protected String getTestPrefix() + { + return "resource/"; + } + + @Test + public void testCdiFieldInjection() + { + testPlainTextReadonlyResource(BASE_URI + getTestPrefix() + "fieldInjection", true); + } + + @Test + public void testCdiConstructorInjection() + { + testPlainTextReadonlyResource(BASE_URI + getTestPrefix() + "constructorInjection", true); + } + + @Test + public void testCdiInitializerInjection() + { + testPlainTextReadonlyResource(BASE_URI + getTestPrefix() + "initializerInjection", true); + } + + @Test + public void testJaxrsFieldInjection() + { + testPlainTextReadonlyResource(BASE_URI + getTestPrefix() + "jaxrsFieldInjection", true); + } + + @Test + public void testJaxrsFieldInjection2() + { + testPlainTextReadonlyResource(BASE_URI + getTestPrefix() + "jaxrsFieldInjection2?foo=bar", "bar"); + } + + @Test + public void testJaxrsSetterInjection() + { + testPlainTextReadonlyResource(BASE_URI + getTestPrefix() + "jaxrsSetterInjection", true); + } + + @Test + public void testJaxrsMethodInjection() + { + testPlainTextReadonlyResource(BASE_URI + getTestPrefix() + "jaxrsMethodInjection?foo=bar", "bar"); + } +} Index: resteasy-cdi-war/src/test/java/org/jboss/resteasy/cdi/test/ProviderTest.java =================================================================== --- resteasy-cdi-war/src/test/java/org/jboss/resteasy/cdi/test/ProviderTest.java (revision 0) +++ resteasy-cdi-war/src/test/java/org/jboss/resteasy/cdi/test/ProviderTest.java (revision 0) @@ -0,0 +1,30 @@ +package org.jboss.resteasy.cdi.test; + +import org.testng.annotations.Test; + +public class ProviderTest extends ResteasyCdiTest +{ + @Test + public void testCdiFieldInjection() + { + testPlainTextReadonlyResource(BASE_URI + "resource/providers", "CDI field injection: true"); + } + + @Test + public void testCdiConstructorInjection() + { + testPlainTextReadonlyResource(BASE_URI + "resource/providers", "CDI constructor injection: true"); + } + + @Test + public void testCdiInitializerInjection() + { + testPlainTextReadonlyResource(BASE_URI + "resource/providers", "CDI initializer injection: true"); + } + + @Test + public void testJaxrsFieldInjection() + { + testPlainTextReadonlyResource(BASE_URI + "resource/providers", "JAX-RS field injection: true"); + } +} Index: resteasy-cdi-war/src/test/java/org/jboss/resteasy/cdi/test/InterceptorTest.java =================================================================== --- resteasy-cdi-war/src/test/java/org/jboss/resteasy/cdi/test/InterceptorTest.java (revision 0) +++ resteasy-cdi-war/src/test/java/org/jboss/resteasy/cdi/test/InterceptorTest.java (revision 0) @@ -0,0 +1,12 @@ +package org.jboss.resteasy.cdi.test; + +import org.testng.annotations.Test; + +public class InterceptorTest extends ResteasyCdiTest +{ + @Test + public void testInterceptor() + { + testPlainTextReadonlyResource(BASE_URI + "interceptor", true); + } +} Index: resteasy-cdi-war/src/test/java/org/jboss/resteasy/cdi/test/AlternativeTest.java =================================================================== --- resteasy-cdi-war/src/test/java/org/jboss/resteasy/cdi/test/AlternativeTest.java (revision 0) +++ resteasy-cdi-war/src/test/java/org/jboss/resteasy/cdi/test/AlternativeTest.java (revision 0) @@ -0,0 +1,12 @@ +package org.jboss.resteasy.cdi.test; + +import org.testng.annotations.Test; + +public class AlternativeTest extends ResteasyCdiTest +{ + @Test + public void testAlternative() + { + testPlainTextReadonlyResource(BASE_URI + "alternative", "MockResource"); + } +} Index: resteasy-cdi-war/src/test/java/org/jboss/resteasy/cdi/test/DependentResourceTest.java =================================================================== --- resteasy-cdi-war/src/test/java/org/jboss/resteasy/cdi/test/DependentResourceTest.java (revision 0) +++ resteasy-cdi-war/src/test/java/org/jboss/resteasy/cdi/test/DependentResourceTest.java (revision 0) @@ -0,0 +1,10 @@ +package org.jboss.resteasy.cdi.test; + +public class DependentResourceTest extends ResourceTest +{ + @Override + protected String getTestPrefix() + { + return "dependentResource/"; + } +} Index: resteasy-cdi-war/src/test/resources/testng.xml =================================================================== --- resteasy-cdi-war/src/test/resources/testng.xml (revision 0) +++ resteasy-cdi-war/src/test/resources/testng.xml (revision 0) @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file Index: resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/basic/Foo.java =================================================================== --- resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/basic/Foo.java (revision 0) +++ resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/basic/Foo.java (revision 0) @@ -0,0 +1,22 @@ +package org.jboss.resteasy.cdi.test.basic; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.UriInfo; + +@Path("foo") +@Produces("text/plain") +public class Foo +{ + + @Context + private UriInfo info; + + @GET + public String foo() + { + return String.valueOf(info); + } +} Index: resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/basic/TestResource.java =================================================================== --- resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/basic/TestResource.java (revision 0) +++ resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/basic/TestResource.java (revision 0) @@ -0,0 +1,113 @@ +package org.jboss.resteasy.cdi.test.basic; + +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.UriInfo; + +import org.jboss.resteasy.cdi.test.Cat; +import org.jboss.resteasy.cdi.test.Dog; + + +@Path("/resource") +@Produces("text/plain") +public class TestResource +{ + @Inject + private Cat cat; + private Cat constructorCat; + private Cat initializerCat; + @Context + private UriInfo uriInfo; + @QueryParam("foo") String fieldQuery; + private UriInfo setterUriInfo; + + public TestResource() + { + } + + @Inject + public TestResource(Cat cat) + { + constructorCat = cat; + } + + @Inject + public void init(Cat cat) + { + initializerCat = cat; + } + + @GET + @Path("/fieldInjection") + public boolean fieldInjection() + { + return cat != null; + } + + @GET + @Path("/jaxrsFieldInjection") + public boolean jaxrsFieldInjection() + { + return uriInfo != null; + } + + @GET + @Path("/jaxrsFieldInjection2") + public String jaxrsFieldInjection2() + { + return fieldQuery; + } + + @GET + @Path("/jaxrsSetterInjection") + public boolean jaxrsSetterInjection() + { + return setterUriInfo != null; + } + + @GET + @Path("/constructorInjection") + public boolean constructorInjection() + { + return constructorCat != null; + } + + @GET + @Path("/initializerInjection") + public boolean initializerInjection() + { + return initializerCat != null; + } + + @GET + @Path("/jaxrsMethodInjection") + public String jaxrsMethodInjection(@QueryParam("foo") String query) + { + return query; + } + + @GET + @Path("/toString") + @Override + public String toString() + { + return super.toString(); + } + + @GET + @Path("/providers") + public Dog testProviders() + { + return new Dog(); + } + + @Context + public void setSetterUriInfo(UriInfo setterUriInfo) + { + this.setterUriInfo = setterUriInfo; + } +} Index: resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/basic/TestProvider.java =================================================================== --- resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/basic/TestProvider.java (revision 0) +++ resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/basic/TestProvider.java (revision 0) @@ -0,0 +1,71 @@ +package org.jboss.resteasy.cdi.test.basic; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import javax.inject.Inject; +import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +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 javax.ws.rs.ext.Providers; + +import org.jboss.resteasy.cdi.test.Cat; +import org.jboss.resteasy.cdi.test.Dog; + +@Provider +@Produces("text/plain") +public class TestProvider implements MessageBodyWriter +{ + + @Inject + private Cat cat; + private Cat constructorCat; + private Cat initializerCat; + @Context + private Providers providers; + + public TestProvider() + { + } + + @Inject + public TestProvider(Cat cat) + { + 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; + } + + public boolean isWriteable(Class type, Type genericType, Annotation[] annotations, MediaType mediaType) + { + return type.isAssignableFrom(Dog.class); + } + + public void writeTo(Dog t, Class type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap 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()); + bw.flush(); + } +} Index: resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/basic/DependentTestResource.java =================================================================== --- resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/basic/DependentTestResource.java (revision 0) +++ resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/basic/DependentTestResource.java (revision 0) @@ -0,0 +1,115 @@ +package org.jboss.resteasy.cdi.test.basic; + +import javax.enterprise.context.Dependent; +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.UriInfo; + +import org.jboss.resteasy.cdi.test.Cat; +import org.jboss.resteasy.cdi.test.Dog; + + +@Path("/dependentResource") +@Produces("text/plain") +@Dependent +public class DependentTestResource +{ + @Inject + private Cat cat; + private Cat constructorCat; + private Cat initializerCat; + @Context + private UriInfo uriInfo; + @QueryParam("foo") String fieldQuery; + private UriInfo setterUriInfo; + + public DependentTestResource() + { + } + + @Inject + public DependentTestResource(Cat cat) + { + constructorCat = cat; + } + + @Inject + public void init(Cat cat) + { + initializerCat = cat; + } + + @GET + @Path("/fieldInjection") + public boolean fieldInjection() + { + return cat != null; + } + + @GET + @Path("/jaxrsFieldInjection") + public boolean jaxrsFieldInjection() + { + return uriInfo != null; + } + + @GET + @Path("/jaxrsFieldInjection2") + public String jaxrsFieldInjection2() + { + return fieldQuery; + } + + @GET + @Path("/jaxrsSetterInjection") + public boolean jaxrsSetterInjection() + { + return setterUriInfo != null; + } + + @GET + @Path("/constructorInjection") + public boolean constructorInjection() + { + return constructorCat != null; + } + + @GET + @Path("/initializerInjection") + public boolean initializerInjection() + { + return initializerCat != null; + } + + @GET + @Path("/jaxrsMethodInjection") + public String jaxrsMethodInjection(@QueryParam("foo") String query) + { + return query; + } + + @GET + @Path("/toString") + @Override + public String toString() + { + return super.toString(); + } + + @GET + @Path("/providers") + public Dog testProviders() + { + return new Dog(); + } + + @Context + public void setSetterUriInfo(UriInfo setterUriInfo) + { + this.setterUriInfo = setterUriInfo; + } +} Index: resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/Cat.java =================================================================== --- resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/Cat.java (revision 0) +++ resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/Cat.java (revision 0) @@ -0,0 +1,6 @@ +package org.jboss.resteasy.cdi.test; + +public class Cat +{ + +} Index: resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/Dog.java =================================================================== --- resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/Dog.java (revision 0) +++ resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/Dog.java (revision 0) @@ -0,0 +1,6 @@ +package org.jboss.resteasy.cdi.test; + +public class Dog +{ + +} Index: resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/alternative/MockResource.java =================================================================== --- resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/alternative/MockResource.java (revision 0) +++ resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/alternative/MockResource.java (revision 0) @@ -0,0 +1,17 @@ +package org.jboss.resteasy.cdi.test.alternative; + +import javax.enterprise.inject.Alternative; +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +@Path("/alternative") +@Alternative +public class MockResource extends ProductionResource +{ + @Override + @GET + public String getValue() + { + return "MockResource"; + } +} Index: resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/alternative/ProductionResource.java =================================================================== --- resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/alternative/ProductionResource.java (revision 0) +++ resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/alternative/ProductionResource.java (revision 0) @@ -0,0 +1,16 @@ +package org.jboss.resteasy.cdi.test.alternative; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +@Path("/alternative") +@Produces("text/plain") +public class ProductionResource +{ + @GET + public String getValue() + { + return "ProductionResource"; + } +} Index: resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/interceptor/TestResource.java =================================================================== --- resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/interceptor/TestResource.java (revision 0) +++ resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/interceptor/TestResource.java (revision 0) @@ -0,0 +1,17 @@ +package org.jboss.resteasy.cdi.test.interceptor; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +@Path("/interceptor") +@Produces("text/plain") +@TestInterceptorBinding +public class TestResource +{ + @GET + public boolean getValue() + { + return false; + } +} Index: resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/interceptor/TestInterceptorBinding.java =================================================================== --- resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/interceptor/TestInterceptorBinding.java (revision 0) +++ resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/interceptor/TestInterceptorBinding.java (revision 0) @@ -0,0 +1,19 @@ +package org.jboss.resteasy.cdi.test.interceptor; + +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import java.lang.annotation.Target; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.ElementType.METHOD; + +import javax.interceptor.InterceptorBinding; + + +@InterceptorBinding +@Target( { TYPE, METHOD } ) +@Retention(RUNTIME) +@Inherited +public @interface TestInterceptorBinding +{ +} Index: resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/interceptor/TestInterceptor.java =================================================================== --- resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/interceptor/TestInterceptor.java (revision 0) +++ resteasy-cdi-war/src/main/java/org/jboss/resteasy/cdi/test/interceptor/TestInterceptor.java (revision 0) @@ -0,0 +1,17 @@ +package org.jboss.resteasy.cdi.test.interceptor; + +import javax.interceptor.AroundInvoke; +import javax.interceptor.Interceptor; +import javax.interceptor.InvocationContext; + +@Interceptor +@TestInterceptorBinding +public class TestInterceptor +{ + @AroundInvoke + public Object intercept(InvocationContext ctx) throws Exception + { + // Do a negation + return !((Boolean) ctx.proceed()); + } +} Index: resteasy-cdi-war/src/main/webapp/WEB-INF/beans.xml =================================================================== --- resteasy-cdi-war/src/main/webapp/WEB-INF/beans.xml (revision 0) +++ resteasy-cdi-war/src/main/webapp/WEB-INF/beans.xml (revision 0) @@ -0,0 +1,19 @@ + + + + + + org.jboss.resteasy.cdi.test.alternative.MockResource + + + org.jboss.resteasy.cdi.test.interceptor.TestInterceptor + + + Index: resteasy-cdi-war/src/main/webapp/WEB-INF/web.xml =================================================================== --- resteasy-cdi-war/src/main/webapp/WEB-INF/web.xml (revision 0) +++ resteasy-cdi-war/src/main/webapp/WEB-INF/web.xml (revision 0) @@ -0,0 +1,33 @@ + + + + RESTEasy-CDI testing application + + + resteasy.scan + true + + + + resteasy.use.deployment.sensitive.factory + true + + + + org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap + + + + Resteasy + org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher + + + + Resteasy + /* + + + + Index: resteasy-cdi-war/pom.xml =================================================================== --- resteasy-cdi-war/pom.xml (revision 0) +++ resteasy-cdi-war/pom.xml (revision 0) @@ -0,0 +1,172 @@ + + 4.0.0 + + + org.jboss.resteasy + resteasy-jaxrs-all + 2.0-beta-2-SNAPSHOT + + + resteasy-cdi-war + war + RESTEasy-CDI testing application + + + + + org.jboss.resteasy + jaxrs-api + ${project.version} + + + + org.jboss.resteasy + resteasy-jaxrs + ${project.version} + + + javassist + javassist + + + org.apache.httpcomponents + httpclient + + + javax.activation + activation + + + net.jcip + jcip-annotations + + + + + + org.jboss.resteasy + resteasy-cdi + ${project.version} + + + + org.slf4j + slf4j-api + provided + + + + javax.enterprise + cdi-api + 1.0 + provided + + + + javax.annotation + jsr250-api + 1.0 + provided + + + + + commons-httpclient + commons-httpclient + test + + + + org.slf4j + jcl-over-slf4j + test + + + + org.slf4j + slf4j-simple + test + + + + org.testng + testng + jdk15 + 5.10 + test + + + + + + resteasy-cdi + + + org.codehaus.mojo + jboss-maven-plugin + 1.4 + + ${jboss.home} + + + + jboss-deploy + pre-integration-test + + deploy + + + + ${basedir}/target/${build.finalName}.war + + + + + jboss-undeploy + post-integration-test + + undeploy + + + + ${basedir}/target/${build.finalName}.war + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + surefire-it + integration-test + + test + + + false + + src/test/resources/testng.xml + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + + +