use of io.crnk.core.mock.models.Project in project crnk-framework by crnk-project.
the class IncludeLookupSetterBaseTest method setup.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Before
public void setup() {
super.setup();
// get repositories
ResourceRepositoryAdapter taskRepository = resourceRegistry.findEntry(Task.class).getResourceRepository(null);
RelationshipRepositoryAdapter relRepositoryTaskToProject = resourceRegistry.findEntry(Task.class).getRelationshipRepository("projects", null);
RelationshipRepositoryAdapter relRepositoryProjectToTask = resourceRegistry.findEntry(Project.class).getRelationshipRepository("tasks", null);
ResourceRepositoryAdapter projectRepository = resourceRegistry.findEntry(Project.class).getResourceRepository(null);
ResourceRepositoryAdapter hierarchicalTaskRepository = resourceRegistry.findEntry(HierarchicalTask.class).getResourceRepository(null);
// setup test data
ResourceInformation taskInfo = resourceRegistry.findEntry(Task.class).getResourceInformation();
ResourceInformation projectInfo = resourceRegistry.findEntry(Project.class).getResourceInformation();
ResourceField includedTaskField = projectInfo.findRelationshipFieldByName("includedTask");
ResourceField includedProjectField = taskInfo.findRelationshipFieldByName("includedProject");
ResourceField includedProjectsField = taskInfo.findRelationshipFieldByName("includedProjects");
ResourceField projectField = taskInfo.findRelationshipFieldByName("project");
QueryAdapter projectQuey = emptyQueryAdapter(Project.class);
QueryAdapter taskQuery = emptyQueryAdapter(Task.class);
QueryAdapter hierarchicalTaskQuery = emptyQueryAdapter(HierarchicalTask.class);
Project project = new Project();
project.setId(2L);
projectRepository.create(project, projectQuey);
Task task = new Task();
task.setId(1L);
taskRepository.create(task, taskQuery);
relRepositoryTaskToProject.setRelation(task, project.getId(), includedProjectField, projectQuey);
relRepositoryTaskToProject.setRelation(task, project.getId(), projectField, projectQuey);
relRepositoryTaskToProject.addRelations(task, Collections.singletonList(project.getId()), includedProjectsField, projectQuey);
// setup deep nested relationship
Task includedTask = new Task();
includedTask.setId(3L);
taskRepository.create(includedTask, taskQuery);
relRepositoryProjectToTask.setRelation(project, includedTask.getId(), includedTaskField, taskQuery);
Project deepIncludedProject = new Project();
deepIncludedProject.setId(2L);
projectRepository.create(project, projectQuey);
relRepositoryTaskToProject.setRelation(includedTask, deepIncludedProject.getId(), includedProjectField, projectQuey);
relRepositoryTaskToProject.addRelations(includedTask, Collections.singletonList(project.getId()), includedProjectsField, projectQuey);
// setup hierarchy of resources
h = new HierarchicalTask();
h.setId(1L);
h.setName("");
h0 = new HierarchicalTask();
h0.setId(2L);
h0.setName("0");
h0.setParent(h);
h1 = new HierarchicalTask();
h1.setId(3L);
h1.setName("1");
h1.setParent(h);
h11 = new HierarchicalTask();
h11.setId(4L);
h11.setName("11");
h11.setParent(h1);
h.setChildren(Arrays.asList(h0, h1));
h0.setChildren(new ArrayList<HierarchicalTask>());
h1.setChildren(Arrays.asList(h11));
h11.setChildren(new ArrayList<HierarchicalTask>());
hierarchicalTaskRepository.create(h, hierarchicalTaskQuery);
hierarchicalTaskRepository.create(h0, hierarchicalTaskQuery);
hierarchicalTaskRepository.create(h1, hierarchicalTaskQuery);
hierarchicalTaskRepository.create(h11, hierarchicalTaskQuery);
}
use of io.crnk.core.mock.models.Project in project crnk-framework by crnk-project.
the class IncludeLookupSetterBaseTest method includePropertiesProviderNonOverwriteRelationshipLookup.
@Test
public void includePropertiesProviderNonOverwriteRelationshipLookup() throws Exception {
PropertiesProvider propertiesProvider = new PropertiesProvider() {
@Override
public String getProperty(String key) {
if (key.equalsIgnoreCase(CrnkProperties.INCLUDE_AUTOMATICALLY_OVERWRITE)) {
return "false";
}
return null;
}
};
mapper = new DocumentMapper(resourceRegistry, objectMapper, propertiesProvider, resourceFilterDirectory);
QuerySpec querySpec = new QuerySpec(Task.class);
querySpec.includeRelation(Arrays.asList("project"));
Project project = new Project();
project.setId(12L);
Task task = new Task();
task.setId(1L);
task.setProject(project);
Document document = mapper.toDocument(toResponse(task), toAdapter(querySpec));
Resource taskResource = document.getSingleData().get();
Relationship relationship = taskResource.getRelationships().get("project");
assertNotNull(relationship);
assertEquals(relationship.getSingleData().get().getId(), "12");
}
use of io.crnk.core.mock.models.Project in project crnk-framework by crnk-project.
the class AnnotatedRelationshipRepositoryAdapterTest method onClassWithAddRelationsShouldAddValue.
@Test
public void onClassWithAddRelationsShouldAddValue() throws Exception {
// GIVEN
RelationshipRepositoryWithAddRelations repo = spy(RelationshipRepositoryWithAddRelations.class);
AnnotatedRelationshipRepositoryAdapter<Task, Long, Project, Long> sut = new AnnotatedRelationshipRepositoryAdapter<>(repo, parameterProvider);
Task task = new Task();
// WHEN
sut.addRelations(task, Collections.singleton(1L), "project", queryAdapter);
// THEN
verify(repo).addRelations(eq(task), eq(Collections.singleton(1L)), eq("project"));
}
use of io.crnk.core.mock.models.Project in project crnk-framework by crnk-project.
the class AnnotatedRelationshipRepositoryAdapterTest method onClassWithEmptySetRelationShouldThrowException.
@Test(expected = RepositoryMethodException.class)
public void onClassWithEmptySetRelationShouldThrowException() throws Exception {
// GIVEN
RelationshipRepositoryWithEmptySetRelation repo = new RelationshipRepositoryWithEmptySetRelation();
AnnotatedRelationshipRepositoryAdapter<Task, Long, Project, Long> sut = new AnnotatedRelationshipRepositoryAdapter<>(repo, parameterProvider);
// WHEN
sut.setRelation(new Task(), 1L, "project", queryAdapter);
}
use of io.crnk.core.mock.models.Project in project crnk-framework by crnk-project.
the class AnnotatedRelationshipRepositoryAdapterTest method onClassWithoutSetRelationsShouldThrowException.
@Test(expected = RepositoryAnnotationNotFoundException.class)
public void onClassWithoutSetRelationsShouldThrowException() throws Exception {
// GIVEN
RelationshipRepositoryWithoutAnyMethods repo = new RelationshipRepositoryWithoutAnyMethods();
AnnotatedRelationshipRepositoryAdapter<Task, Long, Project, Long> sut = new AnnotatedRelationshipRepositoryAdapter<>(repo, parameterProvider);
// WHEN
sut.setRelations(new Task(), Collections.singleton(1L), "project", queryAdapter);
}
Aggregations