Package javax.validation

Examples of javax.validation.Validator.validate()


      localesMap.put(clientLocale.toString(), interpolator);
    }

    Validator validator = factory.usingContext().messageInterpolator(interpolator).getValidator();
   
    Set<ConstraintViolation<ActionSupport>> constraintViolations = validator.validate(actionAs);
   
    List<Path> invalidFieldNames = new ArrayList<Path>();
    Map parameters = ActionContext.getContext().getParameters();
    for (ConstraintViolation<ActionSupport> constrantViolation : constraintViolations) {
      Path fieldPath = constrantViolation.getPropertyPath();
View Full Code Here


    public void testValidateMultiValuedConstraints() {
        Validator validator = getValidator();
        Engine engine = new Engine();
        engine.serialNumber = "abcd-defg-0123";
        Set<ConstraintViolation<Engine>> violations;
        violations = validator.validate(engine);
        assertEquals(0, violations.size());

        engine.serialNumber = "!)/(/()";
        violations = validator.validate(engine);
        assertEquals(2, violations.size());
View Full Code Here

        Set<ConstraintViolation<Engine>> violations;
        violations = validator.validate(engine);
        assertEquals(0, violations.size());

        engine.serialNumber = "!)/(/()";
        violations = validator.validate(engine);
        assertEquals(2, violations.size());
        for (String msg : new String[]{"must contain alphabetical characters only",
              "must match ....-....-...."}) {
            assertNotNull(TestUtils.getViolationWithMessage(violations, msg));
        }
View Full Code Here

        entity.setText("101");
        entity.setProperty("201");
        entity.setLongValue(301);
        entity.setDecimalValue(new BigDecimal(401));
        Validator validator = getValidator();
        Set<ConstraintViolation<MaxTestEntity>> violations = validator.validate(entity);
        assertEquals(4, violations.size());

        NoValidatorTestEntity entity2 = new NoValidatorTestEntity();
        try {
            validator.validate(entity2);
View Full Code Here

        Set<ConstraintViolation<MaxTestEntity>> violations = validator.validate(entity);
        assertEquals(4, violations.size());

        NoValidatorTestEntity entity2 = new NoValidatorTestEntity();
        try {
            validator.validate(entity2);
            fail("UnexpectedTypeException expected but not thrown");
        } catch (UnexpectedTypeException ex) {
            // we expected this
            assertEquals("No validator could be found for type java.lang.Object. " +
                  "See: @Max at private java.lang.Object " +
View Full Code Here

     * only available validator is associated with a different annotation type.
     */
    public void testInvalidValidator() {
        Validator validator = getValidator();
        try {
            validator.validate(new Person());
            fail("No exception thrown, but no valid validator available.");
        } catch (ConstraintDefinitionException e) {
            // correct
        }
    }
View Full Code Here

        Book book = new Book();
        book.setTitle("");
        book.setAuthor(author);

        Set<ConstraintViolation<Book>> constraintViolations =
              validator.validate(book, First.class, Second.class, Last.class);
        assertEquals("Wrong number of constraints", 3, constraintViolations.size());
        assertNotNull(TestUtils.getViolation(constraintViolations, "title"));
        assertNotNull(TestUtils.getViolation(constraintViolations, "author.firstName"));
        assertNotNull(TestUtils.getViolation(constraintViolations, "author.lastName"));
View Full Code Here

        assertNotNull(TestUtils.getViolation(constraintViolations, "author.lastName"));

        author.setFirstName("Gavin");
        author.setLastName("King");

        constraintViolations = validator.validate(book, First.class, Second.class, Last.class);
        ConstraintViolation constraintViolation = constraintViolations.iterator().next();
        assertEquals(1, constraintViolations.size());
        assertEquals("may not be empty", constraintViolation.getMessage());
        assertEquals(book, constraintViolation.getRootBean());
        assertEquals(book.getTitle(), constraintViolation.getInvalidValue());
View Full Code Here

        assertEquals("title", constraintViolation.getPropertyPath().toString());

        book.setTitle("My fault");
        book.setSubtitle("confessions of a president - a book for a nice price");

        constraintViolations = validator.validate(book, First.class, Second.class, Last.class);
        assertEquals(1, constraintViolations.size());
        constraintViolation = constraintViolations.iterator().next();
        assertEquals("size must be between 0 and 30", constraintViolation.getMessage());
        assertEquals(book, constraintViolation.getRootBean());
        assertEquals(book.getSubtitle(), constraintViolation.getInvalidValue());
View Full Code Here

        assertEquals("subtitle", constraintViolation.getPropertyPath().toString());

        book.setSubtitle("Capitalism in crisis");
        author.setCompany("1234567890ß9876543212578909876542245678987432");

        constraintViolations = validator.validate(book);
        constraintViolation = constraintViolations.iterator().next();
        assertEquals(1, constraintViolations.size());
        assertEquals("size must be between 0 and 40", constraintViolation.getMessage());
        assertEquals(book, constraintViolation.getRootBean());
        assertEquals(author.getCompany(), constraintViolation.getInvalidValue());
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.