Search in sources :

Example 11 with HttpRequestProcessorImpl

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

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

the class ResourceFieldContributorTest method checkInclusionUponRequest.

@Test
public void checkInclusionUponRequest() {
    TaskRepository repo = new TaskRepository();
    Task task = new Task();
    task.setId(1L);
    task.setName("someTask");
    repo.save(task);
    HttpRequestProcessorImpl requestDispatcher = boot.getRequestDispatcher();
    HttpRequestContextProvider httpRequestContextProvider = boot.getModuleRegistry().getHttpRequestContextProvider();
    HttpRequestContext request = Mockito.mock(HttpRequestContext.class);
    httpRequestContextProvider.onRequestStarted(request);
    Map<String, Set<String>> parameters = new HashMap<>();
    parameters.put("include", Sets.newHashSet("contributedProject"));
    Response response = requestDispatcher.dispatchRequest("tasks", "GET", parameters, null, null);
    Document document = response.getDocument();
    Resource resource = document.getCollectionData().get().get(0);
    Assert.assertEquals("1", resource.getId());
    Assert.assertEquals("tasks", resource.getType());
    Assert.assertEquals("someTask", resource.getAttributes().get("name").asText());
    Relationship relationship = resource.getRelationships().get("contributedProject");
    Assert.assertNotNull(relationship);
    ResourceIdentifier relationshipId = relationship.getSingleData().get();
    Assert.assertEquals("projects", relationshipId.getType());
    Assert.assertEquals("11", relationshipId.getId());
    List<Resource> included = document.getIncluded();
    Assert.assertEquals(1, included.size());
    Resource includedResource = included.get(0);
    Assert.assertEquals("projects", includedResource.getType());
    Assert.assertEquals("11", includedResource.getId());
    Assert.assertEquals("someProject", includedResource.getAttributes().get("name").asText());
}
Also used : Task(io.crnk.core.mock.models.Task) Set(java.util.Set) HashMap(java.util.HashMap) ProjectToTaskRepository(io.crnk.core.mock.repository.ProjectToTaskRepository) TaskRepository(io.crnk.core.mock.repository.TaskRepository) Resource(io.crnk.core.engine.document.Resource) Document(io.crnk.core.engine.document.Document) HttpRequestProcessorImpl(io.crnk.core.engine.internal.http.HttpRequestProcessorImpl) Response(io.crnk.core.engine.dispatcher.Response) ResourceIdentifier(io.crnk.core.engine.document.ResourceIdentifier) Relationship(io.crnk.core.engine.document.Relationship) HttpRequestContext(io.crnk.core.engine.http.HttpRequestContext) HttpRequestContextProvider(io.crnk.core.engine.http.HttpRequestContextProvider) Test(org.junit.Test)

Example 13 with HttpRequestProcessorImpl

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

Example 14 with HttpRequestProcessorImpl

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

the class CrnkBootTest method setQuerySpecDeserializer.

@Test
public void setQuerySpecDeserializer() {
    CrnkBoot boot = new CrnkBoot();
    boot.setServiceDiscoveryFactory(serviceDiscoveryFactory);
    boot.setDefaultServiceUrlProvider(mock(ServiceUrlProvider.class));
    QuerySpecDeserializer deserializer = Mockito.mock(QuerySpecDeserializer.class);
    boot.setQuerySpecDeserializer(deserializer);
    Assert.assertSame(deserializer, boot.getQuerySpecDeserializer());
    boot.boot();
    HttpRequestProcessorImpl requestDispatcher = boot.getRequestDispatcher();
    QueryAdapterBuilder queryAdapterBuilder = requestDispatcher.getQueryAdapterBuilder();
    Assert.assertTrue(queryAdapterBuilder instanceof QuerySpecAdapterBuilder);
}
Also used : QuerySpecAdapterBuilder(io.crnk.core.queryspec.internal.QuerySpecAdapterBuilder) QuerySpecDeserializer(io.crnk.core.queryspec.QuerySpecDeserializer) DefaultQuerySpecDeserializer(io.crnk.core.queryspec.DefaultQuerySpecDeserializer) ConstantServiceUrlProvider(io.crnk.core.engine.url.ConstantServiceUrlProvider) ServiceUrlProvider(io.crnk.core.engine.url.ServiceUrlProvider) HttpRequestProcessorImpl(io.crnk.core.engine.internal.http.HttpRequestProcessorImpl) QueryAdapterBuilder(io.crnk.core.engine.query.QueryAdapterBuilder) Test(org.junit.Test)

Example 15 with HttpRequestProcessorImpl

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

the class HomeModuleTest method testNonRootRequestNotTouchedForDifferentContentType.

@Test
public void testNonRootRequestNotTouchedForDifferentContentType() throws IOException {
    HttpRequestContextBase requestContextBase = Mockito.mock(HttpRequestContextBase.class);
    Mockito.when(requestContextBase.getMethod()).thenReturn("GET");
    Mockito.when(requestContextBase.getPath()).thenReturn("/");
    Mockito.when(requestContextBase.getRequestHeader("Accept")).thenReturn("application/doesNotExists");
    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)

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