-
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-1137: In resteasy-validator-provider-11,
ResteasyViolationException is now a subclass of javax.validation.ConstraintViolationException.
- Loading branch information
Showing
13 changed files
with
794 additions
and
135 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
...lian/RESTEASY-TEST-WF8/src/main/java/org/jboss/resteasy/resteasy1137/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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
package org.jboss.resteasy.resteasy1137; | |||
|
|||
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 | |||
{ | |||
} |
25 changes: 25 additions & 0 deletions
25
.../RESTEASY-TEST-WF8/src/main/java/org/jboss/resteasy/resteasy1137/TestClassConstraint.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,25 @@ | |||
package org.jboss.resteasy.resteasy1137; | |||
|
|||
import static java.lang.annotation.ElementType.TYPE; | |||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | |||
|
|||
import java.lang.annotation.Documented; | |||
import java.lang.annotation.Retention; | |||
import java.lang.annotation.Target; | |||
|
|||
import javax.validation.Constraint; | |||
import javax.validation.Payload; | |||
import javax.ws.rs.Path; | |||
|
|||
@Path("/") | |||
@Documented | |||
@Constraint(validatedBy = TestClassValidator.class) | |||
@Target({TYPE}) | |||
@Retention(RUNTIME) | |||
public @interface TestClassConstraint | |||
{ | |||
String message() default "Concatenation of s and t must have length > {value}"; | |||
Class<?>[] groups() default {}; | |||
Class<? extends Payload>[] payload() default {}; | |||
int value(); | |||
} |
20 changes: 20 additions & 0 deletions
20
...n/RESTEASY-TEST-WF8/src/main/java/org/jboss/resteasy/resteasy1137/TestClassValidator.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
package org.jboss.resteasy.resteasy1137; | |||
|
|||
import javax.validation.ConstraintValidator; | |||
import javax.validation.ConstraintValidatorContext; | |||
|
|||
public class TestClassValidator implements ConstraintValidator<TestClassConstraint, TestResource> | |||
{ | |||
int length; | |||
|
|||
public void initialize(TestClassConstraint constraintAnnotation) | |||
{ | |||
length = constraintAnnotation.value(); | |||
} | |||
|
|||
public boolean isValid(TestResource value, ConstraintValidatorContext context) | |||
{ | |||
boolean b = value.retrieveS().length() + value.getT().length() >= length; | |||
return b; | |||
} | |||
} |
56 changes: 56 additions & 0 deletions
56
...rquillian/RESTEASY-TEST-WF8/src/main/java/org/jboss/resteasy/resteasy1137/TestReport.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,56 @@ | |||
package org.jboss.resteasy.resteasy1137; | |||
|
|||
import javax.xml.bind.annotation.XmlAccessType; | |||
import javax.xml.bind.annotation.XmlAccessorType; | |||
import javax.xml.bind.annotation.XmlRootElement; | |||
|
|||
@XmlRootElement(name="testReport") | |||
@XmlAccessorType(XmlAccessType.FIELD) | |||
public class TestReport | |||
{ | |||
private int fieldViolations; | |||
private int propertyViolations; | |||
private int classViolations; | |||
private int parameterViolations; | |||
private int returnValueViolations; | |||
public int getFieldViolations() | |||
{ | |||
return fieldViolations; | |||
} | |||
public void setFieldViolations(int fieldViolations) | |||
{ | |||
this.fieldViolations = fieldViolations; | |||
} | |||
public int getPropertyViolations() | |||
{ | |||
return propertyViolations; | |||
} | |||
public void setPropertyViolations(int propertyViolations) | |||
{ | |||
this.propertyViolations = propertyViolations; | |||
} | |||
public int getClassViolations() | |||
{ | |||
return classViolations; | |||
} | |||
public void setClassViolations(int classViolations) | |||
{ | |||
this.classViolations = classViolations; | |||
} | |||
public int getParameterViolations() | |||
{ | |||
return parameterViolations; | |||
} | |||
public void setParameterViolations(int parameterViolations) | |||
{ | |||
this.parameterViolations = parameterViolations; | |||
} | |||
public int getReturnValueViolations() | |||
{ | |||
return returnValueViolations; | |||
} | |||
public void setReturnValueViolations(int returnValueViolations) | |||
{ | |||
this.returnValueViolations = returnValueViolations; | |||
} | |||
} |
42 changes: 42 additions & 0 deletions
42
...uillian/RESTEASY-TEST-WF8/src/main/java/org/jboss/resteasy/resteasy1137/TestResource.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,42 @@ | |||
package org.jboss.resteasy.resteasy1137; | |||
|
|||
import javax.validation.constraints.Size; | |||
import javax.ws.rs.GET; | |||
import javax.ws.rs.Path; | |||
import javax.ws.rs.PathParam; | |||
|
|||
@Path("all") | |||
@TestClassConstraint(5) | |||
public class TestResource | |||
{ | |||
@Size(min=2, max=4) | |||
@PathParam("s") | |||
String s; | |||
|
|||
private String t; | |||
|
|||
@Size(min=3, max=5) | |||
public String getT() | |||
{ | |||
return t; | |||
} | |||
|
|||
public String retrieveS() | |||
{ | |||
return s; | |||
} | |||
|
|||
@PathParam("t") | |||
public void setT(String t) | |||
{ | |||
this.t = t; | |||
} | |||
|
|||
@GET | |||
@Path("{s}/{t}/{u}") | |||
@Size(max=3) | |||
public String test(@Size(min=4, max=6) @PathParam("u") String u) | |||
{ | |||
return s + t + u; | |||
} | |||
} |
23 changes: 23 additions & 0 deletions
23
...uillian/RESTEASY-TEST-WF8/src/main/java/org/jboss/resteasy/resteasy1137/package-info.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,23 @@ | |||
/** | |||
* This package (along with @see org.jboss.resteasy.test.resteasy1137) tests versioning compatibility | |||
* of the class org.jboss.resteasy.api.validation.ResteasyViolationException in module resteasy-validator-provider11. | |||
* | |||
* As of release 3.0.12.Final, ResteasyViolationException was changed from a subclass of javax.validation.ValidationException | |||
* to a subclass of javax.validation.ConstraintViolationException, which is a subclass of javax.validation.ValidationException. | |||
* | |||
* The jar validation-versioning.jar in src/test/resources/1137 contains the class | |||
* org.jboss.resteasy.test.validation.versioning.CustomExceptionMapper, with the method | |||
* | |||
* <p> | |||
* <pre> | |||
* {@code | |||
* public Response toResponse(ResteasyViolationException rve); | |||
* } | |||
* </pre> | |||
* <p> | |||
* | |||
* which was compiled with the previous version of ResteasyViolationException. The test in these two packages shows | |||
* that the two versions of ResteasyViolationException are binary compatible. | |||
* | |||
*/ | |||
package org.jboss.resteasy.resteasy1137; |
84 changes: 84 additions & 0 deletions
84
...EST-WF8/src/test/java/org/jboss/resteasy/test/resteasy1137/TestCustomExceptionMapper.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,84 @@ | |||
package org.jboss.resteasy.test.resteasy1137; | |||
|
|||
import javax.ws.rs.client.Client; | |||
import javax.ws.rs.client.ClientBuilder; | |||
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.junit.Arquillian; | |||
import org.jboss.resteasy.resteasy1137.TestApplication; | |||
import org.jboss.resteasy.resteasy1137.TestClassConstraint; | |||
import org.jboss.resteasy.resteasy1137.TestClassValidator; | |||
import org.jboss.resteasy.resteasy1137.TestReport; | |||
import org.jboss.resteasy.resteasy1137.TestResource; | |||
import org.jboss.shrinkwrap.api.Archive; | |||
import org.jboss.shrinkwrap.api.ShrinkWrap; | |||
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; | |||
|
|||
/** | |||
* RESTEASY-1137 | |||
* | |||
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a> | |||
* @version $Revision: 1.1 $ | |||
* | |||
* Copyright Jul 20, 2015 | |||
*/ | |||
@RunWith(Arquillian.class) | |||
public class TestCustomExceptionMapper | |||
{ | |||
@Deployment | |||
public static Archive<?> createTestArchive() | |||
{ | |||
WebArchive war = ShrinkWrap.create(WebArchive.class, "RESTEASY-1137.war") | |||
.addClasses(TestApplication.class, TestResource.class) | |||
.addClasses(TestClassConstraint.class, TestClassValidator.class, TestReport.class) | |||
.addAsLibrary("1137/validation-versioning.jar", "validation-versioning.jar") | |||
.addAsWebInfResource("1137/web.xml", "web.xml") | |||
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") | |||
; | |||
System.out.println(war.toString(true)); | |||
return war; | |||
} | |||
|
|||
@Test | |||
public void testExceptionMapperInputViolations() throws Exception | |||
{ | |||
Client client = ClientBuilder.newClient(); | |||
Builder builder = client.target("http://localhost:8080/RESTEASY-1137/test/all/a/b/c").request(); | |||
builder.accept(MediaType.APPLICATION_XML); | |||
Response response = builder.get(); | |||
System.out.println("status: " + response.getStatus()); | |||
Assert.assertEquals(444, response.getStatus()); | |||
TestReport report = response.readEntity(TestReport.class); | |||
countViolations(report, 1, 1, 1, 1, 0); | |||
} | |||
|
|||
@Test | |||
public void testExceptionMapperOutputViolations() throws Exception | |||
{ | |||
Client client = ClientBuilder.newClient(); | |||
Builder builder = client.target("http://localhost:8080/RESTEASY-1137/test/all/abc/defg/hijkl").request(); | |||
builder.accept(MediaType.APPLICATION_XML); | |||
Response response = builder.get(); | |||
System.out.println("status: " + response.getStatus()); | |||
Assert.assertEquals(444, response.getStatus()); | |||
TestReport report = response.readEntity(TestReport.class); | |||
countViolations(report, 0, 0, 0, 0, 1); | |||
} | |||
|
|||
|
|||
protected boolean countViolations(TestReport report, int fieldCount, int propertyCount, int classCount, int parameterCount, int returnValueCount) | |||
{ | |||
return report.getFieldViolations() == fieldCount | |||
&& report.getPropertyViolations() == propertyCount | |||
&& report.getClassViolations() == classCount | |||
&& report.getParameterViolations() == parameterCount | |||
&& report.getReturnValueViolations() == returnValueCount; | |||
} | |||
} |
Binary file added
BIN
+2.6 KB
jaxrs/arquillian/RESTEASY-TEST-WF8/src/test/resources/1137/validation-versioning.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions
5
jaxrs/arquillian/RESTEASY-TEST-WF8/src/test/resources/1137/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 | Original file line | 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> |
Oops, something went wrong.