[hibernate-commits] Hibernate SVN: r16777 - in beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck: tests/metadata and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Fri Jun 12 11:39:36 EDT 2009


Author: hardy.ferentschik
Date: 2009-06-12 11:39:36 -0400 (Fri, 12 Jun 2009)
New Revision: 16777

Added:
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Account.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/AccountChecker.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/AccountValidator.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/BeanDescriptorTest.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ConstraintDescriptorTest.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Customer.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ElementDescriptorTest.java
   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/Order.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Person.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/PropertyDescriptorTest.java
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/UnconstraintEntity.java
Modified:
   beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java
Log:
bean metadata tests

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Account.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Account.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Account.java	2009-06-12 15:39:36 UTC (rev 16777)
@@ -0,0 +1,46 @@
+// $Id: Account.java 16264 2009-04-06 15:10:53Z hardy.ferentschik $
+/*
+* 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.metadata;
+
+import javax.validation.Valid;
+
+/**
+ * Class with no constraints but with a cascade @Valid annotation
+ */
+ at AccountChecker
+public class Account {
+	private String accountLogin;
+	private Customer customer;
+
+	public String getAccountLogin() {
+		return accountLogin;
+	}
+
+	public void setAccountLogin(String accountLogin) {
+		this.accountLogin = accountLogin;
+	}
+
+	@Valid
+	public Customer getCustomer() {
+		return customer;
+	}
+
+	public void setCustomer(Customer customer) {
+		this.customer = customer;
+	}
+}

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/AccountChecker.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/AccountChecker.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/AccountChecker.java	2009-06-12 15:39:36 UTC (rev 16777)
@@ -0,0 +1,41 @@
+// $Id: AccountChecker.java 16264 2009-04-06 15:10:53Z hardy.ferentschik $
+/*
+* 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.metadata;
+
+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;
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at Constraint(validatedBy = AccountValidator.class)
+ at Documented
+ at Target({ METHOD, FIELD, TYPE })
+ at Retention(RUNTIME)
+public @interface AccountChecker {
+
+	public abstract String message() default "Account information inconsistent.";
+
+	public abstract Class<?>[] groups() default { };
+}

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/AccountValidator.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/AccountValidator.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/AccountValidator.java	2009-06-12 15:39:36 UTC (rev 16777)
@@ -0,0 +1,34 @@
+// $Id: AccountValidator.java 16264 2009-04-06 15:10:53Z hardy.ferentschik $
+/*
+* 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.metadata;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class AccountValidator implements ConstraintValidator<AccountChecker, Account> {
+
+	public void initialize(AccountChecker parameters) {
+	}
+
+	public boolean isValid(Account account, ConstraintValidatorContext constraintValidatorContext) {
+		return false;
+	}
+}

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/BeanDescriptorTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/BeanDescriptorTest.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/BeanDescriptorTest.java	2009-06-12 15:39:36 UTC (rev 16777)
@@ -0,0 +1,161 @@
+// $Id: BeanDescriptorTest.java 16264 2009-04-06 15:10:53Z hardy.ferentschik $
+/*
+* 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.metadata;
+
+import java.util.Set;
+import javax.validation.BeanDescriptor;
+import javax.validation.PropertyDescriptor;
+import javax.validation.Validator;
+
+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 static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at Artifact(artifactType = ArtifactType.JSR303)
+ at Classes(TestUtil.class)
+public class BeanDescriptorTest extends AbstractTest {
+
+	@Test
+	public void testIsBeanConstrained() {
+		Validator validator = TestUtil.getDefaultValidator();
+		BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Customer.class );
+
+		// constraint via @Valid
+		assertFalse( beanDescriptor.hasConstraints(), "There should be no direct constraints on the specified bean." );
+		assertTrue( beanDescriptor.isBeanConstrained(), "Bean should be constrainted due to @valid " );
+
+		// constraint hosted on bean itself
+		beanDescriptor = validator.getConstraintsForClass( Account.class );
+		assertTrue( beanDescriptor.hasConstraints(), "There should be direct constraints on the specified bean." );
+		assertTrue( beanDescriptor.isBeanConstrained(), "Bean should be constrainted due to @valid" );
+
+		// constraint on bean property
+		beanDescriptor = validator.getConstraintsForClass( Order.class );
+		assertFalse( beanDescriptor.hasConstraints(), "There should be no direct constraints on the specified bean." );
+		assertTrue( beanDescriptor.isBeanConstrained(), "Bean should be constrainted due to @NotNull" );
+	}
+
+	@Test
+	public void testUnconstraintClass() {
+		Validator validator = TestUtil.getDefaultValidator();
+		BeanDescriptor beanDescriptor = validator.getConstraintsForClass( UnconstraintEntity.class );
+		assertFalse( beanDescriptor.hasConstraints(), "There should be no direct constraints on the specified bean." );
+		assertFalse( beanDescriptor.isBeanConstrained(), "Bean should be unconstrainted." );
+	}
+
+	@Test
+	public void testGetConstraintForExistingConstrainedProperty() {
+		Validator validator = TestUtil.getDefaultValidator();
+		BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
+		PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty( "orderNumber" );
+		assertEquals(
+				propertyDescriptor.getConstraintDescriptors().size(), 1, "There should be one constraint descriptor"
+		);
+
+		beanDescriptor = validator.getConstraintsForClass( Customer.class );
+		propertyDescriptor = beanDescriptor.getConstraintsForProperty( "orderList" );
+		assertEquals(
+				propertyDescriptor.getConstraintDescriptors().size(), 0, "There should be no constraint descriptors"
+		);
+		assertTrue( propertyDescriptor.isCascaded(), "The property should be cascaded" );
+	}
+
+	@Test
+	public void testGetConstraintForUnConstrainedProperty() {
+		Validator validator = TestUtil.getDefaultValidator();
+		BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Customer.class );
+		PropertyDescriptor propertyDescriptor = beanDescriptor.getConstraintsForProperty( "orderList" );
+		assertEquals(
+				propertyDescriptor.getConstraintDescriptors().size(), 0, "There should be no constraint descriptors"
+		);
+		assertTrue( propertyDescriptor.isCascaded(), "The property should be cascaded" );
+	}
+
+	@Test
+	public void testGetConstraintsForNonExistingProperty() {
+		Validator validator = TestUtil.getDefaultValidator();
+		BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
+		assertNull( beanDescriptor.getConstraintsForProperty( "foobar" ), "There should be no descriptor" );
+	}
+
+	/**
+	 * @todo Is this corect or should we get a IllegalArgumentException
+	 */
+	@Test
+	public void testGetConstraintsForNullProperty() {
+		Validator validator = TestUtil.getDefaultValidator();
+		BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
+		assertNull( beanDescriptor.getConstraintsForProperty( null ), "There should be no descriptor" );
+	}
+
+	@Test
+	public void testGetConstrainedProperties() {
+		Validator validator = TestUtil.getDefaultValidator();
+		BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
+		Set<PropertyDescriptor> constraintProperties = beanDescriptor.getConstrainedProperties();
+		assertEquals( constraintProperties.size(), 1, "There should be only one property" );
+		boolean hasOrderNumber = false;
+		for ( PropertyDescriptor pd : constraintProperties ) {
+			hasOrderNumber |= pd.getPropertyName().equals( "orderNumber" );
+		}
+		assertTrue( hasOrderNumber, "Wrong property" );
+	}
+
+	@Test
+	public void testGetConstrainedPropertiesImmutable() {
+		Validator validator = TestUtil.getDefaultValidator();
+		BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
+		Set<PropertyDescriptor> constraintProperties = beanDescriptor.getConstrainedProperties();
+		try {
+			constraintProperties.add( null );
+			fail( "Set should be immutable" );
+		}
+		catch ( UnsupportedOperationException e ) {
+			// success
+		}
+
+		try {
+			constraintProperties.remove( constraintProperties.iterator().next() );
+			fail( "Set should be immutable" );
+		}
+		catch ( UnsupportedOperationException e ) {
+			// success
+		}
+	}
+
+	@Test
+	public void testGetConstrainedPropertiesForUnconstraintEntity() {
+		Validator validator = TestUtil.getDefaultValidator();
+		BeanDescriptor beanDescriptor = validator.getConstraintsForClass( UnconstraintEntity.class );
+		Set<PropertyDescriptor> constraintProperties = beanDescriptor.getConstrainedProperties();
+		assertEquals( constraintProperties.size(), 0, "We should get the empty set." );
+	}
+}

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ConstraintDescriptorTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ConstraintDescriptorTest.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ConstraintDescriptorTest.java	2009-06-12 15:39:36 UTC (rev 16777)
@@ -0,0 +1,147 @@
+// $Id: ConstraintDescriptorTest.java 16748 2009-06-10 18:41:22Z epbernard $
+/*
+* 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.metadata;
+
+import java.lang.annotation.Annotation;
+import java.util.Map;
+import java.util.Set;
+import javax.validation.ConstraintDescriptor;
+import javax.validation.constraints.NotNull;
+import javax.validation.groups.Default;
+
+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 static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.getConstraintDescriptorsFor;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at Artifact(artifactType = ArtifactType.JSR303)
+ at Classes(TestUtil.class)
+public class ConstraintDescriptorTest extends AbstractTest {
+
+	@Test
+	public void testConstraintDescriptorImmutable() {
+		ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class, "orderNumber" );
+
+		try {
+			descriptor.getGroups().add( Default.class );
+			fail( "Should be immutable" );
+		}
+		catch ( UnsupportedOperationException e ) {
+			// success
+		}
+
+		try {
+			descriptor.getAttributes().put( "foo", "bar" );
+			fail( "Should be immutable" );
+		}
+		catch ( UnsupportedOperationException e ) {
+			// success
+		}
+
+		try {
+			descriptor.getConstraintValidatorClasses().add( null );
+			fail( "Should be immutable" );
+		}
+		catch ( UnsupportedOperationException e ) {
+			// success
+		}
+
+		try {
+			descriptor.getComposingConstraints().add( null );
+			fail( "Should be immutable" );
+		}
+		catch ( UnsupportedOperationException e ) {
+			// success
+		}
+	}
+
+	@Test
+	public void testReportAsSingleViolation() {
+		ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class, "orderNumber" );
+		assertFalse( descriptor.isReportAsSingleViolation() );
+
+		descriptor = getConstraintDescriptor( Person.class, "firstName" );
+		assertTrue( descriptor.isReportAsSingleViolation() );
+	}
+
+	@Test
+	public void testComposingConstraints() {
+		ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class, "orderNumber" );
+		assertTrue( descriptor.getComposingConstraints().isEmpty() );
+	}
+
+	/**
+	 * @todo Is getComposingConstraints() recursive and hence the result should be 4?
+	 */
+	@Test
+	public void testEmptyComposingConstraints() {
+		ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Person.class, "firstName" );
+		assertEquals( descriptor.getComposingConstraints().size(), 2, "Wrong number of composing constraints" );
+	}
+
+	@Test
+	public void testGetAnnotation() {
+		ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class, "orderNumber" );
+		Annotation annotation = descriptor.getAnnotation();
+		assertNotNull( annotation );
+		assertTrue( annotation instanceof NotNull );
+	}
+
+	@Test
+	public void testDefaultGroupIsReturned() {
+		ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class, "orderNumber" );
+		Set<Class<?>> groups = descriptor.getGroups();
+		assertTrue( groups.size() == 1 );
+		assertEquals( groups.iterator().next(), Default.class, "Wrong group" );
+	}
+
+//	@Test
+//	public void testGetConstraintValidatorClasses() {
+//		Set<ConstraintDescriptor<?>> descriptors = getConstraintDescriptorsFor( Order.class, "orderNumber" );
+//		assertTrue( descriptors.size() == 1, "There should only by one descriptor." );
+//		ConstraintDescriptor<?> descriptor = descriptors.iterator().next();
+//		assertEquals( descriptor.getConstraintValidatorClasses().get( 0 ), NotNullValidator.class, "Wrong classes" );
+//	}
+
+	@Test
+	public void testGetAttributes() {
+		ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Order.class, "orderNumber" );
+		Map<String, Object> attributes = descriptor.getAttributes();
+		assertTrue( attributes.containsKey( "message" ) );
+		assertTrue( attributes.containsKey( "groups" ) );
+	}
+
+	private ConstraintDescriptor<?> getConstraintDescriptor(Class<?> clazz, String property) {
+		Set<ConstraintDescriptor<?>> descriptors = getConstraintDescriptorsFor( clazz, property );
+		assertTrue( descriptors.size() == 1, "There should only by one descriptor." );
+		return descriptors.iterator().next();
+	}
+}
\ No newline at end of file

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Customer.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Customer.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Customer.java	2009-06-12 15:39:36 UTC (rev 16777)
@@ -0,0 +1,67 @@
+// $Id: Customer.java 16264 2009-04-06 15:10:53Z hardy.ferentschik $
+/*
+* 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.metadata;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.validation.Valid;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Customer implements Person {
+
+	private String firstName;
+	private String middleName;
+	private String lastName;
+
+	@Valid
+	private List<Order> orderList = new ArrayList<Order>();
+
+	public void addOrder(Order order) {
+		orderList.add( order );
+	}
+
+	public List<Order> getOrderList() {
+		return orderList;
+	}
+
+	public String getFirstName() {
+		return firstName;
+	}
+
+	public void setFirstName(String firstName) {
+		this.firstName = firstName;
+	}
+
+	public String getMiddleName() {
+		return middleName;
+	}
+
+	public void setMiddleName(String middleName) {
+		this.middleName = middleName;
+	}
+
+	public String getLastName() {
+		return lastName;
+	}
+
+	public void setLastName(String lastName) {
+		this.lastName = lastName;
+	}
+}

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ElementDescriptorTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ElementDescriptorTest.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/ElementDescriptorTest.java	2009-06-12 15:39:36 UTC (rev 16777)
@@ -0,0 +1,92 @@
+// $Id: ElementDescriptorTest.java 16264 2009-04-06 15:10:53Z hardy.ferentschik $
+/*
+* 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.metadata;
+
+import java.util.Set;
+import javax.validation.BeanDescriptor;
+import javax.validation.ConstraintDescriptor;
+import javax.validation.ElementDescriptor;
+import javax.validation.Validator;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+import org.testng.annotations.Test;
+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.hibernate.jsr303.tck.util.TestUtil;
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at Artifact(artifactType = ArtifactType.JSR303)
+ at Classes(TestUtil.class)
+public class ElementDescriptorTest extends AbstractTest {
+
+
+	@Test
+	public void testGetTypeForConstrainedBean() {
+		Validator validator = TestUtil.getDefaultValidator();
+		BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Customer.class );
+		assertEquals( beanDescriptor.getType(), Customer.class, "Wrong type." );
+	}
+
+	@Test
+	public void testGetTypeForConstrainedProperty() {
+		ElementDescriptor elementDescriptor = TestUtil.getPropertyDescriptor( Order.class, "orderNumber" );
+		assertEquals( elementDescriptor.getType(), Integer.class, "Wrong type." );
+	}
+
+	/**
+	 * HV-95
+	 */
+	@Test
+	public void testElementDescriptorForProperty() {
+		ElementDescriptor elementDescriptor = TestUtil.getPropertyDescriptor( Order.class, "orderNumber" );
+		Set<ConstraintDescriptor<?>> constraintDescriptors = elementDescriptor.getConstraintDescriptors();
+		assertTrue( constraintDescriptors.size() == 1, "There should be a descriptor" );
+	}
+
+	/**
+	 * HV-95
+	 */
+	@Test
+	public void testElementDescriptorImmutable() {
+		ElementDescriptor elementDescriptor = TestUtil.getPropertyDescriptor( Order.class, "orderNumber" );
+		Set<ConstraintDescriptor<?>> constraintDescriptors = elementDescriptor.getConstraintDescriptors();
+
+		try {
+			constraintDescriptors.add( null );
+			fail( "Set should be immutable" );
+		}
+		catch ( UnsupportedOperationException e ) {
+			// success
+		}
+
+		try {
+			constraintDescriptors.remove( null );
+			fail( "Set should be immutable" );
+		}
+		catch ( UnsupportedOperationException e ) {
+			// success
+		}
+	}
+}
\ No newline at end of file

