Return-Path: X-Original-To: apmail-bval-commits-archive@www.apache.org Delivered-To: apmail-bval-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 654E410463 for ; Mon, 26 Aug 2013 14:00:28 +0000 (UTC) Received: (qmail 56913 invoked by uid 500); 26 Aug 2013 14:00:28 -0000 Delivered-To: apmail-bval-commits-archive@bval.apache.org Received: (qmail 56884 invoked by uid 500); 26 Aug 2013 14:00:28 -0000 Mailing-List: contact commits-help@bval.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@bval.apache.org Delivered-To: mailing list commits@bval.apache.org Received: (qmail 56874 invoked by uid 99); 26 Aug 2013 14:00:27 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Aug 2013 14:00:27 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_FILL_THIS_FORM_SHORT X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Aug 2013 14:00:23 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 007522388C27; Mon, 26 Aug 2013 13:59:32 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1517540 [13/15] - in /bval/branches/bval-11/bval-jsr: ./ src/ src/main/ src/main/appended-resources/ src/main/appended-resources/META-INF/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/bval/ src/main/... Date: Mon, 26 Aug 2013 13:59:20 -0000 To: commits@bval.apache.org From: rmannibucau@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130826135932.007522388C27@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/ValidationTest.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/ValidationTest.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/ValidationTest.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/ValidationTest.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,719 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr; + +import junit.framework.Assert; +import junit.framework.TestCase; +import org.apache.bval.constraints.NotNullValidator; +import org.apache.bval.jsr.example.AccessTestBusinessObject; +import org.apache.bval.jsr.example.AccessTestBusinessObjectSub; +import org.apache.bval.jsr.example.Address; +import org.apache.bval.jsr.example.Author; +import org.apache.bval.jsr.example.Book; +import org.apache.bval.jsr.example.BusinessAddress; +import org.apache.bval.jsr.example.Continent; +import org.apache.bval.jsr.example.Country; +import org.apache.bval.jsr.example.First; +import org.apache.bval.jsr.example.Last; +import org.apache.bval.jsr.example.RecursiveFoo; +import org.apache.bval.jsr.util.TestUtils; + +import javax.validation.ConstraintViolation; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.validation.groups.Default; +import javax.validation.metadata.BeanDescriptor; +import javax.validation.metadata.ConstraintDescriptor; +import javax.validation.metadata.PropertyDescriptor; +import java.lang.reflect.Array; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +/** + * Description:
+ */ +public class ValidationTest extends TestCase { + static ValidatorFactory factory; + + static { + factory = Validation.buildDefaultValidatorFactory(); + ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH); + } + + /** + * Validator instance to test + */ + protected Validator validator; + + /** + * {@inheritDoc} + */ + @Override + public void setUp() throws Exception { + super.setUp(); + validator = createValidator(); + } + + /** + * Create the validator instance. + * + * @return Validator + */ + protected Validator createValidator() { + return factory.getValidator(); + } + + public void testAccessStrategies_field_method() { + AccessTestBusinessObject o1 = new AccessTestBusinessObject("1"); + AccessTestBusinessObjectSub o2 = new AccessTestBusinessObjectSub("3"); + Set> errors = validator.validate(o1); + assertTrue(errors.isEmpty()); + Set> errors2 = validator.validate(o2); + assertTrue(errors2.isEmpty()); + + o2 = new AccessTestBusinessObjectSub("1"); + errors2 = validator.validate(o2); + assertEquals(1, errors2.size()); + + // assert, that getvar2() and getVar2() are both validated with their + // getter method + o2 = new AccessTestBusinessObjectSub("3"); + o2.setVar2("1"); + o2.setvar2("2"); + errors2 = validator.validate(o2); + assertEquals(2, errors2.size()); + + o2.setvar2("5"); + o2.setVar2("6"); + errors2 = validator.validate(o2); + assertEquals(0, errors2.size()); + + o2.setvar2("5"); + o2.setVar2("-1"); + errors2 = validator.validate(o2); + assertEquals(1, errors2.size()); + } + + public void testAccessStrategies_on_children() { + AccessTestBusinessObject o1 = new AccessTestBusinessObject("1"); + AccessTestBusinessObject o2 = new AccessTestBusinessObject("2"); + o1.next(o2); + Set> errors = validator.validate(o1); + // assert, that field access 'next' is used and not getNext() is + // called!!! + assertEquals(1, errors.size()); + o2 = new AccessTestBusinessObject("1"); + o1.next(o2); + errors = validator.validate(o1); + assertEquals(0, errors.size()); + + // assert that toBeIgnored not validated, because not annotated with + // @Valid + o1.setToBeIgnored(new AccessTestBusinessObject("99")); + errors = validator.validate(o1); + assertEquals(0, errors.size()); + + o1.setNext(new AccessTestBusinessObject("99")); + errors = validator.validate(o1); + assertEquals(1, errors.size()); + } + + public void testBook() { + Author author = new Author(); + author.setLastName("Baudelaire"); + author.setFirstName(""); + Book book = new Book(); + book.setAuthor(author); + book.setSubtitle("12345678900125678901234578901234567890"); + + // NotEmpty failure on the title field + Set> errors = validator.validate(book, Book.All.class); + Assert.assertTrue(!errors.isEmpty()); + + book.setTitle("Les fleurs du mal"); + author.setCompany("Some random publisher with a very very very long name"); + + // author.firstName fails to pass the NotEmpty constraint + // author.company fails to pass the Size constraint + } + + /** + * test: - dynamic resolution of associated object types. - inheritance of validation constraints - complex + * valiation, different groups, nested object net + */ + public void testValidAnnotation() { + Author a = new Author(); + a.setAddresses(new ArrayList
()); + BusinessAddress adr = new BusinessAddress(); + adr.setCountry(new Country()); + adr.setAddressline1("line1"); + adr.setAddressline2("line2"); + + adr.setZipCode("1234567890123456789"); + a.getAddresses().add(adr); + + a.setFirstName("Karl"); + a.setLastName("May"); + + Set> found = validator.validate(a, Default.class, First.class, Last.class); + Assert.assertTrue(!found.isEmpty()); + Assert.assertEquals(4, found.size()); + + adr.setCity("Berlin"); + adr.setZipCode("12345"); + adr.setCompany("apache"); + found = validator.validate(a, Default.class, First.class, Last.class); + Assert.assertEquals(1, found.size()); + ConstraintViolation ic = found.iterator().next(); + Assert.assertEquals("addresses[0].country.name", ic.getPropertyPath().toString()); + } + + public void testPropertyPathWithIndex() { + Author a = new Author(); + a.setAddresses(new ArrayList
()); + Address adr = new Address(); + adr.setAddressline1("adr1"); + adr.setCity("Santiago"); + a.getAddresses().add(adr); + adr = new Address(); + adr.setAddressline1("adr2"); + adr.setCity("Havanna"); + a.getAddresses().add(adr); + adr = new Address(); + adr.setAddressline1("adr3"); + adr.setCity("Trinidad"); + a.getAddresses().add(adr); + + Set> constraints = validator.validate(a); + Assert.assertTrue(!constraints.isEmpty()); + + assertPropertyPath("addresses[0].country", constraints); + assertPropertyPath("addresses[1].country", constraints); + assertPropertyPath("addresses[2].country", constraints); + } + + /** + * Check correct path reporting when validating a set of beans. + */ + public void testPropertyPathOnSet() { + Continent c = new Continent(); + c.name = "c1"; + Country country = new Country(); + country.setISO2Code("xx"); + country.setISO3Code("xxx"); + country.setName(null); + c.countries.add(country); + + Set> constraints = validator.validate(c); + Assert.assertEquals("Incorrect number of violations detected", 1, constraints.size()); + assertPropertyPath("countries[].name", constraints); + + } + + private void assertPropertyPath(String propertyPath, Set> constraints) { + for (ConstraintViolation each : constraints) { + if (each.getPropertyPath().toString().equals(propertyPath)) + return; + } + Assert.fail(propertyPath + " not found in " + constraints); + } + + public void testPropertyPathRecursive() { + RecursiveFoo foo1 = new RecursiveFoo(); // root + RecursiveFoo foo11 = new RecursiveFoo(); + foo1.getFoos().add(foo11); // foos[0] + RecursiveFoo foo12 = new RecursiveFoo(); + foo1.getFoos().add(foo12); // foos[1] + RecursiveFoo foo2 = new RecursiveFoo(); + foo11.getFoos().add(foo2); // foos[0].foos[0] + + Set> constraints = validator.validate(foo1); + assertPropertyPath("foos[0].foos[0].foos", constraints); + assertPropertyPath("foos[1].foos", constraints); + } + + public void testNullElementInCollection() { + try { + validator.validate(null); + Assert.fail(); + } catch (IllegalArgumentException ex) { + } + RecursiveFoo foo = new RecursiveFoo(); + foo.getFoos().add(new RecursiveFoo()); + foo.getFoos().add(null); + Assert.assertTrue(!validator.validate(foo).isEmpty()); + // check that no nullpointer exception gets thrown + } + + public void testGroups() { + Author author = new Author(); + author.setCompany("ACME"); + Book book = new Book(); + book.setTitle(""); + book.setAuthor(author); + boolean foundTitleConstraint = false; + Set> constraintViolations = validator.validate(book, Book.All.class); + assertEquals(1, constraintViolations.size()); + // assuming an english locale, the interpolated message is returned + for (ConstraintViolation constraintViolation : constraintViolations) { + if (constraintViolation.getRootBean().getClass() == Book.class) { + Assert.assertEquals("may not be empty", constraintViolation.getMessage()); + Assert.assertTrue(book == constraintViolation.getRootBean()); + + // the offending property + if (constraintViolation.getPropertyPath().toString().equals("title")) { + foundTitleConstraint = true; + // the offending value + Assert.assertEquals(book.getTitle(), constraintViolation.getInvalidValue()); + } + } + } + Assert.assertTrue(foundTitleConstraint); + } + + /** + * Example 2.14. Using the fluent API to build custom constraint violations. test that: the + * {@link org.apache.bval.constraints.ZipCodeCityCoherenceValidator} adds custom messages to the context and + * suppresses the default message + */ + public void testConstraintValidatorContextFluentAPI() { + Address ad = new Address(); + ad.setCity("error"); + ad.setZipCode("error"); + ad.setAddressline1("something"); + ad.setCountry(new Country()); + ad.getCountry().setName("something"); + Set> violations = validator.validate(ad); + Assert.assertEquals(2, violations.size()); + for (ConstraintViolation
each : violations) { + Assert.assertTrue(each.getMessage().endsWith(" not OK")); + } + assertNotNull(TestUtils.getViolation(violations, "city")); + assertNotNull(TestUtils.getViolation(violations, "")); + } + + public void testValidateNestedPropertyPath() throws InvocationTargetException, NoSuchMethodException, + IllegalAccessException { + final String propPath = "addresses[0].country.ISO2Code"; + + Author author = new Author(); + author.setAddresses(new ArrayList
()); + Address adr = new Address(); + author.getAddresses().add(adr); + Country country = new Country(); + adr.setCountry(country); + country.setISO2Code("too_long"); + + Set> iv = validator.validateProperty(author, propPath); + Assert.assertEquals(1, iv.size()); + ConstraintViolation vio = iv.iterator().next(); + assertEquals(propPath, vio.getPropertyPath().toString()); + assertSame(author, vio.getRootBean()); + assertSame(author.getAddresses().get(0).getCountry(), vio.getLeafBean()); + + country.setISO2Code("23"); + iv = validator.validateProperty(author, propPath); + Assert.assertEquals(0, iv.size()); + + iv = validator.validateValue(Author.class, propPath, "345"); + Assert.assertEquals(1, iv.size()); + vio = iv.iterator().next(); + assertEquals(propPath, vio.getPropertyPath().toString()); + assertNull(vio.getRootBean()); + assertNull(vio.getLeafBean()); + + iv = validator.validateValue(Author.class, propPath, "34"); + Assert.assertEquals(0, iv.size()); + } + + public void testValidateCascadingNestedBean() throws InvocationTargetException, NoSuchMethodException, + IllegalAccessException { + final String propPath = "addresses[0]"; + + CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class); + Author author = new Author(); + author.setAddresses(new ArrayList
()); + Address adr = new Address(); + author.getAddresses().add(adr); + Country country = new Country(); + adr.setCity("dark"); + adr.setCountry(country); + + Set> iv = v.validateProperty(author, propPath); + Assert.assertEquals(1, iv.size()); // null address line 1 (no cascade) + + country.setISO2Code("too_long"); + iv = v.validateProperty(author, propPath, true); + Assert.assertEquals(3, iv.size()); // null address line 1 + null + // country.name + too long + // country.iso2code + + country.setISO2Code("23"); + iv = v.validateProperty(author, propPath, true); + Assert.assertEquals(2, iv.size()); // null address line 1 + null + // country.name, country.iso2code + // fixed + + Address value = new Address(); + value.setCity("whatever"); + value.setAddressline1("1 address line"); + iv = v.validateValue(Author.class, propPath, value, true); + Assert.assertEquals(1, iv.size()); // null country + + value.setCountry(new Country()); + iv = v.validateValue(Author.class, propPath, value, true); + Assert.assertEquals(1, iv.size()); // null country.name + + value.getCountry().setName("NWO"); + iv = v.validateValue(Author.class, propPath, value, true); + Assert.assertEquals(0, iv.size()); + } + + public void testValidateCascadingNestedProperty() throws InvocationTargetException, NoSuchMethodException, + IllegalAccessException { + final String propPath = "addresses[0].country"; + + CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class); + Author author = new Author(); + author.setAddresses(new ArrayList
()); + Address adr = new Address(); + author.getAddresses().add(adr); + Country country = new Country(); + adr.setCity("dark"); + adr.setCountry(country); + + Set> iv = v.validateProperty(author, propPath); + Assert.assertEquals(0, iv.size()); + + country.setISO2Code("too_long"); + iv = v.validateProperty(author, propPath, true); + Assert.assertEquals(2, iv.size()); + // country.name + too long + // country.iso2code + + country.setISO2Code("23"); + iv = v.validateProperty(author, propPath, true); + Assert.assertEquals(1, iv.size()); + // country.name, country.iso2code + + Country value = null; + iv = v.validateValue(Author.class, propPath, value, true); + Assert.assertEquals(1, iv.size()); // null country + + value = new Country(); + iv = v.validateValue(Author.class, propPath, value, true); + Assert.assertEquals(1, iv.size()); // null country.name + + value.setName("NWO"); + iv = v.validateValue(Author.class, propPath, value, true); + Assert.assertEquals(0, iv.size()); + } + + public void testValidateCascadingNestedTipProperty() { + final String propPath = "addresses[0].country.name"; + + CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class); + Author author = new Author(); + author.setAddresses(new ArrayList
()); + Address adr = new Address(); + author.getAddresses().add(adr); + Country country = new Country(); + adr.setCity("dark"); + adr.setCountry(country); + + Set> iv = v.validateProperty(author, propPath); + Assert.assertEquals(1, iv.size()); + + iv = v.validateProperty(author, propPath, true); + Assert.assertEquals(1, iv.size()); + } + + public void testValidateCascadingKeyedElement() throws InvocationTargetException, NoSuchMethodException, + IllegalAccessException { + final String propPath = "[foo]"; + + CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class); + final Address adr = new Address(); + @SuppressWarnings("serial") + Object map = new HashMap() { + { + put("foo", adr); + } + }; + Country country = new Country(); + adr.setCity("dark"); + adr.setCountry(country); + Set> iv = v.validateProperty(map, propPath); + Assert.assertEquals(1, iv.size()); // null address line 1 (no cascade) + + country.setISO2Code("too_long"); + iv = v.validateProperty(map, propPath, true); + Assert.assertEquals(3, iv.size()); // null address line 1 + null + // country.name + too long + // country.iso2code + + country.setISO2Code("23"); + iv = v.validateProperty(map, propPath, true); + Assert.assertEquals(2, iv.size()); // null address line 1 + null + // country.name, country.iso2code + // fixed + + Address value = new Address(); + value.setCity("whatever"); + value.setAddressline1("1 address line"); + + Set iv2 = v.validateValue(map.getClass(), propPath, value, true); + Assert.assertEquals(1, iv2.size()); // null country + + value.setCountry(new Country()); + iv2 = v.validateValue(map.getClass(), propPath, value, true); + Assert.assertEquals(1, iv2.size()); // null country.name + + value.getCountry().setName("NWO"); + iv2 = v.validateValue(map.getClass(), propPath, value, true); + Assert.assertEquals(0, iv2.size()); + } + + @SuppressWarnings("unchecked") + public void testValidateCascadingKeyedGenericElement() throws InvocationTargetException, NoSuchMethodException, + IllegalAccessException { + final String propPath = "[foo]"; + + CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class); + final Address adr = new Address(); + Object map = new HashMap(); + ((Map) map).put("foo", adr); + Country country = new Country(); + adr.setCity("dark"); + adr.setCountry(country); + Set iv = v.validateProperty(map, propPath); + Assert.assertEquals(1, iv.size()); // null address line 1 (no cascade) + + country.setISO2Code("too_long"); + iv = v.validateProperty(map, propPath, true); + Assert.assertEquals(3, iv.size()); // null address line 1 + null + // country.name + too long + // country.iso2code + + country.setISO2Code("23"); + iv = v.validateProperty(map, propPath, true); + Assert.assertEquals(2, iv.size()); // null address line 1 + null + // country.name, country.iso2code + // fixed + + Address value = new Address(); + value.setCity("whatever"); + value.setAddressline1("1 address line"); + + Set iv2 = v.validateValue(Map.class, propPath, value, true); + Assert.assertEquals(1, iv2.size()); // null country + + value.setCountry(new Country()); + iv2 = v.validateValue(Map.class, propPath, value, true); + Assert.assertEquals(1, iv2.size()); // null country.name + + value.getCountry().setName("NWO"); + iv2 = v.validateValue(Map.class, propPath, value, true); + Assert.assertEquals(0, iv2.size()); + } + + public void testValidateCascadingIndexedElement() throws InvocationTargetException, NoSuchMethodException, + IllegalAccessException { + final String propPath = "[0]"; + CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class); + Address value = new Address(); + value.setCity("whatever"); + value.setAddressline1("1 address line"); + Set> iv; + Address[] array = { value }; + iv = v.validateProperty(array, propPath, true); + Assert.assertEquals(1, iv.size()); // null country + + value.setCountry(new Country()); + iv = v.validateProperty(array, propPath, true); + Assert.assertEquals(1, iv.size()); // null country.name + + value.getCountry().setName("NWO"); + iv = v.validateProperty(array, propPath, true); + Assert.assertEquals(0, iv.size()); + + value = new Address(); + value.setCity("whatever"); + value.setAddressline1("1 address line"); + Set iv2; + iv2 = v.validateValue(array.getClass(), propPath, value, true); + Assert.assertEquals(1, iv2.size()); // null country + + value.setCountry(new Country()); + iv2 = v.validateValue(array.getClass(), propPath, value, true); + Assert.assertEquals(1, iv2.size()); // null country.name + + value.getCountry().setName("NWO"); + iv2 = v.validateValue(array.getClass(), propPath, value, true); + Assert.assertEquals(0, iv2.size()); + } + + public void testValidateCascadingIndexedGenericElement() throws InvocationTargetException, NoSuchMethodException, + IllegalAccessException { + final String propPath = "[0]"; + CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class); + Address value = new Address(); + value.setCity("whatever"); + value.setAddressline1("1 address line"); + Set iv; + Object list = Collections.singletonList(value); + iv = v.validateProperty(list, propPath, true); + Assert.assertEquals(1, iv.size()); // null country + + value.setCountry(new Country()); + iv = v.validateProperty(list, propPath, true); + Assert.assertEquals(1, iv.size()); // null country.name + + value.getCountry().setName("NWO"); + iv = v.validateProperty(list, propPath, true); + Assert.assertEquals(0, iv.size()); + + value = new Address(); + value.setCity("whatever"); + value.setAddressline1("1 address line"); + Set iv2; + iv2 = v.validateValue(List.class, propPath, value, true); + Assert.assertEquals(1, iv2.size()); // null country + + value.setCountry(new Country()); + iv2 = v.validateValue(List.class, propPath, value, true); + Assert.assertEquals(1, iv2.size()); // null country.name + + value.getCountry().setName("NWO"); + iv2 = v.validateValue(List.class, propPath, value, true); + Assert.assertEquals(0, iv2.size()); + } + + public interface Foo { + } + + public static class FooAddress extends Address { + /** + * {@inheritDoc} + */ + @Override + @NotNull(groups = Foo.class) + public String getCity() { + return super.getCity(); + } + } + + public void testValidateCascadingPropertyWithMultipleGroupsIgnoresSiblingProperties() { + final String propPath = "addresses[0].country"; + + CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class); + Author author = new Author(); + author.setAddresses(new ArrayList
()); + Address adr = new FooAddress(); + author.getAddresses().add(adr); + Country country = new Country(); + adr.setCountry(country); + + Set> iv = v.validateProperty(author, propPath, true, Default.class, Foo.class); + Assert.assertEquals(1, iv.size()); + } + + public void testMetadataAPI() { + BeanDescriptor bookBeanDescriptor = validator.getConstraintsForClass(Book.class); + + // expect no constraints on Book's Class-Level + Assert.assertFalse(bookBeanDescriptor.hasConstraints()); + // but there are constraints on Book's Property-Level + Assert.assertTrue(bookBeanDescriptor.isBeanConstrained()); + Assert.assertTrue(bookBeanDescriptor.getConstraintDescriptors().size() == 0); // no + // constraint + // more specifically "author" and "title" + Assert.assertEquals(4, bookBeanDescriptor.getConstrainedProperties().size()); + // not a property + Assert.assertTrue(bookBeanDescriptor.getConstraintsForProperty("doesNotExist") == null); + // property with no constraint + Assert.assertTrue(bookBeanDescriptor.getConstraintsForProperty("description") == null); + PropertyDescriptor propertyDescriptor = bookBeanDescriptor.getConstraintsForProperty("title"); + Assert.assertEquals(2, propertyDescriptor.getConstraintDescriptors().size()); + Assert.assertTrue("title".equals(propertyDescriptor.getPropertyName())); + // assuming the implementation returns the NotEmpty constraint first + Iterator> iter = propertyDescriptor.getConstraintDescriptors().iterator(); + ConstraintDescriptor constraintDescriptor = null; + while (iter.hasNext()) { + constraintDescriptor = iter.next(); + if (constraintDescriptor.getAnnotation().annotationType().equals(NotNull.class)) { + break; + } + + } + Assert.assertTrue(constraintDescriptor != null); + Assert.assertTrue(constraintDescriptor.getGroups().size() == 1); // "first" + Assert.assertEquals(NotNullValidator.class, constraintDescriptor.getConstraintValidatorClasses().get(0)); + // assuming the implementation returns the Size constraint first + propertyDescriptor = bookBeanDescriptor.getConstraintsForProperty("subtitle"); + Iterator> iterator = propertyDescriptor.getConstraintDescriptors().iterator(); + constraintDescriptor = iterator.next(); + Assert.assertTrue(constraintDescriptor.getAnnotation().annotationType().equals(Size.class)); + Assert.assertTrue(((Integer) constraintDescriptor.getAttributes().get("max")) == 30); + Assert.assertTrue(constraintDescriptor.getGroups().size() == 1); + propertyDescriptor = bookBeanDescriptor.getConstraintsForProperty("author"); + Assert.assertTrue(propertyDescriptor.getConstraintDescriptors().size() == 1); + Assert.assertTrue(propertyDescriptor.isCascaded()); + Assert.assertNull(bookBeanDescriptor.getConstraintsForProperty("unconstraintField")); + } + + public void testKeyedMetadata() { + @SuppressWarnings("serial") + BeanDescriptor beanDescriptor = validator.getConstraintsForClass(new HashMap() {}.getClass()); + Assert.assertNotNull(beanDescriptor); + Assert.assertFalse(beanDescriptor.isBeanConstrained()); + Assert.assertNull(beanDescriptor.getConstraintsForProperty("[foo]")); + } + + public void testGenericKeyedMetadata() { + BeanDescriptor beanDescriptor = validator.getConstraintsForClass(Map.class); + Assert.assertNotNull(beanDescriptor); + Assert.assertFalse(beanDescriptor.isBeanConstrained()); + Assert.assertNull(beanDescriptor.getConstraintsForProperty("[foo]")); + } + + public void testIndexedMetadata() { + BeanDescriptor beanDescriptor = validator.getConstraintsForClass(Array.newInstance(Author.class, 0).getClass()); + Assert.assertNotNull(beanDescriptor); + Assert.assertFalse(beanDescriptor.isBeanConstrained()); + Assert.assertNull(beanDescriptor.getConstraintsForProperty("[0]")); + } + + public void testGenericIndexedMetadata() { + BeanDescriptor beanDescriptor = validator.getConstraintsForClass(List.class); + Assert.assertNotNull(beanDescriptor); + Assert.assertFalse(beanDescriptor.isBeanConstrained()); + Assert.assertNull(beanDescriptor.getConstraintsForProperty("[0]")); + } +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/ValidatorResolutionTest.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/ValidatorResolutionTest.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/ValidatorResolutionTest.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/ValidatorResolutionTest.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr; + +import junit.framework.TestCase; + +import javax.validation.Constraint; +import javax.validation.ConstraintDefinitionException; +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; +import javax.validation.Payload; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; +import javax.validation.constraints.NotNull; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import java.util.Locale; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + + +/** + * Checks the correct behavior of the validator resolution algorithm. + * + * @author Carlos Vara + */ +public class ValidatorResolutionTest extends TestCase { + static ValidatorFactory factory; + + static { + factory = Validation.buildDefaultValidatorFactory(); + ((DefaultMessageInterpolator) factory.getMessageInterpolator()).setLocale(Locale.ENGLISH); + } + + /** + * Validator instance to test + */ + protected Validator validator; + + /** + * {@inheritDoc} + */ + @Override + public void setUp() throws Exception { + super.setUp(); + validator = createValidator(); + } + + /** + * Create the validator instance. + * + * @return Validator + */ + protected Validator createValidator() { + return factory.getValidator(); + } + + /** + * Check that a {@link ConstraintDefinitionException} is thrown when the + * only available validator is associated with a different annotation type. + */ + public void testInvalidValidator() { + try { + validator.validate(new Person()); + fail("No exception thrown, but no valid validator available."); + } catch (ConstraintDefinitionException e) { + // correct + } + } + + public static class Person { + @PersonName + public String name; + } + + @Constraint(validatedBy = { InvalidPersonNameValidator.class }) + @Documented + @Target( { METHOD, FIELD, TYPE }) + @Retention(RUNTIME) + public static @interface PersonName { + String message() default "Wrong person name"; + + Class[] groups() default {}; + + Class[] payload() default {}; + } + + public static class InvalidPersonNameValidator implements ConstraintValidator { + public void initialize(NotNull constraintAnnotation) { + // Nothing + } + + public boolean isValid(String value, ConstraintValidatorContext context) { + return true; + } + } + +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/AccessTestBusinessObject.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/AccessTestBusinessObject.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/AccessTestBusinessObject.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/AccessTestBusinessObject.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + + +import org.apache.bval.constraints.HasValue; + +import javax.validation.Valid; + +/** + * Description:
+ */ +public class AccessTestBusinessObject { + // test that field-access is used, not method-access + @HasValue({"1", "3"}) + protected String var1; + + // test that field-access is used, not method-access + @SuppressWarnings("unused") + @Valid + private AccessTestBusinessObject next; + + // not annotated with @Valid, not validated!! + private AccessTestBusinessObject toBeIgnored; + private AccessTestBusinessObject _next; + + public AccessTestBusinessObject(String var1) { + this.var1 = var1; + } + + @HasValue("3") + public String getVar1() { + return "3"; + } + + public void next(AccessTestBusinessObject next) { + this._next = next; + } + + + public void setNext(AccessTestBusinessObject next) { + this.next = next; + } + + @Valid + public AccessTestBusinessObject getNext() { + return _next; // method returns '_next', not the field 'next' + } + + public AccessTestBusinessObject getToBeIgnored() { + return toBeIgnored; + } + + public void setToBeIgnored(AccessTestBusinessObject toBeIgnored) { + this.toBeIgnored = toBeIgnored; + } +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/AccessTestBusinessObjectSub.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/AccessTestBusinessObjectSub.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/AccessTestBusinessObjectSub.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/AccessTestBusinessObjectSub.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + +import org.apache.bval.constraints.HasValue; + +/** + * Description:
+ */ +public class AccessTestBusinessObjectSub extends AccessTestBusinessObject { + private String var2, _var2; + + public void setVar2(String var2) { + this.var2 = var2; + } + + public void setvar2(String _var2) { + this._var2 = _var2; + } + + public AccessTestBusinessObjectSub(String var1) { + super(var1); + } + + // getVar1() is called on subclass, although annotated on superclass + public String getVar1() { + return var1; + } + + //// test that getvar2() is called, not getVar2() + + @HasValue("5") + public String getvar2() { + return _var2; + } + + @HasValue("6") + public String getVar2() { + return var2; + } +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Address.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Address.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Address.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Address.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + + +import org.apache.bval.constraints.ZipCodeCityCoherence; + +import javax.validation.GroupSequence; +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.validation.groups.Default; + +@ZipCodeCityCoherence +public class Address implements ZipCodeCityCarrier { + @NotNull + @Size(max = 30) + private String addressline1; + @Size(max = 30) + private String addressline2; + @Size(max = 11) + private String zipCode; + @NotNull + @Valid + private Country country; + private String city; + + public String getAddressline1() { + return addressline1; + } + + public void setAddressline1(String addressline1) { + this.addressline1 = addressline1; + } + + public String getAddressline2() { + return addressline2; + } + + public void setAddressline2(String addressline2) { + this.addressline2 = addressline2; + } + + public String getZipCode() { + return zipCode; + } + + public void setZipCode(String zipCode) { + this.zipCode = zipCode; + } + + @Size(max = 30) + @NotNull + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public Country getCountry() { + return country; + } + + public void setCountry(Country country) { + this.country = country; + } + + /** + * Check coherence on the overall object + * Needs basic checking to be green first + */ + public interface HighLevelCoherence { + } + + /** + * Check both basic constraints and high level ones. + * High level constraints are not checked if basic constraints fail. + */ + @GroupSequence(value = {Default.class, HighLevelCoherence.class}) + public interface Complete { + } +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Author.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Author.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Author.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Author.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + + +import org.apache.bval.constraints.NotEmpty; + +import javax.validation.GroupSequence; +import javax.validation.Valid; +import javax.validation.constraints.Size; +import java.util.List; + +@GroupSequence({First.class, Author.class, Last.class}) +public class Author { + @NotEmpty(groups = Last.class) + private String firstName; + @NotEmpty(groups = First.class) + private String lastName; + @Size(max = 40, groups = First.class) + private String company; + + @Valid + private List
addresses; + + public List
getAddresses() { + return addresses; + } + + public void setAddresses(List
addresses) { + this.addresses = addresses; + } + + 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; + } +} \ No newline at end of file Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Book.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Book.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Book.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Book.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + + +import org.apache.bval.constraints.NotEmpty; + +import javax.validation.GroupSequence; +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +@GroupSequence({First.class, Second.class, Book.class, Last.class}) +public class Book { + @NotNull(groups = First.class) + @NotEmpty(groups = First.class) + private String title; + + @Size(max = 30, groups = Second.class) + private String subtitle; + + @Valid + @NotNull(groups = First.class) + private Author author; + + @SuppressWarnings("unused") + @NotNull + private int uselessField; + + private int unconstraintField; + + public int getUnconstraintField() { + return unconstraintField; + } + + public void setUnconstraintField(int unconstraintField) { + this.unconstraintField = unconstraintField; + } + + 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 { + } +} \ No newline at end of file Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/BusinessAddress.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/BusinessAddress.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/BusinessAddress.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/BusinessAddress.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + +import javax.validation.constraints.NotNull; + +/** + * Description:
+ */ +public class BusinessAddress extends Address { + private String company; + + @NotNull + public String getCompany() { + return company; + } + + public void setCompany(String company) { + this.company = company; + } +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/CompanyAddress.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/CompanyAddress.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/CompanyAddress.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/CompanyAddress.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + +import org.apache.bval.constraints.CompanyEmail; + +/** + * Description:
+ */ +public class CompanyAddress { + @SuppressWarnings("unused") + @CompanyEmail + private String email; + + public CompanyAddress() { + } + + public CompanyAddress(String email) { + this.email = email; + } + + // do not provided getters & setters to test that value access + // of combined constraints directly use the private field 'email' +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Continent.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Continent.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Continent.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Continent.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import java.util.HashSet; +import java.util.Set; + +/** + * A continent has a name and a set of {@link Country}s. + * + * @author Carlos Vara + */ +public class Continent { + + @NotNull + public String name; + + @Valid + public Set countries = new HashSet(); + +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Country.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Country.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Country.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Country.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + + +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +public class Country { + @NotNull + private String name; + @Size(max = 2) + private String ISO2Code; + @Size(max = 3) + private String ISO3Code; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getISO2Code() { + return ISO2Code; + } + + public void setISO2Code(String ISO2Code) { + this.ISO2Code = ISO2Code; + } + + public String getISO3Code() { + return ISO3Code; + } + + public void setISO3Code(String ISO3Code) { + this.ISO3Code = ISO3Code; + } +} \ No newline at end of file Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Customer.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Customer.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Customer.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Customer.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + + +import org.apache.bval.constraints.Email; +import org.apache.bval.constraints.Password; + +import javax.validation.constraints.NotNull; + +public class Customer implements Person { + private String firstName; + private String middleName; + private String lastName; + @NotNull + private String customerId; + @Password(robustness = 5) + private String password; + + @Email + private String emailAddress; + + public String getEmailAddress() { + return emailAddress; + } + + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + } + + 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; + } + + public String getCustomerId() { + return customerId; + } + + public void setCustomerId(String customerId) { + this.customerId = customerId; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } +} \ No newline at end of file Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Employee.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Employee.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Employee.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Employee.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + +/** + * Description:
+ */ +public class Employee implements Person { + private String firstName, lastName; + + public Employee(String firstN, String lastN) { + this.firstName = firstN; + this.lastName = lastN; + } + + public String getFirstName() { + return firstName; + } + + public String getMiddleName() { + return null; // not supported + } + + public String getLastName() { + return lastName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Engine.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Engine.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Engine.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Engine.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + +import javax.validation.constraints.Pattern; + +public class Engine { + @Pattern.List({ + @Pattern(regexp = "^[A-Z0-9-]+$", flags = Pattern.Flag.CASE_INSENSITIVE, + message = "must contain alphabetical characters only"), + @Pattern( + regexp = "^....-....-....$", message = "must match ....-....-....")}) + public String serialNumber; + + +} \ No newline at end of file Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/First.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/First.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/First.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/First.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + +/** + * Description:
+ */ +public interface First { +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/FrenchAddress.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/FrenchAddress.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/FrenchAddress.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/FrenchAddress.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + +import org.apache.bval.constraints.FrenchZipCode; + +/** + * Description:
+ */ +public class FrenchAddress { + @FrenchZipCode(size = 7) + String zipCode; + + public FrenchAddress() { + } + + public FrenchAddress(String zipCode) { + this.zipCode = zipCode; + } + + public String getZipCode() { + return zipCode; + } + + public void setZipCode(String zipCode) { + this.zipCode = zipCode; + } + + @FrenchZipCode + String zipCode2 = "123456"; + +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/IllustratedBook.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/IllustratedBook.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/IllustratedBook.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/IllustratedBook.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.bval.jsr.example; + +/** + * Add a non-cascaded bean to a book. + * + * @version $Rev: 1004764 $ $Date: 2010-10-05 13:35:42 -0500 (Tue, 05 Oct 2010) $ + */ +public class IllustratedBook extends Book { + private Person illustrator; + + /** + * @return the illustrator + */ + public Person getIllustrator() { + return illustrator; + } + + /** + * @param illustrator + * the illustrator to set + */ + public void setIllustrator(Person illustrator) { + this.illustrator = illustrator; + } +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Last.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Last.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Last.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Last.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + +/** + * Description:
+ */ +public interface Last { +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Library.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Library.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Library.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Library.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Description:
+ */ +public class Library { + @NotNull + private String libraryName; + @Valid + private final Map taggedBooks = new HashMap(); + + private Person[] persons; + + public String getLibraryName() { + return libraryName; + } + + public void setLibraryName(String libraryName) { + this.libraryName = libraryName; + } + + public Map getTaggedBooks() { + return taggedBooks; + } + + public Person[] getPersons() { + return persons; + } + + public void setPersons(Person[] persons) { + this.persons = persons; + } + + @Valid + public List getEmployees() { + if (persons == null) + return Collections.emptyList(); + + ArrayList emps = new ArrayList(persons.length); + for (Person each : persons) { + if (each instanceof Employee) + emps.add((Employee) each); + } + return emps; + } +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/MaxTestEntity.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/MaxTestEntity.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/MaxTestEntity.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/MaxTestEntity.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + +import javax.validation.constraints.Max; +import java.math.BigDecimal; + +/** + * Description:
+ */ +public class MaxTestEntity { + @Max(100) + private String text; + private String property; + + @Max(300) + private long longValue; + + private BigDecimal decimalValue; + + public String getText() { + return text; + } + + @Max(200) + public String getProperty() { + return property; + } + + public long getLongValue() { + return longValue; + } + + @Max(400) + public BigDecimal getDecimalValue() { + return decimalValue; + } + + public void setText(String text) { + this.text = text; + } + + public void setProperty(String property) { + this.property = property; + } + + public void setLongValue(long longValue) { + this.longValue = longValue; + } + + public void setDecimalValue(BigDecimal decimalValue) { + this.decimalValue = decimalValue; + } +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/NoValidatorTestEntity.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/NoValidatorTestEntity.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/NoValidatorTestEntity.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/NoValidatorTestEntity.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + +import javax.validation.constraints.Max; + +/** + * Description:
+ */ +public class NoValidatorTestEntity { + @SuppressWarnings("unused") + @Max(20) + private Object anything; + +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Person.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Person.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Person.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Person.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + +import org.apache.bval.constraints.NotEmpty; + +public interface Person { + @NotEmpty + String getFirstName(); + + String getMiddleName(); + + @NotEmpty + String getLastName(); +} \ No newline at end of file Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/PreferredGuest.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/PreferredGuest.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/PreferredGuest.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/PreferredGuest.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + +import javax.validation.constraints.Digits; + +public class PreferredGuest extends Customer { + @Digits(integer = 10, fraction = 0) + private String guestCreditCardNumber; + + public String getGuestCreditCardNumber() { + return guestCreditCardNumber; + } + + public void setGuestCreditCardNumber(String guestCreditCardNumber) { + this.guestCreditCardNumber = guestCreditCardNumber; + } +} \ No newline at end of file Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/RecursiveFoo.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/RecursiveFoo.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/RecursiveFoo.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/RecursiveFoo.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + + +import org.apache.bval.constraints.NotEmpty; + +import javax.validation.Valid; +import java.util.ArrayList; +import java.util.Collection; + +/** + * Description:
+ */ +public class RecursiveFoo { + @NotEmpty + @Valid + Collection foos = new ArrayList(); + + public Collection getFoos() { + return foos; + } + + public void setFoos(Collection foos) { + this.foos = foos; + } +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Second.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Second.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Second.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/Second.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + +/** + * Description:
+ */ +public interface Second { +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/SizeTestEntity.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/SizeTestEntity.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/SizeTestEntity.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/SizeTestEntity.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + +import javax.validation.constraints.Size; +import java.util.Collection; +import java.util.Map; + +/** + * Description:
+ */ +public class SizeTestEntity { + @Size(max=2) + public Map map; + @Size(max=2) + public Collection coll; + @Size(max=2) + public String text; + + @Size(max=2) + public Object[] oa; + @Size(max=2) + public byte[] ba; + @Size(max=2) + public int[] it; + @Size(max=2) + public Integer[] oa2; + @Size(max=2) + public boolean[] boa; + @Size(max=2) + public char[] ca; + @Size(max=2) + public double[] da; + @Size(max=2) + public float[] fa; + @Size(max=2) + public long[] la; + @Size(max=2) + public short[] sa; +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/XmlEntitySampleBean.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/XmlEntitySampleBean.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/XmlEntitySampleBean.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/XmlEntitySampleBean.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + +/** + * Description: bean used to test constraints described in XML
+ */ +public class XmlEntitySampleBean { + private String zipCode; + private String valueCode; + + private String firstName; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getZipCode() { + return zipCode; + } + + public void setZipCode(String zipCode) { + this.zipCode = zipCode; + } + + public String getValueCode() { + return valueCode; + } + + public void setValueCode(String valueCode) { + this.valueCode = valueCode; + } +} Added: bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/ZipCodeCityCarrier.java URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/ZipCodeCityCarrier.java?rev=1517540&view=auto ============================================================================== --- bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/ZipCodeCityCarrier.java (added) +++ bval/branches/bval-11/bval-jsr/src/test/java/org/apache/bval/jsr/example/ZipCodeCityCarrier.java Mon Aug 26 13:59:15 2013 @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.bval.jsr.example; + +/** + * Description:
+ */ +public interface ZipCodeCityCarrier { + String getZipCode(); + String getCity(); +}