Search in sources :

Example 21 with JsonPath

use of io.crnk.core.engine.internal.dispatcher.path.JsonPath in project crnk-framework by crnk-project.

the class ResourcePatchTest method omittedFieldsShouldBeIgnored.

@Test
public void omittedFieldsShouldBeIgnored() throws Exception {
    // GIVEN
    ResourceRepositoryAdapter taskRepo = resourceRegistry.getEntry(Task.class).getResourceRepository(null);
    Task task = new Task();
    task.setName("Mary Joe");
    JsonApiResponse jsonApiResponse = taskRepo.create(task, emptyTaskQuery);
    task = (Task) (jsonApiResponse.getEntity());
    // GIVEN
    Resource data = new Resource();
    data.setType("tasks");
    data.setAttribute("category", objectMapper.readTree("\"TestCategory\""));
    Document taskPatch = new Document();
    taskPatch.setData(Nullable.of((Object) data));
    JsonPath jsonPath = pathBuilder.build("/tasks/" + task.getId());
    ResourcePatch sut = new ResourcePatch(resourceRegistry, PROPERTIES_PROVIDER, typeParser, objectMapper, documentMapper, modificationFilters);
    // WHEN
    Response response = sut.handle(jsonPath, emptyTaskQuery, null, taskPatch);
    // THEN
    Assert.assertNotNull(response);
    assertThat(response.getDocument().getSingleData().get().getType()).isEqualTo("tasks");
    Resource updatedTask = response.getDocument().getSingleData().get();
    assertThat(updatedTask.getAttributes().get("name").asText()).isEqualTo("Mary Joe");
    assertThat(updatedTask.getAttributes().get("category").asText()).isEqualTo("TestCategory");
    assertThat(updatedTask.getId()).isEqualTo(task.getId().toString());
    Assert.assertEquals("Mary Joe", task.getName());
    Assert.assertEquals("TestCategory", task.getCategory());
}
Also used : JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) Response(io.crnk.core.engine.dispatcher.Response) Task(io.crnk.core.mock.models.Task) ResourceRepositoryAdapter(io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter) Resource(io.crnk.core.engine.document.Resource) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) Document(io.crnk.core.engine.document.Document) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) ResourcePatch(io.crnk.core.engine.internal.dispatcher.controller.ResourcePatch) BaseControllerTest(io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest) Test(org.junit.Test)

Example 22 with JsonPath

use of io.crnk.core.engine.internal.dispatcher.path.JsonPath in project crnk-framework by crnk-project.

the class ResourcePatchTest method omittedFieldsSettersAreNotCalled.

/*
	 * see github #122
	 */
@Test
public void omittedFieldsSettersAreNotCalled() throws Exception {
    // GIVEN
    ResourceRepositoryAdapter taskRepo = resourceRegistry.getEntry(Task.class).getResourceRepository(null);
    Task task = new Task();
    task.setName("Mary Joe");
    JsonApiResponse jsonApiResponse = taskRepo.create(task, emptyTaskQuery);
    task = (Task) (jsonApiResponse.getEntity());
    // GIVEN
    Document taskPatch = new Document();
    Resource data = new Resource();
    taskPatch.setData(Nullable.of((Object) data));
    data.setType("tasks");
    data.setAttribute("name", objectMapper.readTree("\"Mary Jane\""));
    JsonPath jsonPath = pathBuilder.build("/tasks/" + task.getId());
    ResourcePatch sut = new ResourcePatch(resourceRegistry, PROPERTIES_PROVIDER, typeParser, objectMapper, documentMapper, modificationFilters);
    // WHEN
    Response response = sut.handle(jsonPath, emptyTaskQuery, null, taskPatch);
    // THEN
    Assert.assertNotNull(response);
    assertThat(response.getDocument().getSingleData().get().getType()).isEqualTo("tasks");
    Resource updatedTask = response.getDocument().getSingleData().get();
    assertThat(updatedTask.getAttributes().get("name").asText()).isEqualTo("Mary Jane");
    assertThat(updatedTask.getId()).isEqualTo(task.getId().toString());
    assertThat(updatedTask.getAttributes().get("category")).isNull();
}
Also used : JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) Response(io.crnk.core.engine.dispatcher.Response) Task(io.crnk.core.mock.models.Task) ResourceRepositoryAdapter(io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter) Resource(io.crnk.core.engine.document.Resource) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) Document(io.crnk.core.engine.document.Document) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) ResourcePatch(io.crnk.core.engine.internal.dispatcher.controller.ResourcePatch) BaseControllerTest(io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest) Test(org.junit.Test)

