[hibernate-commits] Hibernate SVN: r16147 - in validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine: graphnavigation and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Mar 12 14:21:01 EDT 2009


Author: hardy.ferentschik
Date: 2009-03-12 14:21:01 -0400 (Thu, 12 Mar 2009)
New Revision: 16147

Added:
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/Address.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/GraphNavigationTest.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/Order.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/OrderLine.java
   validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/User.java
Log:
HV-126 Added testcase. Still needs code changes.

Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/Address.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/Address.java	                        (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/Address.java	2009-03-12 18:21:01 UTC (rev 16147)
@@ -0,0 +1,83 @@
+// $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.engine.graphnavigation;
+
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
+
+import org.hibernate.validation.constraints.Length;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Address {
+
+	@NotNull
+	@Length(max = 30)
+	private String addressline1;
+
+	private String zipCode;
+
+	@Length(max = 30)
+	@NotNull
+	private String city;
+
+	@Valid
+	private User inhabitant;
+
+	public Address() {
+	}
+
+	public Address(String addressline1, String zipCode, String city) {
+		this.addressline1 = addressline1;
+		this.zipCode = zipCode;
+		this.city = city;
+	}
+
+	public String getAddressline1() {
+		return addressline1;
+	}
+
+	public void setAddressline1(String addressline1) {
+		this.addressline1 = addressline1;
+	}
+
+	public String getZipCode() {
+		return zipCode;
+	}
+
+	public void setZipCode(String zipCode) {
+		this.zipCode = zipCode;
+	}
+
+	public String getCity() {
+		return city;
+	}
+
+	public void setCity(String city) {
+		this.city = city;
+	}
+
+	public User getInhabitant() {
+		return inhabitant;
+	}
+
+	public void setInhabitant(User inhabitant) {
+		this.inhabitant = inhabitant;
+	}
+}


Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/Address.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/GraphNavigationTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/GraphNavigationTest.java	                        (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/GraphNavigationTest.java	2009-03-12 18:21:01 UTC (rev 16147)
@@ -0,0 +1,63 @@
+// $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.engine.graphnavigation;
+
+import java.util.Set;
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
+import org.hibernate.validation.util.TestUtil;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class GraphNavigationTest {
+
+	@Test
+	public void testGraphNavigationDeterminism() {
+		// build the test object graph
+		User user = new User( "John", "Doe" );
+
+		Address address1 = new Address( null, "11122", "Stockholm" );
+		address1.setInhabitant( user );
+
+		Address address2 = new Address( "Kungsgatan 5", "11122", "Stockholm" );
+		address2.setInhabitant( user );
+
+		user.addAddress( address1 );
+		user.addAddress( address2 );
+
+		Order order = new Order( 1 );
+		order.setShippingAddress( address1 );
+		order.setBillingAddress( address2 );
+		order.setCustomer( user );
+
+		OrderLine line1 = new OrderLine( order, 42 );
+		OrderLine line2 = new OrderLine( order, 101 );
+		order.addOrderLine( line1 );
+		order.addOrderLine( line2 );
+
+		Validator validator = TestUtil.getValidator();
+
+		Set<ConstraintViolation<Order>> constraintViolations = validator.validate( order );
+		assertEquals( "Wrong number of constraints", 1, constraintViolations.size() );
+	}
+}


Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/GraphNavigationTest.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/Order.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/Order.java	                        (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/Order.java	2009-03-12 18:21:01 UTC (rev 16147)
@@ -0,0 +1,80 @@
+// $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.engine.graphnavigation;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Order {
+	@NotNull
+	Integer orderId;
+
+	@Valid
+	private List<OrderLine> orderLines = new ArrayList<OrderLine>();
+
+	@Valid
+	private User customer;
+
+	@Valid
+	private Address shippingAddress;
+
+	@Valid
+	private Address billingAddress;
+
+	public Order(Integer id) {
+		orderId = id;
+	}
+
+	public void addOrderLine(OrderLine orderLine) {
+		orderLines.add( orderLine );
+	}
+
+	public List<OrderLine> getOrderLines() {
+		return Collections.unmodifiableList( orderLines );
+	}
+
+	public User getCustomer() {
+		return customer;
+	}
+
+	public void setCustomer(User customer) {
+		this.customer = customer;
+	}
+
+	public Address getShippingAddress() {
+		return shippingAddress;
+	}
+
+	public void setShippingAddress(Address shippingAddress) {
+		this.shippingAddress = shippingAddress;
+	}
+
+	public Address getBillingAddress() {
+		return billingAddress;
+	}
+
+	public void setBillingAddress(Address billingAddress) {
+		this.billingAddress = billingAddress;
+	}
+}


Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/Order.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/OrderLine.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/OrderLine.java	                        (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/OrderLine.java	2009-03-12 18:21:01 UTC (rev 16147)
@@ -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.validation.engine.graphnavigation;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.Valid;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class OrderLine {
+	@NotNull
+	Integer articleNumber;
+
+	@Valid
+	Order order;
+
+	public OrderLine(Order order, Integer articleNumber) {
+		this.articleNumber = articleNumber;
+		this.order = order;
+	}
+
+	public Integer getArticleNumber() {
+		return articleNumber;
+	}
+
+	public void setArticleNumber(Integer articleNumber) {
+		this.articleNumber = articleNumber;
+	}
+}


Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/OrderLine.java
___________________________________________________________________
Name: svn:keywords
   + Id

Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/User.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/User.java	                        (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/User.java	2009-03-12 18:21:01 UTC (rev 16147)
@@ -0,0 +1,71 @@
+// $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.engine.graphnavigation;
+
+import java.util.HashSet;
+import java.util.Set;
+import javax.validation.constraints.NotNull;
+import javax.validation.groups.Default;
+import javax.validation.Valid;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class User {
+
+	@NotNull
+	private String firstName;
+
+	@NotNull(groups = Default.class)
+	private String lastName;
+
+	@Valid
+	private Set<Address> addresses = new HashSet<Address>();
+
+	public User() {
+	}
+
+	public User(String firstName, String lastName) {
+		this.firstName = firstName;
+		this.lastName = lastName;
+	}
+
+	public Set<Address> getAddresses() {
+		return addresses;
+	}
+
+	public void addAddress(Address address) {
+		addresses.add( address );
+	}
+
+	public String getFirstName() {
+		return firstName;
+	}
+
+	public void setFirstName(String firstName) {
+		this.firstName = firstName;
+	}
+
+	public String getLastName() {
+		return lastName;
+	}
+
+	public void setLastName(String lastName) {
+		this.lastName = lastName;
+	}
+}


Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/graphnavigation/User.java
___________________________________________________________________
Name: svn:keywords
   + Id




More information about the hibernate-commits mailing list