Search in sources :

Example 1 with PropertiesProvider

use of io.crnk.core.engine.properties.PropertiesProvider in project crnk-framework by crnk-project.

the class CrnkConfigV3 method crnkBoot.

@Bean
@ConditionalOnMissingBean(CrnkBoot.class)
public CrnkBoot crnkBoot(ServiceDiscovery serviceDiscovery) {
    CrnkBoot boot = new CrnkBoot();
    boot.setObjectMapper(objectMapper);
    if (properties.getDomainName() != null && properties.getPathPrefix() != null) {
        String baseUrl = properties.getDomainName() + properties.getPathPrefix();
        boot.setServiceUrlProvider(new ConstantServiceUrlProvider(baseUrl));
    }
    boot.setServiceDiscovery(serviceDiscovery);
    boot.setDefaultPageLimit(properties.getDefaultPageLimit());
    boot.setMaxPageLimit(properties.getMaxPageLimit());
    boot.setPropertiesProvider(new PropertiesProvider() {

        @Override
        public String getProperty(String key) {
            if (CrnkProperties.RESOURCE_SEARCH_PACKAGE.equals(key)) {
                return properties.getResourcePackage();
            }
            if (CrnkProperties.RESOURCE_DEFAULT_DOMAIN.equals(key)) {
                return properties.getDomainName();
            }
            if (CrnkProperties.WEB_PATH_PREFIX.equals(key)) {
                return properties.getPathPrefix();
            }
            if (CrnkProperties.ALLOW_UNKNOWN_ATTRIBUTES.equals(key)) {
                return String.valueOf(properties.getAllowUnknownAttributes());
            }
            if (CrnkProperties.ALLOW_UNKNOWN_PARAMETERS.equals(key)) {
                return String.valueOf(properties.getAllowUnknownParameters());
            }
            if (CrnkProperties.RETURN_404_ON_NULL.equals(key)) {
                return String.valueOf(properties.getReturn404OnNull());
            }
            return applicationContext.getEnvironment().getProperty(key);
        }
    });
    boot.setAllowUnknownAttributes();
    boot.addModule(new ServletModule(boot.getModuleRegistry().getHttpRequestContextProvider()));
    boot.boot();
    return boot;
}
Also used : PropertiesProvider(io.crnk.core.engine.properties.PropertiesProvider) CrnkBoot(io.crnk.core.boot.CrnkBoot) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) ServletModule(io.crnk.servlet.internal.ServletModule) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with PropertiesProvider

use of io.crnk.core.engine.properties.PropertiesProvider in project crnk-framework by crnk-project.

the class CrnkBootTest method setServiceLocator.

@Test
public void setServiceLocator() {
    JsonServiceLocator locator = mock(JsonServiceLocator.class);
    PropertiesProvider propertiesProvider = mock(PropertiesProvider.class);
    Mockito.when(propertiesProvider.getProperty(eq(CrnkProperties.RESOURCE_SEARCH_PACKAGE))).thenReturn("a.b.c");
    CrnkBoot boot = new CrnkBoot();
    boot.setPropertiesProvider(propertiesProvider);
    boot.setServiceLocator(locator);
    boot.setServiceDiscoveryFactory(mock(ServiceDiscoveryFactory.class));
    boot.boot();
    ReflectionsServiceDiscovery serviceDiscovery = (ReflectionsServiceDiscovery) boot.getServiceDiscovery();
    Assert.assertSame(locator, serviceDiscovery.getLocator());
}
Also used : PropertiesProvider(io.crnk.core.engine.properties.PropertiesProvider) ServiceDiscoveryFactory(io.crnk.core.module.discovery.ServiceDiscoveryFactory) JsonServiceLocator(io.crnk.legacy.locator.JsonServiceLocator) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) Test(org.junit.Test)

Example 3 with PropertiesProvider

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

use of io.crnk.core.engine.properties.PropertiesProvider in project crnk-framework by crnk-project.

the class IncludeLookupSetterBaseTest method includePropertiesProviderNonOverwriteRelationshipLookup.

