use of io.crnk.legacy.queryParams.QueryParams in project crnk-framework by crnk-project.
the class RelationshipsResourcePostTest method onExistingResourcesShouldAddToOneRelationship.
@Test
public void onExistingResourcesShouldAddToOneRelationship() throws Exception {
// GIVEN
Document newTaskBody = new Document();
newTaskBody.setData(Nullable.of((Object) createTask()));
JsonPath taskPath = pathBuilder.build("/tasks");
ResourcePost resourcePost = new ResourcePost(resourceRegistry, PROPERTIES_PROVIDER, typeParser, OBJECT_MAPPER, documentMapper, modificationFilters);
// WHEN -- adding a task
Response taskResponse = resourcePost.handle(taskPath, emptyTaskQuery, null, newTaskBody);
// THEN
assertThat(taskResponse.getDocument().getSingleData().get().getType()).isEqualTo("tasks");
Long taskId = Long.parseLong(taskResponse.getDocument().getSingleData().get().getId());
assertThat(taskId).isNotNull();
/* ------- */
// GIVEN
Document newProjectBody = new Document();
newProjectBody.setData(Nullable.of((Object) createProject()));
JsonPath projectPath = pathBuilder.build("/projects");
// WHEN -- adding a project
Response projectResponse = resourcePost.handle(projectPath, emptyProjectQuery, null, newProjectBody);
// THEN
assertThat(projectResponse.getDocument().getSingleData().get().getType()).isEqualTo("projects");
assertThat(projectResponse.getDocument().getSingleData().get().getId()).isNotNull();
assertThat(projectResponse.getDocument().getSingleData().get().getAttributes().get("name").asText()).isEqualTo("sample project");
Long projectId = Long.parseLong(projectResponse.getDocument().getSingleData().get().getId());
assertThat(projectId).isNotNull();
/* ------- */
// GIVEN
Document newTaskToProjectBody = new Document();
newTaskToProjectBody.setData(Nullable.of((Object) createProject(Long.toString(projectId))));
JsonPath savedTaskPath = pathBuilder.build("/tasks/" + taskId + "/relationships/project");
RelationshipsResourcePost sut = new RelationshipsResourcePost(resourceRegistry, typeParser, modificationFilters);
// WHEN -- adding a relation between task and project
Response projectRelationshipResponse = sut.handle(savedTaskPath, emptyProjectQuery, null, newTaskToProjectBody);
assertThat(projectRelationshipResponse).isNotNull();
// THEN
TaskToProjectRepository taskToProjectRepository = new TaskToProjectRepository();
Project project = taskToProjectRepository.findOneTarget(taskId, "project", new QueryParams());
assertThat(project.getId()).isEqualTo(projectId);
ResourceIdentifier projectResourceId = new ResourceIdentifier(projectId.toString(), "projects");
// TODO properly implement ResourceIdentifier vs Resource in relationship repositories
// Mockito.validate(modificationFilter, Mockito.times(1)).modifyOneRelationship(Mockito.any(), Mockito.any(ResourceField.class), Mockito.eq(projectResourceId));
}
use of io.crnk.legacy.queryParams.QueryParams in project crnk-framework by crnk-project.
the class QueryParamsClientTest method testAccessQuerySpecRepository.
@Test
public void testAccessQuerySpecRepository() {
List<Schedule> schedule = scheduleRepo.findAll(new QueryParams());
Assert.assertTrue(schedule.isEmpty());
}
use of io.crnk.legacy.queryParams.QueryParams in project crnk-framework by crnk-project.
the class QueryParamsClientTest method testDelete.
@Test
public void testDelete() {
Task task = new Task();
task.setId(1L);
task.setName("test");
taskRepo.create(task);
taskRepo.delete(1L);
List<Task> tasks = taskRepo.findAll(new QueryParams());
Assert.assertEquals(0, tasks.size());
}
use of io.crnk.legacy.queryParams.QueryParams in project crnk-framework by crnk-project.
the class QueryParamsClientTest method testSaveAndFind.
@Test
public void testSaveAndFind() {
Task task = new Task();
task.setId(1L);
task.setName("test");
taskRepo.create(task);
// check retrievable with findAll
List<Task> tasks = taskRepo.findAll(new QueryParams());
Assert.assertEquals(1, tasks.size());
Task savedTask = tasks.get(0);
Assert.assertEquals(task.getId(), savedTask.getId());
Assert.assertEquals(task.getName(), savedTask.getName());
// check retrievable with findAll(ids)
tasks = taskRepo.findAll(Arrays.asList(1L), new QueryParams());
Assert.assertEquals(1, tasks.size());
savedTask = tasks.get(0);
Assert.assertEquals(task.getId(), savedTask.getId());
Assert.assertEquals(task.getName(), savedTask.getName());
// check retrievable with findOne
savedTask = taskRepo.findOne(1L, new QueryParams());
Assert.assertEquals(task.getId(), savedTask.getId());
Assert.assertEquals(task.getName(), savedTask.getName());
}
use of io.crnk.legacy.queryParams.QueryParams in project crnk-framework by crnk-project.
the class QueryParamsClientTest method testFindEmpty.
@Test
public void testFindEmpty() {
List<Task> tasks = taskRepo.findAll(new QueryParams());
Assert.assertTrue(tasks.isEmpty());
}
Aggregations