use of io.crnk.validation.mock.models.Project in project crnk-framework by crnk-project.
the class TaskToProjectRepository method findOneTarget.
@Override
public Project findOneTarget(Long sourceId, String fieldName, QueryParams queryParams) {
for (Relation<Task> relation : THREAD_LOCAL_REPOSITORY.keySet()) {
if (relation.getSource().getId().equals(sourceId) && relation.getFieldName().equals(fieldName)) {
Project project = new Project();
project.setId((Long) relation.getTargetId());
return project;
}
}
return null;
}
use of io.crnk.validation.mock.models.Project in project crnk-framework by crnk-project.
the class TaskToProjectRepository method findManyTargets.
@Override
public Iterable<Project> findManyTargets(Long sourceId, String fieldName, QueryParams queryParams) {
List<Project> projects = new LinkedList<>();
for (Relation<Task> relation : THREAD_LOCAL_REPOSITORY.keySet()) {
if (relation.getSource().getId().equals(sourceId) && relation.getFieldName().equals(fieldName)) {
Project project = new Project();
project.setId((Long) relation.getTargetId());
projects.add(project);
}
}
return projects;
}
use of io.crnk.validation.mock.models.Project in project crnk-framework by crnk-project.
the class ValidationEndToEndTest method testPropertyNotNull.
@Test
public void testPropertyNotNull() {
Project project = new Project();
project.setId(1L);
// violation
project.setName(null);
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("name", violation.getPropertyPath().toString());
Assert.assertNotNull(violation.getMessage());
Assert.assertTrue(violation.getMessage().contains("null"));
Assert.assertEquals("/data/attributes/name", violation.getErrorData().getSourcePointer());
}
}
use of io.crnk.validation.mock.models.Project in project crnk-framework by crnk-project.
the class ValidationEndToEndTest method testListAttribute.
@Test
public void testListAttribute() {
Project project = new Project();
project.setId(1L);
project.setName("test");
project.getKeywords().add("1");
project.getKeywords().add("2");
project.getKeywords().add("3");
project.getKeywords().add("4");
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.Size.message}", violation.getMessageTemplate());
Assert.assertEquals("keywords", violation.getPropertyPath().toString());
// message depends on local
Assert.assertNotNull(violation.getMessage());
Assert.assertTrue(violation.getMessage().contains("0"));
Assert.assertTrue(violation.getMessage().contains("3"));
Assert.assertEquals("/data/attributes/keywords", violation.getErrorData().getSourcePointer());
}
}
use of io.crnk.validation.mock.models.Project in project crnk-framework by crnk-project.
the class ValidationEndToEndTest method testSetElementAttributeNotNull.
@Test
public void testSetElementAttributeNotNull() {
Project project = new Project();
project.setId(1L);
project.setName("test");
// ProjectData corrupedElement = null;
for (int i = 0; i < 11; i++) {
ProjectData data = new ProjectData();
if (i != 3) {
data.setValue(Integer.toString(i));
// corrupedElement = data;
}
project.getDataSet().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.assertTrue(violation.getPropertyPath().toString().startsWith("dataSet["));
Assert.assertTrue(violation.getPropertyPath().toString().endsWith("].value"));
Assert.assertTrue(violation.getErrorData().getSourcePointer().startsWith("/data/attributes/dataSet/"));
// TODO attempt to preserver order in Crnk by comparing incoming request, sourcePointer and server Set
// or use of order preserving sets
// List<ProjectData> list = new ArrayList<>(project.getDataSet());
// int index = list.indexOf(corrupedElement);
// Assert.assertEquals(violation.getErrorData().getSourcePointer(), "/data/attributes/dataSet/" + index +
// "/value");
}
}
Aggregations