Search in sources :

Example 36 with QueryParams

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));
}
Also used : Response(io.crnk.core.engine.dispatcher.Response) Project(io.crnk.core.mock.models.Project) ResourceIdentifier(io.crnk.core.engine.document.ResourceIdentifier) TaskToProjectRepository(io.crnk.core.mock.repository.TaskToProjectRepository) QueryParams(io.crnk.legacy.queryParams.QueryParams) RelationshipsResourcePost(io.crnk.core.engine.internal.dispatcher.controller.RelationshipsResourcePost) Document(io.crnk.core.engine.document.Document) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) ResourcePost(io.crnk.core.engine.internal.dispatcher.controller.ResourcePost) RelationshipsResourcePost(io.crnk.core.engine.internal.dispatcher.controller.RelationshipsResourcePost) BaseControllerTest(io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest) Test(org.junit.Test)

Example 37 with QueryParams

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());
}
Also used : Schedule(io.crnk.test.mock.models.Schedule) QueryParams(io.crnk.legacy.queryParams.QueryParams) Test(org.junit.Test)

Example 38 with QueryParams

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());
}
Also used : Task(io.crnk.test.mock.models.Task) QueryParams(io.crnk.legacy.queryParams.QueryParams) Test(org.junit.Test)

Example 39 with QueryParams

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());
}
Also used : Task(io.crnk.test.mock.models.Task) QueryParams(io.crnk.legacy.queryParams.QueryParams) Test(org.junit.Test)

Example 40 with QueryParams

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());
}
Also used : Task(io.crnk.test.mock.models.Task) QueryParams(io.crnk.legacy.queryParams.QueryParams) Test(org.junit.Test)

Aggregations

QueryParams (io.crnk.legacy.queryParams.QueryParams)46 Test (org.junit.Test)37 QueryParamsAdapter (io.crnk.legacy.internal.QueryParamsAdapter)10 Response (io.crnk.core.engine.dispatcher.Response)9 JsonPath (io.crnk.core.engine.internal.dispatcher.path.JsonPath)9 Document (io.crnk.core.engine.document.Document)7 BaseControllerTest (io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest)7 Project (io.crnk.core.mock.models.Project)7 AbstractJpaJerseyTest (io.crnk.jpa.AbstractJpaJerseyTest)7 Resource (io.crnk.core.engine.document.Resource)6 TaskToProjectRepository (io.crnk.core.mock.repository.TaskToProjectRepository)6 TestEntity (io.crnk.jpa.model.TestEntity)6 Task (io.crnk.test.mock.models.Task)6 ResourcePost (io.crnk.core.engine.internal.dispatcher.controller.ResourcePost)5 Task (io.crnk.core.mock.models.Task)5 DefaultQueryParamsParser (io.crnk.legacy.queryParams.DefaultQueryParamsParser)5 QueryParamsBuilder (io.crnk.legacy.queryParams.QueryParamsBuilder)5 Relationship (io.crnk.core.engine.document.Relationship)3 ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)3 ResourceModificationFilter (io.crnk.core.engine.filter.ResourceModificationFilter)3