Search in sources :

Example 1 with SimpleModule

use of io.crnk.core.module.SimpleModule in project crnk-framework by crnk-project.

the class ApprovalTestApplication method createApprovalModule.

// tag::approvalModule[]
public static SimpleModule createApprovalModule(ApprovalManager approvalManager) {
    FilterSpec approvalFilter = new FilterSpec(Arrays.asList("definitionKey"), FilterOperator.EQ, "scheduleChange");
    List<FilterSpec> approvalFilters = Arrays.asList(approvalFilter);
    SimpleModule module = new SimpleModule("approval");
    module.addRepositoryDecoratorFactory(ApprovalRepositoryDecorator.createFactory(approvalManager));
    module.addRepository(new ApprovalRelationshipRepository(Schedule.class, ScheduleApprovalProcessInstance.class, "approval", "approval/schedule", approvalFilters));
    return module;
}
Also used : Schedule(io.crnk.test.mock.models.Schedule) ScheduleApprovalProcessInstance(io.crnk.activiti.example.model.ScheduleApprovalProcessInstance) ApprovalRelationshipRepository(io.crnk.activiti.example.approval.ApprovalRelationshipRepository) FilterSpec(io.crnk.core.queryspec.FilterSpec) SimpleModule(io.crnk.core.module.SimpleModule)

Example 2 with SimpleModule

use of io.crnk.core.module.SimpleModule in project crnk-framework by crnk-project.

the class HomeResourceFilteringTest method setup.

@Before
public void setup() {
    filter = Mockito.mock(ResourceFilter.class);
    SimpleModule filterModule = new SimpleModule("filter");
    filterModule.addResourceFilter(filter);
    this.module = Mockito.spy(HomeModule.create());
    boot = new CrnkBoot();
    boot.addModule(module);
    boot.addModule(new TestModule());
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider("http://localhost"));
    boot.addModule(filterModule);
    boot.boot();
}
Also used : ResourceFilter(io.crnk.core.engine.filter.ResourceFilter) CrnkBoot(io.crnk.core.boot.CrnkBoot) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) TestModule(io.crnk.test.mock.TestModule) SimpleModule(io.crnk.core.module.SimpleModule) Before(org.junit.Before)

Example 3 with SimpleModule

use of io.crnk.core.module.SimpleModule in project crnk-framework by crnk-project.

the class ResourceFilterTest method prepare.

@Before
public void prepare() {
    boot = new CrnkBoot();
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider(ResourceRegistryTest.TEST_MODELS_URL));
    SimpleModule filterModule = new SimpleModule("filter");
    filterModule.addResourceFilter(filter);
    boot.addModule(filterModule);
    boot.boot();
    resourceRegistry = boot.getResourceRegistry();
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) SimpleModule(io.crnk.core.module.SimpleModule) Before(org.junit.Before)

Example 4 with SimpleModule

use of io.crnk.core.module.SimpleModule in project crnk-framework by crnk-project.

the class CrnkBootTest method setInvalidRepository.

@Test
public void setInvalidRepository() {
    SimpleModule module = new SimpleModule("test");
    module.addRepository("not a repository");
    CrnkBoot boot = new CrnkBoot();
    boot.boot();
}
Also used : SimpleModule(io.crnk.core.module.SimpleModule) Test(org.junit.Test)

Example 5 with SimpleModule

use of io.crnk.core.module.SimpleModule 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)

Aggregations

SimpleModule (io.crnk.core.module.SimpleModule)18 Before (org.junit.Before)9 CrnkBoot (io.crnk.core.boot.CrnkBoot)7 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)6 ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)5 DocumentFilter (io.crnk.core.engine.filter.DocumentFilter)3 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)3 DocumentFilterChain (io.crnk.core.engine.filter.DocumentFilterChain)2 DocumentFilterContext (io.crnk.core.engine.filter.DocumentFilterContext)2 ResourceInformationProvider (io.crnk.core.engine.information.resource.ResourceInformationProvider)2 CoreModule (io.crnk.core.engine.internal.CoreModule)2 DefaultResourceFieldInformationProvider (io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider)2 DefaultResourceInformationProvider (io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider)2 JacksonResourceFieldInformationProvider (io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider)2 NullPropertiesProvider (io.crnk.core.engine.properties.NullPropertiesProvider)2 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)2 DefaultQuerySpecConverter (io.crnk.legacy.internal.DefaultQuerySpecConverter)2 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ApprovalRelationshipRepository (io.crnk.activiti.example.approval.ApprovalRelationshipRepository)1