Search in sources :

Example 56 with RegistryEntry

use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.

the class DefaultQuerySpecSerializerTest method testPagingOnRelation.

@Test
public void testPagingOnRelation() throws InstantiationException, IllegalAccessException {
    QuerySpec querySpec = new QuerySpec(Task.class);
    querySpec.setLimit(2L);
    querySpec.setOffset(1L);
    RegistryEntry entry = resourceRegistry.getEntry(Task.class);
    String actualUrl = urlBuilder.buildUrl(entry.getResourceInformation(), 1L, querySpec, "projects");
    assertEquals("http://127.0.0.1/tasks/1/relationships/projects?page[limit]=2&page[offset]=1", actualUrl);
}
Also used : RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) Test(org.junit.Test)

Example 57 with RegistryEntry

use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.

the class BasicProxyFactory method createResourceProxy.

@Override
public <T> T createResourceProxy(Class<T> clazz, Object id) {
    T instance = ClassUtils.newInstance(clazz);
    ResourceRegistry resourceRegistry = context.getModuleRegistry().getResourceRegistry();
    RegistryEntry entry = resourceRegistry.findEntry(clazz);
    ResourceInformation resourceInformation = entry.getResourceInformation();
    resourceInformation.setId(instance, id);
    return instance;
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 58 with RegistryEntry

use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.

the class ResourceIdControllerTest method toQueryAdapter.

private QueryAdapter toQueryAdapter(QueryParams requestParams, Class resourceType) {
    ResourceRegistry resourceRegistry = moduleRegistry.getResourceRegistry();
    RegistryEntry entry = resourceRegistry.getEntry(resourceType);
    ResourceInformation resourceInformation = entry.getResourceInformation();
    return new QueryParamsAdapter(resourceInformation, requestParams, moduleRegistry);
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) QueryParamsAdapter(io.crnk.legacy.internal.QueryParamsAdapter) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 59 with RegistryEntry

use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.

the class ResourceFilterDirectoryImplTest method checkForbiddenRelationshipsField.

@Test
public void checkForbiddenRelationshipsField() {
    ResourceInformation projectsInformation = Mockito.mock(ResourceInformation.class);
    Mockito.when(filter.filterField(Mockito.eq(resourceField), Mockito.any(HttpMethod.class))).thenReturn(FilterBehavior.NONE);
    Mockito.when(resourceField.getResourceFieldType()).thenReturn(ResourceFieldType.RELATIONSHIP);
    Mockito.when(resourceField.getOppositeResourceType()).thenReturn("projects");
    RegistryEntry projectsEntry = Mockito.mock(RegistryEntry.class);
    Mockito.when(projectsEntry.getResourceInformation()).thenReturn(projectsInformation);
    Mockito.when(resourceRegistry.getEntry(Mockito.eq("projects"))).thenReturn(projectsEntry);
    // forbid related resource
    Mockito.when(filter.filterResource(Mockito.eq(projectsInformation), Mockito.any(HttpMethod.class))).thenReturn(FilterBehavior.FORBIDDEN);
    Assert.assertEquals(FilterBehavior.FORBIDDEN, directory.get(resourceField, HttpMethod.GET));
    // allow related resource
    Mockito.when(filter.filterResource(Mockito.eq(projectsInformation), Mockito.any(HttpMethod.class))).thenReturn(FilterBehavior.NONE);
    Assert.assertEquals(FilterBehavior.NONE, directory.get(resourceField, HttpMethod.GET));
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) HttpMethod(io.crnk.core.engine.http.HttpMethod) Test(org.junit.Test)

Example 60 with RegistryEntry

use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.

the class RelationshipRepositoryBehaviorTest method checkRelationIdTriggersImplicitOwnerRepo.

@Test
public void checkRelationIdTriggersImplicitOwnerRepo() {
    RegistryEntry entry = resourceRegistry.getEntry(RelationshipBehaviorTestResource.class);
    Object relRepository = entry.getRelationshipRepository("testRelationId", null).getRelationshipRepository();
    Assert.assertEquals(ForwardingRelationshipRepository.class, relRepository.getClass());
}
Also used : RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) ResourceRegistryTest(io.crnk.core.resource.registry.ResourceRegistryTest) Test(org.junit.Test)

Aggregations

RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)119 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)60 Test (org.junit.Test)38 ResourceField (io.crnk.core.engine.information.resource.ResourceField)36 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)19 QuerySpec (io.crnk.core.queryspec.QuerySpec)18 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)14 Serializable (java.io.Serializable)14 Task (io.crnk.core.mock.models.Task)13 Response (io.crnk.core.engine.dispatcher.Response)12 Document (io.crnk.core.engine.document.Document)11 Resource (io.crnk.core.engine.document.Resource)11 ResourceRegistryTest (io.crnk.core.resource.registry.ResourceRegistryTest)10 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)9 FilterSpec (io.crnk.core.queryspec.FilterSpec)9 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)8 Before (org.junit.Before)8 Collection (java.util.Collection)7 HashSet (java.util.HashSet)7 HttpMethod (io.crnk.core.engine.http.HttpMethod)6