Search in sources :

Example 46 with CrnkBoot

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

the class ResourceRepositoryBaseTest method setup.

@Before
public void setup() {
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
    boot.setPropertiesProvider(new PropertiesProvider() {

        @Override
        public String getProperty(String key) {
            if (key.equals(CrnkProperties.RETURN_404_ON_NULL)) {
                return "true";
            }
            return null;
        }
    });
    boot.boot();
    repository = new TestRepository();
    repository.setResourceRegistry(boot.getResourceRegistry());
}
Also used : PropertiesProvider(io.crnk.core.engine.properties.PropertiesProvider) CrnkBoot(io.crnk.core.boot.CrnkBoot) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) Before(org.junit.Before)

Example 47 with CrnkBoot

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

the class CustomResourceRegistryTest method test.

@Test
public void test() {
    CrnkBoot boot = new CrnkBoot();
    boot.addModule(new CustomRegistryPartModule());
    boot.setServiceDiscovery(new TestServiceDiscovery());
    boot.boot();
    ResourceRegistry resourceRegistry = boot.getResourceRegistry();
    RegistryEntry entry = resourceRegistry.getEntry("somePrefix/custom");
    Assert.assertNotNull(entry);
    ResourceRepositoryAdapter adapter = entry.getResourceRepository();
    QueryAdapter queryAdapter = new QuerySpecAdapter(new QuerySpec("somePrefix/custom"), resourceRegistry);
    JsonApiResponse response = adapter.findAll(queryAdapter);
    Assert.assertNotNull(response.getEntity());
    List<Resource> resources = (List<Resource>) response.getEntity();
    Assert.assertEquals(1, resources.size());
}
Also used : QueryAdapter(io.crnk.core.engine.query.QueryAdapter) Resource(io.crnk.core.engine.document.Resource) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) CrnkBoot(io.crnk.core.boot.CrnkBoot) TestServiceDiscovery(io.crnk.core.module.discovery.TestServiceDiscovery) ResourceRepositoryAdapter(io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) List(java.util.List) QuerySpec(io.crnk.core.queryspec.QuerySpec) Test(org.junit.Test)

Example 48 with CrnkBoot

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

the class JsonApiFormatTest method setup.

@Before
public void setup() {
    MetaModuleConfig config = new MetaModuleConfig();
    config.addMetaProvider(new ResourceMetaProvider());
    MetaModule metaModule = MetaModule.createServerModule(config);
    this.module = Mockito.spy(HomeModule.create(HomeFormat.JSON_API));
    boot = new CrnkBoot();
    boot.addModule(module);
    boot.addModule(metaModule);
    boot.addModule(new TestModule());
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider("http://localhost"));
    boot.boot();
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) ResourceMetaProvider(io.crnk.meta.provider.resource.ResourceMetaProvider) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) MetaModule(io.crnk.meta.MetaModule) TestModule(io.crnk.test.mock.TestModule) MetaModuleConfig(io.crnk.meta.MetaModuleConfig) Before(org.junit.Before)

Example 49 with CrnkBoot

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

the class GuiceServiceDiscoveryTest method exceptionMapperDiscovery.

@Test
public void exceptionMapperDiscovery() {
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceDiscovery(discovery);
    boot.boot();
    Optional<JsonApiExceptionMapper> mapper = boot.getExceptionMapperRegistry().findMapperFor(TestException.class);
    Assert.assertTrue(mapper.isPresent());
    Assert.assertTrue(mapper.get() instanceof TestExceptionMapper);
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) JsonApiExceptionMapper(io.crnk.core.engine.error.JsonApiExceptionMapper) TestExceptionMapper(io.crnk.test.mock.TestExceptionMapper) Test(org.junit.Test)

Example 50 with CrnkBoot

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

the class JsonHomeFormatTest method setup.

@Before
public void setup() {
    MetaModuleConfig config = new MetaModuleConfig();
    config.addMetaProvider(new ResourceMetaProvider());
    MetaModule metaModule = MetaModule.createServerModule(config);
    this.module = Mockito.spy(HomeModule.create(HomeFormat.JSON_HOME));
    boot = new CrnkBoot();
    boot.addModule(module);
    boot.addModule(metaModule);
    boot.addModule(new TestModule());
    boot.setServiceUrlProvider(new ConstantServiceUrlProvider("http://localhost"));
    boot.boot();
}
Also used : CrnkBoot(io.crnk.core.boot.CrnkBoot) ResourceMetaProvider(io.crnk.meta.provider.resource.ResourceMetaProvider) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) MetaModule(io.crnk.meta.MetaModule) TestModule(io.crnk.test.mock.TestModule) MetaModuleConfig(io.crnk.meta.MetaModuleConfig) 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