Search in sources :

Example 6 with ResourceRegistry

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

the class FieldResourceGetTest method onNonRelationRequestShouldDenyIt.

@Test
public void onNonRelationRequestShouldDenyIt() {
    // GIVEN
    JsonPath jsonPath = new ResourcePath("tasks");
    ResourceRegistry resourceRegistry = mock(ResourceRegistry.class);
    FieldResourceGet sut = new FieldResourceGet(resourceRegistry, typeParser, documentMapper);
    // WHEN
    boolean result = sut.isAcceptable(jsonPath, REQUEST_TYPE);
    // THEN
    assertThat(result).isFalse();
}
Also used : ResourcePath(io.crnk.core.engine.internal.dispatcher.path.ResourcePath) FieldResourceGet(io.crnk.core.engine.internal.dispatcher.controller.FieldResourceGet) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) BaseControllerTest(io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest) Test(org.junit.Test)

Example 7 with ResourceRegistry

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

the class FieldResourceGetTest method onRelationshipRequestShouldDenyIt.

@Test
public void onRelationshipRequestShouldDenyIt() {
    // GIVEN
    JsonPath jsonPath = new ResourcePath("tasks/1/relationships/project");
    ResourceRegistry resourceRegistry = mock(ResourceRegistry.class);
    FieldResourceGet sut = new FieldResourceGet(resourceRegistry, typeParser, documentMapper);
    // WHEN
    boolean result = sut.isAcceptable(jsonPath, REQUEST_TYPE);
    // THEN
    assertThat(result).isFalse();
}
Also used : ResourcePath(io.crnk.core.engine.internal.dispatcher.path.ResourcePath) FieldResourceGet(io.crnk.core.engine.internal.dispatcher.controller.FieldResourceGet) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) BaseControllerTest(io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest) Test(org.junit.Test)

Example 8 with ResourceRegistry

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

the class FieldResourceGetTest method onValidRequestShouldAcceptIt.

@Test
public void onValidRequestShouldAcceptIt() {
    // GIVEN
    JsonPath jsonPath = pathBuilder.build("tasks/1/project");
    ResourceRegistry resourceRegistry = mock(ResourceRegistry.class);
    FieldResourceGet sut = new FieldResourceGet(resourceRegistry, typeParser, documentMapper);
    // WHEN
    boolean result = sut.isAcceptable(jsonPath, REQUEST_TYPE);
    // THEN
    assertThat(result).isTrue();
}
Also used : FieldResourceGet(io.crnk.core.engine.internal.dispatcher.controller.FieldResourceGet) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) BaseControllerTest(io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest) Test(org.junit.Test)

Example 9 with ResourceRegistry

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

the class CrnkBootTest method boot.

@Test
public void boot() {
    CrnkBoot boot = new CrnkBoot();
    boot.setDefaultServiceUrlProvider(new ServiceUrlProvider() {

        @Override
        public String getUrl() {
            return "http://127.0.0.1";
        }
    });
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
    boot.addModule(new SimpleModule("test"));
    boot.boot();
    RequestDispatcher requestDispatcher = boot.getRequestDispatcher();
    ResourceRegistry resourceRegistry = boot.getResourceRegistry();
    RegistryEntry taskEntry = resourceRegistry.getEntry(Task.class);
    Assert.assertNotEquals(0, taskEntry.getRelationshipEntries().size());
    ResourceRepositoryAdapter<?, ?> repositoryAdapter = taskEntry.getResourceRepository(null);
    Assert.assertNotNull(repositoryAdapter.getResourceRepository());
    JsonApiResponse response = repositoryAdapter.findAll(new QueryParamsAdapter(taskEntry.getResourceInformation(), new QueryParams(), boot.getModuleRegistry()));
    Assert.assertNotNull(response);
    Assert.assertNotNull(requestDispatcher);
    ServiceDiscovery serviceDiscovery = boot.getServiceDiscovery();
    Assert.assertNotNull(serviceDiscovery);
    Assert.assertNotNull(boot.getModuleRegistry());
    Assert.assertNotNull(boot.getExceptionMapperRegistry());
    List<Module> modules = boot.getModuleRegistry().getModules();
    Assert.assertEquals(4, modules.size());
    boot.setDefaultPageLimit(20L);
    boot.setMaxPageLimit(100L);
    Assert.assertEquals(1, boot.getPagingBehaviors().size());
    Assert.assertTrue(boot.getPagingBehaviors().get(0) instanceof OffsetLimitPagingBehavior);
}
Also used : OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) ServiceUrlProvider(io.crnk.core.engine.url.ServiceUrlProvider) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) RequestDispatcher(io.crnk.core.engine.dispatcher.RequestDispatcher) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) QueryParams(io.crnk.legacy.queryParams.QueryParams) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) QueryParamsAdapter(io.crnk.legacy.internal.QueryParamsAdapter) SimpleModule(io.crnk.core.module.SimpleModule) Module(io.crnk.core.module.Module) SimpleModule(io.crnk.core.module.SimpleModule) ServiceDiscovery(io.crnk.core.module.discovery.ServiceDiscovery) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) Test(org.junit.Test)

Example 10 with ResourceRegistry

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

the class ResourceMetaFilter method getResourceInformation.

private ResourceInformation getResourceInformation(MetaResourceBase meta, boolean allowNull) {
    ResourceRegistry resourceRegistry = context.getModuleContext().getResourceRegistry();
    if (meta instanceof MetaResource) {
        RegistryEntry entry = resourceRegistry.getEntry(((MetaResource) meta).getResourceType());
        if (entry != null) {
            return entry.getResourceInformation();
        }
    }
    Class<?> resourceClass = meta.getImplementationClass();
    ResourceInformationProvider infoBuilder = context.getModuleContext().getResourceInformationBuilder();
    if (infoBuilder.accept(resourceClass)) {
        return infoBuilder.build(resourceClass);
    }
    if (allowNull) {
        return null;
    }
    throw new IllegalStateException("failed to get information for " + resourceClass.getName());
}
Also used : MetaResource(io.crnk.meta.model.resource.MetaResource) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) ResourceInformationProvider(io.crnk.core.engine.information.resource.ResourceInformationProvider) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Aggregations

ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)48 Test (org.junit.Test)25 JsonPath (io.crnk.core.engine.internal.dispatcher.path.JsonPath)21 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)19 BaseControllerTest (io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest)17 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)15 ResourcePath (io.crnk.core.engine.internal.dispatcher.path.ResourcePath)10 ResourceField (io.crnk.core.engine.information.resource.ResourceField)5 PathBuilder (io.crnk.core.engine.internal.dispatcher.path.PathBuilder)4 ModuleRegistry (io.crnk.core.module.ModuleRegistry)4 QueryParamsAdapter (io.crnk.legacy.internal.QueryParamsAdapter)4 Before (org.junit.Before)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 FieldResourceGet (io.crnk.core.engine.internal.dispatcher.controller.FieldResourceGet)3 RelationshipsResourceGet (io.crnk.core.engine.internal.dispatcher.controller.RelationshipsResourceGet)3 ResourceRegistryImpl (io.crnk.core.engine.internal.registry.ResourceRegistryImpl)3 DefaultResourceRegistryPart (io.crnk.core.engine.registry.DefaultResourceRegistryPart)3 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)3 RequestDispatcher (io.crnk.core.engine.dispatcher.RequestDispatcher)2 ResourceModificationFilter (io.crnk.core.engine.filter.ResourceModificationFilter)2