Search in sources :

Example 6 with ControllerRegistry

use of io.crnk.core.engine.internal.dispatcher.ControllerRegistry 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 7 with ControllerRegistry

use of io.crnk.core.engine.internal.dispatcher.ControllerRegistry 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)

Example 8 with ControllerRegistry

use of io.crnk.core.engine.internal.dispatcher.ControllerRegistry in project crnk-framework by crnk-project.

the class HttpRequestProcessorImplTest method shouldNotifyWhenActionIsExeecuted.

@Test
public void shouldNotifyWhenActionIsExeecuted() throws Exception {
    // GIVEN
    String path = "/actionResource/1/someAction";
    String requestType = "GET";
    ControllerRegistry controllerRegistry = new ControllerRegistry(null);
    QuerySpecAdapterBuilder queryAdapterBuilder = new QuerySpecAdapterBuilder(new DefaultQuerySpecDeserializer(), moduleRegistry);
    RequestDispatcher sut = new HttpRequestProcessorImpl(moduleRegistry, controllerRegistry, null, queryAdapterBuilder);
    // WHEN
    Map<String, Set<String>> parameters = new HashMap<>();
    sut.dispatchAction(path, "GET", parameters);
    // THEN
    ArgumentCaptor<DocumentFilterContext> filterContextCaptor = ArgumentCaptor.forClass(DocumentFilterContext.class);
    Mockito.verify(documentFilter, Mockito.times(1)).filter(filterContextCaptor.capture(), Mockito.any(DocumentFilterChain.class));
    DocumentFilterContext filterContext = filterContextCaptor.getValue();
    Assert.assertEquals("GET", filterContext.getMethod());
    Assert.assertTrue(filterContext.getJsonPath() instanceof ActionPath);
}
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) DefaultQuerySpecDeserializer(io.crnk.core.queryspec.DefaultQuerySpecDeserializer) DocumentFilterChain(io.crnk.core.engine.filter.DocumentFilterChain) ActionPath(io.crnk.core.engine.internal.dispatcher.path.ActionPath) Matchers.anyString(org.mockito.Matchers.anyString) RequestDispatcher(io.crnk.core.engine.dispatcher.RequestDispatcher) HttpRequestProcessorImpl(io.crnk.core.engine.internal.http.HttpRequestProcessorImpl) DocumentFilterContext(io.crnk.core.engine.filter.DocumentFilterContext) ExceptionMapperRegistryTest(io.crnk.core.engine.internal.exception.ExceptionMapperRegistryTest) Test(org.junit.Test)

Example 9 with ControllerRegistry

use of io.crnk.core.engine.internal.dispatcher.ControllerRegistry in project crnk-framework by crnk-project.

the class ControllerRegistryBuilderTest method onBuildShouldAddAllControllers.

@Test
public void onBuildShouldAddAllControllers() throws Exception {
    // GIVEN
    PropertiesProvider propertiesProvider = Mockito.mock(PropertiesProvider.class);
    ResourceFilterDirectory resourceFilterDirectory = Mockito.mock(ResourceFilterDirectory.class);
    ControllerRegistryBuilder sut = new ControllerRegistryBuilder(null, null, null, propertiesProvider, resourceFilterDirectory, (List) Collections.emptyList());
    // WHEN
    ControllerRegistry result = sut.build();
    // THEN
    result.getController(new ResourcePath("path"), "GET");
}
Also used : PropertiesProvider(io.crnk.core.engine.properties.PropertiesProvider) ControllerRegistry(io.crnk.core.engine.internal.dispatcher.ControllerRegistry) ResourcePath(io.crnk.core.engine.internal.dispatcher.path.ResourcePath) ResourceFilterDirectory(io.crnk.core.engine.filter.ResourceFilterDirectory) ControllerRegistryBuilder(io.crnk.core.engine.internal.dispatcher.ControllerRegistryBuilder) Test(org.junit.Test)

Example 10 with ControllerRegistry

use of io.crnk.core.engine.internal.dispatcher.ControllerRegistry in project crnk-framework by crnk-project.

the class CrnkBoot method createRequestDispatcher.

private HttpRequestProcessorImpl createRequestDispatcher(ExceptionMapperRegistry exceptionMapperRegistry) {
    ControllerRegistryBuilder controllerRegistryBuilder = newControllerRegistryBuilder(resourceRegistry, moduleRegistry.getTypeParser(), objectMapper, propertiesProvider, moduleRegistry.getContext().getResourceFilterDirectory(), moduleRegistry.getResourceModificationFilters());
    ControllerRegistry controllerRegistry = controllerRegistryBuilder.build();
    this.documentMapper = controllerRegistryBuilder.getDocumentMapper();
    QueryAdapterBuilder queryAdapterBuilder;
    if (queryParamsBuilder != null) {
        queryAdapterBuilder = new QueryParamsAdapterBuilder(queryParamsBuilder, moduleRegistry);
    } else {
        queryAdapterBuilder = new QuerySpecAdapterBuilder(querySpecDeserializer, moduleRegistry);
    }
    return new HttpRequestProcessorImpl(moduleRegistry, controllerRegistry, exceptionMapperRegistry, queryAdapterBuilder);
}
Also used : ControllerRegistry(io.crnk.core.engine.internal.dispatcher.ControllerRegistry) QuerySpecAdapterBuilder(io.crnk.core.queryspec.internal.QuerySpecAdapterBuilder) QueryParamsAdapterBuilder(io.crnk.legacy.internal.QueryParamsAdapterBuilder) QueryAdapterBuilder(io.crnk.core.engine.query.QueryAdapterBuilder) HttpRequestProcessorImpl(io.crnk.core.engine.internal.http.HttpRequestProcessorImpl) ControllerRegistryBuilder(io.crnk.core.engine.internal.dispatcher.ControllerRegistryBuilder)

Aggregations

ControllerRegistry (io.crnk.core.engine.internal.dispatcher.ControllerRegistry)10 HttpRequestProcessorImpl (io.crnk.core.engine.internal.http.HttpRequestProcessorImpl)8 QuerySpecAdapterBuilder (io.crnk.core.queryspec.internal.QuerySpecAdapterBuilder)8 Test (org.junit.Test)8 DefaultQuerySpecDeserializer (io.crnk.core.queryspec.DefaultQuerySpecDeserializer)7 RequestDispatcher (io.crnk.core.engine.dispatcher.RequestDispatcher)6 JsonPath (io.crnk.core.engine.internal.dispatcher.path.JsonPath)6 ExceptionMapperRegistryTest (io.crnk.core.engine.internal.exception.ExceptionMapperRegistryTest)6 Document (io.crnk.core.engine.document.Document)3 CollectionGet (io.crnk.core.engine.internal.dispatcher.controller.CollectionGet)3 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)3 RepositoryMethodParameterProvider (io.crnk.legacy.internal.RepositoryMethodParameterProvider)3 HashMap (java.util.HashMap)3 Set (java.util.Set)3 Matchers.anyString (org.mockito.Matchers.anyString)3 Response (io.crnk.core.engine.dispatcher.Response)2 ControllerRegistryBuilder (io.crnk.core.engine.internal.dispatcher.ControllerRegistryBuilder)2 PathBuilder (io.crnk.core.engine.internal.dispatcher.path.PathBuilder)2 CrnkBoot (io.crnk.core.boot.CrnkBoot)1 DocumentFilterChain (io.crnk.core.engine.filter.DocumentFilterChain)1