Search in sources :

Example 6 with HttpRequestProcessorImpl

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

the class CrnkBootTest method setQueryParamsBuilder.

@Test
public void setQueryParamsBuilder() {
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceDiscoveryFactory(serviceDiscoveryFactory);
    boot.setDefaultServiceUrlProvider(mock(ServiceUrlProvider.class));
    QueryParamsBuilder deserializer = mock(QueryParamsBuilder.class);
    boot.setQueryParamsBuilds(deserializer);
    boot.boot();
    HttpRequestProcessorImpl requestDispatcher = boot.getRequestDispatcher();
    QueryAdapterBuilder queryAdapterBuilder = requestDispatcher.getQueryAdapterBuilder();
    Assert.assertTrue(queryAdapterBuilder instanceof QueryParamsAdapterBuilder);
}
Also used : ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) ServiceUrlProvider(io.crnk.core.engine.url.ServiceUrlProvider) QueryParamsBuilder(io.crnk.legacy.queryParams.QueryParamsBuilder) QueryParamsAdapterBuilder(io.crnk.legacy.internal.QueryParamsAdapterBuilder) HttpRequestProcessorImpl(io.crnk.core.engine.internal.http.HttpRequestProcessorImpl) QueryAdapterBuilder(io.crnk.core.engine.query.QueryAdapterBuilder) Test(org.junit.Test)

Example 7 with HttpRequestProcessorImpl

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

the class FilterTest 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));
    // GIVEN
    filter = mock(TestFilter.class);
    SimpleModule filterModule = new SimpleModule("filter");
    filterModule.addFilter(filter);
    boot.addModule(filterModule);
    boot.boot();
    resourceRegistry = boot.getResourceRegistry();
    moduleRegistry = boot.getModuleRegistry();
    pathBuilder = new PathBuilder(resourceRegistry);
    ControllerRegistry controllerRegistry = new ControllerRegistry(null);
    collectionGet = mock(CollectionGet.class);
    controllerRegistry.addController(collectionGet);
    QuerySpecAdapterBuilder queryAdapterBuilder = new QuerySpecAdapterBuilder(new DefaultQuerySpecDeserializer(), moduleRegistry);
    dispatcher = new HttpRequestProcessorImpl(moduleRegistry, controllerRegistry, null, queryAdapterBuilder);
}
Also used : ControllerRegistry(io.crnk.core.engine.internal.dispatcher.ControllerRegistry) PathBuilder(io.crnk.core.engine.internal.dispatcher.path.PathBuilder) CrnkBoot(io.crnk.core.boot.CrnkBoot) CollectionGet(io.crnk.core.engine.internal.dispatcher.controller.CollectionGet) QuerySpecAdapterBuilder(io.crnk.core.queryspec.internal.QuerySpecAdapterBuilder) DefaultQuerySpecDeserializer(io.crnk.core.queryspec.DefaultQuerySpecDeserializer) ReflectionsServiceDiscovery(io.crnk.core.module.discovery.ReflectionsServiceDiscovery) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) SimpleModule(io.crnk.core.module.SimpleModule) HttpRequestProcessorImpl(io.crnk.core.engine.internal.http.HttpRequestProcessorImpl) Before(org.junit.Before)

Example 8 with HttpRequestProcessorImpl

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

the class HomeModuleTest method testNonRootRequestNotTouchedForDifferentUrl.

@Test
public void testNonRootRequestNotTouchedForDifferentUrl() throws IOException {
    HttpRequestContextBase requestContextBase = Mockito.mock(HttpRequestContextBase.class);
    // create json api request
    Mockito.when(requestContextBase.getMethod()).thenReturn("GET");
    Mockito.when(requestContextBase.getPath()).thenReturn("/doesNotExists");
    Mockito.when(requestContextBase.getRequestHeader("Accept")).thenReturn("*");
    // execute
    HttpRequestProcessorImpl requestDispatcher = boot.getRequestDispatcher();
    requestDispatcher.process(requestContextBase);
    Mockito.verify(requestContextBase, Mockito.times(0)).setResponse(Mockito.anyInt(), (byte[]) Mockito.anyObject());
}
Also used : HttpRequestContextBase(io.crnk.core.engine.http.HttpRequestContextBase) HttpRequestProcessorImpl(io.crnk.core.engine.internal.http.HttpRequestProcessorImpl) Test(org.junit.Test)

Example 9 with HttpRequestProcessorImpl

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

the class HttpRequestProcessorImplTest method shouldThrowExceptionAsIsIfMapperIsNotAvailable.