Example 23 with JsonPath

use of io.crnk.core.engine.internal.dispatcher.path.JsonPath in project crnk-framework by crnk-project.

the class FieldResourceGetTest method onNonRelationRequestShouldDenyIt.

@Test
public void onNonRelationRequestShouldDenyIt() {
    // GIVEN
    JsonPath jsonPath = new ResourcePath("tasks");
    ResourceRegistry resourceRegistry = mock(ResourceRegistry.class);
    FieldResourceGet sut = new FieldResourceGet(resourceRegistry, typeParser, documentMapper);
    // WHEN
    boolean result = sut.isAcceptable(jsonPath, REQUEST_TYPE);
    // THEN
    assertThat(result).isFalse();
}
Also used : ResourcePath(io.crnk.core.engine.internal.dispatcher.path.ResourcePath) FieldResourceGet(io.crnk.core.engine.internal.dispatcher.controller.FieldResourceGet) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) BaseControllerTest(io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest) Test(org.junit.Test)

Example 24 with JsonPath

use of io.crnk.core.engine.internal.dispatcher.path.JsonPath in project crnk-framework by crnk-project.

the class FieldResourceGetTest method onRelationshipRequestShouldDenyIt.

@Test
public void onRelationshipRequestShouldDenyIt() {
    // GIVEN
    JsonPath jsonPath = new ResourcePath("tasks/1/relationships/project");
    ResourceRegistry resourceRegistry = mock(ResourceRegistry.class);
    FieldResourceGet sut = new FieldResourceGet(resourceRegistry, typeParser, documentMapper);
    // WHEN
    boolean result = sut.isAcceptable(jsonPath, REQUEST_TYPE);
    // THEN
    assertThat(result).isFalse();
}
Also used : ResourcePath(io.crnk.core.engine.internal.dispatcher.path.ResourcePath) FieldResourceGet(io.crnk.core.engine.internal.dispatcher.controller.FieldResourceGet) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) BaseControllerTest(io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest) Test(org.junit.Test)

Example 25 with JsonPath

use of io.crnk.core.engine.internal.dispatcher.path.JsonPath in project crnk-framework by crnk-project.

the class FieldResourceGetTest method onGivenRequestFieldResourceGetShouldHandleIt.

@Test
public void onGivenRequestFieldResourceGetShouldHandleIt() throws Exception {
    // GIVEN
    JsonPath jsonPath = pathBuilder.build("/tasks/1/project");
    FieldResourceGet sut = new FieldResourceGet(resourceRegistry, typeParser, documentMapper);
    // WHEN
    Response response = sut.handle(jsonPath, emptyProjectQuery, null, null);
    // THEN
    Assert.assertNotNull(response);
}
Also used : Response(io.crnk.core.engine.dispatcher.Response) FieldResourceGet(io.crnk.core.engine.internal.dispatcher.controller.FieldResourceGet) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) BaseControllerTest(io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest) Test(org.junit.Test)

Aggregations

JsonPath (io.crnk.core.engine.internal.dispatcher.path.JsonPath)88 Test (org.junit.Test)80 BaseControllerTest (io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest)72 Response (io.crnk.core.engine.dispatcher.Response)50 Document (io.crnk.core.engine.document.Document)46 Resource (io.crnk.core.engine.document.Resource)41 ResourcePost (io.crnk.core.engine.internal.dispatcher.controller.ResourcePost)36 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)20 ResourcePatch (io.crnk.core.engine.internal.dispatcher.controller.ResourcePatch)16 Project (io.crnk.core.mock.models.Project)14 Relationship (io.crnk.core.engine.document.Relationship)13 RelationshipsResourcePost (io.crnk.core.engine.internal.dispatcher.controller.RelationshipsResourcePost)12 ResourceIdentifier (io.crnk.core.engine.document.ResourceIdentifier)11 ResourcePath (io.crnk.core.engine.internal.dispatcher.path.ResourcePath)10 QuerySpec (io.crnk.core.queryspec.QuerySpec)10 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)10 Task (io.crnk.core.mock.models.Task)9 TaskToProjectRepository (io.crnk.core.mock.repository.TaskToProjectRepository)9 QueryParams (io.crnk.legacy.queryParams.QueryParams)9 ResourceModificationFilter (io.crnk.core.engine.filter.ResourceModificationFilter)8