Search in sources :

Example 1 with JsonApiRequestProcessor

use of io.crnk.core.engine.internal.http.JsonApiRequestProcessor 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 2 with JsonApiRequestProcessor

use of io.crnk.core.engine.internal.http.JsonApiRequestProcessor in project crnk-framework by crnk-project.

the class CrnkBoot method setupComponents.

private void setupComponents() {
    // not that the provided default implementation here are added last and
    // as a consequence,
    // can be overriden by other modules, like the
    // JaxrsResourceRepositoryInformationBuilder.
    SimpleModule module = new SimpleModule("discovery") {

        @Override
        public void setupModule(ModuleContext context) {
            this.addHttpRequestProcessor(new JsonApiRequestProcessor(context));
            super.setupModule(context);
        }
    };
    for (JsonApiExceptionMapper<?> exceptionMapper : getInstancesByType(JsonApiExceptionMapper.class)) {
        module.addExceptionMapper(exceptionMapper);
    }
    for (DocumentFilter filter : getInstancesByType(DocumentFilter.class)) {
        module.addFilter(filter);
    }
    for (Object repository : getInstancesByType(Repository.class)) {
        module.addRepository(repository);
    }
    for (Object repository : serviceDiscovery.getInstancesByAnnotation(JsonApiResourceRepository.class)) {
        JsonApiResourceRepository annotation = ClassUtils.getAnnotation(repository.getClass(), JsonApiResourceRepository.class).get();
        Class<?> resourceClass = annotation.value();
        module.addRepository(resourceClass, repository);
    }
    for (Object repository : serviceDiscovery.getInstancesByAnnotation(JsonApiRelationshipRepository.class)) {
        JsonApiRelationshipRepository annotation = ClassUtils.getAnnotation(repository.getClass(), JsonApiRelationshipRepository.class).get();
        module.addRepository(annotation.source(), annotation.target(), repository);
    }
    moduleRegistry.addModule(module);
    moduleRegistry.addModule(new CoreModule());
}
Also used : JsonApiRequestProcessor(io.crnk.core.engine.internal.http.JsonApiRequestProcessor) JsonApiRelationshipRepository(io.crnk.legacy.repository.annotations.JsonApiRelationshipRepository) JsonApiResourceRepository(io.crnk.legacy.repository.annotations.JsonApiResourceRepository) DocumentFilter(io.crnk.core.engine.filter.DocumentFilter) CoreModule(io.crnk.core.engine.internal.CoreModule) SimpleModule(io.crnk.core.module.SimpleModule)

Aggregations

JsonApiRequestProcessor (io.crnk.core.engine.internal.http.JsonApiRequestProcessor)2 CrnkBoot (io.crnk.core.boot.CrnkBoot)1 DocumentFilter (io.crnk.core.engine.filter.DocumentFilter)1 CoreModule (io.crnk.core.engine.internal.CoreModule)1 HttpRequestContextBaseAdapter (io.crnk.core.engine.internal.http.HttpRequestContextBaseAdapter)1 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)1 Task (io.crnk.core.mock.models.Task)1 TaskLinks (io.crnk.core.mock.models.TaskLinks)1 TaskRepository (io.crnk.core.mock.repository.TaskRepository)1 Module (io.crnk.core.module.Module)1 SimpleModule (io.crnk.core.module.SimpleModule)1 ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)1 JsonApiRelationshipRepository (io.crnk.legacy.repository.annotations.JsonApiRelationshipRepository)1 JsonApiResourceRepository (io.crnk.legacy.repository.annotations.JsonApiResourceRepository)1 Before (org.junit.Before)1