use of io.crnk.core.queryspec.internal.QuerySpecAdapter in project crnk-framework by crnk-project.
the class HasNextBasedPagedLinksInformationTest method testPaging.
@Test
public void testPaging() throws InstantiationException, IllegalAccessException {
QuerySpecAdapter querySpec = new QuerySpecAdapter(querySpec(2L, 2L), resourceRegistry);
JsonApiResponse results = adapter.findAll(querySpec);
HasMoreResourcesMetaInformation metaInformation = (HasMoreResourcesMetaInformation) results.getMetaInformation();
Assert.assertTrue(metaInformation.getHasMoreResources());
PagedLinksInformation linksInformation = (PagedLinksInformation) results.getLinksInformation();
Assert.assertEquals("http://127.0.0.1/tasks?page[limit]=2", linksInformation.getFirst());
Assert.assertNull(linksInformation.getLast());
Assert.assertEquals("http://127.0.0.1/tasks?page[limit]=2", linksInformation.getPrev());
Assert.assertEquals("http://127.0.0.1/tasks?page[limit]=2&page[offset]=4", linksInformation.getNext());
}
use of io.crnk.core.queryspec.internal.QuerySpecAdapter in project crnk-framework by crnk-project.
the class HasNextBasedPagedLinksInformationTest method testPagingNoContents.
@Test
public void testPagingNoContents() throws InstantiationException, IllegalAccessException {
HasNextPageTestRepository.clear();
QuerySpecAdapter querySpec = new QuerySpecAdapter(querySpec(0L, 2L), resourceRegistry);
JsonApiResponse results = adapter.findAll(querySpec);
HasMoreResourcesMetaInformation metaInformation = (HasMoreResourcesMetaInformation) results.getMetaInformation();
Assert.assertFalse(metaInformation.getHasMoreResources());
PagedLinksInformation linksInformation = (PagedLinksInformation) results.getLinksInformation();
Assert.assertNull(linksInformation.getFirst());
Assert.assertNull(linksInformation.getLast());
Assert.assertNull(linksInformation.getPrev());
Assert.assertNull(linksInformation.getNext());
}
use of io.crnk.core.queryspec.internal.QuerySpecAdapter in project crnk-framework by crnk-project.
the class HasNextBasedPagedLinksInformationTest method testInvalidPaging.
@Test(expected = BadRequestException.class)
public void testInvalidPaging() throws InstantiationException, IllegalAccessException {
QuerySpecAdapter querySpec = new QuerySpecAdapter(querySpec(1L, 3L), resourceRegistry);
adapter.findAll(querySpec).getLinksInformation();
}
use of io.crnk.core.queryspec.internal.QuerySpecAdapter in project crnk-framework by crnk-project.
the class HasNextBasedPagedLinksInformationTest method testNoPaging.
@Test
public void testNoPaging() throws InstantiationException, IllegalAccessException {
QuerySpecAdapter querySpec = new QuerySpecAdapter(querySpec(), resourceRegistry);
JsonApiResponse results = adapter.findAll(querySpec);
HasMoreResourcesMetaInformation metaInformation = (HasMoreResourcesMetaInformation) results.getMetaInformation();
Assert.assertNull(metaInformation.getHasMoreResources());
PagedLinksInformation linksInformation = (PagedLinksInformation) results.getLinksInformation();
Assert.assertNull(linksInformation);
}
use of io.crnk.core.queryspec.internal.QuerySpecAdapter in project crnk-framework by crnk-project.
the class RelationshipsResourcePatchTest method supportPolymorphicRelationshipTypes.
@Test
public void supportPolymorphicRelationshipTypes() {
// GIVEN
Document newTaskBody = new Document();
Resource data = new Resource();
data.setType(ClassUtils.getAnnotation(Task.class, JsonApiResource.class).get().type());
newTaskBody.setData(Nullable.of((Object) data));
JsonPath taskPath = pathBuilder.build("/tasks");
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 taskIdOne = Long.parseLong(taskResponse.getDocument().getSingleData().get().getId());
assertThat(taskIdOne).isNotNull();
taskResponse = resourcePost.handle(taskPath, emptyTaskQuery, null, newTaskBody);
Long taskIdTwo = Long.parseLong(taskResponse.getDocument().getSingleData().get().getId());
assertThat(taskIdOne).isNotNull();
taskResponse = resourcePost.handle(taskPath, emptyTaskQuery, null, newTaskBody);
Long taskIdThree = Long.parseLong(taskResponse.getDocument().getSingleData().get().getId());
assertThat(taskIdOne).isNotNull();
newTaskBody = new Document();
// Create ProjectPolymorphic object
Document newProjectBody = new Document();
data = new Resource();
String type = ClassUtils.getAnnotation(ProjectPolymorphic.class, JsonApiResource.class).get().type();
data.setType(type);
data.getRelationships().put("task", new Relationship(new ResourceIdentifier(taskIdOne.toString(), "tasks")));
data.getRelationships().put("tasks", new Relationship(Arrays.asList(new ResourceIdentifier(taskIdTwo.toString(), "tasks"), new ResourceIdentifier(taskIdThree.toString(), "tasks"))));
newProjectBody.setData(Nullable.of((Object) data));
JsonPath projectPolymorphicTypePath = pathBuilder.build("/" + type);
Response projectResponse = resourcePost.handle(projectPolymorphicTypePath, emptyProjectQuery, null, newProjectBody);
assertThat(projectResponse.getDocument().getSingleData().get().getType()).isEqualTo("projects-polymorphic");
Long projectId = Long.parseLong(projectResponse.getDocument().getSingleData().get().getId());
assertThat(projectId).isNotNull();
Resource projectPolymorphic = projectResponse.getDocument().getSingleData().get();
assertNotNull(projectPolymorphic.getRelationships().get("task").getSingleData().get());
assertNotNull(projectPolymorphic.getRelationships().get("tasks"));
ProjectPolymorphicRepository resourceRepository = (ProjectPolymorphicRepository) resourceRegistry.getEntry(ProjectPolymorphic.class).getResourceRepository(null).getResourceRepository();
ProjectPolymorphic projectPolymorphicObj = resourceRepository.findOne(projectId, null);
assertEquals(2, projectPolymorphicObj.getTasks().size());
projectPolymorphicTypePath = pathBuilder.build("/" + type + "/" + projectPolymorphic.getId());
ResourcePatch resourcePatch = new ResourcePatch(resourceRegistry, PROPERTIES_PROVIDER, typeParser, objectMapper, documentMapper, modificationFilters);
data = newProjectBody.getSingleData().get();
data.setId(projectId.toString());
projectPolymorphic.setId(Long.toString(projectId));
data.getRelationships().get("tasks").setData(Nullable.of((Object) new ArrayList<ResourceIdentifier>()));
// WHEN
Response baseResponseContext = resourcePatch.handle(projectPolymorphicTypePath, new QuerySpecAdapter(new QuerySpec(ProjectPolymorphic.class), resourceRegistry), null, newProjectBody);
assertThat(baseResponseContext.getDocument().getSingleData().get().getType()).isEqualTo("projects-polymorphic");
projectId = Long.parseLong(baseResponseContext.getDocument().getSingleData().get().getId());
assertThat(projectId).isNotNull();
projectPolymorphic = baseResponseContext.getDocument().getSingleData().get();
assertNotNull(projectPolymorphic.getRelationships().get("task").getSingleData().get());
assertNotNull(projectPolymorphic.getRelationships().get("tasks"));
projectPolymorphicObj = resourceRepository.findOne(projectId, null);
assertEquals(0, projectPolymorphicObj.getTasks().size());
}
Aggregations