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());
}
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();
}
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();
}
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();
}
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);
}
Aggregations