Author: hardy.ferentschik
Date: 2009-08-26 06:50:09 -0400 (Wed, 26 Aug 2009)
New Revision: 17418
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/Friend.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/Name.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/Severity.java
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java
Log:
Added test for payload propagation. Needs still to be mapped to n assertion
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java 2009-08-25
16:07:55 UTC (rev 17417)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionTest.java 2009-08-26
10:50:09 UTC (rev 17418)
@@ -22,6 +22,7 @@
import java.util.List;
import java.util.Set;
import javax.validation.ConstraintDefinitionException;
+import javax.validation.ConstraintPayload;
import javax.validation.ConstraintViolation;
import javax.validation.UnexpectedTypeException;
import javax.validation.Validator;
@@ -262,6 +263,25 @@
}
}
+ @Test
+ public void testPayloadPropagationInComposedConstraints() {
+ Friend john = new Friend( "John", "Doe" );
+
+ Validator validator = TestUtil.getValidatorUnderTest();
+ Set<ConstraintViolation<Friend>> constraintViolations = validator.validate(
john );
+
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertCorrectConstraintTypes( constraintViolations, NotNull.class );
+
+ ConstraintViolation<Friend> constraintViolation =
constraintViolations.iterator().next();
+ Set<Class<ConstraintPayload>> payloads =
constraintViolation.getConstraintDescriptor().getPayload();
+
+ assertTrue( payloads.size() == 1, "There should be one payload in the set"
);
+ Class<ConstraintPayload> payload = payloads.iterator().next();
+ assertTrue( payload.getName().equals( Severity.Warn.class.getName() ), "Unexpected
payload" );
+ }
+
+
private FrenchAddress getFrenchAddressWithoutZipCode() {
FrenchAddress address = new FrenchAddress();
address.setAddressline1( "10 rue des Treuils" );
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/Friend.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/Friend.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/Friend.java 2009-08-26
10:50:09 UTC (rev 17418)
@@ -0,0 +1,61 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jsr303.tck.tests.constraints.constraintcomposition;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Friend {
+ @Name(payload = Severity.Error.class)
+ private String firstName;
+
+ @Name(payload = Severity.Error.class)
+ private String lastName;
+
+ @Name(payload = Severity.Warn.class)
+ private String nickName;
+
+ public Friend(String firstName, String lastName) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ }
+
+ public String getNickName() {
+ return nickName;
+ }
+
+ public void setNickName(String nickName) {
+ this.nickName = nickName;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+}
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/Name.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/Name.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/Name.java 2009-08-26
10:50:09 UTC (rev 17418)
@@ -0,0 +1,47 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jsr303.tck.tests.constraints.constraintcomposition;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.ConstraintPayload;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Documented
+@NotNull
+@Size
+@Constraint(validatedBy = { })
+@Target({ TYPE, METHOD, FIELD })
+@Retention(RUNTIME)
+public @interface Name {
+ String message() default "Not a valid name.";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends ConstraintPayload>[] payload() default { };
+}
\ No newline at end of file
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/Severity.java
===================================================================
---
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/Severity.java
(rev 0)
+++
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/Severity.java 2009-08-26
10:50:09 UTC (rev 17418)
@@ -0,0 +1,35 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jsr303.tck.tests.constraints.constraintcomposition;
+
+import javax.validation.ConstraintPayload;
+
+/**
+ * @author Hardy Ferentschik
+ */
+
+public class Severity {
+ public static class Info implements ConstraintPayload {
+ }
+
+ public static class Warn implements ConstraintPayload {
+ }
+
+ public static class Error implements ConstraintPayload {
+ }
+}