Search in sources :

Example 1 with CollectionGet

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

the class HttpRequestProcessorImplTest method onGivenPathAndRequestTypeControllerShouldHandleRequest.

@Test
public void onGivenPathAndRequestTypeControllerShouldHandleRequest() throws Exception {
    // GIVEN
    String path = "/tasks/";
    String requestType = "GET";
    ControllerRegistry controllerRegistry = new ControllerRegistry(null);
    CollectionGet controller = mock(CollectionGet.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) 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) CollectionGet(io.crnk.core.engine.internal.dispatcher.controller.CollectionGet) RepositoryMethodParameterProvider(io.crnk.legacy.internal.RepositoryMethodParameterProvider) ExceptionMapperRegistryTest(io.crnk.core.engine.internal.exception.ExceptionMapperRegistryTest) Test(org.junit.Test)

Example 2 with CollectionGet

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

the class HttpRequestProcessorImplTest method checkProcess.

@Test
public void checkProcess() throws IOException {
    HttpRequestContextBase requestContextBase = Mockito.mock(HttpRequestContextBase.class);
    HttpRequestContextBaseAdapter requestContext = new HttpRequestContextBaseAdapter(requestContextBase);
    Mockito.when(requestContextBase.getMethod()).thenReturn("GET");
    Mockito.when(requestContextBase.getPath()).thenReturn("/tasks/");
    Mockito.when(requestContextBase.getRequestHeader("Accept")).thenReturn("*");
    ControllerRegistry controllerRegistry = new ControllerRegistry(null);
    CollectionGet controller = mock(CollectionGet.class);
    when(controller.isAcceptable(any(JsonPath.class), eq("GET"))).thenCallRealMethod();
    controllerRegistry.addController(controller);
    QuerySpecAdapterBuilder queryAdapterBuilder = new QuerySpecAdapterBuilder(new DefaultQuerySpecDeserializer(), moduleRegistry);
    RequestDispatcher sut = new HttpRequestProcessorImpl(moduleRegistry, controllerRegistry, null, queryAdapterBuilder);
    sut.process(requestContext);
    verify(controller, times(1)).handle(any(JsonPath.class), any(QueryAdapter.class), any(RepositoryMethodParameterProvider.class), any(Document.class));
}
Also used : HttpRequestContextBaseAdapter(io.crnk.core.engine.internal.http.HttpRequestContextBaseAdapter) ControllerRegistry(io.crnk.core.engine.internal.dispatcher.ControllerRegistry) CollectionGet(io.crnk.core.engine.internal.dispatcher.controller.CollectionGet) QuerySpecAdapterBuilder(io.crnk.core.queryspec.internal.QuerySpecAdapterBuilder) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) DefaultQuerySpecDeserializer(io.crnk.core.queryspec.DefaultQuerySpecDeserializer) JsonPath(io.crnk.core.engine.internal.dispatcher.path.JsonPath) Document(io.crnk.core.engine.document.Document) RepositoryMethodParameterProvider(io.crnk.legacy.internal.RepositoryMethodParameterProvider) 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 3 with CollectionGet

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

Aggregations

ControllerRegistry (io.crnk.core.engine.internal.dispatcher.ControllerRegistry)3 CollectionGet (io.crnk.core.engine.internal.dispatcher.controller.CollectionGet)3 HttpRequestProcessorImpl (io.crnk.core.engine.internal.http.HttpRequestProcessorImpl)3 DefaultQuerySpecDeserializer (io.crnk.core.queryspec.DefaultQuerySpecDeserializer)3 QuerySpecAdapterBuilder (io.crnk.core.queryspec.internal.QuerySpecAdapterBuilder)3 RequestDispatcher (io.crnk.core.engine.dispatcher.RequestDispatcher)2 Document (io.crnk.core.engine.document.Document)2 JsonPath (io.crnk.core.engine.internal.dispatcher.path.JsonPath)2 ExceptionMapperRegistryTest (io.crnk.core.engine.internal.exception.ExceptionMapperRegistryTest)2 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)2 RepositoryMethodParameterProvider (io.crnk.legacy.internal.RepositoryMethodParameterProvider)2 Test (org.junit.Test)2 CrnkBoot (io.crnk.core.boot.CrnkBoot)1 PathBuilder (io.crnk.core.engine.internal.dispatcher.path.PathBuilder)1 HttpRequestContextBaseAdapter (io.crnk.core.engine.internal.http.HttpRequestContextBaseAdapter)1 ConstantServiceUrlProvider (io.crnk.core.engine.url.ConstantServiceUrlProvider)1 SimpleModule (io.crnk.core.module.SimpleModule)1 ReflectionsServiceDiscovery (io.crnk.core.module.discovery.ReflectionsServiceDiscovery)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1