Search in sources :

Example 1 with DefaultResourceRegistryPart

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

the class ModuleRegistryTest method setup.

@Before
public void setup() {
    moduleRegistry = new ModuleRegistry();
    moduleRegistry.getHttpRequestContextProvider().setServiceUrlProvider(new ConstantServiceUrlProvider("http://localhost"));
    resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
    testModule = new TestModule();
    moduleRegistry.addModule(testModule);
    moduleRegistry.addModule(new CoreModule());
    moduleRegistry.addModule(new JacksonModule(new ObjectMapper(), false, ImmutableList.of(new OffsetLimitPagingBehavior())));
    moduleRegistry.setServiceDiscovery(serviceDiscovery);
    moduleRegistry.init(new ObjectMapper());
    Assert.assertEquals(resourceRegistry, moduleRegistry.getResourceRegistry());
}
Also used : OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) ResourceRegistryImpl(io.crnk.core.engine.internal.registry.ResourceRegistryImpl) DefaultResourceRegistryPart(io.crnk.core.engine.registry.DefaultResourceRegistryPart) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) CoreModule(io.crnk.core.engine.internal.CoreModule) JacksonModule(io.crnk.core.engine.internal.jackson.JacksonModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 2 with DefaultResourceRegistryPart

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

the class ResourceRegistryTest method resetResourceRegistry.

@Before
public void resetResourceRegistry() {
    moduleRegistry = new ModuleRegistry();
    moduleRegistry.getHttpRequestContextProvider().setServiceUrlProvider(new ConstantServiceUrlProvider(TEST_MODELS_URL));
    resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
}
Also used : ModuleRegistry(io.crnk.core.module.ModuleRegistry) ResourceRegistryImpl(io.crnk.core.engine.internal.registry.ResourceRegistryImpl) DefaultResourceRegistryPart(io.crnk.core.engine.registry.DefaultResourceRegistryPart) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) Before(org.junit.Before)

Example 3 with DefaultResourceRegistryPart

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

the class QueryParamsAdapterTest method test.

@Test
public void test() {
    ModuleRegistry moduleRegistry = new ModuleRegistry();
    moduleRegistry.getHttpRequestContextProvider().setServiceUrlProvider(new ConstantServiceUrlProvider("http://localhost"));
    ResourceRegistry resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
    QueryParams params = new QueryParams();
    DefaultResourceInformationProvider builder = new DefaultResourceInformationProvider(new NullPropertiesProvider(), new OffsetLimitPagingBehavior(), new DefaultResourceFieldInformationProvider(), new JacksonResourceFieldInformationProvider());
    builder.init(new DefaultResourceInformationProviderContext(builder, new DefaultInformationBuilder(moduleRegistry.getTypeParser()), moduleRegistry.getTypeParser(), new ObjectMapper()));
    ResourceInformation info = builder.build(Task.class);
    QueryParamsAdapter adapter = new QueryParamsAdapter(info, params, moduleRegistry);
    Assert.assertEquals(Task.class, adapter.getResourceInformation().getResourceClass());
    Assert.assertEquals(resourceRegistry, adapter.getResourceRegistry());
}
Also used : OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ModuleRegistry(io.crnk.core.module.ModuleRegistry) ResourceRegistryImpl(io.crnk.core.engine.internal.registry.ResourceRegistryImpl) NullPropertiesProvider(io.crnk.core.engine.properties.NullPropertiesProvider) DefaultResourceInformationProviderContext(io.crnk.legacy.registry.DefaultResourceInformationProviderContext) DefaultResourceInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) JacksonResourceFieldInformationProvider(io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider) DefaultInformationBuilder(io.crnk.core.engine.internal.information.DefaultInformationBuilder) DefaultResourceRegistryPart(io.crnk.core.engine.registry.DefaultResourceRegistryPart) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) QueryParamsAdapter(io.crnk.legacy.internal.QueryParamsAdapter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultResourceFieldInformationProvider(io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider) Test(org.junit.Test)

Example 4 with DefaultResourceRegistryPart

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

the class QuerySpecAdapterTest method test.

@Test
public void test() {
    ModuleRegistry moduleRegistry = new ModuleRegistry();
    ResourceRegistry resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
    ResourceInformation resourceInformation = new ResourceInformation(moduleRegistry.getTypeParser(), Task.class, "tasks", null, null, new OffsetLimitPagingBehavior());
    resourceRegistry.addEntry(new RegistryEntry(new DirectResponseResourceEntry(null, new ResourceRepositoryInformationImpl("tasks", resourceInformation, RepositoryMethodAccess.ALL))));
    QuerySpec spec = new QuerySpec(Task.class);
    spec.includeField(Arrays.asList("test"));
    spec.includeRelation(Arrays.asList("relation"));
    QuerySpecAdapter adapter = new QuerySpecAdapter(spec, resourceRegistry);
    Assert.assertEquals(Task.class, adapter.getResourceInformation().getResourceClass());
    Assert.assertEquals(spec, adapter.getQuerySpec());
    TypedParams<IncludedFieldsParams> includedFields = adapter.getIncludedFields();
    IncludedFieldsParams includedFieldsParams = includedFields.getParams().get("tasks");
    Assert.assertEquals(1, includedFieldsParams.getParams().size());
    Assert.assertEquals("test", includedFieldsParams.getParams().iterator().next());
    TypedParams<IncludedRelationsParams> includedRelations = adapter.getIncludedRelations();
    IncludedRelationsParams includedRelationsParams = includedRelations.getParams().get("tasks");
    Assert.assertEquals(1, includedRelationsParams.getParams().size());
    Assert.assertEquals("relation", includedRelationsParams.getParams().iterator().next().getPath());
    Assert.assertEquals(new OffsetLimitPagingSpec(), adapter.getPagingSpec());
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) DirectResponseResourceEntry(io.crnk.legacy.internal.DirectResponseResourceEntry) OffsetLimitPagingSpec(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingSpec) ModuleRegistry(io.crnk.core.module.ModuleRegistry) ResourceRegistryImpl(io.crnk.core.engine.internal.registry.ResourceRegistryImpl) IncludedRelationsParams(io.crnk.legacy.queryParams.params.IncludedRelationsParams) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) IncludedFieldsParams(io.crnk.legacy.queryParams.params.IncludedFieldsParams) ResourceRepositoryInformationImpl(io.crnk.core.engine.internal.information.repository.ResourceRepositoryInformationImpl) DefaultResourceRegistryPart(io.crnk.core.engine.registry.DefaultResourceRegistryPart) Test(org.junit.Test)

