Package javax.validation

Examples of javax.validation.Validator.validate()


        emp.setEmpId("M1234");
        emp.setFirstName("MADHUMITA");
        emp.setLastName("SADHUKHAN");
        emp.setEmail("madhu@redhat.com");

        Set<ConstraintViolation<Employee>> constraintViolations = validator.validate(emp);
        assertEquals("Wrong number of constraints", constraintViolations.size(), 1);
        assertEquals("Created by default factory", constraintViolations.iterator().next().getMessage());

        // get a new factory using a custom configuration
        configuration.constraintValidatorFactory(new CustomConstraintValidatorFactory(configuration
View Full Code Here


        configuration.constraintValidatorFactory(new CustomConstraintValidatorFactory(configuration
                .getDefaultConstraintValidatorFactory()));

        factory = configuration.buildValidatorFactory();
        validator = factory.getValidator();
        constraintViolations = validator.validate(emp);
        assertEquals("Wrong number of constraints", constraintViolations.size(), 1);
        assertEquals("Created by custom factory", constraintViolations.iterator().next().getMessage());
    }

    /**
 
View Full Code Here

        emp.setFirstName("Joe");
        emp.setLastName("Cocker");
        emp.setEmail("none@jboss.org");
        emp.setWebsite("<script> Cross-site scripting http://en.wikipedia.org/wiki/Joe_Cocker <script/>.");

        Set<ConstraintViolation<Employee>> constraintViolations = validator.validate(emp);
        assertEquals("Wrong number of constraints", constraintViolations.size(), 1);
    }

    /**
     * A custom constraint validator factory.
View Full Code Here

        // Create a Car
        Car car = new Car("CET5678", passengers);
        car.setModel("SKODA Octavia");

        // validate Car with default group as per GroupSequenceProvider
        Set<ConstraintViolation<Car>> result = validator.validate(car);
        assertEquals(1, result.size());
        assertEquals("The Car has to pass the fuel test and inspection test before being driven", result.iterator().next()
                .getMessage());

        Driver driver = new Driver("Sebastian", "Vettel");
View Full Code Here

        Driver driver = new Driver("Sebastian", "Vettel");
        driver.setAge(25);
        driver.setAddress("ABC");

        result = validator.validate(car);
        assertEquals(1, result.size());
        assertEquals("The Car has to pass the fuel test and inspection test before being driven", result.iterator().next()
                .getMessage());
        car.setPassedVehicleInspection(true);
View Full Code Here

        assertEquals(1, result.size());
        assertEquals("The Car has to pass the fuel test and inspection test before being driven", result.iterator().next()
                .getMessage());
        car.setPassedVehicleInspection(true);

        result = validator.validate(car);
        // New group set in defaultsequence for Car as per CarGroupSequenceProvider should be implemented now
        assertEquals(2, result.size());

        car.setDriver(driver);
        // implementing validation for group associated with associated objects of Car(in this case Driver)
View Full Code Here

        // New group set in defaultsequence for Car as per CarGroupSequenceProvider should be implemented now
        assertEquals(2, result.size());

        car.setDriver(driver);
        // implementing validation for group associated with associated objects of Car(in this case Driver)
        Set<ConstraintViolation<Car>> driverResult = validator.validate(car, DriverChecks.class);
        assertEquals(1, driverResult.size());
        driver.setHasValidDrivingLicense(true);
        assertEquals(0, validator.validate(car, DriverChecks.class).size());

        car.setSeats(5);
View Full Code Here

        car.setDriver(driver);
        // implementing validation for group associated with associated objects of Car(in this case Driver)
        Set<ConstraintViolation<Car>> driverResult = validator.validate(car, DriverChecks.class);
        assertEquals(1, driverResult.size());
        driver.setHasValidDrivingLicense(true);
        assertEquals(0, validator.validate(car, DriverChecks.class).size());

        car.setSeats(5);
        car.setHasBeenPaid(true);

        assertEquals(0, validator.validate(car).size());
View Full Code Here

        assertEquals(0, validator.validate(car, DriverChecks.class).size());

        car.setSeats(5);
        car.setHasBeenPaid(true);

        assertEquals(0, validator.validate(car).size());

    }
}
View Full Code Here

        // create employee
        Employee emp = new Employee();
        emp.setEmail("MADHUMITA");

        Set<ConstraintViolation<Employee>> constraintViolations = validator.validate(emp);

        assertEquals("Wrong number of constraints", constraintViolations.size(), 1);
        assertEquals(CustomMessageInterpolator.MESSAGE, constraintViolations.iterator().next().getMessage());
    }
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.