use of io.crnk.core.repository.response.JsonApiResponse 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.repository.response.JsonApiResponse 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.repository.response.JsonApiResponse 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.repository.response.JsonApiResponse in project crnk-framework by crnk-project.
the class TestExceptionMapper method fromErrorResponse.
@Override
public TestException fromErrorResponse(ErrorResponse errorResponse) {
JsonApiResponse response = errorResponse.getResponse();
List<ErrorData> errors = (List<ErrorData>) response.getEntity();
StringBuilder message = new StringBuilder();
for (ErrorData error : errors) {
String title = error.getDetail();
message.append(title);
}
return new TestException(message.toString());
}
use of io.crnk.core.repository.response.JsonApiResponse in project crnk-framework by crnk-project.
the class RelationshipRepositoryAdapter method removeRelations.
@SuppressWarnings("rawtypes")
public JsonApiResponse removeRelations(T source, Iterable<J> targetIds, ResourceField field, QueryAdapter queryAdapter) {
RepositoryRequestFilterChainImpl chain = new RepositoryRequestFilterChainImpl() {
@Override
protected JsonApiResponse invoke(RepositoryFilterContext context) {
RepositoryRequestSpec request = context.getRequest();
Object source = request.getEntity();
Iterable<?> targetIds = request.getIds();
ResourceField field = request.getRelationshipField();
QueryAdapter queryAdapter = request.getQueryAdapter();
if (isAnnotated) {
((AnnotatedRelationshipRepositoryAdapter) relationshipRepository).removeRelations(source, targetIds, field.getUnderlyingName(), queryAdapter);
} else if (relationshipRepository instanceof RelationshipRepositoryV2) {
((RelationshipRepositoryV2) relationshipRepository).removeRelations(source, targetIds, field.getUnderlyingName());
} else {
((RelationshipRepository) relationshipRepository).removeRelations(source, targetIds, field.getUnderlyingName());
}
return new JsonApiResponse();
}
};
RepositoryRequestSpec requestSpec = RepositoryRequestSpecImpl.forRelation(moduleRegistry, HttpMethod.DELETE, source, queryAdapter, targetIds, field);
return chain.doFilter(newRepositoryFilterContext(requestSpec));
}
Aggregations