Search in sources :

Example 1 with ConstantServiceUrlProvider

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

use of io.crnk.core.engine.url.ConstantServiceUrlProvider 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)

Example 3 with ConstantServiceUrlProvider

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

the class JsonApiRequestProcessorTest method setup.

@Before
public void setup() {
    TaskRepository.clear();
    boot = new CrnkBoot();
    boot.addModule(new Module() {

        @Override
        public String getModuleName() {
            return "test";
        }

        @Override
        public void setupModule(ModuleContext context) {
            moduleContext = context;
        }
    });
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider("http://localhost:8080"));
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
    boot.boot();
    Task task = new Task();
    task.setId(1L);
    task.setName("SomeTask");
    task.setLinksInformation(new TaskLinks());
    TaskRepository tasks = new TaskRepository();
    tasks.save(task);
    processor = new JsonApiRequestProcessor(moduleContext);
    requestContextBase = Mockito.mock(HttpRequestContextBase.class);
    requestContext = new HttpRequestContextBaseAdapter(requestContextBase);
    HttpRequestContextProvider requestContextProvider = boot.getModuleRegistry().getHttpRequestContextProvider();
    requestContextProvider.onRequestStarted(requestContext);
}
Also used : HttpRequestContextBaseAdapter(io.crnk.core.engine.internal.http.HttpRequestContextBaseAdapter) Task(io.crnk.core.mock.models.Task) TaskRepository(io.crnk.core.mock.repository.TaskRepository) JsonApiRequestProcessor(io.crnk.core.engine.internal.http.JsonApiRequestProcessor) CrnkBoot(io.crnk.core.boot.CrnkBoot) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) Module(io.crnk.core.module.Module) TaskLinks(io.crnk.core.mock.models.TaskLinks) Before(org.junit.Before)

Example 4 with ConstantServiceUrlProvider

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

the class ResourceFilterTest method prepare.

@Before
public void prepare() {
    boot = new CrnkBoot();
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider(ResourceRegistryTest.TEST_MODELS_URL));
    SimpleModule filterModule = new SimpleModule("filter");
    filterModule.addResourceFilter(filter);
    boot.addModule(filterModule);
    boot.boot();
    resourceRegistry = boot.getResourceRegistry();
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) SimpleModule(io.crnk.core.module.SimpleModule) Before(org.junit.Before)

Example 5 with ConstantServiceUrlProvider

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

the class BaseControllerTest method prepare.

@Before
public void prepare() {
    modificationFilter = Mockito.spy(new ResourceModificationFilterBase());
    modificationFilters = Arrays.asList(modificationFilter);
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider(ResourceRegistryTest.TEST_MODELS_URL));
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
    boot.boot();
    objectMapper = boot.getObjectMapper();
    resourceRegistry = boot.getResourceRegistry();
    moduleRegistry = boot.getModuleRegistry();
    pathBuilder = new PathBuilder(resourceRegistry);
    typeParser = moduleRegistry.getTypeParser();
    documentMapper = boot.getDocumentMapper();
    MockRepositoryUtil.clear();
    emptyTaskQuery = new QuerySpecAdapter(new QuerySpec(Task.class), resourceRegistry);
    emptyProjectQuery = new QuerySpecAdapter(new QuerySpec(Project.class), resourceRegistry);
    emptyUserQuery = new QuerySpecAdapter(new QuerySpec(User.class), resourceRegistry);
    emptyComplexPojoQuery = new QuerySpecAdapter(new QuerySpec(ComplexPojo.class), resourceRegistry);
    emptyMemorandumQuery = new QuerySpecAdapter(new QuerySpec(Memorandum.class), resourceRegistry);
}
Also used : PathBuilder(io.crnk.core.engine.internal.dispatcher.path.PathBuilder) CrnkBoot(io.crnk.core.boot.CrnkBoot) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) ResourceModificationFilterBase(io.crnk.core.engine.filter.ResourceModificationFilterBase) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) QuerySpec(io.crnk.core.queryspec.QuerySpec) Before(org.junit.Before)

Aggregations

ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)40 CrnkBoot (io.crnk.core.boot.CrnkBoot)34 Before (org.junit.Before)27 ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)24 Test (org.junit.Test)8 JsonApiUrlBuilder (io.crnk.core.engine.internal.utils.JsonApiUrlBuilder)6 TestModule (io.crnk.test.mock.TestModule)6 Task (io.crnk.core.mock.models.Task)5 ResourceMetaProvider (io.crnk.meta.provider.resource.ResourceMetaProvider)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 ResourceRegistryImpl (io.crnk.core.engine.internal.registry.ResourceRegistryImpl)4 DefaultResourceRegistryPart (io.crnk.core.engine.registry.DefaultResourceRegistryPart)4 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)4 SimpleModule (io.crnk.core.module.SimpleModule)4 PropertiesProvider (io.crnk.core.engine.properties.PropertiesProvider)3 RelationIdTestResource (io.crnk.core.mock.models.RelationIdTestResource)3 ModuleRegistry (io.crnk.core.module.ModuleRegistry)3 CoreModule (io.crnk.core.engine.internal.CoreModule)2 PathBuilder (io.crnk.core.engine.internal.dispatcher.path.PathBuilder)2 DefaultInformationBuilder (io.crnk.core.engine.internal.information.DefaultInformationBuilder)2