Search in sources :

Example 1 with CrnkBoot

use of io.crnk.core.boot.CrnkBoot 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 CrnkBoot

use of io.crnk.core.boot.CrnkBoot in project crnk-framework by crnk-project.

the class ActivitiTestBase method setup.

@Before
public void setup() {
    processEngine = ProcessEngines.getDefaultProcessEngine();
    processEngine.getRepositoryService().createDeployment().addClasspathResource("approval.bpmn20.xml").deploy();
    boot = new CrnkBoot();
    boot.addModule(new TestModule());
    boot.addModule(createActivitiModule());
    boot.boot();
    taskRepository = (TaskResourceRepository<ApproveTask>) boot.getResourceRegistry().getEntry(ApproveTask.class).getResourceRepository().getResourceRepository();
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) TestModule(io.crnk.test.mock.TestModule) ApproveTask(io.crnk.activiti.example.model.ApproveTask) Before(org.junit.Before)

Example 3 with CrnkBoot

use of io.crnk.core.boot.CrnkBoot in project crnk-framework by crnk-project.

the class CdiServiceDiscoveryTest method testExceptionMapper.

@Test
public void testExceptionMapper() {
    CrnkBoot boot = new CrnkBoot();
    boot.boot();
    Optional<JsonApiExceptionMapper> mapper = boot.getExceptionMapperRegistry().findMapperFor(IllegalStateException.class);
    Assert.assertTrue(mapper.isPresent());
    Assert.assertTrue(mapper.get() instanceof CdiTestExceptionMapper);
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) CdiTestExceptionMapper(io.crnk.internal.boot.cdi.model.CdiTestExceptionMapper) JsonApiExceptionMapper(io.crnk.core.engine.error.JsonApiExceptionMapper) Test(org.junit.Test)

Example 4 with CrnkBoot

use of io.crnk.core.boot.CrnkBoot in project crnk-framework by crnk-project.

the class TSGeneratorTest method setup.

@Before
public void setup() {
    Project project = Mockito.mock(Project.class);
    TSGeneratorExtension config = new TSGeneratorExtension(project, null);
    File outputDir = testProjectDir.getRoot();
    MetaModuleConfig metaConfig = new MetaModuleConfig();
    metaConfig.addMetaProvider(new ResourceMetaProvider());
    MetaModule metaModule = MetaModule.createServerModule(metaConfig);
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceDiscovery(new EmptyServiceDiscovery());
    boot.addModule(metaModule);
    boot.boot();
    generator = new TSGenerator(outputDir, metaModule.getLookup(), config);
}
Also used : Project(org.gradle.api.Project) CrnkBoot(io.crnk.core.boot.CrnkBoot) ResourceMetaProvider(io.crnk.meta.provider.resource.ResourceMetaProvider) File(java.io.File) MetaModule(io.crnk.meta.MetaModule) TSGeneratorExtension(io.crnk.gen.typescript.TSGeneratorExtension) MetaModuleConfig(io.crnk.meta.MetaModuleConfig) EmptyServiceDiscovery(io.crnk.core.module.discovery.EmptyServiceDiscovery) Before(org.junit.Before)

Example 5 with CrnkBoot

use of io.crnk.core.boot.CrnkBoot in project crnk-framework by crnk-project.

the class HomeResourceFilteringTest method setup.

@Before
public void setup() {
    filter = Mockito.mock(ResourceFilter.class);
    SimpleModule filterModule = new SimpleModule("filter");
    filterModule.addResourceFilter(filter);
    this.module = Mockito.spy(HomeModule.create());
    boot = new CrnkBoot();
    boot.addModule(module);
    boot.addModule(new TestModule());
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider("http://localhost"));
    boot.addModule(filterModule);
    boot.boot();
}
Also used : ResourceFilter(io.crnk.core.engine.filter.ResourceFilter) CrnkBoot(io.crnk.core.boot.CrnkBoot) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) TestModule(io.crnk.test.mock.TestModule) SimpleModule(io.crnk.core.module.SimpleModule) Before(org.junit.Before)

Aggregations

CrnkBoot (io.crnk.core.boot.CrnkBoot)54 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)34 Before (org.junit.Before)34 ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)28 Test (org.junit.Test)11 TestModule (io.crnk.test.mock.TestModule)9 SimpleModule (io.crnk.core.module.SimpleModule)7 JsonApiUrlBuilder (io.crnk.core.engine.internal.utils.JsonApiUrlBuilder)6 ResourceMetaProvider (io.crnk.meta.provider.resource.ResourceMetaProvider)6 MetaModule (io.crnk.meta.MetaModule)5 NullPropertiesProvider (io.crnk.core.engine.properties.NullPropertiesProvider)4 PropertiesProvider (io.crnk.core.engine.properties.PropertiesProvider)4 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)4 Task (io.crnk.core.mock.models.Task)4 TaskRepository (io.crnk.core.mock.repository.TaskRepository)4 QuerySpec (io.crnk.core.queryspec.QuerySpec)4 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)4 JaxrsModule (io.crnk.rs.internal.JaxrsModule)4 JsonApiExceptionMapper (io.crnk.core.engine.error.JsonApiExceptionMapper)3 HttpRequestContextProvider (io.crnk.core.engine.http.HttpRequestContextProvider)3