Package org.apache.bval.jsr303.example

Examples of org.apache.bval.jsr303.example.Country


        CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class);
        Author author = new Author();
        author.setAddresses(new ArrayList<Address>());
        Address adr = new Address();
        author.getAddresses().add(adr);
        Country country = new Country();
        adr.setCity("dark");
        adr.setCountry(country);

        Set<ConstraintViolation<Author>> 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);
View Full Code Here


        CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class);
        Author author = new Author();
        author.setAddresses(new ArrayList<Address>());
        Address adr = new Address();
        author.getAddresses().add(adr);
        Country country = new Country();
        adr.setCity("dark");
        adr.setCountry(country);

        Set<ConstraintViolation<Author>> 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());
    }
View Full Code Here

        CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class);
        Author author = new Author();
        author.setAddresses(new ArrayList<Address>());
        Address adr = new Address();
        author.getAddresses().add(adr);
        Country country = new Country();
        adr.setCity("dark");
        adr.setCountry(country);

        Set<ConstraintViolation<Author>> iv = v.validateProperty(author, propPath);
        Assert.assertEquals(1, iv.size());
View Full Code Here

        Object map = new HashMap<String, Address>() {
            {
                put("foo", adr);
            }
        };
        Country country = new Country();
        adr.setCity("dark");
        adr.setCountry(country);
        Set<ConstraintViolation<Object>> 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);
View Full Code Here

        CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class);
        final Address adr = new Address();
        Object map = new HashMap<String, Address>();
        ((Map<String, Address>) 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);
View Full Code Here

        Set<ConstraintViolation<Address[]>> 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);
View Full Code Here

        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);
View Full Code Here

        CascadingPropertyValidator v = validator.unwrap(CascadingPropertyValidator.class);
        Author author = new Author();
        author.setAddresses(new ArrayList<Address>());
        Address adr = new FooAddress();
        author.getAddresses().add(adr);
        Country country = new Country();
        adr.setCountry(country);

        Set<ConstraintViolation<Author>> iv = v.validateProperty(author, propPath, true, Default.class, Foo.class);
        Assert.assertEquals(1, iv.size());
    }
View Full Code Here

        assertDefaultBuilderAndFactory(builder);

        ValidatorFactory factory = builder.buildValidatorFactory();
        Validator validator = factory.getValidator();

        Customer customer = new Customer();
        customer.setFirstName("John");

        Set<ConstraintViolation<Customer>> ConstraintViolations = validator.validate(customer);
        Assert.assertFalse(ConstraintViolations.isEmpty());

        builder = Validation.byDefaultProvider().configure();
View Full Code Here

        super.setUp();
        validator = ApacheValidatorFactory.getDefault().getValidator();
    }

    public void testEmail() {
        Customer customer = new Customer();
        customer.setCustomerId("id-1");
        customer.setFirstName("Mary");
        customer.setLastName("Do");
        customer.setPassword("12345");

        Assert.assertEquals(0, validator.validate(customer).size());

        customer.setEmailAddress("some@invalid@address");
        Assert.assertEquals(1, validator.validate(customer).size());

        customer.setEmailAddress("some.valid-012345@address_at-test.org");
        Assert.assertEquals(0, validator.validate(customer).size());
    }
View Full Code Here

TOP

Related Classes of org.apache.bval.jsr303.example.Country

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.