use of io.crnk.core.engine.internal.dispatcher.path.JsonPath in project crnk-framework by crnk-project.
the class ResourceIdControllerTest method checkPatchRelationship.
private void checkPatchRelationship(Resource resource, ResourceIdentifier scheduleId) {
JsonPath path = pathBuilder.build("/relationIdTest/" + resource.getId() + "/relationships/testLookupAlways");
Document newDocument = createDocument(scheduleId);
// WHEN PATCH
RelationshipsResourcePatch sut = new RelationshipsResourcePatch(resourceRegistry, typeParser, modificationFilters);
Response taskResponse = sut.handle(path, emptyTaskQuery, null, newDocument);
// THEN PATCH
assertThat(taskResponse.getHttpStatus()).isEqualTo(HttpStatus.NO_CONTENT_204);
// validate relationship not accessed, only id set => performance
RelationIdTestResource entity = repository.findOne(1L, new QuerySpec(RelationIdTestResource.class));
Assert.assertEquals(scheduleId != null ? Long.parseLong(scheduleId.getId()) : null, entity.getTestLookupAlwaysId());
Assert.assertNull(entity.getTestLookupAlways());
}
use of io.crnk.core.engine.internal.dispatcher.path.JsonPath in project crnk-framework by crnk-project.
the class ResourcePostTest method onGivenRequestCollectionGetShouldDenyIt.
@Test
public void onGivenRequestCollectionGetShouldDenyIt() {
// GIVEN
JsonPath jsonPath = pathBuilder.build("/tasks/1");
ResourcePost sut = new ResourcePost(resourceRegistry, PROPERTIES_PROVIDER, typeParser, objectMapper, documentMapper, modificationFilters);
// WHEN
boolean result = sut.isAcceptable(jsonPath, REQUEST_TYPE);
// THEN
Assert.assertEquals(result, false);
}
use of io.crnk.core.engine.internal.dispatcher.path.JsonPath in project crnk-framework by crnk-project.
the class ResourcePostTest method onUpdatedLazyRelationshipDataShouldReturnThatData.
@Test
public void onUpdatedLazyRelationshipDataShouldReturnThatData() throws Exception {
// GIVEN
Document newTaskBody = new Document();
Resource data = createTask();
newTaskBody.setData(Nullable.of((Object) data));
data.setType("tasks");
JsonPath taskPath = pathBuilder.build("/tasks");
ResourcePost sut = new ResourcePost(resourceRegistry, PROPERTIES_PROVIDER, typeParser, objectMapper, documentMapper, modificationFilters);
// WHEN
Response taskResponse = sut.handle(taskPath, emptyTaskQuery, null, newTaskBody);
// THEN
assertThat(taskResponse.getDocument().getSingleData().get().getType()).isEqualTo("tasks");
assertThat(taskResponse.getDocument().getSingleData().get().getId()).isNotNull();
assertThat(taskResponse.getDocument().getSingleData().get().getAttributes().get("name").asText()).isEqualTo("sample task");
Long taskId = Long.parseLong(taskResponse.getDocument().getSingleData().get().getId());
/* ------- */
// GIVEN
Document newProjectBody = new Document();
data = createProject();
data.setType("projects");
List<ResourceIdentifier> taskIds = Collections.singletonList(new ResourceIdentifier(taskId.toString(), "tasks"));
data.getRelationships().put("tasks", new Relationship(taskIds));
newProjectBody.setData(Nullable.of((Object) data));
JsonPath projectsPath = pathBuilder.build("/projects");
// WHEN
Response projectsResponse = sut.handle(projectsPath, emptyProjectQuery, null, newProjectBody);
// THEN
assertThat(projectsResponse.getDocument().getSingleData().get().getType()).isEqualTo("projects");
Long userId = Long.parseLong(projectsResponse.getDocument().getSingleData().get().getId());
assertThat(userId).isNotNull();
assertThat(projectsResponse.getDocument().getSingleData().get().getAttributes().get("name").asText()).isEqualTo("sample project");
assertThat(projectsResponse.getDocument().getSingleData().get().getRelationships().get("tasks").getCollectionData().get()).hasSize(1);
assertThat(projectsResponse.getDocument().getSingleData().get().getRelationships().get("tasks").getCollectionData().get().get(0).getId()).isEqualTo(taskId.toString());
Mockito.verify(modificationFilter, Mockito.times(1)).modifyManyRelationship(Mockito.any(), Mockito.any(ResourceField.class), Mockito.eq(ResourceRelationshipModificationType.SET), Mockito.eq(taskIds));
}
use of io.crnk.core.engine.internal.dispatcher.path.JsonPath in project crnk-framework by crnk-project.
the class ResourcePostTest method onPostingReadOnlyFieldShouldIgnoreWithIgnoreBehavior.
@Test
public void onPostingReadOnlyFieldShouldIgnoreWithIgnoreBehavior() throws Exception {
// GIVEN
Document requestDocument = new Document();
Resource data = createTask();
data.getAttributes().put("readOnlyValue", objectMapper.readTree("\"newValue\""));
requestDocument.setData(Nullable.of((Object) data));
JsonPath path = pathBuilder.build("/tasks");
PropertiesProvider propertiesProvider = new PropertiesProvider() {
@Override
public String getProperty(String key) {
if (CrnkProperties.RESOURCE_FIELD_IMMUTABLE_WRITE_BEHAVIOR.equals(key)) {
return ResourceFieldImmutableWriteBehavior.IGNORE.toString();
}
return null;
}
};
ResourcePost sut = new ResourcePost(resourceRegistry, propertiesProvider, typeParser, objectMapper, documentMapper, modificationFilters);
// WHEN
Response response = sut.handle(path, emptyTaskQuery, null, requestDocument);
String persistedValue = response.getDocument().getSingleData().get().getAttributes().get("readOnlyValue").asText();
Assert.assertEquals("someReadOnlyValue", persistedValue);
}
use of io.crnk.core.engine.internal.dispatcher.path.JsonPath in project crnk-framework by crnk-project.
the class ResourcePostTest method onNewInheritedResourceShouldPersistThisResource.
@Test
// TODO
@Ignore
public void onNewInheritedResourceShouldPersistThisResource() throws Exception {
// GIVEN
Document newMemorandumBody = new Document();
Resource data = new Resource();
newMemorandumBody.setData(Nullable.of((Object) data));
data.setType("memoranda");
data.setAttribute("title", objectMapper.readTree("\"sample title\""));
data.setAttribute("body", objectMapper.readTree("\"sample body\""));
JsonPath projectPath = pathBuilder.build("/documents");
ResourcePost sut = new ResourcePost(resourceRegistry, PROPERTIES_PROVIDER, typeParser, objectMapper, documentMapper, modificationFilters);
// WHEN
Response memorandumResponse = sut.handle(projectPath, emptyMemorandumQuery, null, newMemorandumBody);
// THEN
assertThat(memorandumResponse.getDocument().getSingleData().get().getType()).isEqualTo("memoranda");
Resource persistedMemorandum = memorandumResponse.getDocument().getSingleData().get();
assertThat(persistedMemorandum.getId()).isNotNull();
assertThat(persistedMemorandum.getAttributes().get("title").asText()).isEqualTo("sample title");
assertThat(persistedMemorandum.getAttributes().get("body").asText()).isEqualTo("sample body");
}
Aggregations