-
Notifications
You must be signed in to change notification settings - Fork 888
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow matching name binding between Applications and interceptors when the Application object is a CDI proxy. [RESTEASY-1708] Fix deploySimpleResource() in NameBoundCDIProxiesTest.
- Loading branch information
Showing
6 changed files
with
159 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...tests/src/test/java/org/jboss/resteasy/test/cdi/interceptors/NameBoundCDIProxiesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.jboss.resteasy.test.cdi.interceptors; | ||
|
||
import java.io.File; | ||
|
||
import javax.ws.rs.client.Client; | ||
import javax.ws.rs.client.ClientBuilder; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.container.test.api.RunAsClient; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.resteasy.test.cdi.interceptors.resource.NameBoundCDIProxiesApplication; | ||
import org.jboss.resteasy.test.cdi.interceptors.resource.NameBoundCDIProxiesInterceptor; | ||
import org.jboss.resteasy.test.cdi.interceptors.resource.NameBoundCDIProxiesResource; | ||
import org.jboss.resteasy.test.cdi.interceptors.resource.NameBoundProxiesAnnotation; | ||
import org.jboss.resteasy.utils.PortProviderUtil; | ||
import org.jboss.resteasy.utils.TestUtil; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.exporter.ZipExporter; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* @tpSubChapter CDI | ||
* @tpChapter Integration tests | ||
* @tpTestCaseDetails Name bound interceptors and Application CDI proxies | ||
* @tpSince RESTEasy 3.6.1 | ||
*/ | ||
@RunWith(Arquillian.class) | ||
@RunAsClient | ||
public class NameBoundCDIProxiesTest { | ||
|
||
@Deployment | ||
public static Archive<?> deploySimpleResource() { | ||
WebArchive war = prepareArchive(NameBoundCDIProxiesTest.class.getSimpleName()); | ||
war.addClass(NameBoundProxiesAnnotation.class); | ||
war.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); | ||
return TestUtil.finishContainerPrepare(war, null, NameBoundCDIProxiesResource.class, NameBoundCDIProxiesInterceptor.class); | ||
} | ||
|
||
// Use specific Application subclass | ||
private static WebArchive prepareArchive(String deploymentName) { | ||
WebArchive war = ShrinkWrap.create(WebArchive.class, deploymentName + ".war"); | ||
war.addClass(NameBoundCDIProxiesApplication.class); | ||
return war; | ||
} | ||
private String generateURL(String path) { | ||
return PortProviderUtil.generateURL(path, NameBoundCDIProxiesTest.class.getSimpleName()); | ||
} | ||
|
||
/** | ||
* @tpTestDetails | ||
* @tpSince RESTEasy 3.6.1 | ||
*/ | ||
@Test | ||
public void testNameBoundInterceptor() throws Exception { | ||
Client client = ClientBuilder.newClient(); | ||
String answer = client.target(generateURL("/test")).request().get(String.class); | ||
Assert.assertEquals("in-test-out", answer); | ||
client.close(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...ava/org/jboss/resteasy/test/cdi/interceptors/resource/NameBoundCDIProxiesApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.jboss.resteasy.test.cdi.interceptors.resource; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import javax.ws.rs.ApplicationPath; | ||
import javax.ws.rs.core.Application; | ||
|
||
@ApplicationPath("") | ||
@NameBoundProxiesAnnotation | ||
public class NameBoundCDIProxiesApplication extends Application { | ||
|
||
public Set<Class<?>> getClasses() { | ||
Set<Class<?>> set = new HashSet<Class<?>>(); | ||
set.add(NameBoundCDIProxiesResource.class); | ||
return set; | ||
} | ||
|
||
public Set<Object> getSingletons() { | ||
Set<Object> set = new HashSet<Object>(); | ||
set.add(new NameBoundCDIProxiesInterceptor()); | ||
return set; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ava/org/jboss/resteasy/test/cdi/interceptors/resource/NameBoundCDIProxiesInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.jboss.resteasy.test.cdi.interceptors.resource; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.ws.rs.ApplicationPath; | ||
import javax.ws.rs.container.ContainerRequestContext; | ||
import javax.ws.rs.container.ContainerRequestFilter; | ||
import javax.ws.rs.container.ContainerResponseContext; | ||
import javax.ws.rs.container.ContainerResponseFilter; | ||
import javax.ws.rs.core.Application; | ||
import javax.ws.rs.core.Context; | ||
|
||
@NameBoundProxiesAnnotation | ||
public class NameBoundCDIProxiesInterceptor implements ContainerRequestFilter, ContainerResponseFilter { | ||
|
||
static private String in = ""; | ||
|
||
/** The application context, used for retrieving the {@link ApplicationPath} value. */ | ||
@Context Application application; | ||
|
||
@Override | ||
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { | ||
Object entity = application.getClass().isSynthetic() ? in + responseContext.getEntity() + "-out" : responseContext.getEntity(); | ||
responseContext.setEntity(entity); | ||
} | ||
|
||
@Override | ||
public void filter(ContainerRequestContext requestContext) throws IOException { | ||
in = "in-"; | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...t/java/org/jboss/resteasy/test/cdi/interceptors/resource/NameBoundCDIProxiesResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.jboss.resteasy.test.cdi.interceptors.resource; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
@Path("") | ||
public class NameBoundCDIProxiesResource { | ||
|
||
@Path("test") | ||
@GET | ||
public String test() { | ||
return "test"; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...st/java/org/jboss/resteasy/test/cdi/interceptors/resource/NameBoundProxiesAnnotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.jboss.resteasy.test.cdi.interceptors.resource; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import javax.ws.rs.NameBinding; | ||
|
||
@Target({ ElementType.TYPE, ElementType.METHOD }) | ||
@Retention(value = RetentionPolicy.RUNTIME) | ||
@NameBinding | ||
public @interface NameBoundProxiesAnnotation {} |