Package org.apache.bval.jsr303.example

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


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

        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

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

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

     */
    public void testValidAnnotation() {
        Author a = new Author();
        a.setAddresses(new ArrayList<Address>());
        BusinessAddress adr = new BusinessAddress();
        adr.setCountry(new Country());
        adr.setAddressline1("line1");
        adr.setAddressline2("line2");

        adr.setZipCode("1234567890123456789");
        a.getAddresses().add(adr);
View Full Code Here

     * 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<ConstraintViolation<Continent>> constraints = validator.validate(c);
        Assert.assertEquals("Incorrect number of violations detected", 1, constraints.size());
        assertPropertyPath("countries[].name", constraints);
View Full Code Here

    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

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