Assert.assertEquals(Group.DEFAULT, gseq.get(0));
Assert.assertEquals(new Group(GClass1.class), gseq.get(1));
}
public void testGroups() {
Validator validator = 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("Wrong number of constraints", 3, constraintViolations.size());
assertNotNull(TestUtils.getViolation(constraintViolations, "title"));
assertNotNull(TestUtils.getViolation(constraintViolations, "author.firstName"));
assertNotNull(TestUtils.getViolation(constraintViolations, "author.lastName"));
author.setFirstName("Gavin");
author.setLastName("King");
constraintViolations = validator.validate(book, First.class, Second.class, Last.class);
ConstraintViolation constraintViolation = constraintViolations.iterator().next();
assertEquals(1, constraintViolations.size());
assertEquals("may not be empty", constraintViolation.getMessage());
assertEquals(book, constraintViolation.getRootBean());
assertEquals(book.getTitle(), constraintViolation.getInvalidValue());
assertEquals("title", constraintViolation.getPropertyPath().toString());
book.setTitle("My fault");
book.setSubtitle("confessions of a president - a book for a nice price");
constraintViolations = validator.validate(book, First.class, Second.class, Last.class);
assertEquals(1, constraintViolations.size());
constraintViolation = constraintViolations.iterator().next();
assertEquals("size must be between 0 and 30", constraintViolation.getMessage());
assertEquals(book, constraintViolation.getRootBean());
assertEquals(book.getSubtitle(), constraintViolation.getInvalidValue());
assertEquals("subtitle", constraintViolation.getPropertyPath().toString());
book.setSubtitle("Capitalism in crisis");
author.setCompany("1234567890ß9876543212578909876542245678987432");
constraintViolations = validator.validate(book);
constraintViolation = constraintViolations.iterator().next();
assertEquals(1, constraintViolations.size());
assertEquals("size must be between 0 and 40", constraintViolation.getMessage());
assertEquals(book, constraintViolation.getRootBean());
assertEquals(author.getCompany(), constraintViolation.getInvalidValue());
assertEquals("author.company", constraintViolation.getPropertyPath().toString());
author.setCompany("apache");
constraintViolations = validator.validate(book, First.class, Second.class, Last.class);
assertEquals(0, constraintViolations.size());
}