use of org.baeldung.javaxval.methodvalidation.model.Customer in project tutorials by eugenp.
the class ValidationIntegrationTest method whenValidationWithValidReturnValue_thenZeroVoilations.
@Test
public void whenValidationWithValidReturnValue_thenZeroVoilations() throws NoSuchMethodException {
ReservationManagement object = new ReservationManagement();
Method method = ReservationManagement.class.getMethod("getAllCustomers");
Object returnValue = Collections.singletonList(new Customer("William", "Smith"));
Set<ConstraintViolation<ReservationManagement>> violations = executableValidator.validateReturnValue(object, method, returnValue);
assertEquals(0, violations.size());
}
use of org.baeldung.javaxval.methodvalidation.model.Customer in project tutorials by eugenp.
the class ValidationIntegrationTest method whenValidationWithInvalidCascadedValue_thenCorrectNumberOfVoilations.
@Test
public void whenValidationWithInvalidCascadedValue_thenCorrectNumberOfVoilations() throws NoSuchMethodException {
ReservationManagement object = new ReservationManagement();
Method method = ReservationManagement.class.getMethod("createReservation", Reservation.class);
Customer customer = new Customer();
customer.setFirstName("John");
customer.setLastName("Doe");
Reservation reservation = new Reservation(LocalDate.now().plusDays(1), LocalDate.now().plusDays(2), customer, 1);
Object[] parameterValues = { reservation };
Set<ConstraintViolation<ReservationManagement>> violations = executableValidator.validateParameters(object, method, parameterValues);
assertEquals(2, violations.size());
}
use of org.baeldung.javaxval.methodvalidation.model.Customer in project tutorials by eugenp.
the class ValidationIntegrationTest method whenCrossParameterValidationWithInvalidConstructorParameters_thenCorrectNumberOfVoilations.
@Test
public void whenCrossParameterValidationWithInvalidConstructorParameters_thenCorrectNumberOfVoilations() throws NoSuchMethodException {
Constructor<Reservation> constructor = Reservation.class.getConstructor(LocalDate.class, LocalDate.class, Customer.class, int.class);
Object[] parameterValues = { LocalDate.now(), LocalDate.now(), new Customer("William", "Smith"), 1 };
Set<ConstraintViolation<Reservation>> violations = executableValidator.validateConstructorParameters(constructor, parameterValues);
assertEquals(1, violations.size());
}
use of org.baeldung.javaxval.methodvalidation.model.Customer in project tutorials by eugenp.
the class ContainerValidationIntegrationTest method whenValidationWithInvalidCascadedValue_thenConstraintViolationException.
@Test
public void whenValidationWithInvalidCascadedValue_thenConstraintViolationException() {
Customer customer = new Customer();
customer.setFirstName("John");
customer.setLastName("Doe");
Reservation reservation = new Reservation(LocalDate.now().plusDays(1), LocalDate.now().plusDays(2), customer, 1);
exception.expect(ConstraintViolationException.class);
reservationManagement.createReservation(reservation);
}
use of org.baeldung.javaxval.methodvalidation.model.Customer in project tutorials by eugenp.
the class ValidationIntegrationTest method whenCrossParameterValidationWithInvalidParameters_thenCorrectNumberOfVoilations.
@Test
public void whenCrossParameterValidationWithInvalidParameters_thenCorrectNumberOfVoilations() throws NoSuchMethodException {
ReservationManagement object = new ReservationManagement();
Method method = ReservationManagement.class.getMethod("createReservation", LocalDate.class, LocalDate.class, Customer.class);
Object[] parameterValues = { LocalDate.now(), LocalDate.now(), new Customer("John", "Doe") };
Set<ConstraintViolation<ReservationManagement>> violations = executableValidator.validateParameters(object, method, parameterValues);
assertEquals(1, violations.size());
}
Aggregations