@Test
public void includePropertiesProviderNonOverwriteRelationshipLookup() throws Exception {
    PropertiesProvider propertiesProvider = new PropertiesProvider() {

        @Override
        public String getProperty(String key) {
            if (key.equalsIgnoreCase(CrnkProperties.INCLUDE_AUTOMATICALLY_OVERWRITE)) {
                return "false";
            }
            return null;
        }
    };
    mapper = new DocumentMapper(resourceRegistry, objectMapper, propertiesProvider, resourceFilterDirectory);
    QuerySpec querySpec = new QuerySpec(Task.class);
    querySpec.includeRelation(Arrays.asList("project"));
    Project project = new Project();
    project.setId(12L);
    Task task = new Task();
    task.setId(1L);
    task.setProject(project);
    Document document = mapper.toDocument(toResponse(task), toAdapter(querySpec));
    Resource taskResource = document.getSingleData().get();
    Relationship relationship = taskResource.getRelationships().get("project");
    assertNotNull(relationship);
    assertEquals(relationship.getSingleData().get().getId(), "12");
}
Also used : PropertiesProvider(io.crnk.core.engine.properties.PropertiesProvider) EmptyPropertiesProvider(io.crnk.core.engine.properties.EmptyPropertiesProvider) Project(io.crnk.core.mock.models.Project) HierarchicalTask(io.crnk.core.mock.models.HierarchicalTask) Task(io.crnk.core.mock.models.Task) DocumentMapper(io.crnk.core.engine.internal.document.mapper.DocumentMapper) Relationship(io.crnk.core.engine.document.Relationship) Resource(io.crnk.core.engine.document.Resource) QuerySpec(io.crnk.core.queryspec.QuerySpec) Document(io.crnk.core.engine.document.Document) AbstractDocumentMapperTest(io.crnk.core.engine.internal.document.mapper.AbstractDocumentMapperTest) Test(org.junit.Test)

Example 5 with PropertiesProvider

use of io.crnk.core.engine.properties.PropertiesProvider in project crnk-framework by crnk-project.

the class FallbackServiceDiscoveryFactoryTest method returnDefaultDiscoveryIfAvailable.

@Test
public void returnDefaultDiscoveryIfAvailable() {
    PropertiesProvider propertiesProvider = new NullPropertiesProvider();
    DefaultServiceDiscoveryFactory defaultFactory = new DefaultServiceDiscoveryFactory();
    FallbackServiceDiscoveryFactory fallbackFactory = new FallbackServiceDiscoveryFactory(defaultFactory, new SampleJsonServiceLocator(), propertiesProvider);
    Assert.assertTrue(fallbackFactory.getInstance() instanceof TestServiceDiscovery);
}
Also used : PropertiesProvider(io.crnk.core.engine.properties.PropertiesProvider) NullPropertiesProvider(io.crnk.core.engine.properties.NullPropertiesProvider) NullPropertiesProvider(io.crnk.core.engine.properties.NullPropertiesProvider) SampleJsonServiceLocator(io.crnk.legacy.locator.SampleJsonServiceLocator) Test(org.junit.Test)

Aggregations

PropertiesProvider (io.crnk.core.engine.properties.PropertiesProvider)17 Test (org.junit.Test)13 Document (io.crnk.core.engine.document.Document)5 Resource (io.crnk.core.engine.document.Resource)5 NullPropertiesProvider (io.crnk.core.engine.properties.NullPropertiesProvider)5 CrnkBoot (io.crnk.core.boot.CrnkBoot)4 BaseControllerTest (io.crnk.core.engine.internal.dispatcher.controller.BaseControllerTest)3 ResourcePost (io.crnk.core.engine.internal.dispatcher.controller.ResourcePost)3 JsonPath (io.crnk.core.engine.internal.dispatcher.path.JsonPath)3 AbstractDocumentMapperTest (io.crnk.core.engine.internal.document.mapper.AbstractDocumentMapperTest)3 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)3 SampleJsonServiceLocator (io.crnk.legacy.locator.SampleJsonServiceLocator)3 DocumentMapper (io.crnk.core.engine.internal.document.mapper.DocumentMapper)2 EmptyPropertiesProvider (io.crnk.core.engine.properties.EmptyPropertiesProvider)2 HierarchicalTask (io.crnk.core.mock.models.HierarchicalTask)2 Task (io.crnk.core.mock.models.Task)2 ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)2 QuerySpec (io.crnk.core.queryspec.QuerySpec)2 Before (org.junit.Before)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1