Search in sources :

Example 16 with JsonApiResponse

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());
}
Also used : HasMoreResourcesMetaInformation(io.crnk.core.resource.meta.HasMoreResourcesMetaInformation) PagedLinksInformation(io.crnk.core.resource.links.PagedLinksInformation) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 17 with JsonApiResponse

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());
}
Also used : HasMoreResourcesMetaInformation(io.crnk.core.resource.meta.HasMoreResourcesMetaInformation) PagedLinksInformation(io.crnk.core.resource.links.PagedLinksInformation) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 18 with JsonApiResponse

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);
}
Also used : HasMoreResourcesMetaInformation(io.crnk.core.resource.meta.HasMoreResourcesMetaInformation) PagedLinksInformation(io.crnk.core.resource.links.PagedLinksInformation) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) AbstractQuerySpecTest(io.crnk.core.queryspec.AbstractQuerySpecTest) Test(org.junit.Test)

Example 19 with JsonApiResponse

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());
}
Also used : JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) List(java.util.List) ErrorData(io.crnk.core.engine.document.ErrorData)

Example 20 with JsonApiResponse

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));
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) RepositoryRequestSpec(io.crnk.core.engine.dispatcher.RepositoryRequestSpec) AnnotatedRelationshipRepositoryAdapter(io.crnk.legacy.internal.AnnotatedRelationshipRepositoryAdapter) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) RepositoryFilterContext(io.crnk.core.engine.filter.RepositoryFilterContext) RelationshipRepositoryV2(io.crnk.core.repository.RelationshipRepositoryV2) BulkRelationshipRepositoryV2(io.crnk.core.repository.BulkRelationshipRepositoryV2)

Aggregations

JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)49 Document (io.crnk.core.engine.document.Document)16 Test (org.junit.Test)16 ResourceField (io.crnk.core.engine.information.resource.ResourceField)15 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)14 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)12 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)11 QuerySpec (io.crnk.core.queryspec.QuerySpec)11 RepositoryRequestSpec (io.crnk.core.engine.dispatcher.RepositoryRequestSpec)10 RepositoryFilterContext (io.crnk.core.engine.filter.RepositoryFilterContext)10 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)10 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)10 Serializable (java.io.Serializable)10 Response (io.crnk.core.engine.dispatcher.Response)9 Resource (io.crnk.core.engine.document.Resource)9 Task (io.crnk.core.mock.models.Task)7 AbstractQuerySpecTest (io.crnk.core.queryspec.AbstractQuerySpecTest)6 BulkRelationshipRepositoryV2 (io.crnk.core.repository.BulkRelationshipRepositoryV2)6 PagedLinksInformation (io.crnk.core.resource.links.PagedLinksInformation)6 HashSet (java.util.HashSet)6