Author: hardy.ferentschik
Date: 2009-06-16 10:17:45 -0400 (Tue, 16 Jun 2009)
New Revision: 16793
Removed:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/AddressWithInvalidGroupSequence.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Animal.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Auditable.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Author.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Billable.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Book.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/BuyInOneClick.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Car.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/CreditCard.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Dictonary.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupTest.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Optional.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Order.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/User.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/inheritance/
Log:
moving group tests into tck
Deleted:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/AddressWithInvalidGroupSequence.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/AddressWithInvalidGroupSequence.java 2009-06-16
13:21:53 UTC (rev 16792)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/AddressWithInvalidGroupSequence.java 2009-06-16
14:17:45 UTC (rev 16793)
@@ -1,12 +0,0 @@
-package org.hibernate.validation.engine.groups;
-
-import javax.validation.GroupSequence;
-import javax.validation.groups.Default;
-
-/**
- * @author Emmanuel Bernard
- */
-@GroupSequence({ Default.class, AddressWithInvalidGroupSequence.HighLevelCoherence.class
})
-public class AddressWithInvalidGroupSequence extends Address {
-
-}
\ No newline at end of file
Deleted:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Animal.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Animal.java 2009-06-16
13:21:53 UTC (rev 16792)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Animal.java 2009-06-16
14:17:45 UTC (rev 16793)
@@ -1,55 +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.validation.engine.groups;
-
-import javax.validation.constraints.NotNull;
-
-import org.hibernate.validation.constraints.NotEmpty;
-import org.hibernate.validation.engine.First;
-import org.hibernate.validation.engine.Second;
-
-/**
- * @author Hardy Ferentschik
- */
-public class Animal {
- public enum Domain {
- PROKARYOTA, EUKARYOTA
- }
-
- @NotEmpty(groups = { First.class, Second.class })
- private String name;
-
- @NotNull(groups = First.class)
- private Domain domain;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Domain getDomain() {
- return domain;
- }
-
- public void setDomain(Domain domain) {
- this.domain = domain;
- }
-}
\ No newline at end of file
Deleted:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Auditable.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Auditable.java 2009-06-16
13:21:53 UTC (rev 16792)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Auditable.java 2009-06-16
14:17:45 UTC (rev 16793)
@@ -1,37 +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.validation.engine.groups;
-
-import javax.validation.constraints.NotNull;
-
-/**
- * @author Hardy Ferentschik
- */
-public interface Auditable {
- @NotNull
- String getCreationDate();
-
- @NotNull
- String getLastUpdate();
-
- @NotNull
- String getLastModifier();
-
- @NotNull
- String getLastReader();
-}
Deleted:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Author.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Author.java 2009-06-16
13:21:53 UTC (rev 16792)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Author.java 2009-06-16
14:17:45 UTC (rev 16793)
@@ -1,64 +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.validation.engine.groups;
-
-import javax.validation.constraints.NotNull;
-
-import org.hibernate.validation.constraints.Length;
-import org.hibernate.validation.constraints.NotEmpty;
-import org.hibernate.validation.engine.First;
-import org.hibernate.validation.engine.Last;
-
-/**
- * @author Hardy Ferentschik
- */
-public class Author {
-
- @NotEmpty(groups = Last.class)
- private String firstName;
-
- @NotEmpty(groups = First.class)
- private String lastName;
-
- @Length(max = 20, groups = Last.class)
- private String company;
-
- 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;
- }
-
- public String getCompany() {
- return company;
- }
-
- public void setCompany(String company) {
- this.company = company;
- }
-}
Deleted:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Billable.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Billable.java 2009-06-16
13:21:53 UTC (rev 16792)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Billable.java 2009-06-16
14:17:45 UTC (rev 16793)
@@ -1,9 +0,0 @@
-package org.hibernate.validation.engine.groups;
-
-/**
- * Validation group checking whether user is billable.
- *
- * @author Emmanuel Bernard
- */
-public interface Billable {
-}
\ No newline at end of file
Deleted:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Book.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Book.java 2009-06-16
13:21:53 UTC (rev 16792)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Book.java 2009-06-16
14:17:45 UTC (rev 16793)
@@ -1,71 +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.validation.engine.groups;
-
-import javax.validation.GroupSequence;
-import javax.validation.Valid;
-import javax.validation.constraints.NotNull;
-
-import org.hibernate.validation.constraints.Length;
-import org.hibernate.validation.constraints.NotEmpty;
-import org.hibernate.validation.engine.First;
-import org.hibernate.validation.engine.Last;
-import org.hibernate.validation.engine.Second;
-
-/**
- * @author Hardy Ferentschik
- */
-public class Book {
- @NotEmpty(groups = First.class)
- private String title;
-
- @Length(max = 30, groups = Second.class)
- private String subtitle;
-
- @Valid
- @NotNull(groups = First.class)
- private Author author;
-
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- public String getSubtitle() {
- return subtitle;
- }
-
- public void setSubtitle(String subtitle) {
- this.subtitle = subtitle;
- }
-
- public Author getAuthor() {
- return author;
- }
-
- public void setAuthor(Author author) {
- this.author = author;
- }
-
- @GroupSequence(value = { First.class, Second.class, Last.class })
- public interface All {
- }
-}
Deleted:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/BuyInOneClick.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/BuyInOneClick.java 2009-06-16
13:21:53 UTC (rev 16792)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/BuyInOneClick.java 2009-06-16
14:17:45 UTC (rev 16793)
@@ -1,11 +0,0 @@
-package org.hibernate.validation.engine.groups;
-
-import javax.validation.groups.Default;
-
-/**
- * Customer can buy without being harrassed by the checking-out process.
- *
- * @author Emmanuel Bernard
- */
-public interface BuyInOneClick extends Default, Billable {
-}
\ No newline at end of file
Deleted:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Car.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Car.java 2009-06-16
13:21:53 UTC (rev 16792)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Car.java 2009-06-16
14:17:45 UTC (rev 16793)
@@ -1,30 +0,0 @@
-package org.hibernate.validation.engine.groups;
-
-import javax.validation.GroupSequence;
-import javax.validation.constraints.Pattern;
-import javax.validation.groups.Default;
-
-import org.hibernate.validation.constraints.Length;
-
-/**
- * @author Emmanuel Bernard
- * @author Hardy Ferentschik
- */
-@GroupSequence({ Car.class, Car.Test.class })
-public class Car {
- @Pattern(regexp = ".*", groups = Default.class)
- @Length(min = 2, max = 20, groups = Car.Test.class)
- private String type;
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public interface Test {
-
- }
-}
\ No newline at end of file
Deleted:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/CreditCard.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/CreditCard.java 2009-06-16
13:21:53 UTC (rev 16792)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/CreditCard.java 2009-06-16
14:17:45 UTC (rev 16793)
@@ -1,34 +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.validation.engine.groups;
-
-/**
- * @author Hardy Ferentschik
- */
-public class CreditCard {
-
- private String number;
-
- public String getNumber() {
- return number;
- }
-
- public void setNumber(String number) {
- this.number = number;
- }
-}
Deleted:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Dictonary.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Dictonary.java 2009-06-16
13:21:53 UTC (rev 16792)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Dictonary.java 2009-06-16
14:17:45 UTC (rev 16793)
@@ -1,57 +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.validation.engine.groups;
-
-import javax.validation.constraints.NotNull;
-
-import org.hibernate.validation.constraints.NotEmpty;
-
-/**
- * @author Hardy Ferentschik
- */
-public class Dictonary extends Book {
- @NotNull(groups = Translate.class)
- @NotEmpty(groups = Translate.class)
- private String translatesTo;
-
- @NotNull(groups = Translate.class)
- @NotEmpty(groups = Translate.class)
- private String translatesFrom;
-
- public String getTranslatesTo() {
- return translatesTo;
- }
-
- public void setTranslatesTo(String translatesTo) {
- this.translatesTo = translatesTo;
- }
-
- public String getTranslatesFrom() {
- return translatesFrom;
- }
-
- public void setTranslatesFrom(String translatesFrom) {
- this.translatesFrom = translatesFrom;
- }
-
- /**
- * Translator related constraints
- */
- public interface Translate {
- }
-}
Deleted:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupTest.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupTest.java 2009-06-16
13:21:53 UTC (rev 16792)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/GroupTest.java 2009-06-16
14:17:45 UTC (rev 16793)
@@ -1,415 +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.validation.engine.groups;
-
-import java.util.Set;
-import javax.validation.metadata.BeanDescriptor;
-import javax.validation.ConstraintViolation;
-import javax.validation.metadata.PropertyDescriptor;
-import javax.validation.ValidationException;
-import javax.validation.Validator;
-import javax.validation.groups.Default;
-
-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.engine.DefaultAlias;
-import org.hibernate.validation.engine.First;
-import org.hibernate.validation.engine.Last;
-import org.hibernate.validation.engine.Second;
-import org.hibernate.validation.util.TestUtil;
-import static org.hibernate.validation.util.TestUtil.assertConstraintViolation;
-
-/**
- * Tests for the group and group sequence feature.
- *
- * @author Hardy Ferentschik
- */
-public class GroupTest {
-
- @Test
- public void testGroups() {
- Validator validator = TestUtil.getValidator();
-
- Author author = new Author();
- author.setLastName( "" );
- author.setFirstName( "" );
- Book book = new Book();
- book.setTitle( "" );
- book.setAuthor( author );
-
- Set<ConstraintViolation<Book>> constraintViolations = validator.validate(
- book, First.class, Second.class, Last.class
- );
- assertEquals( constraintViolations.size(), 3, "Wrong number of constraints"
);
-
- author.setFirstName( "Gavin" );
- author.setLastName( "King" );
-
- constraintViolations = validator.validate( book, First.class, Second.class, Last.class
);
- ConstraintViolation constraintViolation = constraintViolations.iterator().next();
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints"
);
- assertEquals( "may not be empty", constraintViolation.getMessage(),
"Wrong message" );
- assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity"
);
- assertEquals( constraintViolation.getInvalidValue(), book.getTitle(), "Wrong
value" );
- assertEquals( "title", constraintViolation.getPropertyPath(), "Wrong
propertyName" );
-
- book.setTitle( "Hibernate Persistence with JPA" );
- book.setSubtitle( "Revised Edition of Hibernate in Action" );
-
- constraintViolations = validator.validate( book, First.class, Second.class, Last.class
);
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints"
);
- constraintViolation = constraintViolations.iterator().next();
- assertEquals( "length must be between 0 and 30",
constraintViolation.getMessage(), "Wrong message" );
- assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity"
);
- assertEquals( constraintViolation.getInvalidValue(), book.getSubtitle(), "Wrong
value" );
- assertEquals( "subtitle", constraintViolation.getPropertyPath(), "Wrong
propertyName" );
-
- book.setSubtitle( "Revised Edition" );
- author.setCompany( "JBoss a divison of RedHat" );
-
- constraintViolations = validator.validate( book, First.class, Second.class, Last.class
);
- constraintViolation = constraintViolations.iterator().next();
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints"
);
- assertEquals( "length must be between 0 and 20",
constraintViolation.getMessage() );
- assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity"
);
- assertEquals( constraintViolation.getInvalidValue(), author.getCompany(), "Wrong
value" );
- assertEquals( "author.company", constraintViolation.getPropertyPath(),
"Wrong propertyName" );
-
- author.setCompany( "JBoss" );
-
- constraintViolations = validator.validate( book, First.class, Second.class, Last.class
);
- assertEquals( constraintViolations.size(), 0, "Wrong number of constraints"
);
- }
-
- @Test
- public void testGroupSequence() {
- Validator validator = TestUtil.getValidator();
-
- Author author = new Author();
- author.setLastName( "" );
- author.setFirstName( "" );
- Book book = new Book();
- book.setAuthor( author );
-
- Set<ConstraintViolation<Book>> constraintViolations = validator.validate(
book, Book.All.class );
- assertEquals( constraintViolations.size(), 2, "Wrong number of constraints"
);
-
- author.setFirstName( "Gavin" );
- author.setLastName( "King" );
-
- constraintViolations = validator.validate( book, Book.All.class );
- ConstraintViolation constraintViolation = constraintViolations.iterator().next();
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints"
);
- assertEquals( "may not be empty", constraintViolation.getMessage(),
"Wrong message" );
- assertEquals( constraintViolation.getRootBean(), book, "Wrong root entity"
);
- assertEquals( constraintViolation.getInvalidValue(), book.getTitle(), "Wrong
value" );
- assertEquals( "title", constraintViolation.getPropertyPath(), "Wrong
propertyName" );
-
- book.setTitle( "Hibernate Persistence with JPA" );
- book.setSubtitle( "Revised Edition of Hibernate in Action" );
-
- constraintViolations = validator.validate( book, Book.All.class );
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints"
);
-
- book.setSubtitle( "Revised Edition" );
- author.setCompany( "JBoss a divison of RedHat" );
-
- constraintViolations = validator.validate( book, Book.All.class );
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints"
);
-
- author.setCompany( "JBoss" );
-
- constraintViolations = validator.validate( book, Book.All.class );
- assertEquals( constraintViolations.size(), 0, "Wrong number of constraints"
);
- }
-
- @Test
- public void testGroupSequences() {
- Validator validator = TestUtil.getValidator();
-
- Dictonary dictonary = new Dictonary();
- dictonary.setTitle( "English - German" );
- Author author = new Author();
- author.setLastName( "-" );
- author.setFirstName( "-" );
- author.setCompany( "Langenscheidt Publ." );
- dictonary.setAuthor( author );
-
- Set<ConstraintViolation<Dictonary>> constraintViolations =
validator.validate( dictonary, DefaultAlias.class );
- assertEquals( constraintViolations.size(), 0, "Wrong number of constraints"
);
- }
-
- @Test
- public void testValidationFailureInMultipleGroups() {
- Validator validator = TestUtil.getValidator();
- Animal elepfant = new Animal();
- elepfant.setName( "" );
- elepfant.setDomain( Animal.Domain.EUKARYOTA );
-
- Set<ConstraintViolation<Animal>> constraintViolations =
validator.validate(
- elepfant, First.class, Second.class
- );
- assertEquals(
- constraintViolations.size(),
- 1,
- "The should be two invalid constraints since the same propertyName gets
validated in both groups"
- );
- }
-
- @Test
- public void testValidateAgainstDifferentGroups() {
- User user = new User();
-
- // all fields per default null. Depending on the validation groups there should be a
different amount
- // of constraint failures.
- Validator validator = TestUtil.getValidator();
-
- Set<ConstraintViolation<User>> constraintViolations = validator.validate(
user );
- assertEquals(
- constraintViolations.size(),
- 2,
- "There should be two violations against the implicit default group"
- );
-
- constraintViolations = validator.validate( user, Default.class );
- assertEquals(
- constraintViolations.size(),
- 2,
- "There should be two violations against the explicit defualt group"
- );
-
- constraintViolations = validator.validate( user, Billable.class );
- assertEquals(
- constraintViolations.size(),
- 1,
- "There should be one violation against Billable"
- );
-
- constraintViolations = validator.validate( user, Default.class, Billable.class );
- assertEquals(
- constraintViolations.size(),
- 3,
- "There should be 3 violation against Default and Billable"
- );
-
- constraintViolations = validator.validate( user, BuyInOneClick.class );
- assertEquals(
- constraintViolations.size(),
- 3,
- "Three violations expected since BuyInOneClick extends Default and
Billable"
- );
-
- constraintViolations = validator.validate( user, BuyInOneClick.class, Billable.class
);
- assertEquals(
- constraintViolations.size(),
- 3,
- "BuyInOneClick already contains all other groups. Adding Billable does not
change the number of violations"
- );
-
- constraintViolations = validator.validate( user, BuyInOneClick.class, Default.class );
- assertEquals(
- constraintViolations.size(),
- 3,
- "BuyInOneClick already contains all other groups. Adding Default does not change
the number of violations"
- );
-
- constraintViolations = validator.validate( user, BuyInOneClick.class, Default.class,
Billable.class );
- assertEquals(
- constraintViolations.size(),
- 3,
- "BuyInOneClick already contains all other groups. Adding Billable and Default
does not change the number of violations"
- );
-
- constraintViolations = validator.validate( user, Billable.class, Billable.class );
- assertEquals(
- constraintViolations.size(),
- 1,
- "Adding the same group twice is still only leads to a single violation"
- );
- }
-
- /**
- * HV-85
- */
- @Test
- public void testGroupSequenceFollowedByGroup() {
- User user = new User();
- user.setFirstname( "Foo" );
- user.setLastname( "Bar" );
- user.setPhoneNumber( "+46 123-456" );
-
- Validator validator = TestUtil.getValidator();
-
- Set<ConstraintViolation<User>> constraintViolations = validator.validate(
- user, BuyInOneClick.class, Optional.class
- );
- assertEquals(
- constraintViolations.size(),
- 2,
- "There should be two violations against the implicit default group"
- );
-
- for ( ConstraintViolation<User> constraintViolation : constraintViolations ) {
- if ( constraintViolation.getPropertyPath().equals( "defaultCreditCard" ) )
{
- assertConstraintViolation(
- constraintViolation,
- "may not be null",
- User.class,
- null,
- "defaultCreditCard"
- );
- }
- else if ( constraintViolation.getPropertyPath().equals( "phoneNumber" ) ) {
- assertConstraintViolation(
- constraintViolation,
- "must match \"[0-9 -]?\"",
- User.class,
- "+46 123-456",
- "phoneNumber"
- );
- }
- else {
- fail( "Unexpected violation" );
- }
- }
- }
-
- /**
- * HV-113
- */
- @Test
- public void testRedefiningDefaultGroup() {
- Address address = new Address();
- address.setStreet( "Guldmyntgatan" );
- address.setCity( "Gothenborg" );
-
- Validator validator = TestUtil.getValidator();
-
- Set<ConstraintViolation<Address>> constraintViolations =
validator.validate( address );
- assertEquals(
- constraintViolations.size(),
- 1,
- "There should only be one violation for zipcode"
- );
-
- ConstraintViolation<Address> violation = constraintViolations.iterator().next();
- assertConstraintViolation( violation, "may not be null", address.getClass(),
null, "zipcode" );
-
- address.setZipcode( "41841" );
-
- // now the second group in the re-defined default group causes an error
- constraintViolations = validator.validate( address );
- assertEquals(
- constraintViolations.size(),
- 1,
- "There should only be one violation for zipcode"
- );
-
- violation = constraintViolations.iterator().next();
- assertConstraintViolation( violation, "{validator.zipCodeCoherenceChecker}",
address.getClass(), address, "" );
- }
-
- /**
- * HV-113
- */
- @Test
- public void testRedefiningDefaultGroup2() {
- Car car = new Car();
- car.setType( "A" );
-
- Validator validator = TestUtil.getValidator();
-
- Set<ConstraintViolation<Car>> constraintViolations = validator.validate(
car );
- assertEquals(
- constraintViolations.size(),
- 1,
- "There should be one violations due to the re-defintion of the default
group"
- );
- assertEquals(
- "length must be between 2 and 20",
- constraintViolations.iterator().next().getMessage(),
- "Wrong constraint"
- );
-
- constraintViolations = validator.validateProperty( car, "type" );
- assertEquals(
- constraintViolations.size(),
- 1,
- "There should be one violations due to the re-defintion of the default
group"
- );
- assertEquals(
- "length must be between 2 and 20",
- constraintViolations.iterator().next().getMessage(),
- "Wrong constraint"
- );
-
- constraintViolations = validator.validateValue( Car.class, "type",
"A" );
- assertEquals(
- constraintViolations.size(),
- 1,
- "There should be one violations due to the re-defintion of the default
group"
- );
- assertEquals(
- "length must be between 2 and 20",
- constraintViolations.iterator().next().getMessage(),
- "Wrong constraint"
- );
- }
-
- /**
- * HV-113
- */
- @Test
- public void testInvalidRedefinitionOfDefaultGroup() {
- Address address = new AddressWithInvalidGroupSequence();
- Validator validator = TestUtil.getValidator();
- try {
- validator.validate( address );
- fail( "It shoud not be allowed to have Default.class in the group sequence of a
class." );
- }
- catch ( ValidationException e ) {
- assertEquals(
- "'Default.class' cannot appear in default group sequence list.",
e.getMessage(), "Wrong message"
- );
- }
- }
-
- /**
- * HV-115
- */
- @Test
- public void testImplicitGroup() {
- Validator validator = TestUtil.getValidator();
- BeanDescriptor beanDescriptor = validator.getConstraintsForClass( Order.class );
- assertTrue( beanDescriptor.isBeanConstrained() );
-
- Set<PropertyDescriptor> constraintProperties =
beanDescriptor.getConstrainedProperties();
- assertTrue( constraintProperties.size() == 5, "Each of the properties should have
at least one constraint." );
-
- Order order = new Order();
- Set<ConstraintViolation<Order>> violations = validator.validate( order );
- assertTrue( violations.size() == 5, "All 5 NotNull constraints should fail."
);
-
- // use implicit group Auditable
- violations = validator.validate( order, Auditable.class );
- assertTrue( violations.size() == 4, "All 4 NotNull constraints on Auditable should
fail." );
- }
-}
\ No newline at end of file
Deleted:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Optional.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Optional.java 2009-06-16
13:21:53 UTC (rev 16792)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Optional.java 2009-06-16
14:17:45 UTC (rev 16793)
@@ -1,9 +0,0 @@
-package org.hibernate.validation.engine.groups;
-
-/**
- * Validation group checking whether user is billable.
- *
- * @author Emmanuel Bernard
- */
-public interface Optional {
-}
\ No newline at end of file
Deleted:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Order.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Order.java 2009-06-16
13:21:53 UTC (rev 16792)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/Order.java 2009-06-16
14:17:45 UTC (rev 16793)
@@ -1,54 +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.validation.engine.groups;
-
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Size;
-
-/**
- * @author Hardy Ferentschik
- */
-public class Order implements Auditable {
- private String creationDate;
- private String lastUpdate;
- private String lastModifier;
- private String lastReader;
- private String orderNumber;
-
- public String getCreationDate() {
- return this.creationDate;
- }
-
- public String getLastUpdate() {
- return this.lastUpdate;
- }
-
- public String getLastModifier() {
- return this.lastModifier;
- }
-
- public String getLastReader() {
- return this.lastReader;
- }
-
- @NotNull
- @Size(min = 10, max = 10)
- public String getOrderNumber() {
- return this.orderNumber;
- }
-}
Deleted:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/User.java
===================================================================
---
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/User.java 2009-06-16
13:21:53 UTC (rev 16792)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/engine/groups/User.java 2009-06-16
14:17:45 UTC (rev 16793)
@@ -1,58 +0,0 @@
-package org.hibernate.validation.engine.groups;
-
-import javax.validation.GroupSequence;
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Pattern;
-import javax.validation.groups.Default;
-
-
-/**
- * @author Emmanuel Bernard
- * @author Hardy Ferentschik
- */
-@GroupSequence({ User.class })
-public class User {
- @NotNull
- private String firstname;
-
- @NotNull(groups = Default.class)
- private String lastname;
-
- @Pattern(regexp = "[0-9 -]?", groups = Optional.class)
- private String phoneNumber;
-
- @NotNull(groups = { Billable.class, BuyInOneClick.class })
- private CreditCard defaultCreditCard;
-
- 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;
- }
-
- public CreditCard getDefaultCreditCard() {
- return defaultCreditCard;
- }
-
- public void setDefaultCreditCard(CreditCard defaultCreditCard) {
- this.defaultCreditCard = defaultCreditCard;
- }
-
- public String getPhoneNumber() {
- return phoneNumber;
- }
-
- public void setPhoneNumber(String phoneNumber) {
- this.phoneNumber = phoneNumber;
- }
-}
\ No newline at end of file