Package org.apache.bval.jsr303.example

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


    /**
     * {@inheritDoc}
     */
    public ConfigurationState get()
    {
        ConfigurationImpl configuration = new ConfigurationImpl( bootstrapState, validationProvider );
        configuration.traversableResolver( traversableResolver );
        configuration.messageInterpolator( messageInterpolator );
        configuration.constraintValidatorFactory( constraintValidatorFactory );
        return configuration;
    }
View Full Code Here


                }
                // Apply the configuration
                // TODO: Ideally this processing should happen in BVal code. But, the ValidationParser loads the validation xml and
                //       mapping files using the classloader and these files are not always available through the classloader in case
                //       of Java EE (for e.g., WEB-INF/validation.xml)
                ConfigurationImpl config = (ConfigurationImpl) Validation.byDefaultProvider().configure();
                applyConfig(validationConfigType, config);
                config.ignoreXmlConfiguration();
                // Create the factory instance
                ClassLoader oldContextLoader = Thread.currentThread().getContextClassLoader();
                try {
                    Thread.currentThread().setContextClassLoader(classLoader);
                    factory = config.buildValidatorFactory();
                } finally {
                    Thread.currentThread().setContextClassLoader(oldContextLoader);
                }
                if(tmpArchiveFile != null) {
                    tmpArchiveFile.delete();
View Full Code Here

    @Override
    protected void setUp() throws Exception {
        SystemInstance.reset();

        try { // hack for buildbot
            new ConfigurationImpl(null, null);
        } catch (final ValidationException ve) {
            // no-op
        }
    }
View Full Code Here

            try {
                Integer index = token == null ? null : Integer.valueOf(token);
                access = new IndexedAccess(type, index);
                validationContext.setCurrentIndex(index);
            } catch (NumberFormatException e) {
                throw new UnknownPropertyException(String.format("Cannot parse %s as an array/iterable index", token),
                    e);
            }
        } else if (KeyedAccess.getJavaElementType(type) != null) {
            access = new KeyedAccess(type, token);
            validationContext.setCurrentKey(token);
        } else {
            throw new UnknownPropertyException(String.format("Cannot determine index/key type for %s", type));
        }
        Object value = validationContext.getBean();
        Object child = value == null ? null : access.get(value);
        setType(child == null ? access.getJavaType() : child.getClass());
        validationContext.setBean(child,
View Full Code Here

    }

    public void testPropertyPathWithIndex() {
        Author a = new Author();
        a.setAddresses(new ArrayList<Address>());
        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<ConstraintViolation<Author>> constraints = validator.validate(a);
        Assert.assertTrue(!constraints.isEmpty());
View Full Code Here

     * 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<ConstraintViolation<Address>> violations = validator.validate(ad);
        Assert.assertEquals(2, violations.size());
        for (ConstraintViolation<Address> each : violations) {
            Assert.assertTrue(each.getMessage().endsWith(" not OK"));
        }
View Full Code Here

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

        Author author = new Author();
        author.setAddresses(new ArrayList<Address>());
        Address adr = new Address();
        author.getAddresses().add(adr);
        Country country = new Country();
        adr.setCountry(country);
        country.setISO2Code("too_long");

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

        final String propPath = "addresses[0]";

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

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

        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());

        iv = v.validateProperty(author, propPath, true);
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.