Package org.apache.bval.jsr303

Examples of org.apache.bval.jsr303.ConfigurationImpl


        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

        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

        super(name);
    }

    public void testEmail() {
        Validator validator = ApacheValidatorFactory.getDefault().getValidator();
        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

            //check composing constraints recursively
        }
    }

    public void testValidateComposed() {
        FrenchAddress adr = new FrenchAddress();
        Validator val = factory.getValidator();
        Set<ConstraintViolation<FrenchAddress>> findings = val.validate(adr);
        Assert.assertEquals(1, findings.size()); // with @ReportAsSingleConstraintViolation

        ConstraintViolation<FrenchAddress> finding = findings.iterator().next();
        Assert.assertEquals("Wrong zipcode", finding.getMessage());

        adr.setZipCode("1234567");
        findings = val.validate(adr);
        Assert.assertEquals(0, findings.size());

        adr.setZipCode("1234567234567");
        findings = val.validate(adr);
        Assert.assertTrue(findings.size() > 0); // too long
    }
View Full Code Here

        config.addProperty(VALIDATION_XML_PATH, "sample-validation.xml");
        return config.buildValidatorFactory();
    }

    public void testXmlEntitySample() {
        XmlEntitySampleBean bean = new XmlEntitySampleBean();
        bean.setFirstName("tooooooooooooooooooooooooooo long");
        bean.setValueCode("illegal");
        Validator validator = getFactory().getValidator();
        Set<ConstraintViolation<XmlEntitySampleBean>> results = validator.validate(bean);
        assertTrue(!results.isEmpty());
        assertTrue(results.size() == 3);

        bean.setZipCode("123");
        bean.setValueCode("20");
        bean.setFirstName("valid");
        results = validator.validate(bean);
        assertTrue(results.isEmpty());
    }
View Full Code Here

        MethodValidator mv = getValidator().unwrap(MethodValidator.class);
       
        Method personOp1 = service.getClass().getMethod("personOp1", new Class[]{Person.class});
       
        // Validate with invalid person
        Person p = new ExampleMethodService.Person();
        Set<?> results = mv.validateParameters(service.getClass(), personOp1, new Object[]{p});
        assertEquals("Expected 1 violation", 1, results.size());
       
        // validate with valid person
        p.name = "valid name";
View Full Code Here

        // Validate with null person
        Set<?> results = mv.validateParameters(service.getClass(), personOp2, new Object[]{null});
        assertEquals("Expected 1 violation", 1, results.size());
       
        // Validate with invalid person
        Person p = new ExampleMethodService.Person();
        results = mv.validateParameters(service.getClass(), personOp2, new Object[]{p});
        assertEquals("Expected 1 violation", 1, results.size());
       
        // validate with valid person
        p.name = "valid name";
View Full Code Here

TOP

Related Classes of org.apache.bval.jsr303.ConfigurationImpl

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.