use of io.crnk.core.module.discovery.ServiceDiscovery in project crnk-framework by crnk-project.
the class CdiServiceDiscoveryTest method testFactory.
@Test
public void testFactory() {
DefaultServiceDiscoveryFactory factory = new DefaultServiceDiscoveryFactory();
ServiceDiscovery instance = factory.getInstance();
Assert.assertNotNull(instance);
Assert.assertEquals(CdiServiceDiscovery.class, instance.getClass());
List<?> repositories = instance.getInstancesByType(Repository.class);
Assert.assertEquals(1, repositories.size());
Assert.assertTrue(repositories.get(0) instanceof ProjectRepository);
repositories = instance.getInstancesByAnnotation(JsonApiResourceRepository.class);
Assert.assertEquals(1, repositories.size());
Assert.assertTrue(repositories.get(0) instanceof TaskRepository);
}
use of io.crnk.core.module.discovery.ServiceDiscovery in project crnk-framework by crnk-project.
the class CdiTransactionRunnerTest method setup.
@Before
public void setup() {
DefaultServiceDiscoveryFactory factory = new DefaultServiceDiscoveryFactory();
ServiceDiscovery instance = factory.getInstance();
List<TransactionRunner> runners = instance.getInstancesByType(TransactionRunner.class);
Assert.assertEquals(1, runners.size());
runner = runners.get(0);
}
use of io.crnk.core.module.discovery.ServiceDiscovery in project crnk-framework by crnk-project.
the class TransactionOperationFilter method filter.
@Override
public List<OperationResponse> filter(final OperationFilterContext context, final OperationFilterChain chain) {
ServiceDiscovery serviceDiscovery = context.getServiceDiscovery();
List<TransactionRunner> transactionRunners = serviceDiscovery.getInstancesByType(TransactionRunner.class);
PreconditionUtil.assertEquals("expected single transaction runner", 1, transactionRunners.size());
TransactionRunner transactionRunner = transactionRunners.get(0);
return transactionRunner.doInTransaction(new Callable<List<OperationResponse>>() {
@Override
public List<OperationResponse> call() throws Exception {
return chain.doFilter(context);
}
});
}
use of io.crnk.core.module.discovery.ServiceDiscovery 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);
}
use of io.crnk.core.module.discovery.ServiceDiscovery in project crnk-framework by crnk-project.
the class CrnkBootTest method setServiceDiscovery.
@Test
public void setServiceDiscovery() {
CrnkBoot boot = new CrnkBoot();
ServiceDiscovery serviceDiscovery = mock(ServiceDiscovery.class);
boot.setServiceDiscovery(serviceDiscovery);
Assert.assertSame(serviceDiscovery, boot.getServiceDiscovery());
}
Aggregations