Search in sources :

Example 1 with ServiceDiscovery

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);
}
Also used : ProjectRepository(io.crnk.internal.boot.cdi.model.ProjectRepository) DefaultServiceDiscoveryFactory(io.crnk.core.module.discovery.DefaultServiceDiscoveryFactory) JsonApiResourceRepository(io.crnk.legacy.repository.annotations.JsonApiResourceRepository) TaskRepository(io.crnk.internal.boot.cdi.model.TaskRepository) CdiServiceDiscovery(io.crnk.cdi.internal.CdiServiceDiscovery) ServiceDiscovery(io.crnk.core.module.discovery.ServiceDiscovery) Test(org.junit.Test)

Example 2 with ServiceDiscovery

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);
}
Also used : DefaultServiceDiscoveryFactory(io.crnk.core.module.discovery.DefaultServiceDiscoveryFactory) CdiTransactionRunner(io.crnk.cdi.internal.CdiTransactionRunner) TransactionRunner(io.crnk.core.engine.transaction.TransactionRunner) ServiceDiscovery(io.crnk.core.module.discovery.ServiceDiscovery) Before(org.junit.Before)

Example 3 with ServiceDiscovery

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);
        }
    });
}
Also used : TransactionRunner(io.crnk.core.engine.transaction.TransactionRunner) List(java.util.List) ServiceDiscovery(io.crnk.core.module.discovery.ServiceDiscovery)

Example 4 with ServiceDiscovery

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);
}
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)

Example 5 with ServiceDiscovery

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());
}
Also used : ServiceDiscovery(io.crnk.core.module.discovery.ServiceDiscovery) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) Test(org.junit.Test)

Aggregations

ServiceDiscovery (io.crnk.core.module.discovery.ServiceDiscovery)5 Test (org.junit.Test)3 TransactionRunner (io.crnk.core.engine.transaction.TransactionRunner)2 DefaultServiceDiscoveryFactory (io.crnk.core.module.discovery.DefaultServiceDiscoveryFactory)2 ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)2 CdiServiceDiscovery (io.crnk.cdi.internal.CdiServiceDiscovery)1 CdiTransactionRunner (io.crnk.cdi.internal.CdiTransactionRunner)1 RequestDispatcher (io.crnk.core.engine.dispatcher.RequestDispatcher)1 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)1 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)1 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)1 ServiceUrlProvider (io.crnk.core.engine.url.ServiceUrlProvider)1 Module (io.crnk.core.module.Module)1 SimpleModule (io.crnk.core.module.SimpleModule)1 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)1 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)1 ProjectRepository (io.crnk.internal.boot.cdi.model.ProjectRepository)1 TaskRepository (io.crnk.internal.boot.cdi.model.TaskRepository)1 QueryParamsAdapter (io.crnk.legacy.internal.QueryParamsAdapter)1 QueryParams (io.crnk.legacy.queryParams.QueryParams)1