Package de.huepattl.playground.validation.validator

Examples of de.huepattl.playground.validation.validator.SimpleConstraintValidator


        Employee employee = super.newValidBean();

        /*
         * Validate and report.
         */
        SimpleConstraintValidator defaultValidator = new SimpleConstraintValidator();
        Set<ConstraintViolation<Object>> validationResult = defaultValidator.validate(employee);

        super.printValidationMessages(validationResult);
        assertTrue(validationResult.isEmpty());
    }
View Full Code Here


        }

        /*
         * Validate and report.
         */
        SimpleConstraintValidator defaultValidator = new SimpleConstraintValidator();
        Set<ConstraintViolation<Object>> validationResult = defaultValidator.validate(employee);

        super.printValidationMessages(validationResult);
        assertFalse(validationResult.isEmpty());
    }
View Full Code Here

     * @throws Exception BAM!
     */
    @Test
    public void testGroups() throws Exception {
        Employee employee = super.newValidBean();
        SimpleConstraintValidator defaultValidator = new SimpleConstraintValidator();
        Set<ConstraintViolation<Object>> validationResult;

        /*
         * Validate with implicit default group.
         * Expecting NotNull to raise error.
         */
        employee.setStricterValueThanOthers(null);
        validationResult = defaultValidator.validate(employee);
        super.printValidationMessages(validationResult);
        assertTrue(validationResult.size() == 1);

        /*
         * Validate with implicit default group.
         * Expecting no issue because value is not null. However, the value is too short but will not be thrown
         * because that constraint is only active for the StricterValidationGroup, which is not active here.
         */
        employee.setStricterValueThanOthers("A");
        validationResult = defaultValidator.validate(employee);
        super.printValidationMessages(validationResult);
        assertTrue(validationResult.isEmpty());

        /*
         * Validate with explicit default StricterValidationGroup group.
         * Expecting error because value is too short.
         */
        employee.setStricterValueThanOthers("A");
        validationResult = defaultValidator.validate(employee, StricterValidationGroup.class);
        super.printValidationMessages(validationResult);
        assertTrue(validationResult.size() == 1);

        /*
         *  Validate with explicit default StricterValidationGroup group.
         *  Expecting no error because value os long enough.
         */
        employee.setStricterValueThanOthers("ABC");
        validationResult = defaultValidator.validate(employee, StricterValidationGroup.class);
        super.printValidationMessages(validationResult);
        assertTrue(validationResult.isEmpty());

        /*
         * Validate with explicit default StricterValidationGroup group.
         * Expecting NotNull NOT to fire because it is in the default group
         * and thus does not apply.
         */
        employee.setStricterValueThanOthers(null); //notnull does not apply!
        validationResult = defaultValidator.validate(employee, StricterValidationGroup.class);
        super.printValidationMessages(validationResult);
        assertTrue(validationResult.isEmpty());

        /*
         * Validate with default and StricterValidationGroup groups.
         * Expecintg NotNull to apply because we now took the default group back into the game.
         */
        employee.setStricterValueThanOthers(null); //notnull does not apply!
        validationResult = defaultValidator.validate(employee, Default.class, StricterValidationGroup.class);
        super.printValidationMessages(validationResult);
        assertTrue(validationResult.size() == 1);
    }
View Full Code Here

    public void testSeverity() throws Exception {
        Employee employee = super.newValidBean();
        employee.setUsingSeverity("A"); // too short
        boolean foundWarning = false;

        SimpleConstraintValidator defaultValidator = new SimpleConstraintValidator();
        Set<ConstraintViolation<Object>> validationResult = defaultValidator.validate(employee);

        for (final ConstraintViolation cv : validationResult) {
            foundWarning = cv.getConstraintDescriptor().getPayload().contains(Severity.WARNING.class);
        }
View Full Code Here

TOP

Related Classes of de.huepattl.playground.validation.validator.SimpleConstraintValidator

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.