use of org.hibernate.validator.test.internal.engine.methodvalidation.model.Customer in project hibernate-validator by hibernate.
the class AbstractConstructorValidationTest method cascadedConstructorParameterValidationYieldsConstraintViolation.
@Test
public void cascadedConstructorParameterValidationYieldsConstraintViolation() throws Exception {
Set<ConstraintViolation<CustomerRepositoryImpl>> violations = executableValidator.validateConstructorParameters(CustomerRepositoryImpl.class.getConstructor(Customer.class), new Customer[] { new Customer(null) });
assertThat(violations).containsOnlyViolations(violationOf(NotNull.class).withMessage(messagePrefix() + "must not be null").withInvalidValue(null).withRootBeanClass(CustomerRepositoryImpl.class).withPropertyPath(pathWith().constructor(CustomerRepositoryImpl.class).parameter("customer", 0).property("name")));
}
use of org.hibernate.validator.test.internal.engine.methodvalidation.model.Customer in project hibernate-validator by hibernate.
the class AbstractMethodValidationTest method cascadingMapReturnValue.
@Test
public void cascadingMapReturnValue() {
try {
customerRepositoryValidatingProxy.cascadingMapReturnValue();
fail("Expected ConstraintViolationException wasn't thrown.");
} catch (ConstraintViolationException e) {
Customer customer = new Customer(null);
Map<String, Customer> expectedReturnValue = newHashMap();
expectedReturnValue.put("Bob", customer);
assertThat(e.getConstraintViolations()).containsOnlyViolations(violationOf(NotNull.class).withPropertyPath(pathWith().method("cascadingMapReturnValue").returnValue().property("name", true, "Bob", null, Map.class, 1)).withMessage(messagePrefix() + "must not be null").withRootBeanClass(CustomerRepositoryImpl.class).withInvalidValue(null));
ConstraintViolation<?> constraintViolation = e.getConstraintViolations().iterator().next();
assertEquals(constraintViolation.getMessage(), messagePrefix() + "must not be null");
assertMethod(constraintViolation, "cascadingMapReturnValue");
assertMethodValidationType(constraintViolation, ElementKind.RETURN_VALUE);
assertEquals(constraintViolation.getPropertyPath().toString(), "cascadingMapReturnValue.<return value>[Bob].name");
assertEquals(constraintViolation.getRootBeanClass(), CustomerRepositoryImpl.class);
assertEquals(constraintViolation.getRootBean(), customerRepositoryOriginalBean);
assertEquals(constraintViolation.getLeafBean(), customer);
assertEquals(constraintViolation.getInvalidValue(), null);
assertEquals(constraintViolation.getExecutableParameters(), null);
assertEquals(constraintViolation.getExecutableReturnValue(), expectedReturnValue);
}
}
use of org.hibernate.validator.test.internal.engine.methodvalidation.model.Customer in project hibernate-validator by hibernate.
the class AbstractMethodValidationTest method cascadingArrayParameter.
// HV-1428 Container element support is disabled for arrays
@Test(enabled = false)
public void cascadingArrayParameter() {
Customer customer = new Customer(null);
try {
customerRepositoryValidatingProxy.cascadingArrayParameter(null, customer);
fail("Expected ConstraintViolationException wasn't thrown.");
} catch (ConstraintViolationException e) {
assertThat(e.getConstraintViolations()).containsOnlyViolations(violationOf(NotNull.class).withPropertyPath(pathWith().method("cascadingArrayParameter").parameter("customer", 0).property("name", true, null, 1, Object[].class, null)).withMessage(messagePrefix() + "must not be null").withRootBeanClass(CustomerRepositoryImpl.class).withInvalidValue(null));
ConstraintViolation<?> constraintViolation = e.getConstraintViolations().iterator().next();
assertEquals(constraintViolation.getMessage(), messagePrefix() + "must not be null");
assertMethod(constraintViolation, "cascadingArrayParameter", Customer[].class);
assertParameterIndex(constraintViolation, 0);
assertMethodValidationType(constraintViolation, ElementKind.PARAMETER);
assertEquals(constraintViolation.getPropertyPath().toString(), "cascadingArrayParameter.customer[1].name");
assertEquals(constraintViolation.getRootBeanClass(), CustomerRepositoryImpl.class);
assertEquals(constraintViolation.getRootBean(), customerRepositoryOriginalBean);
assertEquals(constraintViolation.getLeafBean(), customer);
assertEquals(constraintViolation.getInvalidValue(), null);
assertEquals(constraintViolation.getExecutableParameters(), new Object[] { new Object[] { null, customer } });
assertEquals(constraintViolation.getExecutableReturnValue(), null);
}
}
use of org.hibernate.validator.test.internal.engine.methodvalidation.model.Customer in project hibernate-validator by hibernate.
the class CustomerRepositoryImpl method cascadingMapReturnValue.
@Override
public Map<String, Customer> cascadingMapReturnValue() {
Map<String, Customer> theValue = newHashMap();
theValue.put("Bob", new Customer(null));
return theValue;
}
use of org.hibernate.validator.test.internal.engine.methodvalidation.model.Customer in project hibernate-validator by hibernate.
the class AbstractMethodValidationTest method methodValidationWithCascadingParameterAndCascadingConstraint.
@Test
public void methodValidationWithCascadingParameterAndCascadingConstraint() {
Address address = new Address(null);
Customer customer = new Customer("Bob", address);
try {
customerRepositoryValidatingProxy.persistCustomer(customer);
fail("Expected ConstraintViolationException wasn't thrown.");
} catch (ConstraintViolationException e) {
assertThat(e.getConstraintViolations()).containsOnlyViolations(violationOf(NotNull.class).withPropertyPath(pathWith().method("persistCustomer").parameter("customer", 0).property("address").property("city")).withMessage(messagePrefix() + "must not be null").withRootBeanClass(CustomerRepositoryImpl.class).withInvalidValue(null));
ConstraintViolation<?> constraintViolation = e.getConstraintViolations().iterator().next();
assertEquals(constraintViolation.getMessage(), messagePrefix() + "must not be null");
assertMethod(constraintViolation, "persistCustomer", Customer.class);
assertParameterIndex(constraintViolation, 0);
assertMethodValidationType(constraintViolation, ElementKind.PARAMETER);
assertEquals(constraintViolation.getPropertyPath().toString(), "persistCustomer.customer.address.city");
assertEquals(constraintViolation.getRootBeanClass(), CustomerRepositoryImpl.class);
assertEquals(constraintViolation.getRootBean(), customerRepositoryOriginalBean);
assertEquals(constraintViolation.getLeafBean(), address);
assertEquals(constraintViolation.getInvalidValue(), null);
assertEquals(constraintViolation.getExecutableParameters(), new Object[] { customer });
assertEquals(constraintViolation.getExecutableReturnValue(), null);
}
}
Aggregations