use of io.crnk.validation.mock.models.Project in project crnk-framework by crnk-project.
the class ValidationEndToEndTest method testNestedPropertyNotNull.
@Test
public void testNestedPropertyNotNull() {
ProjectData data = new ProjectData();
// violation
data.setValue(null);
Project project = new Project();
project.setId(1L);
project.setName("test");
project.setData(data);
try {
projectRepo.create(project);
} catch (ConstraintViolationException e) {
Set<ConstraintViolation<?>> violations = e.getConstraintViolations();
Assert.assertEquals(1, violations.size());
ConstraintViolationImpl violation = (ConstraintViolationImpl) violations.iterator().next();
Assert.assertEquals("{javax.validation.constraints.NotNull.message}", violation.getMessageTemplate());
Assert.assertEquals("data.value", violation.getPropertyPath().toString());
Assert.assertEquals("/data/attributes/data/value", violation.getErrorData().getSourcePointer());
}
}
use of io.crnk.validation.mock.models.Project in project crnk-framework by crnk-project.
the class ValidationEndToEndTest method testMapElementAttributeNotNull.
@Test
public void testMapElementAttributeNotNull() {
ProjectData data = new ProjectData();
// violation
data.setValue(null);
Project project = new Project();
project.setId(1L);
project.setName("test");
project.setDataMap(new LinkedHashMap());
project.getDataMap().put("someKey", data);
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
try {
projectRepo.create(project);
} catch (ConstraintViolationException e) {
Set<ConstraintViolation<?>> violations = e.getConstraintViolations();
Assert.assertEquals(1, violations.size());
ConstraintViolationImpl violation = (ConstraintViolationImpl) violations.iterator().next();
Assert.assertEquals("{javax.validation.constraints.NotNull.message}", violation.getMessageTemplate());
Assert.assertEquals("dataMap[someKey].value", violation.getPropertyPath().toString());
Assert.assertNotNull(violation.getMessage());
Assert.assertEquals("/data/attributes/dataMap/someKey/value", violation.getErrorData().getSourcePointer());
}
}
Aggregations