use of io.crnk.validation.mock.models.Project in project crnk-framework by crnk-project.
the class ValidationEndToEndTest method testRelationProperty.
@Test
public void testRelationProperty() {
Task task = new Task();
task.setId(1L);
task.setName("test");
taskRepo.create(task);
task.setName(ComplexValidator.INVALID_NAME);
Project project = new Project();
project.setName("test");
project.setTask(task);
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("{complex.message}", violation.getMessageTemplate());
Assert.assertEquals("task", violation.getPropertyPath().toString());
Assert.assertEquals("/data/relationships/task", violation.getErrorData().getSourcePointer());
}
}
use of io.crnk.validation.mock.models.Project in project crnk-framework by crnk-project.
the class ValidationEndToEndTest method testResourceObjectValidation.
@Test
public void testResourceObjectValidation() {
Project project = new Project();
project.setId(1L);
project.setName(ComplexValidator.INVALID_NAME);
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("{complex.message}", violation.getMessageTemplate());
Assert.assertEquals("", violation.getPropertyPath().toString());
Assert.assertEquals("", violation.getErrorData().getSourcePointer());
}
}
use of io.crnk.validation.mock.models.Project in project crnk-framework by crnk-project.
the class ValidationEndToEndTest method testListElementAttributeNotNull.
@Test
public void testListElementAttributeNotNull() {
ProjectData data = new ProjectData();
// violation
data.setValue(null);
Project project = new Project();
project.setId(1L);
project.setName("test");
project.getDataList().add(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("dataList[0].value", violation.getPropertyPath().toString());
Assert.assertNotNull(violation.getMessage());
Assert.assertEquals("/data/attributes/dataList/0/value", violation.getErrorData().getSourcePointer());
}
}
use of io.crnk.validation.mock.models.Project in project crnk-framework by crnk-project.
the class ValidationEndToEndTest method testValidationException.
@Test
public void testValidationException() {
Project project = new Project();
project.setId(1L);
// trigger ValidationException
project.setName(ValidationException.class.getSimpleName());
try {
projectRepo.create(project);
} catch (ValidationException e) {
Assert.assertEquals("messageKey", e.getMessage());
}
}
use of io.crnk.validation.mock.models.Project in project crnk-framework by crnk-project.
the class ValidationEndToEndTest method testPropertyOnRelation.
@Test
public void testPropertyOnRelation() {
Task task = new Task();
task.setId(1L);
task.setName("test");
taskRepo.create(task);
task.setName(null);
Project project = new Project();
project.setId(2L);
project.setName("test");
project.getTasks().add(task);
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("tasks[0]", violation.getPropertyPath().toString());
Assert.assertEquals("/data/relationships/tasks/0", violation.getErrorData().getSourcePointer());
}
}
Aggregations