Package org.apache.bval.jsr303.example

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


    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<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);
        Assert.assertEquals(0, iv2.size());
    }
View Full Code Here


    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<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);
        Assert.assertEquals(0, iv2.size());
    }
View Full Code Here

    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<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);
        Assert.assertEquals(0, iv2.size());
    }
View Full Code Here

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

        final String propPath = "addresses[0].country";

        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

        author.setFirstName("Peter");
        author.setLastName("Ford");
        author.setCompany("IBM");
        author.setAddresses(new ArrayList<Address>());

        Address adr1, adr2, adr3;
        adr1 = new Address();
        adr1.setCountry(new Country());
        adr1.getCountry().setName("Germany");
        adr1.setCity("Bonn");
        adr1.setAddressline1("Strasse 1");

        adr2 = new Address();
        adr2.setCountry(new Country());
        adr2.getCountry().setName("Cuba");
        adr2.setCity("Habana");
        adr2.setAddressline1("Calle 2");

        adr3 = new Address();
        adr3.setCountry(new Country());
        adr3.getCountry().setName("USA");
        adr3.setCity("San Francisco");
        adr3.setAddressline1("Street 3");
View Full Code Here

        book1.setSubtitle("How it really works");
        Author hawking = new Author();
        hawking.setFirstName("Stephen");
        hawking.setFirstName("Hawking");
        hawking.setAddresses(new ArrayList<Address>(1));
        Address adr = new Address();
        adr.setAddressline1("Street 1");
        adr.setCity("London");
        adr.setCountry(new Country());
        adr.getCountry().setName("England");
        hawking.getAddresses().add(adr);
        book1.setAuthor(hawking);

        book2 = new Book();
        Author castro = new Author();
View Full Code Here

        findings = val.validate(adr);
        Assert.assertTrue(findings.size() > 0); // too long
    }

    public void testOverridesAttributeConstraintIndex() {
        CompanyAddress adr = new CompanyAddress("invalid-string");
        Validator val = factory.getValidator();
        Set<ConstraintViolation<CompanyAddress>> findings = val.validate(adr);
        assertEquals(2, findings.size()); // without @ReportAsSingleConstraintViolation
        assertNotNull(TestUtils.getViolationWithMessage(findings, "Not COMPANY"));
        assertNotNull(TestUtils.getViolationWithMessage(findings, "Not an email"));

        adr =  new CompanyAddress("JOHN_DO@WEB.DE");
        findings = val.validate(adr);
        assertEquals(1, findings.size());
        assertNotNull(TestUtils.getViolationWithMessage(findings, "Not COMPANY"));

        adr =  new CompanyAddress("JOHN_DO@COMPANY.DE");
        findings = val.validate(adr);
        Assert.assertTrue(findings.isEmpty());
    }
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.Address

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.