Package javax.validation

Examples of javax.validation.Validator.validate()


     */
    public void testValidationStopsWhenFailuresOnGroup() {
        Validator validator = getValidator();
       
        // Validate Dummy with its redefined Default group
        Set<ConstraintViolation<Dummy>> violations = validator.validate(new Dummy());
        assertEquals("Only 1 violation expected", 1, violations.size());
        ConstraintViolation<Dummy> violation = violations.iterator().next();
        assertEquals("Group1 should be evaluated first", "field1", violation.getPropertyPath().toString());
    }
   
View Full Code Here


        AccessTestBusinessObject o1 = new AccessTestBusinessObject("1");
        AccessTestBusinessObject o2 = new AccessTestBusinessObject("2");
        o1.next(o2);
        Validator validator = getValidator();
        Set<ConstraintViolation<AccessTestBusinessObject>> errors =
              validator.validate(o1);
        // assert, that field access 'next' is used and not getNext() is called!!!
        assertEquals(1, errors.size());
        o2 = new AccessTestBusinessObject("1");
        o1.next(o2);
        errors = validator.validate(o1);
View Full Code Here

              validator.validate(o1);
        // assert, that field access 'next' is used and not getNext() is called!!!
        assertEquals(1, errors.size());
        o2 = new AccessTestBusinessObject("1");
        o1.next(o2);
        errors = validator.validate(o1);
        assertEquals(0, errors.size());

        // assert that toBeIgnored not validated, because not annotated with @Valid
        o1.setToBeIgnored(new AccessTestBusinessObject("99"));
        errors = validator.validate(o1);
View Full Code Here

        errors = validator.validate(o1);
        assertEquals(0, errors.size());

        // assert that toBeIgnored not validated, because not annotated with @Valid
        o1.setToBeIgnored(new AccessTestBusinessObject("99"));
        errors = validator.validate(o1);
        assertEquals(0, errors.size());

        o1.setNext(new AccessTestBusinessObject("99"));
        errors = validator.validate(o1);
        assertEquals(1, errors.size());
View Full Code Here

        o1.setToBeIgnored(new AccessTestBusinessObject("99"));
        errors = validator.validate(o1);
        assertEquals(0, errors.size());

        o1.setNext(new AccessTestBusinessObject("99"));
        errors = validator.validate(o1);
        assertEquals(1, errors.size());
    }

    public void testBook() {
        Validator validator = getValidator();
View Full Code Here

        Book book = new Book();
        book.setAuthor(author);
        book.setSubtitle("12345678900125678901234578901234567890");

        // NotEmpty failure on the title field
        Set<ConstraintViolation<Book>> errors = validator.validate(book, Book.All.class);
        Assert.assertTrue(!errors.isEmpty());

        book.setTitle("Les fleurs du mal");
        author.setCompany("Some random publisher with a very very very long name");
View Full Code Here

        a.setFirstName("Karl");
        a.setLastName("May");

        Validator v = getValidator();
        Set found = v.validate(a, Default.class, First.class, Last.class);
        Assert.assertTrue(!found.isEmpty());
        Assert.assertEquals(4, found.size());

        adr.setCity("Berlin");
        adr.setZipCode("12345");
View Full Code Here

        Assert.assertEquals(4, found.size());

        adr.setCity("Berlin");
        adr.setZipCode("12345");
        adr.setCompany("apache");
        found = v.validate(a, Default.class, First.class, Last.class);
        Assert.assertEquals(1, found.size());
        ConstraintViolation ic = (ConstraintViolation) found.iterator().next();
        Assert.assertEquals("addresses[0].country.name", ic.getPropertyPath().toString());
    }
View Full Code Here

        Book book = new Book();
        book.setTitle("");
        book.setAuthor(author);
        boolean foundTitleConstraint = false;
        Set<ConstraintViolation<Book>> constraintViolations =
              validator.validate(book, Book.All.class);
        assertEquals(1, constraintViolations.size());
        //assuming an english locale, the interpolated message is returned
        for (ConstraintViolation constraintViolation : constraintViolations) {
            if (constraintViolation.getRootBean().getClass() == Book.class) {
                Assert.assertEquals(
View Full Code Here

        ad.setZipCode("error");
        ad.setAddressline1("something");
        ad.setCountry(new Country());
        ad.getCountry().setName("something");
        Validator v = getValidator();
        Set<ConstraintViolation<Address>> violations = v.validate(ad);
        Assert.assertEquals(2, violations.size());
        for (ConstraintViolation each : violations) {
            Assert.assertTrue(each.getMessage().endsWith(" not OK"));
        }
        assertNotNull(TestUtils.getViolation(violations, "city"));
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.