Added: 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	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/NotEmpty.java	2009-06-12 15:39:36 UTC (rev 16777)
@@ -0,0 +1,45 @@
+// $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.metadata;
+
+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.ReportAsSingleViolation;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+/**
+ * @author Emmanuel Bernard
+ */
+ at Documented
+ at Constraint(validatedBy = {})
+ at Target({ METHOD, FIELD })
+ at Retention(RUNTIME)
+ at ReportAsSingleViolation
+ at NotNull
+ at Size(min=1)
+public @interface NotEmpty {
+	public abstract String message() default "{org.hibernate.validation.constraints.NotEmpty.message}";
+
+	public abstract Class<?>[] groups() default { };
+}
\ No newline at end of file


Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/NotEmpty.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Order.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Order.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Order.java	2009-06-12 15:39:36 UTC (rev 16777)
@@ -0,0 +1,36 @@
+// $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.metadata;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Order {
+	@NotNull
+	Integer orderNumber;
+
+	public Integer getOrderNumber() {
+		return orderNumber;
+	}
+
+	public void setOrderNumber(Integer orderNumber) {
+		this.orderNumber = orderNumber;
+	}
+}


Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Order.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Person.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Person.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Person.java	2009-06-12 15:39:36 UTC (rev 16777)
@@ -0,0 +1,31 @@
+// $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.metadata;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface Person {
+	@NotEmpty
+	String getFirstName();
+
+	String getMiddleName();
+
+	@NotEmpty
+	String getLastName();
+}
\ No newline at end of file


Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Person.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/PropertyDescriptorTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/PropertyDescriptorTest.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/PropertyDescriptorTest.java	2009-06-12 15:39:36 UTC (rev 16777)
@@ -0,0 +1,59 @@
+// $Id: PropertyDescriptorTest.java 16264 2009-04-06 15:10:53Z hardy.ferentschik $
+/*
+* 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.metadata;
+
+import javax.validation.PropertyDescriptor;
+
+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 static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.getPropertyDescriptor;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at Artifact(artifactType = ArtifactType.JSR303)
+ at Classes(TestUtil.class)
+public class PropertyDescriptorTest extends AbstractTest {
+	@Test
+	public void testIsNotCascaded() {
+		PropertyDescriptor descriptor = getPropertyDescriptor( Order.class, "orderNumber" );
+		assertFalse( descriptor.isCascaded(), "Should not be cascaded" );
+	}
+
+	@Test
+	public void testIsCascaded() {
+		PropertyDescriptor descriptor = getPropertyDescriptor( Customer.class, "orderList" );
+		assertTrue( descriptor.isCascaded(), "Should be cascaded" );
+	}
+
+	@Test
+	public void testPropertyName() {
+		String propertyName = "orderList";
+		PropertyDescriptor descriptor = getPropertyDescriptor( Customer.class, propertyName );
+		assertEquals( descriptor.getPropertyName(), propertyName, "Wrong property name" );
+	}
+}
\ No newline at end of file

Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/UnconstraintEntity.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/UnconstraintEntity.java	                        (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/UnconstraintEntity.java	2009-06-12 15:39:36 UTC (rev 16777)
@@ -0,0 +1,26 @@
+// : Person.java 69 2008-09-08 11:05:07Z hardy.ferentschik $
+/*
+* 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.metadata;
+
+/**
+ * Empty un-constraint test class.
+ *
+ * @author Hardy Ferentschik
+ */
+public class UnconstraintEntity {
+}

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-06-12 15:19:34 UTC (rev 16776)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/util/TestUtil.java	2009-06-12 15:39:36 UTC (rev 16777)
@@ -21,7 +21,10 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
+import javax.validation.ConstraintDescriptor;
 import javax.validation.ConstraintViolation;
+import javax.validation.ElementDescriptor;
+import javax.validation.PropertyDescriptor;
 import javax.validation.Validation;
 import javax.validation.Validator;
 
@@ -107,4 +110,15 @@
 				"Wrong invalid value."
 		);
 	}
+
+
+	public static PropertyDescriptor getPropertyDescriptor(Class<?> clazz, String property) {
+		Validator validator = getDefaultValidator();
+		return validator.getConstraintsForClass( clazz ).getConstraintsForProperty( property );
+	}
+
+	public static Set<ConstraintDescriptor<?>> getConstraintDescriptorsFor(Class<?> clazz, String property) {
+		ElementDescriptor elementDescriptor = getPropertyDescriptor( clazz, property );
+		return elementDescriptor.getConstraintDescriptors();
+	}
 }




More information about the hibernate-commits mailing list