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);
}
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));
}
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);
}
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");
}
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);
}
Aggregations