Search in sources :

Example 1 with Customer

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

the class ContainerValidationIntegrationTest method whenValidationWithValidCascadedValue_thenCNoException.

@Test
public void whenValidationWithValidCascadedValue_thenCNoException() {
    Customer customer = new Customer();
    customer.setFirstName("William");
    customer.setLastName("Smith");
    Reservation reservation = new Reservation(LocalDate.now().plusDays(1), LocalDate.now().plusDays(2), customer, 1);
    reservationManagement.createReservation(reservation);
}
Also used : Reservation(org.baeldung.javaxval.methodvalidation.model.Reservation) Customer(org.baeldung.javaxval.methodvalidation.model.Customer) Test(org.junit.Test)

Example 2 with Customer

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

the class ValidationIntegrationTest method whenCrossParameterValidationWithValidConstructorParameters_thenZeroVoilations.

@Test
public void whenCrossParameterValidationWithValidConstructorParameters_thenZeroVoilations() throws NoSuchMethodException {
    Constructor<Reservation> constructor = Reservation.class.getConstructor(LocalDate.class, LocalDate.class, Customer.class, int.class);
    Object[] parameterValues = { LocalDate.now().plusDays(1), LocalDate.now().plusDays(2), new Customer("William", "Smith"), 1 };
    Set<ConstraintViolation<Reservation>> violations = executableValidator.validateConstructorParameters(constructor, parameterValues);
    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)

Example 3 with Customer

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

the class ValidationIntegrationTest method whenValidationWithInvalidConstructorReturnValue_thenCorrectNumberOfVoilations.

@Test
public void whenValidationWithInvalidConstructorReturnValue_thenCorrectNumberOfVoilations() throws NoSuchMethodException {
    Constructor<Reservation> constructor = Reservation.class.getConstructor(LocalDate.class, LocalDate.class, Customer.class, int.class);
    Reservation createdObject = new Reservation(LocalDate.now(), LocalDate.now(), new Customer("William", "Smith"), 0);
    Set<ConstraintViolation<Reservation>> violations = executableValidator.validateConstructorReturnValue(constructor, createdObject);
    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 4 with Customer

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

the class ValidationIntegrationTest method whenValidationWithValidCascadedValue_thenCorrectNumberOfVoilations.

@Test
public void whenValidationWithValidCascadedValue_thenCorrectNumberOfVoilations() throws NoSuchMethodException {
    ReservationManagement object = new ReservationManagement();
    Method method = ReservationManagement.class.getMethod("createReservation", Reservation.class);
    Customer customer = new Customer();
    customer.setFirstName("William");
    customer.setLastName("Smith");
    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(0, violations.size());
}
Also used : Reservation(org.baeldung.javaxval.methodvalidation.model.Reservation) Customer(org.baeldung.javaxval.methodvalidation.model.Customer) ConstraintViolation(javax.validation.ConstraintViolation) ReservationManagement(org.baeldung.javaxval.methodvalidation.model.ReservationManagement) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 5 with Customer

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

the class ValidationIntegrationTest method whenValidationWithValidMethodParameters_thenZeroVoilations.

@Test
public void whenValidationWithValidMethodParameters_thenZeroVoilations() throws NoSuchMethodException {
    ReservationManagement object = new ReservationManagement();
    Method method = ReservationManagement.class.getMethod("createReservation", LocalDate.class, int.class, Customer.class);
    Object[] parameterValues = { LocalDate.now().plusDays(1), 1, new Customer("John", "Doe") };
    Set<ConstraintViolation<ReservationManagement>> violations = executableValidator.validateParameters(object, method, parameterValues);
    assertEquals(0, violations.size());
}
Also used : Customer(org.baeldung.javaxval.methodvalidation.model.Customer) ConstraintViolation(javax.validation.ConstraintViolation) ReservationManagement(org.baeldung.javaxval.methodvalidation.model.ReservationManagement) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

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