use of io.crnk.core.exception.CrnkException in project crnk-framework by crnk-project.
the class ResourcePatchTest method onGivenRequestResourceShouldThrowException.
@Test
public void onGivenRequestResourceShouldThrowException() throws Exception {
// GIVEN
Document newTaskBody = new Document();
Resource data = createTask();
newTaskBody.setData(Nullable.of((Object) data));
data.setType("tasks");
JsonPath taskPath = pathBuilder.build("/tasks");
// WHEN
ResourcePost resourcePost = new ResourcePost(resourceRegistry, PROPERTIES_PROVIDER, typeParser, objectMapper, documentMapper, modificationFilters);
Response taskResponse = resourcePost.handle(taskPath, emptyTaskQuery, null, newTaskBody);
assertThat(taskResponse.getDocument().getSingleData().get().getType()).isEqualTo("tasks");
Long taskId = Long.parseLong(taskResponse.getDocument().getSingleData().get().getId());
assertThat(taskId).isNotNull();
// GIVEN
Document taskPatch = new Document();
data = new Resource();
taskPatch.setData(Nullable.of((Object) data));
data.setType("WRONG_AND_MISSING_TYPE");
data.setAttribute("name", objectMapper.readTree("\"task updated\""));
JsonPath jsonPath = pathBuilder.build("/tasks/" + taskId);
ResourcePatch sut = new ResourcePatch(resourceRegistry, PROPERTIES_PROVIDER, typeParser, objectMapper, documentMapper, modificationFilters);
// WHEN
Response response = null;
try {
response = sut.handle(jsonPath, emptyTaskQuery, null, taskPatch);
Assert.fail("Should have recieved exception.");
} catch (CrnkException rbe) {
// Got correct exception
} catch (Error ex) {
Assert.fail("Got bad exception: " + ex);
}
}
Aggregations