Package org.apache.bval.jsr303.util

Examples of org.apache.bval.jsr303.util.PathImplTest


    /**
     * {@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

            PropertyAccess access = new PropertyAccess(rawType, token);
            if (access.isKnown()) {
                // add heretofore unknown, but valid, property on the fly:
                mp = Jsr303MetaBeanFactory.addMetaProperty(metaBean, access);
            } else {
                throw new UnknownPropertyException("unknown property '" + token + "' in " + metaBean.getId());
            }
        }
        validationContext.setMetaProperty(mp);
        setType(mp.getType());
    }
View Full Code Here

     */
    public void moveDownIfNecessary() {
        MetaProperty mp = validationContext.getMetaProperty();
        if (mp != null) {
            if (mp.getMetaBean() == null) {
                throw new UnknownPropertyException(String.format("Property %s.%s is not cascaded", mp
                    .getParentMetaBean().getId(), mp.getName()));
            }
            validationContext.moveDown(mp, new NullSafePropertyAccess(validationContext.getMetaBean().getBeanClass(),
                mp.getName()));
        }
View Full Code Here

    protected Validator createValidator() {
        return factory.getValidator();
    }

    public void testValidateList() {
        Author author = new Author();
        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");

        author.getAddresses().add(adr1);
        author.getAddresses().add(adr2);
        author.getAddresses().add(adr3);

        Set<ConstraintViolation<Author>> violations;

        violations = validator.validate(author);
        assertEquals(0, violations.size());
View Full Code Here

        Book book1, book2, book3;

        book1 = new Book();
        book1.setTitle("History of time");
        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();
        castro.setFirstName("Fidel");
        castro.setLastName("Castro Ruz");
        book2.setAuthor(castro);
        book2.setTitle("My life");

        book3 = new Book();
        book3.setTitle("World best jokes");
        Author someone = new Author();
        someone.setFirstName("John");
        someone.setLastName("Do");
        book3.setAuthor(someone);

        lib.getTaggedBooks().put("science", book1);
        lib.getTaggedBooks().put("politics", book2);
        lib.getTaggedBooks().put("humor", book3);
View Full Code Here

    public void testValidateMapAndRedefinedDefaultGroupOnNonRootBean() {
        Library lib = new Library();
        lib.setLibraryName("Leibnitz Bibliothek");

        Book book1, book2, book3;

        book1 = new Book();
        book1.setTitle("History of time");
        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();
        castro.setFirstName("Fidel");
        castro.setLastName("Castro Ruz");
        book2.setAuthor(castro);
        book2.setTitle("My life");

        book3 = new Book();
        book3.setTitle("World best jokes");
        Author someone = new Author();
        someone.setFirstName("John");
        someone.setLastName("Do");
        book3.setAuthor(someone);

        lib.getTaggedBooks().put("science", book1);
        lib.getTaggedBooks().put("politics", book2);
        lib.getTaggedBooks().put("humor", book3);

        Set<ConstraintViolation<Library>> violations;

        violations = validator.validate(lib);
        assertTrue(violations.isEmpty());

        book2.setTitle(null);
        book3.getAuthor().setFirstName(""); // violate NotEmpty validation
        book1.getAuthor().getAddresses().get(0).setCity(null);
        /*
         * This, by the way, tests redefined default group sequence behavior on
         * non-root-beans (Library.Book)!!
         */
        violations = validator.validate(lib);
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

TOP

Related Classes of org.apache.bval.jsr303.util.PathImplTest

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.