Mail System Error - Returned Mail
by The Post Office
The original message was received at Wed, 22 Jul 2009 16:39:12 +0300 from [100.46.212.35]
----- The following addresses had permanent fatal errors -----
<hibernate-commits(a)lists.jboss.org>
14 years, 9 months
Hibernate SVN: r17190 - in beanvalidation/trunk/validation-tck/src/main: java/org/hibernate/jsr303/tck/tests/validation and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-07-22 09:20:08 -0400 (Wed, 22 Jul 2009)
New Revision: 17190
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/NotEmpty.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateWithGroups.java
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/NotEmpty.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Address.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java
beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
Log:
tests for using groups in the different validation methods
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/NotEmpty.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/NotEmpty.java 2009-07-22 12:24:20 UTC (rev 17189)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/NotEmpty.java 2009-07-22 13:20:08 UTC (rev 17190)
@@ -41,7 +41,7 @@
@NotNull
@Size
public @interface NotEmpty {
- public abstract String message() default "{org.hibernate.validation.constraints.NotEmpty.message}";
+ public abstract String message() default "cannot be empty";
public abstract Class<?>[] groups() default { };
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Address.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Address.java 2009-07-22 12:24:20 UTC (rev 17189)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Address.java 2009-07-22 13:20:08 UTC (rev 17190)
@@ -17,39 +17,40 @@
*/
package org.hibernate.jsr303.tck.tests.validation;
-import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
+import javax.validation.constraints.NotNull;
+import javax.validation.groups.Default;
/**
* @author Hardy Ferentschik
*/
public class Address {
- @NotNull
- @Size(max = 30)
- private String addressline1;
- @NotNull
- @Size(max = 30)
- private String addressline2;
+ @NotEmpty(groups = Minimal.class)
+ private String street;
+ @NotNull(message = "You have to specify a city.")
+ @Size(max = 30, message = "City name cannot be longer than {max} characters.")
+ private String city;
+
+ @NotEmpty(groups = { Minimal.class, Default.class })
private String zipCode;
- private String city;
- public String getAddressline1() {
- return addressline1;
+ public String getStreet1() {
+ return street;
}
- public void setAddressline1(String addressline1) {
- this.addressline1 = addressline1;
+ public void setStreet(String street) {
+ this.street = street;
}
- public String getAddressline2() {
- return addressline2;
+ public String getCity() {
+ return city;
}
- public void setAddressline2(String addressline2) {
- this.addressline2 = addressline2;
+ public void setCity(String city) {
+ this.city = city;
}
public String getZipCode() {
@@ -60,13 +61,6 @@
this.zipCode = zipCode;
}
- @Size(max = 30, message = "City name cannot be longer than 30 characters.")
- @NotNull(message = "You have to specify a city.")
- public String getCity() {
- return city;
+ public interface Minimal {
}
-
- public void setCity(String city) {
- this.city = city;
- }
}
\ No newline at end of file
Copied: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/NotEmpty.java (from rev 17143, beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/NotEmpty.java)
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/NotEmpty.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/NotEmpty.java 2009-07-22 13:20:08 UTC (rev 17190)
@@ -0,0 +1,52 @@
+// $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.validation;
+
+import java.lang.annotation.Documented;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+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.OverridesAttribute;
+import javax.validation.ReportAsSingleViolation;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Documented
+@Constraint(validatedBy = { })
+@Target({ METHOD, FIELD })
+@Retention(RUNTIME)
+@ReportAsSingleViolation
+@NotNull
+@Size
+public @interface NotEmpty {
+ public abstract String message() default "cannot be empty";
+
+ public abstract Class<?>[] groups() default { };
+
+ public abstract Class<? extends ConstraintPayload>[] payload() default { };
+
+ @OverridesAttribute(constraint = Size.class, name = "min")
+ public abstract int min() default 5;
+}
\ No newline at end of file
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java 2009-07-22 12:24:20 UTC (rev 17189)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java 2009-07-22 13:20:08 UTC (rev 17190)
@@ -64,7 +64,6 @@
}
}
-
@Test
@SpecAssertion(section = "4.1.1", id = "e")
public void testIllegalArgumentExceptionIsThrownForNullValue() {
@@ -171,8 +170,8 @@
Validator validator = TestUtil.getDefaultValidator();
Address address = new Address();
- address.setAddressline1( null );
- address.setAddressline2( null );
+ address.setStreet( null );
+ address.setZipCode( null );
String townInNorthWales = "Llanfairpwllgwyngyllgogerychwyrndrobwyll-llantysiliogogogoch";
address.setCity( townInNorthWales );
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java 2009-07-22 12:24:20 UTC (rev 17189)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java 2009-07-22 13:20:08 UTC (rev 17190)
@@ -23,6 +23,7 @@
import javax.validation.ValidationException;
import javax.validation.Validator;
import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
import javax.validation.groups.Default;
import javax.validation.metadata.BeanDescriptor;
import javax.validation.metadata.ConstraintDescriptor;
@@ -44,6 +45,7 @@
import static org.hibernate.jsr303.tck.util.TestUtil.assertConstraintViolation;
import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectPropertyPaths;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectConstraintTypes;
/**
* Tests for the implementation of <code>Validator</code>.
@@ -116,12 +118,13 @@
Validator validator = TestUtil.getDefaultValidator();
Address address = new Address();
- address.setAddressline1( null );
- address.setAddressline2( null );
+ address.setStreet( null );
+ address.setZipCode( null );
address.setCity( "Llanfairpwllgwyngyllgogerychwyrndrobwyll-llantysiliogogogoch" ); //town in North Wales
Set<ConstraintViolation<Address>> constraintViolations = validator.validate( address );
- assertCorrectNumberOfViolations( constraintViolations, 3 );
+ assertCorrectNumberOfViolations( constraintViolations, 2 );
+ assertCorrectConstraintTypes(constraintViolations, Size.class, NotEmpty.class );
}
@Test
Copied: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateWithGroups.java (from rev 17189, beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java)
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateWithGroups.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateWithGroups.java 2009-07-22 13:20:08 UTC (rev 17190)
@@ -0,0 +1,130 @@
+// $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.validation;
+
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+import javax.validation.constraints.NotNull;
+import javax.validation.groups.Default;
+
+import org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.test.audit.annotations.SpecAssertions;
+import org.jboss.testharness.AbstractTest;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.ArtifactType;
+import org.jboss.testharness.impl.packaging.Classes;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectConstraintTypes;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectPropertyPaths;
+
+/**
+ * Tests for the implementation of {@code Validator}.
+ *
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+@Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
+public class ValidateWithGroups extends AbstractTest {
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "4.1.2", id = "a"),
+ @SpecAssertion(section = "4.1.2", id = "b")
+ })
+ public void testCorrectGroupsAreAppliedForValidate() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Set<ConstraintViolation<Address>> constraintViolations = validator.validate( new Address() );
+ assertCorrectNumberOfViolations( constraintViolations, 2 );
+ assertCorrectConstraintTypes( constraintViolations, NotNull.class, NotEmpty.class );
+ assertCorrectPropertyPaths( constraintViolations, "city", "zipCode" );
+
+ constraintViolations = validator.validate( new Address(), Default.class );
+ assertCorrectNumberOfViolations( constraintViolations, 2 );
+ assertCorrectConstraintTypes( constraintViolations, NotNull.class, NotEmpty.class );
+ assertCorrectPropertyPaths( constraintViolations, "city", "zipCode" );
+
+ constraintViolations = validator.validate( new Address(), Address.Minimal.class );
+ assertCorrectNumberOfViolations( constraintViolations, 2 );
+ assertCorrectConstraintTypes( constraintViolations, NotEmpty.class, NotEmpty.class );
+ assertCorrectPropertyPaths( constraintViolations, "street", "zipCode" );
+
+ constraintViolations = validator.validate( new Address(), Default.class, Address.Minimal.class );
+ assertCorrectNumberOfViolations( constraintViolations, 3 );
+ assertCorrectConstraintTypes( constraintViolations, NotNull.class, NotEmpty.class, NotEmpty.class );
+ assertCorrectPropertyPaths( constraintViolations, "city", "street", "zipCode" );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "4.1.2", id = "a"),
+ @SpecAssertion(section = "4.1.2", id = "b")
+ })
+ public void testCorrectGroupsAreAppliedForValidateProperty() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Set<ConstraintViolation<Address>> constraintViolations = validator.validateProperty( new Address(), "city" );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertCorrectConstraintTypes( constraintViolations, NotNull.class );
+ assertCorrectPropertyPaths( constraintViolations, "city" );
+
+ constraintViolations = validator.validateProperty( new Address(), "city", Default.class );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertCorrectConstraintTypes( constraintViolations, NotNull.class );
+ assertCorrectPropertyPaths( constraintViolations, "city" );
+
+ constraintViolations = validator.validateProperty( new Address(), "city", Address.Minimal.class );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+
+ constraintViolations = validator.validateProperty( new Address(), "street", Address.Minimal.class );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertCorrectConstraintTypes( constraintViolations, NotEmpty.class );
+ assertCorrectPropertyPaths( constraintViolations, "street" );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "4.1.2", id = "a"),
+ @SpecAssertion(section = "4.1.2", id = "b")
+ })
+ public void testCorrectGroupsAreAppliedForValidateValue() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Set<ConstraintViolation<Address>> constraintViolations = validator.validateValue( Address.class, "city", null );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertCorrectConstraintTypes( constraintViolations, NotNull.class );
+ assertCorrectPropertyPaths( constraintViolations, "city" );
+
+ constraintViolations = validator.validateValue( Address.class, "city", null, Default.class );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertCorrectConstraintTypes( constraintViolations, NotNull.class );
+ assertCorrectPropertyPaths( constraintViolations, "city" );
+
+ constraintViolations = validator.validateValue( Address.class, "city", null, Address.Minimal.class );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+
+ constraintViolations = validator.validateValue( Address.class, "street", null, Address.Minimal.class );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertCorrectConstraintTypes( constraintViolations, NotEmpty.class );
+ assertCorrectPropertyPaths( constraintViolations, "street" );
+ }
+}
\ No newline at end of file
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java 2009-07-22 12:24:20 UTC (rev 17189)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java 2009-07-22 13:20:08 UTC (rev 17190)
@@ -102,7 +102,7 @@
for ( Class<?> expectedConstraintType : expectedConsraintTypes ) {
assertTrue(
actualConstraintTypes.contains( expectedConstraintType.getName() ),
- "The constraint type " + expectedConstraintType.getName() + " should have been violated."
+ "The constraint type " + expectedConstraintType.getName() + " is not in the list of actual violated constraint types: " + actualConstraintTypes
);
}
}
Modified: beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-07-22 12:24:20 UTC (rev 17189)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-07-22 13:20:08 UTC (rev 17190)
@@ -564,8 +564,7 @@
</section>
<section id="4.1.2" title="groups">
<assertion id="a">
- <text>All constraints belonging to the targeted group are applied during the Section
- 3.5</text>
+ <text>All constraints belonging to the targeted group are applied during the validation routine.</text>
</assertion>
<assertion id="b">
<text>If no group is passed, the Default group is assumed</text>
@@ -574,9 +573,6 @@
<text>When more than one group is evaluated and passed to the various validate methods,
order is not constrained</text>
</assertion>
- <assertion id="d">
- <text>If the group definition is invalid, a GroupDefinitionException is raised</text>
- </assertion>
</section>
<section id="4.2" title="ConstraintViolation">
<assertion id="a">
14 years, 9 months
Hibernate SVN: r17189 - in beanvalidation/trunk/validation-tck/src/main: java/org/hibernate/jsr303/tck/util and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-07-22 08:24:20 -0400 (Wed, 22 Jul 2009)
New Revision: 17189
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/BadlyBehavedEntity.java
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Address.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Order.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateValueTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java
beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
Log:
tests for the different validate methods
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Address.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Address.java 2009-07-22 09:51:41 UTC (rev 17188)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Address.java 2009-07-22 12:24:20 UTC (rev 17189)
@@ -61,7 +61,7 @@
}
@Size(max = 30, message = "City name cannot be longer than 30 characters.")
- @NotNull
+ @NotNull(message = "You have to specify a city.")
public String getCity() {
return city;
}
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/BadlyBehavedEntity.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/BadlyBehavedEntity.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/BadlyBehavedEntity.java 2009-07-22 12:24:20 UTC (rev 17189)
@@ -0,0 +1,32 @@
+// $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.validation;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class BadlyBehavedEntity {
+
+ @NotNull
+ public Object getValue() {
+ throw new RuntimeException( "BadlyBehavedEntity.getValue() always throws an exception." );
+ }
+
+}
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Order.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Order.java 2009-07-22 09:51:41 UTC (rev 17188)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/Order.java 2009-07-22 12:24:20 UTC (rev 17189)
@@ -23,7 +23,7 @@
* @author Hardy Ferentschik
*/
public class Order {
- @NotNull
+ @NotNull(message = "An order must have an order number.")
Integer orderNumber;
public Integer getOrderNumber() {
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java 2009-07-22 09:51:41 UTC (rev 17188)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidatePropertyTest.java 2009-07-22 12:24:20 UTC (rev 17189)
@@ -19,6 +19,7 @@
import java.util.Set;
import javax.validation.ConstraintViolation;
+import javax.validation.ValidationException;
import javax.validation.Validator;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
@@ -39,7 +40,7 @@
import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
/**
- * Tests for the implementation of <code>Validator</code>.
+ * Tests for the implementation of {@code Validator}.
*
* @author Hardy Ferentschik
*/
@@ -47,8 +48,8 @@
@Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
public class ValidatePropertyTest extends AbstractTest {
- //TODO Needs verification
@Test
+ @SpecAssertion(section = "4.1.1", id = "e")
@SuppressWarnings("NullArgumentToVariableArgMethod")
public void testPassingNullAsGroup() {
Validator validator = TestUtil.getDefaultValidator();
@@ -78,7 +79,10 @@
}
@Test
- @SpecAssertion(section = "4.1.1", id = "e")
+ @SpecAssertions({
+ @SpecAssertion(section = "4.1.1", id = "e"),
+ @SpecAssertion(section = "4.1.1", id = "f")
+ })
public void testValidatePropertyWithInvalidPropertyPath() {
Validator validator = TestUtil.getDefaultValidator();
@@ -95,7 +99,7 @@
}
try {
- validator.validateProperty( customer, "" );
+ validator.validateProperty( customer, "foobar" );
fail();
}
catch ( IllegalArgumentException e ) {
@@ -103,15 +107,16 @@
}
try {
- validator.validateProperty( customer, "foobar" );
+ validator.validateProperty( customer, "orders[].foobar" );
fail();
}
catch ( IllegalArgumentException e ) {
// success
}
+ // firstname exists, but the capitalisation is wrong
try {
- validator.validateProperty( customer, "orders[].foobar" );
+ validator.validateProperty( customer, "FirstName" );
fail();
}
catch ( IllegalArgumentException e ) {
@@ -120,9 +125,47 @@
}
@Test
+ @SpecAssertion(section = "4.1.1", id = "e")
+ public void testValidatePropertyWithNullProperty() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Customer customer = new Customer();
+ Order order = new Order();
+ customer.addOrder( order );
+
+
+ try {
+ validator.validateProperty( customer, null );
+ fail();
+ }
+ catch ( IllegalArgumentException e ) {
+ // success
+ }
+ }
+
+ @Test
+ @SpecAssertion(section = "4.1.1", id = "e")
+ public void testValidatePropertyWithEmptyProperty() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Customer customer = new Customer();
+ Order order = new Order();
+ customer.addOrder( order );
+
+ try {
+ validator.validateProperty( customer, "" );
+ fail();
+ }
+ catch ( IllegalArgumentException e ) {
+ // success
+ }
+ }
+
+ @Test
@SpecAssertions({
+ @SpecAssertion(section = "4.1.1", id = "c"),
@SpecAssertion(section = "4.1.1", id = "d"),
- @SpecAssertion(section = "4.1.1", id = "c")
+ @SpecAssertion(section = "4.1.1", id = "f")
})
public void testValidateProperty() {
Validator validator = TestUtil.getDefaultValidator();
@@ -149,8 +192,9 @@
@Test
@SpecAssertions({
+ @SpecAssertion(section = "4.1.1", id = "c"),
@SpecAssertion(section = "4.1.1", id = "d"),
- @SpecAssertion(section = "4.1.1", id = "c")
+ @SpecAssertion(section = "4.1.1", id = "f")
})
public void testValidatePropertyWithIndexedPath() {
Validator validator = TestUtil.getDefaultValidator();
@@ -177,4 +221,24 @@
assertConstraintViolation( violation, ActorListBased.class, null, property );
assertCorrectConstraintViolationMessages( constraintViolations, "Everyone has a last name." );
}
+
+ @Test
+ @SpecAssertion(section = "4.1.1", id = "g")
+ public void testValidIsNotHonoredValidateProperty() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Customer customer = new Customer();
+ Order order = new Order();
+ customer.addOrder( order );
+
+ Set<ConstraintViolation<Customer>> constraintViolations = validator.validateProperty( customer, "orders" );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
+ @Test(expectedExceptions = ValidationException.class)
+ @SpecAssertion(section = "4.1.1", id = "k")
+ public void testUnexpectedExceptionsInValidatePropertyGetWrappedInValidationExceptions() {
+ Validator validator = TestUtil.getDefaultValidator();
+ validator.validateProperty( new BadlyBehavedEntity(), "value" );
+ }
}
\ No newline at end of file
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java 2009-07-22 09:51:41 UTC (rev 17188)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateTest.java 2009-07-22 12:24:20 UTC (rev 17189)
@@ -41,6 +41,7 @@
import org.testng.annotations.Test;
import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertConstraintViolation;
import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectPropertyPaths;
@@ -73,11 +74,19 @@
@SpecAssertion(section = "4.1.1", id = "b")
@Test(expectedExceptions = IllegalArgumentException.class)
- public void testValidateWithNull() {
+ public void testValidateWithNullValue() {
Validator validator = TestUtil.getDefaultValidator();
validator.validate( null );
}
+ @SpecAssertion(section = "4.1.1", id = "b")
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ @SuppressWarnings("NullArgumentToVariableArgMethod")
+ public void testValidateWithNullGroup() {
+ Validator validator = TestUtil.getDefaultValidator();
+ validator.validate( new Boy(), null );
+ }
+
@Test
@SpecAssertions({
@SpecAssertion(section = "4.1.1", id = "a"),
@@ -90,15 +99,15 @@
Engine engine = new Engine();
engine.setSerialNumber( "mail(a)foobar.com" );
Set<ConstraintViolation<Engine>> constraintViolations = validator.validate( engine );
- assertEquals( constraintViolations.size(), 2, "Wrong number of constraints" );
+ assertCorrectNumberOfViolations( constraintViolations, 2 );
engine.setSerialNumber( "ABCDEFGH1234" );
constraintViolations = validator.validate( engine );
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
engine.setSerialNumber( "ABCD-EFGH-1234" );
constraintViolations = validator.validate( engine );
- assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
}
@Test
@@ -112,11 +121,7 @@
address.setCity( "Llanfairpwllgwyngyllgogerychwyrndrobwyll-llantysiliogogogoch" ); //town in North Wales
Set<ConstraintViolation<Address>> constraintViolations = validator.validate( address );
- assertEquals(
- constraintViolations.size(),
- 3,
- "We should have been 2 @NotNull violations for addresslines and one @Length violation for city."
- );
+ assertCorrectNumberOfViolations( constraintViolations, 3 );
}
@Test
@@ -136,7 +141,7 @@
engine.setSerialNumber( "mail(a)foobar.com" );
engine.setSerialNumber( "ABCDEFGH1234" );
Set<ConstraintViolation<Engine>> constraintViolations = validator.validate( engine );
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
ConstraintViolation<Engine> violation = constraintViolations.iterator().next();
@@ -152,7 +157,7 @@
engine.setSerialNumber( "ABCD-EFGH-1234" );
constraintViolations = validator.validate( engine );
- assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
}
@Test
@@ -170,11 +175,11 @@
customer.addOrder( order );
Set<ConstraintViolation<Customer>> constraintViolations = validator.validate( customer );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertCorrectPropertyPaths( constraintViolations, "orders[].orderNumber" );
ConstraintViolation constraintViolation = constraintViolations.iterator().next();
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
assertEquals( constraintViolation.getRootBean(), customer, "Wrong root entity" );
assertEquals( constraintViolation.getInvalidValue(), order.getOrderNumber(), "Wrong value" );
- assertCorrectPropertyPaths( constraintViolations, "orders[].orderNumber" );
}
@Test
@@ -198,7 +203,8 @@
Set<ConstraintViolation<Actor>> constraintViolations = validator.validate( clint );
- assertEquals( constraintViolations.size(), 2, "Wrong number of constraints" );
+ assertCorrectNumberOfViolations( constraintViolations, 2 );
+
ConstraintViolation constraintViolation = constraintViolations.iterator().next();
assertEquals( "Everyone has a last name.", constraintViolation.getMessage(), "Wrong message" );
assertEquals( constraintViolation.getRootBean(), clint, "Wrong root entity" );
@@ -229,7 +235,7 @@
clint.addPlayedWith( morgan );
Set<ConstraintViolation<Actor>> constraintViolations = validator.validate( clint );
- assertEquals( constraintViolations.size(), 2, "Wrong number of constraints" );
+ assertCorrectNumberOfViolations( constraintViolations, 2 );
ConstraintViolation constraintViolation = constraintViolations.iterator().next();
assertEquals( "Everyone has a last name.", constraintViolation.getMessage(), "Wrong message" );
assertEquals( constraintViolation.getRootBean(), clint, "Wrong root entity" );
@@ -269,9 +275,9 @@
customer.addOrder( order );
Set<ConstraintViolation<Person>> constraintViolations = validator.validate( ( Person ) customer );
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
- TestUtil.assertConstraintViolation(
+ assertConstraintViolation(
constraintViolations.iterator().next(),
Customer.class,
null,
@@ -281,7 +287,7 @@
order.setOrderNumber( 123 );
constraintViolations = validator.validate( ( Person ) customer );
- assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
}
@Test
@@ -300,7 +306,7 @@
Set<ConstraintViolation<Customer>> constraintViolations = validator.validate(
customer, Default.class, First.class, Second.class, Last.class
);
- assertEquals( constraintViolations.size(), 100, "Wrong number of constraints" );
+ assertCorrectNumberOfViolations( constraintViolations, 100 );
}
@Test
@@ -340,6 +346,13 @@
assertCorrectNumberOfViolations( violations, 0 );
}
+ @Test(expectedExceptions = ValidationException.class)
+ @SpecAssertion(section = "4.1.1", id = "k")
+ public void testUnexpectedExceptionsInValidateGetWrappedInValidationExceptions() {
+ Validator validator = TestUtil.getDefaultValidator();
+ validator.validate( new BadlyBehavedEntity() );
+ }
+
class Car {
@Pattern(regexp = "[A-Z][A-Z][A-Z]-[0-9][0-9][0-9]", groups = { First.class, Second.class })
private String licensePlateNumber;
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateValueTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateValueTest.java 2009-07-22 09:51:41 UTC (rev 17188)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/validation/ValidateValueTest.java 2009-07-22 12:24:20 UTC (rev 17189)
@@ -21,6 +21,7 @@
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
+import org.jboss.test.audit.annotations.SpecAssertion;
import org.jboss.testharness.AbstractTest;
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.ArtifactType;
@@ -30,6 +31,9 @@
import org.testng.annotations.Test;
import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertConstraintViolation;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectConstraintViolationMessages;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectNumberOfViolations;
import static org.hibernate.jsr303.tck.util.TestUtil.assertCorrectPropertyPaths;
/**
@@ -38,44 +42,59 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
+@Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
public class ValidateValueTest extends AbstractTest {
+ @Test
+ @SpecAssertion(section = "4.1.1", id = "h")
+ public void testValidateValueSuccess() {
+ Validator validator = TestUtil.getDefaultValidator();
+ Set<ConstraintViolation<Address>> constraintViolations = validator.validateValue(
+ Address.class, "city", "Paris"
+ );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
+
@Test
- @SuppressWarnings("NullArgumentToVariableArgMethod")
- public void testPassingNullAsGroup() {
+ @SpecAssertion(section = "4.1.1", id = "h")
+ public void testValidateValueFailure() {
Validator validator = TestUtil.getDefaultValidator();
- Customer customer = new Customer();
- try {
- validator.validate( customer, null );
- }
- catch ( IllegalArgumentException e ) {
- // success
- }
- try {
- validator.validateProperty( customer, "firstName", null );
- fail();
- }
- catch ( IllegalArgumentException e ) {
- // success
- }
+ Set<ConstraintViolation<Address>> constraintViolations = validator.validateValue(
+ Address.class, "city", null
+ );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertCorrectConstraintViolationMessages( constraintViolations, "You have to specify a city." );
+ }
- try {
- validator.validateValue( Customer.class, "firstName", "foobar", null );
- fail();
- }
- catch ( IllegalArgumentException e ) {
- // success
- }
+ @Test
+ @SpecAssertion(section = "4.1.1", id = "h")
+ public void testValidateValue() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Set<ConstraintViolation<Customer>> constraintViolations = validator.validateValue(
+ Customer.class, "orders[0].orderNumber", null
+ );
+ assertCorrectNumberOfViolations( constraintViolations, 1 );
+ assertCorrectPropertyPaths( constraintViolations, "orders[0].orderNumber" );
+ assertCorrectConstraintViolationMessages( constraintViolations, "An order must have an order number." );
+
+ ConstraintViolation constraintViolation = constraintViolations.iterator().next();
+ assertConstraintViolation( constraintViolation, Customer.class, null, "orders[0].orderNumber" );
+ assertEquals( constraintViolation.getRootBeanClass(), Customer.class, "Wrong root bean class" );
+
+ constraintViolations = validator.validateValue( Customer.class, "orders[0].orderNumber", 1234 );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
}
@Test
- public void testValidateWithNullProperty() {
+ @SpecAssertion(section = "4.1.1", id = "i")
+ public void testValidateValueWithInvalidPropertyPath() {
Validator validator = TestUtil.getDefaultValidator();
+
try {
- validator.validate( null );
+ validator.validateValue( Customer.class, "foobar", null );
fail();
}
catch ( IllegalArgumentException e ) {
@@ -83,15 +102,16 @@
}
try {
- validator.validateProperty( null, "firstName" );
+ validator.validateValue( Customer.class, "orders[0].foobar", null );
fail();
}
catch ( IllegalArgumentException e ) {
// success
}
+ // firstname exists, but the capitalisation is wrong
try {
- validator.validateValue( null, "firstName", "foobar" );
+ validator.validateValue( Customer.class, "FirstName", null );
fail();
}
catch ( IllegalArgumentException e ) {
@@ -100,68 +120,25 @@
}
@Test
- public void testMultipleValidationMethods() {
+ @SuppressWarnings("NullArgumentToVariableArgMethod")
+ @SpecAssertion(section = "4.1.1", id = "i")
+ public void testValidateValuePassingNullAsGroup() {
Validator validator = TestUtil.getDefaultValidator();
- Address address = new Address();
- address.setAddressline1( null );
- address.setAddressline2( null );
- address.setCity( "Llanfairpwllgwyngyllgogerychwyrndrobwyll-llantysiliogogogoch" ); //town in North Wales
-
- Set<ConstraintViolation<Address>> constraintViolations = validator.validate( address );
- assertEquals(
- constraintViolations.size(),
- 3,
- "we should have been 2 not null violation for addresslines and one length violation for city"
- );
-
- constraintViolations = validator.validateProperty( address, "city" );
- assertEquals(
- constraintViolations.size(),
- 1,
- "only city should be validated"
- );
-
- constraintViolations = validator.validateProperty( address, "city" );
- assertEquals(
- constraintViolations.size(),
- 1,
- "only city should be validated"
- );
-
- constraintViolations = validator.validateValue( Address.class, "city", "Paris" );
- assertEquals(
- constraintViolations.size(),
- 0,
- "Paris should be a valid city name."
- );
+ try {
+ validator.validateValue( Customer.class, "firstName", "foobar", null );
+ fail();
+ }
+ catch ( IllegalArgumentException e ) {
+ // success
+ }
}
@Test
- public void testValidateValue() {
+ @SpecAssertion(section = "4.1.1", id = "i")
+ public void testValidateValueWithEmptyPropertyPath() {
Validator validator = TestUtil.getDefaultValidator();
- Set<ConstraintViolation<Customer>> constraintViolations = validator.validateValue(
- Customer.class, "orders[0].orderNumber", null
- );
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
-
- ConstraintViolation constraintViolation = constraintViolations.iterator().next();
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
- assertEquals( constraintViolation.getMessage(), "may not be null", "Wrong message" );
- assertEquals( constraintViolation.getRootBean(), null, "Wrong root entity" );
- assertEquals( constraintViolation.getRootBeanClass(), Customer.class, "Wrong root bean class" );
- assertEquals( constraintViolation.getInvalidValue(), null, "Wrong value" );
- assertCorrectPropertyPaths( constraintViolations, "orders[0].orderNumber" );
-
- constraintViolations = validator.validateValue( Customer.class, "orders[0].orderNumber", 1234 );
- assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
- }
-
- @Test
- public void testValidateValueWithInvalidPropertyPath() {
- Validator validator = TestUtil.getDefaultValidator();
-
try {
validator.validateValue( Customer.class, "", null );
fail();
@@ -169,21 +146,46 @@
catch ( IllegalArgumentException e ) {
// success
}
+ }
+ @Test
+ @SpecAssertion(section = "4.1.1", id = "i")
+ public void testValidateValueWithNullObject() {
+ Validator validator = TestUtil.getDefaultValidator();
try {
- validator.validateValue( Customer.class, "foobar", null );
+ validator.validateValue( null, "firstName", "foobar" );
fail();
}
catch ( IllegalArgumentException e ) {
// success
}
+ }
+ @Test
+ @SpecAssertion(section = "4.1.1", id = "i")
+ public void testValidateValueWithNullPropertyName() {
+ Validator validator = TestUtil.getDefaultValidator();
try {
- validator.validateValue( Customer.class, "orders[0].foobar", null );
+ validator.validateValue( Customer.class, null, "foobar" );
fail();
}
catch ( IllegalArgumentException e ) {
// success
}
}
+
+ @Test
+ @SpecAssertion(section = "4.1.1", id = "j")
+ public void testValidIsNotHonoredValidateValue() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Customer customer = new Customer();
+ Order order = new Order();
+ customer.addOrder( order );
+
+ Set<ConstraintViolation<Customer>> constraintViolations = validator.validateValue(
+ Customer.class, "orders", order
+ );
+ assertCorrectNumberOfViolations( constraintViolations, 0 );
+ }
}
\ No newline at end of file
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java 2009-07-22 09:51:41 UTC (rev 17188)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java 2009-07-22 12:24:20 UTC (rev 17189)
@@ -134,7 +134,7 @@
}
assertEquals(
- violation.getRootBean().getClass(),
+ violation.getRootBeanClass(),
rootBean,
"Wrong root bean."
);
Modified: beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-07-22 09:51:41 UTC (rev 17188)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-07-22 12:24:20 UTC (rev 17189)
@@ -524,8 +524,7 @@
<text>validate(T object, Class... groups) is used to validate a given object</text>
</assertion>
<assertion id="b">
- <text>An IllegalArgumentException is thrown if object is null when validate() is
- called.</text>
+ <text>An IllegalArgumentException is thrown when validateProperty is called and object is null or null is passed to the varargs groups.</text>
</assertion>
<assertion id="c">
<text>A Set containing all ConstraintViolation objects representing the failing
@@ -536,15 +535,15 @@
field or property of an object</text>
</assertion>
<assertion id="e">
- <text>An IllegalArgumentException is thrown if object is null or propertyName is null
- empty or invalid when validateProperty() is called.</text>
+ <text>An IllegalArgumentException is thrown when validateProperty is called and object is null or propertyName is null
+ empty or invalid or null is passed to the varargs groups.</text>
</assertion>
<assertion id="f">
- <text>The property name is the JavaBeans property name (as defined by the JavaBeans
+ <text>The property name in validateProperty is the JavaBeans property name (as defined by the JavaBeans
Introspector class)</text>
</assertion>
<assertion id="g">
- <text>@Valid is not honored by validateProperty()</text>
+ <text>@Valid is not honored by a call to validateProperty.</text>
</assertion>
<assertion id="h">
<text>validateValue(Class beanType, String propertyName, Object value, Class... groups)
@@ -552,11 +551,11 @@
superclasses, if the property value were value.</text>
</assertion>
<assertion id="i">
- <text>An IllegalArgumentException is thrown if object is null or propertyName is null
- empty or invalid when validateValue() is called.</text>
+ <text>An IllegalArgumentException is thrown when validateValue is called and object is null or propertyName is null
+ empty or invalid or null is passed to the varargs groups.</text>
</assertion>
<assertion id="j">
- <text>@Valid is not honored by validateValue()</text>
+ <text>@Valid is not honored by validateValue.</text>
</assertion>
<assertion id="k">
<text>If some unrecoverable failure happens during validation, a ValidationException is
14 years, 9 months
Hibernate SVN: r17188 - beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-07-22 05:51:41 -0400 (Wed, 22 Jul 2009)
New Revision: 17188
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/CustomConstraint.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/ValidatorResolutionTest.java
Log:
validator resolution tests
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/CustomConstraint.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/CustomConstraint.java 2009-07-22 00:16:59 UTC (rev 17187)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/CustomConstraint.java 2009-07-22 09:51:41 UTC (rev 17188)
@@ -35,9 +35,11 @@
* @author Hardy Ferentschik
*/
@Constraint(validatedBy = {
- CustomConstraint.AmbigiousValidatorBaseClass.class,
- CustomConstraint.AmbigiousValidatorForSubClassA.class,
- CustomConstraint.AmbigiousValidatorForSubClassB.class
+ CustomConstraint.ValidatorBaseClass.class,
+ CustomConstraint.ValidatorForSubClassA.class,
+ CustomConstraint.ValidatorForSubClassB.class,
+ CustomConstraint.ValidatorForCustomClass.class,
+ CustomConstraint.ValidatorForCustomInterface.class
})
@Documented
@Target({ METHOD, FIELD, TYPE })
@@ -50,7 +52,7 @@
public abstract Class<? extends ConstraintPayload>[] payload() default { };
- public class AmbigiousValidatorBaseClass implements ConstraintValidator<CustomConstraint, BaseClass> {
+ public class ValidatorBaseClass implements ConstraintValidator<CustomConstraint, BaseClass> {
public void initialize(CustomConstraint parameters) {
}
@@ -60,7 +62,7 @@
}
}
- public class AmbigiousValidatorForSubClassA implements ConstraintValidator<CustomConstraint, SubClassA> {
+ public class ValidatorForSubClassA implements ConstraintValidator<CustomConstraint, SubClassA> {
static int callCounter = 0;
public void initialize(CustomConstraint parameters) {
@@ -75,7 +77,7 @@
}
}
- public class AmbigiousValidatorForSubClassB implements ConstraintValidator<CustomConstraint, SubClassB> {
+ public class ValidatorForSubClassB implements ConstraintValidator<CustomConstraint, SubClassB> {
static int callCounter = 0;
public void initialize(CustomConstraint parameters) {
@@ -89,4 +91,36 @@
return true;
}
}
+
+ public class ValidatorForCustomClass
+ implements ConstraintValidator<CustomConstraint, ValidatorResolutionTest.CustomClass> {
+ static int callCounter = 0;
+
+ public void initialize(CustomConstraint parameters) {
+ }
+
+ public boolean isValid(ValidatorResolutionTest.CustomClass customClass, ConstraintValidatorContext constraintValidatorContext) {
+ callCounter++;
+ if ( callCounter > 1 ) {
+ throw new IllegalStateException( "This method should have been only called once during the tests." );
+ }
+ return true;
+ }
+ }
+
+ public class ValidatorForCustomInterface
+ implements ConstraintValidator<CustomConstraint, ValidatorResolutionTest.CustomInterface> {
+ static int callCounter = 0;
+
+ public void initialize(CustomConstraint parameters) {
+ }
+
+ public boolean isValid(ValidatorResolutionTest.CustomInterface customInterface, ConstraintValidatorContext constraintValidatorContext) {
+ callCounter++;
+ if ( callCounter > 1 ) {
+ throw new IllegalStateException( "This method should have been only called once during the tests." );
+ }
+ return true;
+ }
+ }
}
\ No newline at end of file
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/ValidatorResolutionTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/ValidatorResolutionTest.java 2009-07-22 00:16:59 UTC (rev 17187)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/ValidatorResolutionTest.java 2009-07-22 09:51:41 UTC (rev 17188)
@@ -48,28 +48,85 @@
public class ValidatorResolutionTest {
@Test
+ @SpecAssertion(section = "3.5.3", id = "a")
+ public void testTargetTypeIsInterface() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+
+ assertEquals(
+ CustomConstraint.ValidatorForCustomInterface.callCounter,
+ 0,
+ "The validate method of ValidatorForCustomInterface should have been called yet."
+ );
+
+ validator.validate( new CustomInterfaceImpl() );
+
+ assertEquals(
+ CustomConstraint.ValidatorForCustomInterface.callCounter,
+ 1,
+ "The validate method of ValidatorForCustomInterface should have been called."
+ );
+ }
+
+ @Test
+ @SpecAssertion(section = "3.5.3", id = "a")
+ public void testTargetTypeIsCLass() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+
+ assertEquals(
+ CustomConstraint.ValidatorForCustomClass.callCounter,
+ 0,
+ "The validate method of ValidatorForCustomClass should have been called yet."
+ );
+
+ validator.validate( new CustomClass() );
+
+ assertEquals(
+ CustomConstraint.ValidatorForCustomClass.callCounter,
+ 1,
+ "The validate method of ValidatorForCustomClass should have been called."
+ );
+ }
+
+
+ @Test
@SpecAssertion(section = "3.5.3", id = "b")
- public void testFieldTypeIsTargetedType() {
+ public void testTargetedTypeIsField() {
Validator validator = TestUtil.getDefaultValidator();
+
+ assertEquals(
+ CustomConstraint.ValidatorForSubClassA.callCounter,
+ 0,
+ "The validate method of ValidatorForSubClassA should have been called yet."
+ );
+
validator.validate( new SubClassAHolder( new SubClassA() ) );
assertEquals(
- CustomConstraint.AmbigiousValidatorForSubClassA.callCounter,
+ CustomConstraint.ValidatorForSubClassA.callCounter,
1,
- "The validated method of AmbigiousValidatorForSubClassA should have benn called."
+ "The validate method of ValidatorForSubClassA should have been called."
);
}
@Test
@SpecAssertion(section = "3.5.3", id = "c")
- public void testGetterTypeIsTargetedType() {
+ public void testTargetedTypeIsGetter() {
Validator validator = TestUtil.getDefaultValidator();
+
+ assertEquals(
+ CustomConstraint.ValidatorForSubClassB.callCounter,
+ 0,
+ "The validate method of ValidatorForSubClassB should have been called yet."
+ );
+
validator.validate( new SubClassBHolder( new SubClassB() ) );
assertEquals(
- CustomConstraint.AmbigiousValidatorForSubClassB.callCounter,
+ CustomConstraint.ValidatorForSubClassB.callCounter,
1,
- "The validated method of AmbigiousValidatorForSubClassA should have benn called."
+ "The validate method of ValidatorForSubClassB should have been called."
);
}
@@ -228,4 +285,17 @@
return ( SubClassB ) baseClass;
}
}
+
+ @CustomConstraint
+ public class CustomClass {
+
+ }
+
+ @CustomConstraint
+ public interface CustomInterface {
+ }
+
+ public class CustomInterfaceImpl implements CustomInterface {
+
+ }
}
\ No newline at end of file
14 years, 9 months
Hibernate SVN: r17187 - in core/trunk/annotations/src: main/java/org/hibernate/cfg/annotations and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-07-21 20:16:59 -0400 (Tue, 21 Jul 2009)
New Revision: 17187
Added:
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/MapKeyJoinColumnDelegator.java
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/Ejb3Column.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/Ejb3JoinColumn.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/indexcoll/Atmosphere.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/target/Brand.java
Log:
ANN-857 implement @MapKeyJoinColumn and @MapKeyJoinColumns + _KEY default column name for key. Also keep legacy support for old naming solution
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2009-07-21 15:57:57 UTC (rev 17186)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2009-07-22 00:16:59 UTC (rev 17187)
@@ -74,6 +74,8 @@
import javax.persistence.CollectionTable;
import javax.persistence.UniqueConstraint;
import javax.persistence.MapKeyColumn;
+import javax.persistence.MapKeyJoinColumns;
+import javax.persistence.MapKeyJoinColumn;
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
@@ -135,6 +137,7 @@
import org.hibernate.cfg.annotations.TableBinder;
import org.hibernate.cfg.annotations.MapKeyColumnDelegator;
import org.hibernate.cfg.annotations.CustomizableColumns;
+import org.hibernate.cfg.annotations.MapKeyJoinColumnDelegator;
import org.hibernate.engine.FilterDefinition;
import org.hibernate.engine.Versioning;
import org.hibernate.id.MultipleHiLoPerTableGenerator;
@@ -1540,39 +1543,88 @@
mappings
);
}
+ {
+ Column[] keyColumns = null;
+ //JPA 2 has priority and has different default column values, differenciate legacy from JPA 2
+ Boolean isJPA2 = null;
+ if ( property.isAnnotationPresent( MapKeyColumn.class ) ) {
+ isJPA2 = Boolean.TRUE;
+ keyColumns = new Column[] { new MapKeyColumnDelegator( property.getAnnotation( MapKeyColumn.class ) ) };
+ }
+ else if ( property.isAnnotationPresent( org.hibernate.annotations.MapKey.class ) ) {
+ if ( isJPA2 == null) {
+ isJPA2 = Boolean.FALSE;
+ }
+ keyColumns = property.getAnnotation( org.hibernate.annotations.MapKey.class ).columns();
+ }
- Column[] keyColumns = null;
- //JPA 2 has priority
- if ( property.isAnnotationPresent( MapKeyColumn.class ) ) {
- keyColumns = new Column[] { new MapKeyColumnDelegator( property.getAnnotation( MapKeyColumn.class ) ) };
+ //not explicitly legacy
+ if ( isJPA2 == null) {
+ isJPA2 = Boolean.TRUE;
+ }
+
+ //nullify empty array
+ keyColumns = keyColumns != null && keyColumns.length > 0 ? keyColumns : null;
+
+ PropertyData mapKeyVirtualProperty = new WrappedInferredData( inferredData, "mapkey" );
+ Ejb3Column[] mapColumns = Ejb3Column.buildColumnFromAnnotation(
+ keyColumns,
+ null,
+ Nullability.FORCED_NOT_NULL,
+ propertyHolder,
+ isJPA2 ? inferredData : mapKeyVirtualProperty,
+ isJPA2 ? "_KEY" : null,
+ entityBinder.getSecondaryTables(),
+ mappings
+ );
+ collectionBinder.setMapKeyColumns( mapColumns );
}
- else if ( property.isAnnotationPresent( org.hibernate.annotations.MapKey.class ) ) {
- keyColumns = property.getAnnotation( org.hibernate.annotations.MapKey.class ).columns();
- }
- //nullify empty array
- keyColumns = keyColumns != null && keyColumns.length > 0 ? keyColumns : null;
+ {
+ JoinColumn[] joinKeyColumns = null;
+ //JPA 2 has priority and has different default column values, differenciate legacy from JPA 2
+ Boolean isJPA2 = null;
+ if ( property.isAnnotationPresent( MapKeyJoinColumns.class ) ) {
+ isJPA2 = Boolean.TRUE;
+ final MapKeyJoinColumn[] mapKeyJoinColumns = property.getAnnotation( MapKeyJoinColumns.class ).value();
+ joinKeyColumns = new JoinColumn[mapKeyJoinColumns.length];
+ int index = 0;
+ for ( MapKeyJoinColumn joinColumn : mapKeyJoinColumns ) {
+ joinKeyColumns[index] = new MapKeyJoinColumnDelegator( joinColumn );
+ index++;
+ }
+ if ( joinKeyColumns != null ) {
+ throw new AnnotationException( "@MapKeyJoinColumn and @MapKeyJoinColumns used on the same property: "
+ + StringHelper.qualify( propertyHolder.getClassName(), property.getName() ) );
+ }
+ }
+ else if ( property.isAnnotationPresent( MapKeyJoinColumn.class ) ) {
+ isJPA2 = Boolean.TRUE;
+ joinKeyColumns = new JoinColumn[] { new MapKeyJoinColumnDelegator( property.getAnnotation( MapKeyJoinColumn.class ) ) };
+ }
+ else if ( property.isAnnotationPresent( org.hibernate.annotations.MapKeyManyToMany.class ) ) {
+ if ( isJPA2 == null) {
+ isJPA2 = Boolean.FALSE;
+ }
+ joinKeyColumns = property.getAnnotation( org.hibernate.annotations.MapKeyManyToMany.class ).joinColumns();
+ }
- PropertyData mapKeyVirtualProperty = new WrappedInferredData( inferredData, "mapkey" );
- Ejb3Column[] mapColumns = Ejb3Column.buildColumnFromAnnotation(
- keyColumns,
- null,
- Nullability.FORCED_NOT_NULL,
- propertyHolder,
- mapKeyVirtualProperty,
- entityBinder.getSecondaryTables(),
- mappings
- );
- collectionBinder.setMapKeyColumns( mapColumns );
+ //not explicitly legacy
+ if ( isJPA2 == null) {
+ isJPA2 = Boolean.TRUE;
+ }
- MapKeyManyToMany mapKeyManyToMany = property.getAnnotation( MapKeyManyToMany.class );
- Ejb3JoinColumn[] mapJoinColumns = Ejb3JoinColumn.buildJoinColumns(
- mapKeyManyToMany != null ?
- mapKeyManyToMany.joinColumns() :
- null,
- null, entityBinder.getSecondaryTables(),
- propertyHolder, mapKeyVirtualProperty.getPropertyName(), mappings
- );
- collectionBinder.setMapKeyManyToManyColumns( mapJoinColumns );
+ PropertyData mapKeyVirtualProperty = new WrappedInferredData( inferredData, "mapkey" );
+ Ejb3JoinColumn[] mapJoinColumns = Ejb3JoinColumn.buildJoinColumnsWithDefaultColumnSuffix(
+ joinKeyColumns,
+ null,
+ entityBinder.getSecondaryTables(),
+ propertyHolder,
+ isJPA2 ? inferredData.getPropertyName() : mapKeyVirtualProperty.getPropertyName(),
+ isJPA2 ? "_KEY" : null,
+ mappings
+ );
+ collectionBinder.setMapKeyManyToManyColumns( mapJoinColumns );
+ }
//potential element
collectionBinder.setEmbedded( property.isAnnotationPresent( Embedded.class ) );
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/Ejb3Column.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/Ejb3Column.java 2009-07-21 15:57:57 UTC (rev 17186)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/Ejb3Column.java 2009-07-22 00:16:59 UTC (rev 17187)
@@ -336,6 +336,18 @@
PropertyData inferredData,
Map<String, Join> secondaryTables,
ExtendedMappings mappings
+ ){
+ return buildColumnFromAnnotation(
+ anns,
+ formulaAnn, nullability, propertyHolder, inferredData, null, secondaryTables, mappings);
+ }
+ public static Ejb3Column[] buildColumnFromAnnotation(
+ javax.persistence.Column[] anns,
+ org.hibernate.annotations.Formula formulaAnn, Nullability nullability, PropertyHolder propertyHolder,
+ PropertyData inferredData,
+ String suffixForDefaultColumnName,
+ Map<String, Join> secondaryTables,
+ ExtendedMappings mappings
) {
Ejb3Column[] columns;
if ( formulaAnn != null ) {
@@ -361,7 +373,12 @@
log.debug( "Column(s) overridden for property {}", inferredData.getPropertyName() );
}
if ( actualCols == null ) {
- columns = buildImplicitColumn( inferredData, secondaryTables, propertyHolder, nullability, mappings );
+ columns = buildImplicitColumn( inferredData,
+ suffixForDefaultColumnName,
+ secondaryTables,
+ propertyHolder,
+ nullability,
+ mappings );
}
else {
final int length = actualCols.length;
@@ -376,6 +393,12 @@
column.setPrecision( col.precision() );
column.setScale( col.scale() );
column.setLogicalColumnName( col.name() );
+ //support for explicit property name + suffix
+ if ( StringHelper.isEmpty( column.getLogicalColumnName() )
+ && ! StringHelper.isEmpty( suffixForDefaultColumnName ) ) {
+ column.setLogicalColumnName( inferredData.getPropertyName() + suffixForDefaultColumnName );
+ }
+
column.setPropertyName(
BinderHelper.getRelativePath( propertyHolder, inferredData.getPropertyName() )
);
@@ -398,8 +421,12 @@
}
private static Ejb3Column[] buildImplicitColumn(
- PropertyData inferredData, Map<String, Join> secondaryTables, PropertyHolder propertyHolder,
- Nullability nullability, ExtendedMappings mappings
+ PropertyData inferredData,
+ String suffixForDefaultColumnName,
+ Map<String, Join> secondaryTables,
+ PropertyHolder propertyHolder,
+ Nullability nullability,
+ ExtendedMappings mappings
) {
Ejb3Column[] columns;
columns = new Ejb3Column[1];
@@ -412,12 +439,22 @@
column.setNullable( false );
}
column.setLength( DEFAULT_COLUMN_LENGTH );
+ final String propertyName = inferredData.getPropertyName();
column.setPropertyName(
- BinderHelper.getRelativePath( propertyHolder, inferredData.getPropertyName() )
+ BinderHelper.getRelativePath( propertyHolder, propertyName )
);
column.setPropertyHolder( propertyHolder );
column.setJoins( secondaryTables );
column.setMappings( mappings );
+
+ // property name + suffix is an "explicit" column name
+ if ( !StringHelper.isEmpty( suffixForDefaultColumnName ) ) {
+ column.setLogicalColumnName( propertyName + suffixForDefaultColumnName );
+ column.setImplicit( false );
+ }
+ else {
+ column.setImplicit( true );
+ }
column.bind();
columns[0] = column;
return columns;
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/Ejb3JoinColumn.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/Ejb3JoinColumn.java 2009-07-21 15:57:57 UTC (rev 17186)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/Ejb3JoinColumn.java 2009-07-22 00:16:59 UTC (rev 17187)
@@ -134,13 +134,31 @@
String propertyName,
ExtendedMappings mappings
) {
+ return buildJoinColumnsWithDefaultColumnSuffix(anns, mappedBy, joins, propertyHolder, propertyName, "", mappings);
+ }
+
+ public static Ejb3JoinColumn[] buildJoinColumnsWithDefaultColumnSuffix(
+ JoinColumn[] anns,
+ String mappedBy, Map<String, Join> joins,
+ PropertyHolder propertyHolder,
+ String propertyName,
+ String suffixForDefaultColumnName,
+ ExtendedMappings mappings
+ ) {
JoinColumn[] actualColumns = propertyHolder.getOverriddenJoinColumn(
StringHelper.qualify( propertyHolder.getPath(), propertyName )
);
if ( actualColumns == null ) actualColumns = anns;
if ( actualColumns == null || actualColumns.length == 0 ) {
return new Ejb3JoinColumn[] {
- buildJoinColumn( (JoinColumn) null, mappedBy, joins, propertyHolder, propertyName, mappings )
+ buildJoinColumn(
+ (JoinColumn) null,
+ mappedBy,
+ joins,
+ propertyHolder,
+ propertyName,
+ suffixForDefaultColumnName,
+ mappings )
};
}
else {
@@ -153,6 +171,7 @@
joins,
propertyHolder,
propertyName,
+ suffixForDefaultColumnName,
mappings
);
}
@@ -168,6 +187,7 @@
String mappedBy, Map<String, Join> joins,
PropertyHolder propertyHolder,
String propertyName,
+ String suffixForDefaultColumnName,
ExtendedMappings mappings
) {
if ( ann != null ) {
@@ -179,6 +199,10 @@
}
Ejb3JoinColumn joinColumn = new Ejb3JoinColumn();
joinColumn.setJoinAnnotation( ann, null );
+ if ( StringHelper.isEmpty( joinColumn.getLogicalColumnName() )
+ && ! StringHelper.isEmpty( suffixForDefaultColumnName ) ) {
+ joinColumn.setLogicalColumnName( propertyName + suffixForDefaultColumnName );
+ }
joinColumn.setJoins( joins );
joinColumn.setPropertyHolder( propertyHolder );
joinColumn.setPropertyName( BinderHelper.getRelativePath( propertyHolder, propertyName ) );
@@ -192,8 +216,17 @@
joinColumn.setMappedBy( mappedBy );
joinColumn.setJoins( joins );
joinColumn.setPropertyHolder( propertyHolder );
- joinColumn.setPropertyName( BinderHelper.getRelativePath( propertyHolder, propertyName ) );
- joinColumn.setImplicit( true );
+ joinColumn.setPropertyName(
+ BinderHelper.getRelativePath( propertyHolder, propertyName )
+ );
+ // property name + suffix is an "explicit" column name
+ if ( !StringHelper.isEmpty( suffixForDefaultColumnName ) ) {
+ joinColumn.setLogicalColumnName( propertyName + suffixForDefaultColumnName );
+ joinColumn.setImplicit( false );
+ }
+ else {
+ joinColumn.setImplicit( true );
+ }
joinColumn.setMappings( mappings );
joinColumn.bind();
return joinColumn;
Added: core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/MapKeyJoinColumnDelegator.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/MapKeyJoinColumnDelegator.java (rev 0)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/MapKeyJoinColumnDelegator.java 2009-07-22 00:16:59 UTC (rev 17187)
@@ -0,0 +1,54 @@
+package org.hibernate.cfg.annotations;
+
+import java.lang.annotation.Annotation;
+import javax.persistence.Column;
+import javax.persistence.MapKeyJoinColumn;
+import javax.persistence.JoinColumn;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@SuppressWarnings({ "ClassExplicitlyAnnotation" })
+public class MapKeyJoinColumnDelegator implements JoinColumn {
+ private final MapKeyJoinColumn column;
+
+ public MapKeyJoinColumnDelegator(MapKeyJoinColumn column) {
+ this.column = column;
+ }
+
+ public String name() {
+ return column.name();
+ }
+
+ public String referencedColumnName() {
+ return column.referencedColumnName();
+ }
+
+ public boolean unique() {
+ return column.unique();
+ }
+
+ public boolean nullable() {
+ return column.nullable();
+ }
+
+ public boolean insertable() {
+ return column.insertable();
+ }
+
+ public boolean updatable() {
+ return column.updatable();
+ }
+
+ public String columnDefinition() {
+ return column.columnDefinition();
+ }
+
+ public String table() {
+ return column.table();
+ }
+
+ public Class<? extends Annotation> annotationType() {
+ return Column.class;
+ }
+}
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/indexcoll/Atmosphere.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/indexcoll/Atmosphere.java 2009-07-21 15:57:57 UTC (rev 17186)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/indexcoll/Atmosphere.java 2009-07-22 00:16:59 UTC (rev 17187)
@@ -12,10 +12,10 @@
import javax.persistence.JoinTable;
import javax.persistence.JoinColumn;
import javax.persistence.MapKeyColumn;
+import javax.persistence.MapKeyJoinColumn;
import org.hibernate.annotations.MapKey;
import org.hibernate.annotations.CollectionOfElements;
-import org.hibernate.annotations.MapKeyManyToMany;
/**
* @author Emmanuel Bernard
@@ -31,13 +31,31 @@
public Map<String, Gas> gases = new HashMap<String, Gas>();
@ManyToMany(cascade = CascadeType.ALL)
- @MapKeyManyToMany(joinColumns = @JoinColumn(name="gas_id") )
+ @MapKeyJoinColumn(name="gas_id" )
@JoinTable(name = "Gas_per_key")
public Map<GasKey, Gas> gasesPerKey = new HashMap<GasKey, Gas>();
@CollectionOfElements //TODO migrate to @ElementCollection ; @MapKeyManyToMany ??
@Column(name="composition_rate")
- @MapKeyManyToMany(joinColumns = @JoinColumn(name="gas_id"))
+ @MapKeyJoinColumn(name="gas_id" )
@JoinTable(name = "Composition", joinColumns = @JoinColumn(name = "atmosphere_id"))
public Map<Gas, Double> composition = new HashMap<Gas, Double>();
+
+ //use default JPA 2 column name for map key
+ @ManyToMany(cascade = CascadeType.ALL)
+ @MapKeyColumn
+ @JoinTable(name="Atm_Gas_Def")
+ public Map<String, Gas> gasesDef = new HashMap<String, Gas>();
+
+ //use default HAN legacy column name for map key
+ @ManyToMany(cascade = CascadeType.ALL)
+ @MapKey
+ @JoinTable(name="Atm_Gas_DefLeg")
+ public Map<String, Gas> gasesDefLeg = new HashMap<String, Gas>();
+
+ @ManyToMany(cascade = CascadeType.ALL)
+ @MapKeyJoinColumn
+ @JoinTable(name = "Gas_p_key_def")
+ public Map<GasKey, Gas> gasesPerKeyDef = new HashMap<GasKey, Gas>();
+
}
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java 2009-07-21 15:57:57 UTC (rev 17186)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/indexcoll/IndexedCollectionTest.java 2009-07-22 00:16:59 UTC (rev 17187)
@@ -5,10 +5,14 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Iterator;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.Hibernate;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.Collection;
+import org.hibernate.mapping.Column;
import org.hibernate.dialect.HSQLDialect;
import org.hibernate.test.annotations.RequiresDialect;
import org.hibernate.test.annotations.TestCase;
@@ -19,6 +23,35 @@
* @author Emmanuel Bernard
*/
public class IndexedCollectionTest extends TestCase {
+
+ public void testJPA2DefaultMapColumns() throws Exception {
+ isDefaultKeyColumnPresent( "gasesDef" );
+ isDefaultKeyColumnPresent( "gasesPerKeyDef" );
+ isNotDefaultKeyColumnPresent( "gasesDefLeg" );
+ }
+
+ private void isDefaultKeyColumnPresent(String propertyName) {
+ final Collection collection = getCfg().getCollectionMapping( Atmosphere.class.getName() + "." + propertyName );
+ final Iterator columnIterator = collection.getCollectionTable().getColumnIterator();
+ boolean hasDefault = false;
+ while ( columnIterator.hasNext() ) {
+ Column column = (Column) columnIterator.next();
+ if ( (propertyName + "_KEY").equals( column.getName() ) ) hasDefault = true;
+ }
+ assertTrue( "Could not find " + propertyName + "_KEY", hasDefault);
+ }
+
+ private void isNotDefaultKeyColumnPresent(String propertyName) {
+ final Collection collection = getCfg().getCollectionMapping( Atmosphere.class.getName() + "." + propertyName );
+ final Iterator columnIterator = collection.getCollectionTable().getColumnIterator();
+ boolean hasDefault = false;
+ while ( columnIterator.hasNext() ) {
+ Column column = (Column) columnIterator.next();
+ if ( (propertyName + "_KEY").equals( column.getName() ) ) hasDefault = true;
+ }
+ assertFalse( "Could not find " + propertyName + "_KEY", hasDefault);
+ }
+
public void testFkList() throws Exception {
Wardrobe w = new Wardrobe();
Drawer d1 = new Drawer();
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/target/Brand.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/target/Brand.java 2009-07-21 15:57:57 UTC (rev 17186)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/target/Brand.java 2009-07-22 00:16:59 UTC (rev 17187)
@@ -9,6 +9,7 @@
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.MapKeyClass;
+import javax.persistence.JoinColumn;
import org.hibernate.annotations.MapKey;
import org.hibernate.annotations.MapKeyManyToMany;
@@ -27,8 +28,8 @@
private Map<Size, Luggage> luggagesBySize = new HashMap<Size, Luggage>();
@ElementCollection(targetClass = SizeImpl.class)
- @MapKeyManyToMany(targetEntity = LuggageImpl.class)
- //TODO @MapKeyClass(LuggageImpl.class)
+ @MapKeyClass(LuggageImpl.class)
+ @MapKeyManyToMany //legacy column name: was never officially supported BTW
private Map<Luggage, Size> sizePerLuggage = new HashMap<Luggage, Size>();
14 years, 9 months
Hibernate SVN: r17186 - core/trunk/core/src/main/java/org/hibernate/impl.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-07-21 11:57:57 -0400 (Tue, 21 Jul 2009)
New Revision: 17186
Modified:
core/trunk/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java
Log:
HHH-4022 : Add an actual API contract for querying/managing cache regions (from app code)
Modified: core/trunk/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java 2009-07-21 14:54:45 UTC (rev 17185)
+++ core/trunk/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java 2009-07-21 15:57:57 UTC (rev 17186)
@@ -184,9 +184,8 @@
private final transient SQLFunctionRegistry sqlFunctionRegistry;
private final transient SessionFactoryObserver observer;
private final transient HashMap entityNameResolvers = new HashMap();
-
- private final QueryPlanCache queryPlanCache = new QueryPlanCache( this );
-
+ private final transient QueryPlanCache queryPlanCache = new QueryPlanCache( this );
+ private final transient Cache cacheAccess = new CacheImpl();
private transient boolean isClosed = false;
public SessionFactoryImpl(
@@ -195,9 +194,7 @@
Settings settings,
EventListeners listeners,
SessionFactoryObserver observer) throws HibernateException {
-
log.info("building session factory");
-
this.properties = new Properties();
this.properties.putAll( cfg.getProperties() );
this.interceptor = cfg.getInterceptor();
@@ -956,16 +953,15 @@
eventListeners.destroyListeners();
}
- private final Cache cacheAccess = new CacheImpl();
-
- private class CacheImpl implements Cache, Serializable {
+ private class CacheImpl implements Cache {
public boolean containsEntity(Class entityClass, Serializable identifier) {
return containsEntity( entityClass.getName(), identifier );
}
public boolean containsEntity(String entityName, Serializable identifier) {
- // todo : need a contains() method on the underlying regions
- throw new UnsupportedOperationException( "not yet implemented - HHH-4021" );
+ EntityPersister p = getEntityPersister( entityName );
+ return p.hasCache() &&
+ p.getCacheAccessStrategy().getRegion().contains( buildCacheKey( identifier, p ) );
}
public void evictEntity(Class entityClass, Serializable identifier) {
@@ -981,17 +977,20 @@
MessageHelper.infoString( p, identifier, SessionFactoryImpl.this )
);
}
- CacheKey cacheKey = new CacheKey(
- identifier,
- p.getIdentifierType(),
- p.getRootEntityName(),
- EntityMode.POJO,
- SessionFactoryImpl.this
- );
- p.getCacheAccessStrategy().evict( cacheKey );
+ p.getCacheAccessStrategy().evict( buildCacheKey( identifier, p ) );
}
}
+ private CacheKey buildCacheKey(Serializable identifier, EntityPersister p) {
+ return new CacheKey(
+ identifier,
+ p.getIdentifierType(),
+ p.getRootEntityName(),
+ EntityMode.POJO,
+ SessionFactoryImpl.this
+ );
+ }
+
public void evictEntityRegion(Class entityClass) {
evictEntityRegion( entityClass.getName() );
}
@@ -1014,8 +1013,9 @@
}
public boolean containsCollection(String role, Serializable ownerIdentifier) {
- // todo : need a contains() method on the underlying regions
- return false;
+ CollectionPersister p = getCollectionPersister( role );
+ return p.hasCache() &&
+ p.getCacheAccessStrategy().getRegion().contains( buildCacheKey( ownerIdentifier, p ) );
}
public void evictCollection(String role, Serializable ownerIdentifier) {
@@ -1027,17 +1027,21 @@
MessageHelper.collectionInfoString(p, ownerIdentifier, SessionFactoryImpl.this)
);
}
- CacheKey cacheKey = new CacheKey(
- ownerIdentifier,
- p.getKeyType(),
- p.getRole(),
- EntityMode.POJO,
- SessionFactoryImpl.this
- );
+ CacheKey cacheKey = buildCacheKey( ownerIdentifier, p );
p.getCacheAccessStrategy().evict( cacheKey );
}
}
+ private CacheKey buildCacheKey(Serializable ownerIdentifier, CollectionPersister p) {
+ return new CacheKey(
+ ownerIdentifier,
+ p.getKeyType(),
+ p.getRole(),
+ EntityMode.POJO,
+ SessionFactoryImpl.this
+ );
+ }
+
public void evictCollectionRegion(String role) {
CollectionPersister p = getCollectionPersister( role );
if ( p.hasCache() ) {
@@ -1056,8 +1060,7 @@
}
public boolean containsQuery(String regionName) {
- // todo : need a contains() method on the underlying regions
- return false;
+ return queryCaches.get( regionName ) != null;
}
public void evictDefaultQueryRegion() {
14 years, 9 months
Hibernate SVN: r17185 - beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-07-21 10:54:45 -0400 (Tue, 21 Jul 2009)
New Revision: 17185
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/BaseClass.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/CustomConstraint.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/SubClassA.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/SubClassB.java
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/ValidatorResolutionTest.java
Log:
ConstraintValidator resolution tests
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/BaseClass.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/BaseClass.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/BaseClass.java 2009-07-21 14:54:45 UTC (rev 17185)
@@ -0,0 +1,24 @@
+// $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.validatorresolution;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public abstract class BaseClass {
+}
Copied: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/CustomConstraint.java (from rev 17143, beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/Ambigious.java)
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/CustomConstraint.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/CustomConstraint.java 2009-07-21 14:54:45 UTC (rev 17185)
@@ -0,0 +1,92 @@
+// $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.validatorresolution;
+
+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.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * A test constraint which can lead to a error when trying to reslove the validator.
+ *
+ * @author Hardy Ferentschik
+ */
+@Constraint(validatedBy = {
+ CustomConstraint.AmbigiousValidatorBaseClass.class,
+ CustomConstraint.AmbigiousValidatorForSubClassA.class,
+ CustomConstraint.AmbigiousValidatorForSubClassB.class
+})
+@Documented
+@Target({ METHOD, FIELD, TYPE })
+@Retention(RUNTIME)
+public @interface CustomConstraint {
+ public abstract String message() default "my custom constraint";
+
+ public abstract Class<?>[] groups() default { };
+
+ public abstract Class<? extends ConstraintPayload>[] payload() default { };
+
+
+ public class AmbigiousValidatorBaseClass implements ConstraintValidator<CustomConstraint, BaseClass> {
+
+ public void initialize(CustomConstraint parameters) {
+ }
+
+ public boolean isValid(BaseClass baseClass, ConstraintValidatorContext constraintValidatorContext) {
+ return false;
+ }
+ }
+
+ public class AmbigiousValidatorForSubClassA implements ConstraintValidator<CustomConstraint, SubClassA> {
+ static int callCounter = 0;
+
+ public void initialize(CustomConstraint parameters) {
+ }
+
+ public boolean isValid(SubClassA subClass, ConstraintValidatorContext constraintValidatorContext) {
+ callCounter++;
+ if ( callCounter > 1 ) {
+ throw new IllegalStateException( "This method should have been only called once during the tests." );
+ }
+ return true;
+ }
+ }
+
+ public class AmbigiousValidatorForSubClassB implements ConstraintValidator<CustomConstraint, SubClassB> {
+ static int callCounter = 0;
+
+ public void initialize(CustomConstraint parameters) {
+ }
+
+ public boolean isValid(SubClassB subClass, ConstraintValidatorContext constraintValidatorContext) {
+ callCounter++;
+ if ( callCounter > 1 ) {
+ throw new IllegalStateException( "This method should have been only called once during the tests." );
+ }
+ return true;
+ }
+ }
+}
\ No newline at end of file
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/SubClassA.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/SubClassA.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/SubClassA.java 2009-07-21 14:54:45 UTC (rev 17185)
@@ -0,0 +1,24 @@
+// $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.validatorresolution;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class SubClassA extends BaseClass {
+}
\ No newline at end of file
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/SubClassB.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/SubClassB.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/SubClassB.java 2009-07-21 14:54:45 UTC (rev 17185)
@@ -0,0 +1,24 @@
+// $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.validatorresolution;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class SubClassB extends BaseClass {
+}
\ No newline at end of file
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/ValidatorResolutionTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/ValidatorResolutionTest.java 2009-07-21 14:12:43 UTC (rev 17184)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/constraints/validatorresolution/ValidatorResolutionTest.java 2009-07-21 14:54:45 UTC (rev 17185)
@@ -29,6 +29,7 @@
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.ArtifactType;
import org.jboss.testharness.impl.packaging.Classes;
+import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;
import org.testng.annotations.Test;
@@ -43,44 +44,33 @@
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
-(a)Classes({TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class})
+@Classes({ TestUtil.class, TestUtil.PathImpl.class, TestUtil.NodeImpl.class })
public class ValidatorResolutionTest {
@Test
- @SpecAssertions({
- @SpecAssertion(section = "3.5.3", id = "e"),
- @SpecAssertion(section = "2.1", id = "d"),
- @SpecAssertion(section = "2.4", id = "i")
- })
- public void testUnexpectedTypeInValidatorResolution() {
+ @SpecAssertion(section = "3.5.3", id = "b")
+ public void testFieldTypeIsTargetedType() {
Validator validator = TestUtil.getDefaultValidator();
+ validator.validate( new SubClassAHolder( new SubClassA() ) );
- Bar bar = new Bar();
- try {
- validator.validate( bar );
- fail();
- }
- catch ( UnexpectedTypeException e ) {
- // success
- }
+ assertEquals(
+ CustomConstraint.AmbigiousValidatorForSubClassA.callCounter,
+ 1,
+ "The validated method of AmbigiousValidatorForSubClassA should have benn called."
+ );
}
@Test
- @SpecAssertions({
- @SpecAssertion(section = "3.5.3", id = "f"),
- @SpecAssertion(section = "8.3", id = "b")
- })
- public void testAmbigiousValidatorResolution() {
+ @SpecAssertion(section = "3.5.3", id = "c")
+ public void testGetterTypeIsTargetedType() {
Validator validator = TestUtil.getDefaultValidator();
+ validator.validate( new SubClassBHolder( new SubClassB() ) );
- Foo foo = new Foo( new SerializableBarSubclass() );
- try {
- validator.validate( foo );
- fail();
- }
- catch ( UnexpectedTypeException e ) {
- // success
- }
+ assertEquals(
+ CustomConstraint.AmbigiousValidatorForSubClassB.callCounter,
+ 1,
+ "The validated method of AmbigiousValidatorForSubClassA should have benn called."
+ );
}
@@ -88,19 +78,6 @@
@SpecAssertions({
@SpecAssertion(section = "3.5.3", id = "d")
})
- public void testResolutionOfMinMaxForDifferentTypes() {
- Validator validator = TestUtil.getDefaultValidator();
- MinMax minMax = new MinMax( "5", 5 );
- Set<ConstraintViolation<MinMax>> constraintViolations = validator.validate( minMax );
- assertCorrectNumberOfViolations( constraintViolations, 2 );
- assertCorrectPropertyPaths( constraintViolations, new String[] { "number", "numberAsString" } );
- }
-
- @Test
-
- @SpecAssertions({
- @SpecAssertion(section = "3.5.3", id = "d")
- })
public void testResolutionOfMultipleSizeValidators() {
Validator validator = TestUtil.getDefaultValidator();
@@ -176,4 +153,79 @@
constraintViolations = validator.validate( suburb );
assertCorrectNumberOfViolations( constraintViolations, 0 );
}
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "3.5.3", id = "d")
+ })
+ public void testResolutionOfMinMaxForDifferentTypes() {
+ Validator validator = TestUtil.getDefaultValidator();
+ MinMax minMax = new MinMax( "5", 5 );
+ Set<ConstraintViolation<MinMax>> constraintViolations = validator.validate( minMax );
+ assertCorrectNumberOfViolations( constraintViolations, 2 );
+ assertCorrectPropertyPaths( constraintViolations, "number", "numberAsString" );
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "3.5.3", id = "e"),
+ @SpecAssertion(section = "2.1", id = "d"),
+ @SpecAssertion(section = "2.4", id = "i")
+ })
+ public void testUnexpectedTypeInValidatorResolution() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Bar bar = new Bar();
+ try {
+ validator.validate( bar );
+ fail();
+ }
+ catch ( UnexpectedTypeException e ) {
+ // success
+ }
+ }
+
+ @Test
+ @SpecAssertions({
+ @SpecAssertion(section = "3.5.3", id = "f"),
+ @SpecAssertion(section = "8.3", id = "b")
+ })
+ public void testAmbigiousValidatorResolution() {
+ Validator validator = TestUtil.getDefaultValidator();
+
+ Foo foo = new Foo( new SerializableBarSubclass() );
+ try {
+ validator.validate( foo );
+ fail();
+ }
+ catch ( UnexpectedTypeException e ) {
+ // success
+ }
+ }
+
+ public class SubClassAHolder {
+ @CustomConstraint
+ private SubClassA subClass;
+
+ SubClassAHolder(SubClassA subClass) {
+ this.subClass = subClass;
+ }
+
+ public BaseClass getSubClass() {
+ return subClass;
+ }
+ }
+
+ public class SubClassBHolder {
+ private BaseClass baseClass;
+
+ public SubClassBHolder(SubClassB subClass) {
+ this.baseClass = subClass;
+ }
+
+ @CustomConstraint
+ public SubClassB getBaseClass() {
+ return ( SubClassB ) baseClass;
+ }
+ }
}
\ No newline at end of file
14 years, 9 months
Hibernate SVN: r17184 - beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-07-21 10:12:43 -0400 (Tue, 21 Jul 2009)
New Revision: 17184
Removed:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Cloth.java
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/SnifferTraversableResolver.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Suit.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/TraversableResolverTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Trousers.java
Log:
TraversableReslver tests
Deleted: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Cloth.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Cloth.java 2009-07-21 13:54:31 UTC (rev 17183)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Cloth.java 2009-07-21 14:12:43 UTC (rev 17184)
@@ -1,24 +0,0 @@
-// $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.traversableresolver;
-
-/**
- * @author Emmanuel Bernard
- */
-public interface Cloth {
-}
\ No newline at end of file
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/SnifferTraversableResolver.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/SnifferTraversableResolver.java 2009-07-21 13:54:31 UTC (rev 17183)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/SnifferTraversableResolver.java 2009-07-21 14:12:43 UTC (rev 17184)
@@ -25,21 +25,23 @@
/**
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
public class SnifferTraversableResolver implements TraversableResolver {
Set<String> reachPaths = new HashSet<String>();
Set<String> cascadePaths = new HashSet<String>();
- Set<Call> reachCalls = new HashSet<Call>();
- Set<Call> cascadeCalls = new HashSet<Call>();
+ Set<Call> expectedReachCalls = new HashSet<Call>();
+ Set<Call> expectedCascadeCalls = new HashSet<Call>();
+ Set<Call> executedReachableCalls = new HashSet<Call>();
public SnifferTraversableResolver(Suit suit) {
- reachCalls.add( new Call( suit, "size", Suit.class, "", ElementType.FIELD ) );
- reachCalls.add( new Call( suit, "trousers", Suit.class, "", ElementType.FIELD ) );
- cascadeCalls.add( new Call( suit, "trousers", Suit.class, "", ElementType.FIELD ) );
- reachCalls.add( new Call( suit.getTrousers(), "length", Suit.class, "trousers", ElementType.FIELD ) );
- reachCalls.add( new Call( suit, "jacket", Suit.class, "", ElementType.METHOD ) );
- cascadeCalls.add( new Call( suit, "jacket", Suit.class, "", ElementType.METHOD ) );
- reachCalls.add( new Call( suit.getJacket(), "width", Suit.class, "jacket", ElementType.METHOD ) );
+ expectedReachCalls.add( new Call( suit, "size", Suit.class, "", ElementType.FIELD ) );
+ expectedReachCalls.add( new Call( suit, "trousers", Suit.class, "", ElementType.FIELD ) );
+ expectedCascadeCalls.add( new Call( suit, "trousers", Suit.class, "", ElementType.FIELD ) );
+ expectedReachCalls.add( new Call( suit.getTrousers(), "length", Suit.class, "trousers", ElementType.FIELD ) );
+ expectedReachCalls.add( new Call( suit, "jacket", Suit.class, "", ElementType.METHOD ) );
+ expectedCascadeCalls.add( new Call( suit, "jacket", Suit.class, "", ElementType.METHOD ) );
+ expectedReachCalls.add( new Call( suit.getJacket(), "width", Suit.class, "jacket", ElementType.METHOD ) );
}
public Set<String> getReachPaths() {
@@ -50,15 +52,13 @@
return cascadePaths;
}
- public boolean isTraversable(Set<Call> calls, Set<String> paths, Object traversableObject, String traversableProperty, Class<?> rootBeanType, String pathToTraversableObject, ElementType elementType) {
+ public boolean isTraversable(Set<Call> calls, Set<String> paths, Call call, String traversableProperty, String pathToTraversableObject) {
String path = "";
if ( !( pathToTraversableObject == null || pathToTraversableObject.length() == 0 ) ) {
path = pathToTraversableObject + ".";
}
paths.add( path + traversableProperty );
- Call call = new Call(
- traversableObject, traversableProperty, rootBeanType, pathToTraversableObject, elementType
- );
+
if ( !calls.contains( call ) ) {
throw new IllegalStateException( "Unexpected " + call.toString() );
}
@@ -66,27 +66,44 @@
}
public boolean isReachable(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
- return isTraversable(
- reachCalls,
- reachPaths,
+ Call call = new Call(
traversableObject,
traversableProperty.toString(),
rootBeanType,
pathToTraversableObject.toString(),
elementType
);
+ executedReachableCalls.add( call );
+
+ return isTraversable(
+ expectedReachCalls,
+ reachPaths,
+ call,
+ traversableProperty.toString(),
+ pathToTraversableObject.toString()
+ );
}
public boolean isCascadable(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
- return isTraversable(
- cascadeCalls,
- cascadePaths,
+ Call call = new Call(
traversableObject,
traversableProperty.toString(),
rootBeanType,
pathToTraversableObject.toString(),
elementType
);
+ if ( !executedReachableCalls.contains( call ) ) {
+ throw new IllegalStateException( "isCascadable called before a matching isReachable call: " + call.toString() );
+ }
+
+
+ return isTraversable(
+ expectedCascadeCalls,
+ cascadePaths,
+ call,
+ traversableProperty.toString(),
+ pathToTraversableObject.toString()
+ );
}
/**
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Suit.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Suit.java 2009-07-21 13:54:31 UTC (rev 17183)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Suit.java 2009-07-21 14:12:43 UTC (rev 17184)
@@ -26,9 +26,8 @@
/**
* @author Emmanuel Bernard
*/
-@GroupSequence({ Suit.class, Cloth.class })
public class Suit {
- @Max(value = 50, groups = { Default.class, Cloth.class })
+ @Max(value = 50)
@Min(1)
private Integer size;
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/TraversableResolverTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/TraversableResolverTest.java 2009-07-21 13:54:31 UTC (rev 17183)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/TraversableResolverTest.java 2009-07-21 14:12:43 UTC (rev 17184)
@@ -27,7 +27,6 @@
import javax.validation.ValidationException;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
-import javax.validation.groups.Default;
import org.jboss.test.audit.annotations.SpecAssertion;
import org.jboss.test.audit.annotations.SpecAssertions;
@@ -51,7 +50,8 @@
@Test
@SpecAssertions({
@SpecAssertion(section = "3.5.2", id = "a"),
- @SpecAssertion(section = "3.5.2", id = "b")
+ @SpecAssertion(section = "3.5.2", id = "b"),
+ @SpecAssertion(section = "3.5.2", id = "c")
})
public void testCorrectNumberOfCallsToIsReachableAndIsCascadable() {
Suit suit = new Suit();
@@ -71,8 +71,7 @@
ValidatorFactory factory = config.buildValidatorFactory();
Validator v = factory.getValidator();
- //Raises an IllegalStateException if something goes wrong
- v.validate( suit, Default.class, Cloth.class );
+ v.validate( suit );
assertEquals( resolver.getReachPaths().size(), 5 );
assertEquals( resolver.getCascadePaths().size(), 2 );
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Trousers.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Trousers.java 2009-07-21 13:54:31 UTC (rev 17183)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/traversableresolver/Trousers.java 2009-07-21 14:12:43 UTC (rev 17184)
@@ -25,7 +25,7 @@
* @author Emmanuel Bernard
*/
public class Trousers {
- @Min(value = 70, groups = { Default.class, Cloth.class })
+ @Min(value = 70)
@Max(value = 220)
private Integer length;
14 years, 9 months
Hibernate SVN: r17183 - core/trunk/envers.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-07-21 09:54:31 -0400 (Tue, 21 Jul 2009)
New Revision: 17183
Modified:
core/trunk/envers/pom.xml
Log:
EJB-447 - Implement JPA 2.0 criteria apis
Modified: core/trunk/envers/pom.xml
===================================================================
--- core/trunk/envers/pom.xml 2009-07-21 13:46:43 UTC (rev 17182)
+++ core/trunk/envers/pom.xml 2009-07-21 13:54:31 UTC (rev 17183)
@@ -148,11 +148,6 @@
<version>3.2.0.ga</version>
</dependency>
<dependency>
- <groupId>org.hibernate.java-persistence</groupId>
- <artifactId>jpa-api</artifactId>
- <version>2.0.Beta2</version>
- </dependency>
- <dependency>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
<version>1.6.5</version>
14 years, 9 months
Hibernate SVN: r17182 - in core/trunk: entitymanager and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-07-21 09:46:43 -0400 (Tue, 21 Jul 2009)
New Revision: 17182
Modified:
core/trunk/annotations/pom.xml
core/trunk/entitymanager/pom.xml
core/trunk/parent/pom.xml
Log:
EJB-447 - Implement JPA 2.0 criteria apis
Modified: core/trunk/annotations/pom.xml
===================================================================
--- core/trunk/annotations/pom.xml 2009-07-21 13:45:51 UTC (rev 17181)
+++ core/trunk/annotations/pom.xml 2009-07-21 13:46:43 UTC (rev 17182)
@@ -62,7 +62,6 @@
<dependency>
<groupId>org.hibernate.java-persistence</groupId>
<artifactId>jpa-api</artifactId>
- <version>2.0.Beta-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
Modified: core/trunk/entitymanager/pom.xml
===================================================================
--- core/trunk/entitymanager/pom.xml 2009-07-21 13:45:51 UTC (rev 17181)
+++ core/trunk/entitymanager/pom.xml 2009-07-21 13:46:43 UTC (rev 17182)
@@ -69,6 +69,10 @@
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.hibernate.java-persistence</groupId>
+ <artifactId>jpa-api</artifactId>
+ </dependency>
</dependencies>
<dependencyManagement>
Modified: core/trunk/parent/pom.xml
===================================================================
--- core/trunk/parent/pom.xml 2009-07-21 13:45:51 UTC (rev 17181)
+++ core/trunk/parent/pom.xml 2009-07-21 13:46:43 UTC (rev 17182)
@@ -373,6 +373,12 @@
<artifactId>cglib</artifactId>
<version>2.2</version>
</dependency>
+ <!-- Set the version of the JPA api to be used throughout the the project -->
+ <dependency>
+ <groupId>org.hibernate.java-persistence</groupId>
+ <artifactId>jpa-api</artifactId>
+ <version>2.0.Beta-SNAPSHOT</version>
+ </dependency>
</dependencies>
</dependencyManagement>
14 years, 9 months