Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #880 from ronsigal/1186c
[RESTEASY-1186]
- Loading branch information
Showing
17 changed files
with
361 additions
and
1 deletion.
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
140 changes: 140 additions & 0 deletions
140
...ion-tests/src/test/java/org/jboss/resteasy/test/cdi/validation/ValidationWithCDITest.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,140 @@ | ||
package org.jboss.resteasy.test.cdi.validation; | ||
|
||
import java.util.Iterator; | ||
|
||
import javax.ws.rs.client.Client; | ||
import javax.ws.rs.client.ClientBuilder; | ||
import javax.ws.rs.client.WebTarget; | ||
import javax.ws.rs.client.Invocation.Builder; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
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.api.validation.ResteasyConstraintViolation; | ||
import org.jboss.resteasy.api.validation.Validation; | ||
import org.jboss.resteasy.api.validation.ViolationReport; | ||
import org.jboss.resteasy.test.cdi.validation.resource.AbstractAsyncRootResource; | ||
import org.jboss.resteasy.test.cdi.validation.resource.AsyncRootResource; | ||
import org.jboss.resteasy.test.cdi.validation.resource.AsyncRootResourceImpl; | ||
import org.jboss.resteasy.test.cdi.validation.resource.AsyncSubResource; | ||
import org.jboss.resteasy.test.cdi.validation.resource.AsyncSubResourceImpl; | ||
import org.jboss.resteasy.test.cdi.validation.resource.AsyncValidResource; | ||
import org.jboss.resteasy.test.cdi.validation.resource.QueryBeanParam; | ||
import org.jboss.resteasy.test.cdi.validation.resource.QueryBeanParamImpl; | ||
import org.jboss.resteasy.test.cdi.validation.resource.RootResource; | ||
import org.jboss.resteasy.test.cdi.validation.resource.RootResourceImpl; | ||
import org.jboss.resteasy.test.cdi.validation.resource.SubResource; | ||
import org.jboss.resteasy.test.cdi.validation.resource.SubResourceImpl; | ||
import org.jboss.resteasy.test.cdi.validation.resource.TestApplication; | ||
import org.jboss.resteasy.test.cdi.validation.resource.ValidResource; | ||
import org.jboss.resteasy.utils.PortProviderUtil; | ||
import org.jboss.resteasy.utils.TestUtil; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
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 Tests RESTEASY-1186, which reports issues with validation in | ||
* the presence of CDI. | ||
* @tpSince RESTEasy 3.0.18.Final | ||
*/ | ||
@RunWith(Arquillian.class) | ||
@RunAsClient | ||
public class ValidationWithCDITest | ||
{ | ||
@Deployment | ||
public static Archive<?> createTestArchive() | ||
{ | ||
WebArchive war = TestUtil.prepareArchive(ValidationWithCDITest.class.getSimpleName()); | ||
war.addClasses(TestApplication.class) | ||
.addClasses(QueryBeanParam.class, QueryBeanParamImpl.class) | ||
.addClasses(RootResource.class, RootResourceImpl.class, ValidResource.class) | ||
.addClasses(SubResource.class, SubResourceImpl.class) | ||
.addClass(AbstractAsyncRootResource.class) | ||
.addClasses(AsyncRootResource.class, AsyncRootResourceImpl.class) | ||
.addClasses(AsyncSubResource.class, AsyncSubResourceImpl.class) | ||
.addClasses(AsyncValidResource.class) | ||
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") | ||
.addAsWebInfResource(ValidationWithCDITest.class.getPackage(), "web.xml", "/web.xml"); | ||
; | ||
System.out.println(war.toString(true)); | ||
return TestUtil.finishContainerPrepare(war, null, (Class<?>[]) null); | ||
} | ||
|
||
private String generateURL(String path) { | ||
return PortProviderUtil.generateURL(path, ValidationWithCDITest.class.getSimpleName()); | ||
} | ||
|
||
@Test | ||
public void testRoot() throws Exception | ||
{ | ||
Client client = ClientBuilder.newClient(); | ||
WebTarget base = client.target(generateURL("/test/root/sub?foo=x")); | ||
Builder builder = base.request(); | ||
builder.accept(MediaType.APPLICATION_XML); | ||
Response response = builder.get(); | ||
Assert.assertEquals(400, response.getStatus()); | ||
Object header = response.getHeaders().getFirst(Validation.VALIDATION_HEADER); | ||
Assert.assertTrue(header instanceof String); | ||
Assert.assertTrue(Boolean.valueOf(String.class.cast(header))); | ||
ViolationReport report = response.readEntity(ViolationReport.class); | ||
countViolations(report, 0, 0, 0, 1, 0); | ||
} | ||
|
||
@Test | ||
public void testAsynch() throws Exception | ||
{ | ||
Client client = ClientBuilder.newClient(); | ||
WebTarget base = client.target(generateURL("/test/async/sub")); | ||
|
||
{ | ||
Builder builder = base.queryParam("foo", "x").request(); | ||
builder.accept(MediaType.APPLICATION_XML); | ||
Response response = builder.get(); | ||
Assert.assertEquals(400, response.getStatus()); | ||
Object header = response.getHeaders().getFirst(Validation.VALIDATION_HEADER); | ||
Assert.assertTrue(header instanceof String); | ||
Assert.assertTrue(Boolean.valueOf(String.class.cast(header))); | ||
ViolationReport report = response.readEntity(ViolationReport.class); | ||
countViolations(report, 0, 0, 0, 1, 0); | ||
response.close(); | ||
} | ||
|
||
{ | ||
Builder builder = base.queryParam("foo", "xy").request(); | ||
builder.accept(MediaType.APPLICATION_XML); | ||
Response response = builder.get(); | ||
Assert.assertEquals(200, response.getStatus()); | ||
response.close(); | ||
} | ||
|
||
{ | ||
Builder builder = base.queryParam("foo", "x").request(); | ||
builder.accept(MediaType.APPLICATION_XML); | ||
Response response = builder.get(); | ||
Assert.assertEquals(400, response.getStatus()); | ||
Object header = response.getHeaders().getFirst(Validation.VALIDATION_HEADER); | ||
Assert.assertTrue(header instanceof String); | ||
Assert.assertTrue(Boolean.valueOf(String.class.cast(header))); | ||
ViolationReport report = response.readEntity(ViolationReport.class); | ||
countViolations(report, 0, 0, 0, 1, 0); | ||
response.close(); | ||
} | ||
} | ||
|
||
private void countViolations(ViolationReport e, int fieldCount, int propertyCount, int classCount, int parameterCount, int returnValueCount) | ||
{ | ||
Assert.assertEquals(fieldCount, e.getFieldViolations().size()); | ||
Assert.assertEquals(propertyCount, e.getPropertyViolations().size()); | ||
Assert.assertEquals(classCount, e.getClassViolations().size()); | ||
Assert.assertEquals(parameterCount, e.getParameterViolations().size()); | ||
Assert.assertEquals(returnValueCount, e.getReturnValueViolations().size()); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
.../test/java/org/jboss/resteasy/test/cdi/validation/resource/AbstractAsyncRootResource.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.validation.resource; | ||
|
||
import javax.ws.rs.container.AsyncResponse; | ||
import javax.ws.rs.core.Response; | ||
|
||
public abstract class AbstractAsyncRootResource implements AsyncRootResource | ||
{ | ||
@Override | ||
public void getAll(AsyncResponse asyncResponse, QueryBeanParamImpl beanParam) | ||
{ | ||
System.out.println("abstract async#getAll: beanParam#getParam valid? " + beanParam.getParam()); | ||
asyncResponse.resume(Response.ok().build()); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...ests/src/test/java/org/jboss/resteasy/test/cdi/validation/resource/AsyncRootResource.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,18 @@ | ||
package org.jboss.resteasy.test.cdi.validation.resource; | ||
|
||
import javax.ws.rs.BeanParam; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.container.AsyncResponse; | ||
import javax.ws.rs.container.Suspended; | ||
|
||
@Path("async") | ||
public interface AsyncRootResource extends AsyncValidResource | ||
{ | ||
@GET | ||
@Override | ||
void getAll(@Suspended AsyncResponse asyncResponse, @BeanParam QueryBeanParamImpl beanParam); | ||
|
||
@Path("/sub") | ||
AsyncSubResource getSubResource(); | ||
} |
17 changes: 17 additions & 0 deletions
17
.../src/test/java/org/jboss/resteasy/test/cdi/validation/resource/AsyncRootResourceImpl.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,17 @@ | ||
package org.jboss.resteasy.test.cdi.validation.resource; | ||
|
||
import javax.enterprise.context.RequestScoped; | ||
import javax.inject.Inject; | ||
|
||
@RequestScoped | ||
public class AsyncRootResourceImpl extends AbstractAsyncRootResource | ||
{ | ||
@Inject | ||
private AsyncSubResourceImpl subResource; | ||
|
||
@Override | ||
public AsyncSubResource getSubResource() | ||
{ | ||
return subResource; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...tests/src/test/java/org/jboss/resteasy/test/cdi/validation/resource/AsyncSubResource.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.validation.resource; | ||
|
||
import javax.ws.rs.BeanParam; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.container.AsyncResponse; | ||
import javax.ws.rs.container.Suspended; | ||
|
||
public interface AsyncSubResource extends AsyncValidResource | ||
{ | ||
@GET | ||
@Override | ||
void getAll(@Suspended AsyncResponse asyncResponse, @BeanParam QueryBeanParamImpl beanParam); | ||
} |
21 changes: 21 additions & 0 deletions
21
...s/src/test/java/org/jboss/resteasy/test/cdi/validation/resource/AsyncSubResourceImpl.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,21 @@ | ||
package org.jboss.resteasy.test.cdi.validation.resource; | ||
|
||
import javax.enterprise.context.RequestScoped; | ||
import javax.ws.rs.container.AsyncResponse; | ||
import javax.ws.rs.core.Response; | ||
|
||
@RequestScoped | ||
public class AsyncSubResourceImpl implements AsyncSubResource | ||
{ | ||
public AsyncSubResourceImpl() | ||
{ | ||
System.out.println("creating AsyncSubResourceImpl"); | ||
} | ||
|
||
@Override | ||
public void getAll(AsyncResponse asyncResponse, QueryBeanParamImpl beanParam) | ||
{ | ||
System.out.println("sub#getAll: beanParam#getParam valid? " + beanParam.getParam()); | ||
asyncResponse.resume(Response.ok().build()); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...sts/src/test/java/org/jboss/resteasy/test/cdi/validation/resource/AsyncValidResource.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,9 @@ | ||
package org.jboss.resteasy.test.cdi.validation.resource; | ||
|
||
import javax.validation.Valid; | ||
import javax.ws.rs.container.AsyncResponse; | ||
|
||
public interface AsyncValidResource | ||
{ | ||
void getAll(AsyncResponse asyncResponse, @Valid QueryBeanParamImpl beanParam); | ||
} |
9 changes: 9 additions & 0 deletions
9
...n-tests/src/test/java/org/jboss/resteasy/test/cdi/validation/resource/QueryBeanParam.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,9 @@ | ||
package org.jboss.resteasy.test.cdi.validation.resource; | ||
|
||
import javax.validation.constraints.Size; | ||
|
||
public interface QueryBeanParam | ||
{ | ||
@Size(min = 2) | ||
String getParam(); | ||
} |
15 changes: 15 additions & 0 deletions
15
...sts/src/test/java/org/jboss/resteasy/test/cdi/validation/resource/QueryBeanParamImpl.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,15 @@ | ||
package org.jboss.resteasy.test.cdi.validation.resource; | ||
|
||
import javax.ws.rs.QueryParam; | ||
|
||
public class QueryBeanParamImpl implements QueryBeanParam | ||
{ | ||
@QueryParam("foo") | ||
private String param; | ||
|
||
@Override | ||
public String getParam() | ||
{ | ||
return param; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...ion-tests/src/test/java/org/jboss/resteasy/test/cdi/validation/resource/RootResource.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,16 @@ | ||
package org.jboss.resteasy.test.cdi.validation.resource; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.Response; | ||
|
||
@Path("root") | ||
public interface RootResource | ||
{ | ||
@Path("/sub") | ||
SubResource getSubResource(); | ||
|
||
@Path("entered") | ||
@GET | ||
public Response entered(); | ||
} |
25 changes: 25 additions & 0 deletions
25
...tests/src/test/java/org/jboss/resteasy/test/cdi/validation/resource/RootResourceImpl.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,25 @@ | ||
package org.jboss.resteasy.test.cdi.validation.resource; | ||
|
||
import javax.enterprise.context.RequestScoped; | ||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.core.Response; | ||
|
||
@RequestScoped | ||
public class RootResourceImpl implements RootResource | ||
{ | ||
@Inject | ||
private SubResource subResource; | ||
|
||
@Override | ||
public SubResource getSubResource() | ||
{ | ||
return subResource; | ||
} | ||
|
||
@GET | ||
public Response entered() | ||
{ | ||
return Response.status(SubResourceImpl.methodEntered ? 444 : 200).build(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...tion-tests/src/test/java/org/jboss/resteasy/test/cdi/validation/resource/SubResource.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,12 @@ | ||
package org.jboss.resteasy.test.cdi.validation.resource; | ||
|
||
import javax.ws.rs.BeanParam; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.core.Response; | ||
|
||
public interface SubResource extends ValidResource | ||
{ | ||
@GET | ||
@Override | ||
Response getAll(@BeanParam QueryBeanParamImpl beanParam); | ||
} |
18 changes: 18 additions & 0 deletions
18
...-tests/src/test/java/org/jboss/resteasy/test/cdi/validation/resource/SubResourceImpl.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,18 @@ | ||
package org.jboss.resteasy.test.cdi.validation.resource; | ||
|
||
import javax.enterprise.context.RequestScoped; | ||
import javax.ws.rs.core.Response; | ||
|
||
@RequestScoped | ||
public class SubResourceImpl implements SubResource | ||
{ | ||
static boolean methodEntered; | ||
|
||
@Override | ||
public Response getAll(QueryBeanParamImpl beanParam) | ||
{ | ||
System.out.println("beanParam#getParam valid? " + beanParam.getParam()); | ||
methodEntered = true; | ||
return Response.ok().build(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...-tests/src/test/java/org/jboss/resteasy/test/cdi/validation/resource/TestApplication.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,18 @@ | ||
package org.jboss.resteasy.test.cdi.validation.resource; | ||
|
||
import javax.ws.rs.ApplicationPath; | ||
import javax.ws.rs.core.Application; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
/** | ||
* | ||
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a> | ||
* @version $Revision: 1.1 $ | ||
* | ||
* Copyright Jul 20, 2015 | ||
*/ | ||
@Provider | ||
@ApplicationPath("/test") | ||
public class TestApplication extends Application | ||
{ | ||
} |
9 changes: 9 additions & 0 deletions
9
...on-tests/src/test/java/org/jboss/resteasy/test/cdi/validation/resource/ValidResource.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,9 @@ | ||
package org.jboss.resteasy.test.cdi.validation.resource; | ||
|
||
import javax.validation.Valid; | ||
import javax.ws.rs.core.Response; | ||
|
||
public interface ValidResource | ||
{ | ||
Response getAll(@Valid QueryBeanParamImpl beanParam); | ||
} |
5 changes: 5 additions & 0 deletions
5
...suite/integration-tests/src/test/resources/org/jboss/resteasy/test/cdi/validation/web.xml
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,5 @@ | ||
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> | ||
|
||
</web-app> |