use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class DefaultResourceInformationProviderTest method shouldBeReadableAndPostableAndPatchableWithSetter.
@Test
public void shouldBeReadableAndPostableAndPatchableWithSetter() throws Exception {
ResourceInformation resourceInformation = resourceInformationProvider.build(Task.class);
ResourceField field = resourceInformation.findAttributeFieldByName("name");
Assert.assertTrue(field.getAccess().isReadable());
Assert.assertTrue(field.getAccess().isPostable());
Assert.assertTrue(field.getAccess().isPatchable());
}
use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class DefaultResourceInformationProviderTest method shouldBeReadableButNotPostableOrPatchableWithoutSetter.
@Test
public void shouldBeReadableButNotPostableOrPatchableWithoutSetter() throws Exception {
ResourceInformation resourceInformation = resourceInformationProvider.build(Task.class);
ResourceField field = resourceInformation.findAttributeFieldByName("readOnlyValue");
Assert.assertTrue(field.getAccess().isReadable());
Assert.assertFalse(field.getAccess().isPostable());
Assert.assertFalse(field.getAccess().isPatchable());
}
use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class DefaultResourceInformationProviderTest method checkJsonApiAttributeAnnotationDefaults.
@Test
public void checkJsonApiAttributeAnnotationDefaults() throws Exception {
ResourceInformation resourceInformation = resourceInformationProvider.build(Task.class);
ResourceField field = resourceInformation.findAttributeFieldByName("name");
Assert.assertTrue(field.getAccess().isPatchable());
Assert.assertTrue(field.getAccess().isPostable());
}
use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class QuerySpecRepositoryTest method checkCrud.
@SuppressWarnings({ "unchecked" })
private void checkCrud(QueryAdapter queryAdapter) {
// setup data
Project project = new Project();
project.setId(3L);
project.setName("myProject");
projectAdapter.create(project, queryAdapter);
Task task = new Task();
task.setId(2L);
task.setName("myTask");
task.setProject(project);
task.setProjects(Arrays.asList(project));
taskAdapter.create(task, queryAdapter);
// adapter
List<Task> tasks = (List<Task>) taskAdapter.findAll(queryAdapter).getEntity();
Assert.assertEquals(1, tasks.size());
Assert.assertEquals(task, taskAdapter.findOne(2L, queryAdapter).getEntity());
tasks = (List<Task>) taskAdapter.findAll(Arrays.asList(2L), queryAdapter).getEntity();
Assert.assertEquals(1, tasks.size());
// relation adapter
ResourceField projectField = resourceRegistry.getEntry(Task.class).getResourceInformation().findRelationshipFieldByName("project");
ResourceField tasksField = resourceRegistry.getEntry(Project.class).getResourceInformation().findRelationshipFieldByName("tasks");
projectRelAdapter.setRelation(task, project.getId(), projectField, queryAdapter);
Assert.assertNotNull(task.getProject());
Assert.assertEquals(1, project.getTasks().size());
JsonApiResponse response = projectRelAdapter.findOneTarget(2L, projectField, queryAdapter);
Assert.assertEquals(project.getId(), ((Project) response.getEntity()).getId());
projectRelAdapter.setRelation(task, null, projectField, queryAdapter);
response = projectRelAdapter.findOneTarget(2L, projectField, queryAdapter);
Assert.assertNull(task.getProject());
// warning: bidirectionality not properly implemented here, would
// require changes to the model used in many other places
task.setProject(null);
project.getTasks().clear();
tasksRelAdapter.addRelations(project, Arrays.asList(task.getId()), tasksField, queryAdapter);
Assert.assertEquals(project, task.getProject());
Assert.assertEquals(1, project.getTasks().size());
List<Project> projects = (List<Project>) tasksRelAdapter.findManyTargets(3L, tasksField, queryAdapter).getEntity();
Assert.assertEquals(1, projects.size());
tasksRelAdapter.removeRelations(project, Arrays.asList(task.getId()), tasksField, queryAdapter);
Assert.assertEquals(0, project.getTasks().size());
// fix bidirectionality
task.setProject(null);
projects = (List<Project>) tasksRelAdapter.findManyTargets(3L, tasksField, queryAdapter).getEntity();
Assert.assertEquals(0, projects.size());
tasksRelAdapter.setRelations(project, Arrays.asList(task.getId()), tasksField, queryAdapter);
Assert.assertEquals(project, task.getProject());
Assert.assertEquals(1, project.getTasks().size());
projects = (List<Project>) tasksRelAdapter.findManyTargets(3L, tasksField, queryAdapter).getEntity();
Assert.assertEquals(1, projects.size());
// check bulk find
Map<?, JsonApiResponse> bulkMap = tasksRelAdapter.findBulkManyTargets(Arrays.asList(3L), tasksField, queryAdapter);
Assert.assertEquals(1, bulkMap.size());
Assert.assertTrue(bulkMap.containsKey(3L));
projects = (List<Project>) bulkMap.get(3L).getEntity();
Assert.assertEquals(1, projects.size());
bulkMap = projectRelAdapter.findBulkOneTargets(Arrays.asList(2L), projectField, queryAdapter);
Assert.assertEquals(1, bulkMap.size());
Assert.assertTrue(bulkMap.containsKey(2L));
Assert.assertNotNull(bulkMap.get(2L));
// deletion
taskAdapter.delete(task.getId(), queryAdapter);
tasks = (List<Task>) taskAdapter.findAll(queryAdapter).getEntity();
Assert.assertEquals(0, tasks.size());
tasks = (List<Task>) taskAdapter.findAll(Arrays.asList(2L), queryAdapter).getEntity();
Assert.assertEquals(0, tasks.size());
}
use of io.crnk.core.engine.information.resource.ResourceField 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);
}
Aggregations