-
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.
[RESTEASY-2358] Fix duplicate validation violations for EJB resources.
- Loading branch information
Showing
5 changed files
with
198 additions
and
71 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
99 changes: 99 additions & 0 deletions
99
...ion-tests/src/test/java/org/jboss/resteasy/test/cdi/ejb/EJBCDIValidationEJBProxyTest.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,99 @@ | ||
package org.jboss.resteasy.test.cdi.ejb; | ||
|
||
import javax.ws.rs.client.Client; | ||
import javax.ws.rs.client.ClientBuilder; | ||
import javax.ws.rs.client.Entity; | ||
import javax.ws.rs.client.WebTarget; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.hibernate.validator.HibernateValidatorPermission; | ||
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.ViolationReport; | ||
import org.jboss.resteasy.test.cdi.ejb.resource.EJBCDIValidationEJBProxyGreeterResource; | ||
import org.jboss.resteasy.test.cdi.ejb.resource.EJBCDIValidationEJBProxyGreeting; | ||
import org.jboss.resteasy.utils.PermissionUtil; | ||
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.AfterClass; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* @tpSubChapter CDI | ||
* @tpChapter Integration tests | ||
* @tpTestCaseDetails EJB, CDI, Validation, and RESTEasy integration test: RESTEASY-2358 | ||
* @tpSince RESTEasy 3.10.0 | ||
*/ | ||
@RunWith(Arquillian.class) | ||
@RunAsClient | ||
public class EJBCDIValidationEJBProxyTest { | ||
|
||
private static final String VALID_REQUEST = "{\n" | ||
+ "\"name\":\"Hugo\"\n" | ||
+ "}"; | ||
|
||
private static final String INVALID_REQUEST = "{\n" | ||
+ "\"name\":\"123456789010\"\n" | ||
+ "}"; | ||
|
||
private static Client client; | ||
|
||
@Deployment | ||
public static Archive<?> createTestArchive() { | ||
WebArchive war = TestUtil.prepareArchive(EJBCDIValidationEJBProxyTest.class.getSimpleName()); | ||
war.addClass(EJBCDIValidationEJBProxyGreeting.class); | ||
war.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); | ||
war.setWebXML(EJBCDIValidationEJBProxyTest.class.getPackage(), "web.xml"); | ||
war.addAsManifestResource(PermissionUtil.createPermissionsXmlAsset( | ||
new HibernateValidatorPermission("accessPrivateMembers") | ||
), "permissions.xml"); | ||
return TestUtil.finishContainerPrepare(war, null, | ||
EJBCDIValidationEJBProxyGreeterResource.class); | ||
} | ||
|
||
private String generateURL(String path) { | ||
return PortProviderUtil.generateURL(path, EJBCDIValidationEJBProxyTest.class.getSimpleName()); | ||
} | ||
|
||
@BeforeClass | ||
public static void init() { | ||
client = ClientBuilder.newClient(); | ||
} | ||
|
||
@AfterClass | ||
public static void close() { | ||
client.close(); | ||
} | ||
|
||
@Test | ||
public void buggyBeanValidation() { | ||
final WebTarget greeterTarget = client.target(generateURL("/greeter")); | ||
|
||
Response response = greeterTarget.request().post(Entity.entity(INVALID_REQUEST, MediaType.APPLICATION_JSON)); | ||
String answer = response.readEntity(String.class); | ||
ViolationReport r = new ViolationReport(answer); | ||
TestUtil.countViolations(r, 0, 0, 0, 1, 0); | ||
|
||
response = greeterTarget.request().post(Entity.entity(VALID_REQUEST, MediaType.APPLICATION_JSON)); | ||
final String helloHugo = response.readEntity(String.class); | ||
Assert.assertEquals("Hello Hugo!", helloHugo); | ||
|
||
response = greeterTarget.request().post(Entity.entity(INVALID_REQUEST, MediaType.APPLICATION_JSON)); | ||
answer = response.readEntity(String.class); | ||
r = new ViolationReport(answer); | ||
TestUtil.countViolations(r, 0, 0, 0, 1, 0); | ||
|
||
response = greeterTarget.request().post(Entity.entity(INVALID_REQUEST, MediaType.APPLICATION_JSON)); | ||
answer = response.readEntity(String.class); | ||
r = new ViolationReport(answer); | ||
TestUtil.countViolations(r, 0, 0, 0, 1, 0); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ava/org/jboss/resteasy/test/cdi/ejb/resource/EJBCDIValidationEJBProxyGreeterResource.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.ejb.resource; | ||
|
||
import javax.ejb.Remote; | ||
import javax.ejb.Singleton; | ||
import javax.validation.Valid; | ||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
@Singleton | ||
@Remote | ||
@Path("greeter") | ||
public class EJBCDIValidationEJBProxyGreeterResource { | ||
|
||
@POST | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
public String greet(@Valid EJBCDIValidationEJBProxyGreeting greeting) { | ||
return "Hello " + greeting.getName() + "!"; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
.../test/java/org/jboss/resteasy/test/cdi/ejb/resource/EJBCDIValidationEJBProxyGreeting.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.ejb.resource; | ||
|
||
import javax.validation.constraints.Size; | ||
|
||
public class EJBCDIValidationEJBProxyGreeting { | ||
|
||
@Size(min = 0, max = 10, message = "value should be between 0 and 10") | ||
private String name; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
testsuite/integration-tests/src/test/resources/org/jboss/resteasy/test/cdi/ejb/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,24 @@ | ||
<web-app> | ||
|
||
<display-name>Archetype Created Web Application</display-name> | ||
|
||
<servlet> | ||
<servlet-name>Resteasy</servlet-name> | ||
<servlet-class> | ||
org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher | ||
</servlet-class> | ||
</servlet> | ||
|
||
<servlet-mapping> | ||
<servlet-name>Resteasy</servlet-name> | ||
<url-pattern>/*</url-pattern> | ||
</servlet-mapping> | ||
|
||
<context-param> | ||
<param-name>resteasy.jndi.resources</param-name> | ||
<param-value> | ||
java:global/EJBCDIValidationEJBProxyTest/EJBCDIValidationEJBProxyGreeterResource | ||
</param-value> | ||
</context-param> | ||
|
||
</web-app> |