Author: hardy.ferentschik
Date: 2009-06-22 06:59:08 -0400 (Mon, 22 Jun 2009)
New Revision: 16848
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Customer.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/ElementDescriptorTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Order.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Person.java
Log:
ElemetDescriptor tests. Moved back from TCK.
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Customer.java
(from rev 16842,
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Customer.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Customer.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Customer.java 2009-06-22
10:59:08 UTC (rev 16848)
@@ -0,0 +1,67 @@
+// $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.validation.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;
+ }
+}
\ No newline at end of file
Added:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/ElementDescriptorTest.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/ElementDescriptorTest.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/ElementDescriptorTest.java 2009-06-22
10:59:08 UTC (rev 16848)
@@ -0,0 +1,87 @@
+// $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.validation.metadata;
+
+import java.util.Set;
+import javax.validation.Validator;
+import javax.validation.metadata.BeanDescriptor;
+import javax.validation.metadata.ConstraintDescriptor;
+import javax.validation.metadata.ElementDescriptor;
+
+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.hibernate.validation.util.TestUtil;
+
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class ElementDescriptorTest {
+
+
+ @Test
+ public void testGetTypeForConstrainedBean() {
+ Validator validator = TestUtil.getValidator();
+ 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
+ }
+ }
+}
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Order.java
(from rev 16842,
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Order.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Order.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Order.java 2009-06-22
10:59:08 UTC (rev 16848)
@@ -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.validation.metadata;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Order {
+ @NotNull(message = "Order number must be specified")
+ Integer orderNumber;
+
+ public Integer getOrderNumber() {
+ return orderNumber;
+ }
+
+ public void setOrderNumber(Integer orderNumber) {
+ this.orderNumber = orderNumber;
+ }
+}
\ No newline at end of file
Copied:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Person.java
(from rev 16842,
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/metadata/Person.java)
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Person.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/metadata/Person.java 2009-06-22
10:59:08 UTC (rev 16848)
@@ -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.validation.metadata;
+
+import org.hibernate.validation.constraints.NotEmpty;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public interface Person {
+ @NotEmpty(groups = PersonValidation.class)
+ String getFirstName();
+
+ String getMiddleName();
+
+ @NotEmpty
+ String getLastName();
+
+ public interface PersonValidation {
+ }
+}
\ No newline at end of file