Search in sources :

Example 1 with ReservationManagement

use of org.baeldung.javaxval.methodvalidation.model.ReservationManagement 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 2 with ReservationManagement

use of org.baeldung.javaxval.methodvalidation.model.ReservationManagement 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)

Example 3 with ReservationManagement

use of org.baeldung.javaxval.methodvalidation.model.ReservationManagement 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());
}
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)

Example 4 with ReservationManagement

use of org.baeldung.javaxval.methodvalidation.model.ReservationManagement 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());
}
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 ReservationManagement

use of org.baeldung.javaxval.methodvalidation.model.ReservationManagement 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());
}
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

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