Search in sources :

Example 11 with ModuleRegistry

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

the class CrnkBootTest method testServiceDiscovery.

@Test
public void testServiceDiscovery() {
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceDiscoveryFactory(serviceDiscoveryFactory);
    boot.setServiceUrlProvider(mock(ServiceUrlProvider.class));
    Module module = mock(Module.class);
    DocumentFilter filter = mock(DocumentFilter.class);
    JsonApiExceptionMapper exceptionMapper = new TestExceptionMapper();
    Mockito.when(serviceDiscovery.getInstancesByType(eq(DocumentFilter.class))).thenReturn(Arrays.asList(filter));
    Mockito.when(serviceDiscovery.getInstancesByType(eq(Module.class))).thenReturn(Arrays.asList(module));
    Mockito.when(serviceDiscovery.getInstancesByType(eq(JsonApiExceptionMapper.class))).thenReturn(Arrays.asList(exceptionMapper));
    boot.boot();
    ModuleRegistry moduleRegistry = boot.getModuleRegistry();
    Assert.assertTrue(moduleRegistry.getModules().contains(module));
    Assert.assertTrue(moduleRegistry.getFilters().contains(filter));
    Assert.assertTrue(moduleRegistry.getExceptionMapperLookup().getExceptionMappers().contains(exceptionMapper));
}
Also used : ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) ServiceUrlProvider(io.crnk.core.engine.url.ServiceUrlProvider) ModuleRegistry(io.crnk.core.module.ModuleRegistry) DocumentFilter(io.crnk.core.engine.filter.DocumentFilter) SimpleModule(io.crnk.core.module.SimpleModule) Module(io.crnk.core.module.Module) JsonApiExceptionMapper(io.crnk.core.engine.error.JsonApiExceptionMapper) Test(org.junit.Test)

Example 12 with ModuleRegistry

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

the class OffsetLimitPagingBehaviorTest method testBuild.

@Test
public void testBuild() {
    PagingBehavior pagingBehavior = new OffsetLimitPagingBehavior();
    OffsetLimitPagingSpec pagingSpec = new OffsetLimitPagingSpec(0L, 10L);
    ModuleRegistry moduleRegistry = new ModuleRegistry();
    ResourceRegistry resourceRegistry = new ResourceRegistryImpl(new DefaultResourceRegistryPart(), moduleRegistry);
    QuerySpec spec = new QuerySpec(Task.class);
    QuerySpecAdapter querySpecAdapter = new QuerySpecAdapter(spec, resourceRegistry);
    querySpecAdapter.setPagingSpec(pagingSpec);
    PagingSpecUrlBuilder urlBuilder = mock(PagingSpecUrlBuilder.class);
    when(urlBuilder.build(any(QuerySpecAdapter.class))).thenReturn("http://some.org");
    DefaultPagedMetaInformation pagedMetaInformation = new DefaultPagedMetaInformation();
    pagedMetaInformation.setTotalResourceCount(30L);
    ResourceList resourceList = new DefaultResourceList(pagedMetaInformation, null);
    for (int i = 0; i < 30; i++) {
        resourceList.add(new Task());
    }
    PagedLinksInformation pagedLinksInformation = new DefaultPagedLinksInformation();
    pagingBehavior.build(pagedLinksInformation, resourceList, querySpecAdapter, urlBuilder);
    assertThat(pagedLinksInformation.getFirst(), equalTo("http://some.org"));
    assertThat(pagedLinksInformation.getNext(), equalTo("http://some.org"));
    assertNull(pagedLinksInformation.getPrev());
    assertThat(pagedLinksInformation.getLast(), equalTo("http://some.org"));
}
Also used : Task(io.crnk.core.mock.models.Task) DefaultPagedLinksInformation(io.crnk.core.resource.links.DefaultPagedLinksInformation) ModuleRegistry(io.crnk.core.module.ModuleRegistry) ResourceRegistryImpl(io.crnk.core.engine.internal.registry.ResourceRegistryImpl) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) DefaultPagedMetaInformation(io.crnk.core.resource.meta.DefaultPagedMetaInformation) ResourceList(io.crnk.core.resource.list.ResourceList) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) DefaultResourceList(io.crnk.core.resource.list.DefaultResourceList) DefaultPagedLinksInformation(io.crnk.core.resource.links.DefaultPagedLinksInformation) PagedLinksInformation(io.crnk.core.resource.links.PagedLinksInformation) DefaultResourceRegistryPart(io.crnk.core.engine.registry.DefaultResourceRegistryPart) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test)

Example 13 with ModuleRegistry

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

the class MetaModuleTest method createRegistryEntry.

private RegistryEntry createRegistryEntry() {
    ModuleRegistry moduleRegistry = boot.getModuleRegistry();
    RegistryEntryBuilder entryBuilder = moduleRegistry.getContext().newRegistryEntryBuilder();
    entryBuilder.resource().resourceClass(Task.class).resourceType("someNewTask");
    entryBuilder.resourceRepository().instance(new TaskRepository());
    return entryBuilder.build();
}
Also used : Task(io.crnk.test.mock.models.Task) RegistryEntryBuilder(io.crnk.core.engine.registry.RegistryEntryBuilder) TaskRepository(io.crnk.test.mock.repository.TaskRepository) ModuleRegistry(io.crnk.core.module.ModuleRegistry)

Aggregations

ModuleRegistry (io.crnk.core.module.ModuleRegistry)13 ResourceRegistryImpl (io.crnk.core.engine.internal.registry.ResourceRegistryImpl)6 DefaultResourceRegistryPart (io.crnk.core.engine.registry.DefaultResourceRegistryPart)6 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)5 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)5 Before (org.junit.Before)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)4 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)4 Test (org.junit.Test)4 TypeParser (io.crnk.core.engine.parser.TypeParser)3 CoreModule (io.crnk.core.engine.internal.CoreModule)2 DefaultInformationBuilder (io.crnk.core.engine.internal.information.DefaultInformationBuilder)2 ResourceRepositoryInformationImpl (io.crnk.core.engine.internal.information.repository.ResourceRepositoryInformationImpl)2 DefaultResourceFieldInformationProvider (io.crnk.core.engine.internal.information.resource.DefaultResourceFieldInformationProvider)2 DefaultResourceInformationProvider (io.crnk.core.engine.internal.information.resource.DefaultResourceInformationProvider)2 JacksonModule (io.crnk.core.engine.internal.jackson.JacksonModule)2 JacksonResourceFieldInformationProvider (io.crnk.core.engine.internal.jackson.JacksonResourceFieldInformationProvider)2 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)2 Task (io.crnk.core.mock.models.Task)2