Search in sources :

Example 6 with Reservation

use of org.baeldung.javaxval.methodvalidation.model.Reservation 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());
}
Also used : Reservation(org.baeldung.javaxval.methodvalidation.model.Reservation) Customer(org.baeldung.javaxval.methodvalidation.model.Customer) ConstraintViolation(javax.validation.ConstraintViolation) Test(org.junit.Test)

Example 7 with Reservation

use of org.baeldung.javaxval.methodvalidation.model.Reservation 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);
}
Also used : Reservation(org.baeldung.javaxval.methodvalidation.model.Reservation) Customer(org.baeldung.javaxval.methodvalidation.model.Customer) Test(org.junit.Test)

Example 8 with Reservation

use of org.baeldung.javaxval.methodvalidation.model.Reservation in project tutorials by eugenp.

the class ValidationIntegrationTest method whenValidationWithValidConstructorReturnValue_thenZeroVoilations.

@Test
public void whenValidationWithValidConstructorReturnValue_thenZeroVoilations() throws NoSuchMethodException {
    Constructor<Reservation> constructor = Reservation.class.getConstructor(LocalDate.class, LocalDate.class, Customer.class, int.class);
    Reservation createdObject = new Reservation(LocalDate.now().plusDays(1), LocalDate.now().plusDays(2), new Customer("William", "Smith"), 1);
    Set<ConstraintViolation<Reservation>> violations = executableValidator.validateConstructorReturnValue(constructor, createdObject);
    assertEquals(0, violations.size());
}
Also used : Reservation(org.baeldung.javaxval.methodvalidation.model.Reservation) Customer(org.baeldung.javaxval.methodvalidation.model.Customer) ConstraintViolation(javax.validation.ConstraintViolation) Test(org.junit.Test)

Aggregations

Customer (org.baeldung.javaxval.methodvalidation.model.Customer)8 Reservation (org.baeldung.javaxval.methodvalidation.model.Reservation)8 Test (org.junit.Test)8 ConstraintViolation (javax.validation.ConstraintViolation)6 Method (java.lang.reflect.Method)2 ReservationManagement (org.baeldung.javaxval.methodvalidation.model.ReservationManagement)2