Search in sources :

Example 1 with ServiceUrlProvider

use of io.crnk.core.engine.url.ServiceUrlProvider in project crnk-framework by crnk-project.

the class CrnkFeatureTest method testServiceServiceUrlProvider.

@Test
public void testServiceServiceUrlProvider() {
    CrnkFeature feature = new CrnkFeature();
    ServiceUrlProvider serviceUrlProvider = Mockito.mock(ServiceUrlProvider.class);
    feature.setServiceUrlProvider(serviceUrlProvider);
    Assert.assertSame(serviceUrlProvider, feature.getBoot().getServiceUrlProvider());
}
Also used : ServiceUrlProvider(io.crnk.core.engine.url.ServiceUrlProvider) Test(org.junit.Test)

Example 2 with ServiceUrlProvider

use of io.crnk.core.engine.url.ServiceUrlProvider in project crnk-framework by crnk-project.

the class CrnkBootTest method setConstantServiceUrlProvider.

@Test
public void setConstantServiceUrlProvider() {
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceDiscoveryFactory(serviceDiscoveryFactory);
    final Properties properties = new Properties();
    properties.put(CrnkProperties.RESOURCE_DEFAULT_DOMAIN, "http://something");
    PropertiesProvider propertiesProvider = new PropertiesProvider() {

        @Override
        public String getProperty(String key) {
            return (String) properties.get(key);
        }
    };
    boot.setPropertiesProvider(propertiesProvider);
    boot.boot();
    ServiceUrlProvider serviceUrlProvider = boot.getServiceUrlProvider();
    Assert.assertTrue(serviceUrlProvider instanceof ConstantServiceUrlProvider);
    Assert.assertEquals("http://something", serviceUrlProvider.getUrl());
}
Also used : PropertiesProvider(io.crnk.core.engine.properties.PropertiesProvider) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) ServiceUrlProvider(io.crnk.core.engine.url.ServiceUrlProvider) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with ServiceUrlProvider

use of io.crnk.core.engine.url.ServiceUrlProvider 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 4 with ServiceUrlProvider

use of io.crnk.core.engine.url.ServiceUrlProvider in project crnk-framework by crnk-project.

the class CrnkBootTest method setDefaultServiceUrlProvider.

@Test
public void setDefaultServiceUrlProvider() {
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceDiscoveryFactory(serviceDiscoveryFactory);
    ServiceUrlProvider serviceUrlProvider = mock(ServiceUrlProvider.class);
    boot.setDefaultServiceUrlProvider(serviceUrlProvider);
    boot.boot();
    Assert.assertEquals(serviceUrlProvider, boot.getDefaultServiceUrlProvider());
    Assert.assertEquals(serviceUrlProvider, boot.getServiceUrlProvider());
    Assert.assertEquals(serviceUrlProvider, boot.getServiceUrlProvider());
}
Also used : ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) ServiceUrlProvider(io.crnk.core.engine.url.ServiceUrlProvider) Test(org.junit.Test)

Example 5 with ServiceUrlProvider

use of io.crnk.core.engine.url.ServiceUrlProvider in project crnk-framework by crnk-project.

the class JerseyActionStubFactory method createStub.

@Override
public <T> T createStub(Class<T> interfaceClass) {
    ServiceUrlProvider serviceUrlProvider = context.getServiceUrlProvider();
    String serviceUrl = serviceUrlProvider.getUrl();
    WebTarget target = client.target(serviceUrl);
    return WebResourceFactory.newResource(interfaceClass, target);
}
Also used : ServiceUrlProvider(io.crnk.core.engine.url.ServiceUrlProvider) WebTarget(javax.ws.rs.client.WebTarget)

Aggregations

ServiceUrlProvider (io.crnk.core.engine.url.ServiceUrlProvider)6 Test (org.junit.Test)5 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)4 RequestDispatcher (io.crnk.core.engine.dispatcher.RequestDispatcher)1 PropertiesProvider (io.crnk.core.engine.properties.PropertiesProvider)1 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)1 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)1 Module (io.crnk.core.module.Module)1 SimpleModule (io.crnk.core.module.SimpleModule)1 ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)1 ServiceDiscovery (io.crnk.core.module.discovery.ServiceDiscovery)1 OffsetLimitPagingBehavior (io.crnk.core.queryspec.pagingspec.OffsetLimitPagingBehavior)1 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)1 QueryParamsAdapter (io.crnk.legacy.internal.QueryParamsAdapter)1 QueryParams (io.crnk.legacy.queryParams.QueryParams)1 Properties (java.util.Properties)1 WebTarget (javax.ws.rs.client.WebTarget)1