Package de.huepattl.playground.validation

Examples of de.huepattl.playground.validation.Employee


        if (value == null) {
            return true;
        }

        if (value instanceof Employee) {
            Employee bean = (Employee) value;
            if (bean.getLastName() != null
                    && bean.getLastName().equalsIgnoreCase(bean.getFirstName())) {
                // TODO/FIXME: Wee need to specify different error messages if we have more checks here...
                LOG.info("Oops, equal values for stringProperty and stringProperty2: " + bean.getLastName());
                return false;
            }
        } else {
            throw new IllegalArgumentException(
                    "Sorry, I do not know how to validate objects of type "
View Full Code Here


    public void testNoErrors() throws Exception {

        /*
         * Set up correct bean.
         */
        Employee employee = super.newValidBean();

        /*
         * Validate and report.
         */
        SimpleConstraintValidator defaultValidator = new SimpleConstraintValidator();
View Full Code Here

    public void testFailAll() throws Exception {

        /*
         * Set up incorrect bean.
         */
        Employee employee = new Employee();
        {
            // Expecting: true.
            employee.setActive(false);

            // Expecting: Value between 1 and 100, including.
            employee.setId(101);

            // Expecting: Date in the past, not null.
            employee.setDateOfBirth(Date.valueOf(LocalDate.of(9999, Month.DECEMBER, 31)));

            // Expecting: Any string between 3 and 50 characters, not null.
            employee.setLastName("Only1234andChars... ooops!");

            // Expecting: String only consisting of letters and numbers but no special chars, blanks; not null.
            employee.setFirstName("Only1234andChars... ooops!");

            // Expecting: Between 1..100, no more than 3 digits and 2 fractions, not null.
            employee.setSalary(new BigDecimal("2334.0000001"));

            // Expecting: Any string with the number 3...
            employee.setCheckedByCustomAnnotation("A string with another number: 2 (not three)");
        }

        /*
         * Validate and report.
         */
 
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

     * @throws Exception BAM!
     * @see de.huepattl.playground.validation.Severity
     */
    @Test
    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);

View Full Code Here

TOP

Related Classes of de.huepattl.playground.validation.Employee

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.