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));
}
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"));
}
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();
}
Aggregations