Example 5 with DefaultResourceRegistryPart

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

the class SecurityModuleTest method setup.

@Before
public void setup() {
    // TODO simplify ones simple module is fixed
    SimpleModule appModule = new SimpleModule("app") {

        @Override
        public void setupModule(ModuleContext context) {
            super.setupModule(context);
            context.addSecurityProvider(new SecurityProvider() {

                @Override
                public boolean isUserInRole(String role) {
                    return role.equals(allowedRule);
                }
            });
        }
    };
    appModule.addRepository(new TaskRepository());
    appModule.addRepository(new ProjectRepository());
    Builder builder = SecurityConfig.builder();
    builder.permitAll(ResourcePermission.GET);
    builder.permitRole("taskRole", Task.class, ResourcePermission.ALL);
    builder.permitRole("projectRole", "projects", ResourcePermission.POST);
    SecurityConfig config = builder.build();
    securityModule = SecurityModule.newServerModule(config);
    Assert.assertSame(config, securityModule.getConfig());
    ModuleRegistry moduleRegistry = new ModuleRegistry();
    moduleRegistry.setServiceDiscovery(new EmptyServiceDiscovery());
    moduleRegistry.setResourceRegistry(new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry));
    moduleRegistry.addModule(securityModule);
    moduleRegistry.addModule(appModule);
    moduleRegistry.addModule(new JacksonModule(new ObjectMapper(), false, ImmutableList.of(new OffsetLimitPagingBehavior())));
    moduleRegistry.addModule(new CoreModule());
    moduleRegistry.init(new ObjectMapper());
}
Also used : OffsetLimitPagingBehavior(io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior) ProjectRepository(io.crnk.security.model.ProjectRepository) TaskRepository(io.crnk.security.model.TaskRepository) Builder(io.crnk.security.SecurityConfig.Builder) ModuleRegistry(io.crnk.core.module.ModuleRegistry) ResourceRegistryImpl(io.crnk.core.engine.internal.registry.ResourceRegistryImpl) JacksonModule(io.crnk.core.engine.internal.jackson.JacksonModule) SecurityProvider(io.crnk.core.engine.security.SecurityProvider) DefaultResourceRegistryPart(io.crnk.core.engine.registry.DefaultResourceRegistryPart) CoreModule(io.crnk.core.engine.internal.CoreModule) SimpleModule(io.crnk.core.module.SimpleModule) EmptyServiceDiscovery(io.crnk.core.module.discovery.EmptyServiceDiscovery) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Aggregations

ResourceRegistryImpl (io.crnk.core.engine.internal.registry.ResourceRegistryImpl)7 DefaultResourceRegistryPart (io.crnk.core.engine.registry.DefaultResourceRegistryPart)7 ModuleRegistry (io.crnk.core.module.ModuleRegistry)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)4 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)4 Before (org.junit.Before)4 CoreModule (io.crnk.core.engine.internal.CoreModule)3 JacksonModule (io.crnk.core.engine.internal.jackson.JacksonModule)3 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)3 Test (org.junit.Test)3 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)2 EmptyServiceDiscovery (io.crnk.core.module.discovery.EmptyServiceDiscovery)2 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)2 DefaultInformationBuilder (io.crnk.core.engine.internal.information.DefaultInformationBuilder)1 ResourceRepositoryInformationImpl (io.crnk.core.engine.internal.information.repository.ResourceRepositoryInformationImpl)1 DefaultResourceFieldInformationProvider (io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider)1 DefaultResourceInformationProvider (io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider)1 JacksonResourceFieldInformationProvider (io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider)1 NullPropertiesProvider (io.crnk.core.engine.properties.NullPropertiesProvider)1