use of io.crnk.core.mock.repository.ProjectPolymorphicToObjectRepository in project crnk-framework by crnk-project.
the class RelationshipsResourceGetTest method supportPolymorphicRelationshipTypes.
@Test
public void supportPolymorphicRelationshipTypes() throws JsonProcessingException {
// GIVEN
Long projectId = 1L;
String type = ClassUtils.getAnnotation(ProjectPolymorphic.class, JsonApiResource.class).get().type();
ProjectPolymorphic projectPolymorphic = new ProjectPolymorphic();
projectPolymorphic.setId(projectId);
ProjectPolymorphicToObjectRepository projectPolymorphicToObjectRepository = new ProjectPolymorphicToObjectRepository();
projectPolymorphicToObjectRepository.setRelation(projectPolymorphic, 42L, "task");
JsonPath jsonPath = pathBuilder.build("/" + type + "/" + projectId + "/relationships/task");
RelationshipsResourceGet resourceGet = new RelationshipsResourceGet(resourceRegistry, typeParser, documentMapper);
// WHEN
Response baseResponseContext = resourceGet.handle(jsonPath, emptyTaskQuery, null, null);
// THEN
Assert.assertNotNull(baseResponseContext);
String resultJson = objectMapper.writeValueAsString(baseResponseContext.getDocument());
assertThatJson(resultJson).node("data.id").isStringEqualTo("42");
assertThatJson(resultJson).node("data.type").isEqualTo("tasks");
// GIVEN
projectPolymorphicToObjectRepository.setRelations(projectPolymorphic, Arrays.asList(44L, 45L), "tasks");
jsonPath = pathBuilder.build("/" + type + "/" + projectId + "/relationships/tasks");
resourceGet = new RelationshipsResourceGet(resourceRegistry, typeParser, documentMapper);
// WHEN
baseResponseContext = resourceGet.handle(jsonPath, emptyTaskQuery, null, null);
Assert.assertNotNull(baseResponseContext);
resultJson = objectMapper.writeValueAsString(baseResponseContext.getDocument());
ReadContext resultCtx = com.jayway.jsonpath.JsonPath.parse(resultJson);
assertIncludeDoNotCareAboutOrder(new ArrayList<>(Arrays.asList("44", "45")), Arrays.asList(0, 1), resultCtx);
}
Aggregations