@Test
public void shouldThrowExceptionAsIsIfMapperIsNotAvailable() throws Exception {
    ControllerRegistry controllerRegistry = mock(ControllerRegistry.class);
    // noinspection unchecked
    when(controllerRegistry.getController(any(JsonPath.class), anyString())).thenThrow(ArithmeticException.class);
    QuerySpecAdapterBuilder queryAdapterBuilder = new QuerySpecAdapterBuilder(new DefaultQuerySpecDeserializer(), moduleRegistry);
    RequestDispatcher requestDispatcher = new HttpRequestProcessorImpl(moduleRegistry, controllerRegistry, ExceptionMapperRegistryTest.exceptionMapperRegistry, queryAdapterBuilder);
    expectedException.expect(ArithmeticException.class);
    Response response = requestDispatcher.dispatchRequest("tasks", null, null, null, null);
}
Also used : ControllerRegistry(io.crnk.core.engine.internal.dispatcher.ControllerRegistry) Response(io.crnk.core.engine.dispatcher.Response) QuerySpecAdapterBuilder(io.crnk.core.queryspec.internal.QuerySpecAdapterBuilder) DefaultQuerySpecDeserializer(io.crnk.core.queryspec.DefaultQuerySpecDeserializer) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) RequestDispatcher(io.crnk.core.engine.dispatcher.RequestDispatcher) HttpRequestProcessorImpl(io.crnk.core.engine.internal.http.HttpRequestProcessorImpl) ExceptionMapperRegistryTest(io.crnk.core.engine.internal.exception.ExceptionMapperRegistryTest) Test(org.junit.Test)

Example 10 with HttpRequestProcessorImpl

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

the class HttpRequestProcessorImplTest method shouldHandleRelationshipRequest.

@Test
public void shouldHandleRelationshipRequest() throws Exception {
    // GIVEN
    String path = "/tasks/1/relationships/project";
    String requestType = "GET";
    ControllerRegistry controllerRegistry = new ControllerRegistry(null);
    RelationshipsResourceGet controller = mock(RelationshipsResourceGet.class);
    controllerRegistry.addController(controller);
    QuerySpecAdapterBuilder queryAdapterBuilder = new QuerySpecAdapterBuilder(new DefaultQuerySpecDeserializer(), moduleRegistry);
    RequestDispatcher sut = new HttpRequestProcessorImpl(moduleRegistry, controllerRegistry, null, queryAdapterBuilder);
    // WHEN
    when(controller.isAcceptable(any(JsonPath.class), eq(requestType))).thenCallRealMethod();
    Map<String, Set<String>> parameters = new HashMap<>();
    sut.dispatchRequest(path, requestType, parameters, null, null);
    // THEN
    verify(controller, times(1)).handle(any(JsonPath.class), any(QueryAdapter.class), any(RepositoryMethodParameterProvider.class), any(Document.class));
}
Also used : ControllerRegistry(io.crnk.core.engine.internal.dispatcher.ControllerRegistry) QuerySpecAdapterBuilder(io.crnk.core.queryspec.internal.QuerySpecAdapterBuilder) Set(java.util.Set) HashMap(java.util.HashMap) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) DefaultQuerySpecDeserializer(io.crnk.core.queryspec.DefaultQuerySpecDeserializer) RelationshipsResourceGet(io.crnk.core.engine.internal.dispatcher.controller.RelationshipsResourceGet) Matchers.anyString(org.mockito.Matchers.anyString) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) Document(io.crnk.core.engine.document.Document) RequestDispatcher(io.crnk.core.engine.dispatcher.RequestDispatcher) HttpRequestProcessorImpl(io.crnk.core.engine.internal.http.HttpRequestProcessorImpl) RepositoryMethodParameterProvider(io.crnk.legacy.internal.RepositoryMethodParameterProvider) ExceptionMapperRegistryTest(io.crnk.core.engine.internal.exception.ExceptionMapperRegistryTest) Test(org.junit.Test)

Aggregations

HttpRequestProcessorImpl (io.crnk.core.engine.internal.http.HttpRequestProcessorImpl)17 Test (org.junit.Test)12 QuerySpecAdapterBuilder (io.crnk.core.queryspec.internal.QuerySpecAdapterBuilder)9 ControllerRegistry (io.crnk.core.engine.internal.dispatcher.ControllerRegistry)8 DefaultQuerySpecDeserializer (io.crnk.core.queryspec.DefaultQuerySpecDeserializer)8 RequestDispatcher (io.crnk.core.engine.dispatcher.RequestDispatcher)6 HttpRequestContextBase (io.crnk.core.engine.http.HttpRequestContextBase)6 ExceptionMapperRegistryTest (io.crnk.core.engine.internal.exception.ExceptionMapperRegistryTest)6 JsonPath (io.crnk.core.engine.internal.dispatcher.path.JsonPath)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Document (io.crnk.core.engine.document.Document)4 HashMap (java.util.HashMap)4 Set (java.util.Set)4 Response (io.crnk.core.engine.dispatcher.Response)3 CollectionGet (io.crnk.core.engine.internal.dispatcher.controller.CollectionGet)3 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)3 QueryAdapterBuilder (io.crnk.core.engine.query.QueryAdapterBuilder)3 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)3 RepositoryMethodParameterProvider (io.crnk.legacy.internal.RepositoryMethodParameterProvider)3 Matchers.anyString (org.mockito.Matchers.anyString)3