use of io.crnk.core.queryspec.DefaultQuerySpecDeserializer in project crnk-framework by crnk-project.
the class CrnkFeatureTest method testQuerySpecConstructor.
@Test
public void testQuerySpecConstructor() {
ObjectMapper objectMapper = new ObjectMapper();
QuerySpecDeserializer querySpecDeserializer = new DefaultQuerySpecDeserializer();
SampleJsonServiceLocator serviceLocator = new SampleJsonServiceLocator();
CrnkFeature feature = new CrnkFeature(objectMapper, querySpecDeserializer, serviceLocator);
Assert.assertSame(objectMapper, feature.getObjectMapper());
Assert.assertSame(querySpecDeserializer, feature.getBoot().getQuerySpecDeserializer());
}
use of io.crnk.core.queryspec.DefaultQuerySpecDeserializer 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));
}
use of io.crnk.core.queryspec.DefaultQuerySpecDeserializer 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));
}
use of io.crnk.core.queryspec.DefaultQuerySpecDeserializer in project crnk-framework by crnk-project.
the class HttpRequestProcessorImplTest method shouldMapExceptionToErrorResponseIfMapperIsAvailable.
@Test
public void shouldMapExceptionToErrorResponseIfMapperIsAvailable() throws Exception {
ControllerRegistry controllerRegistry = mock(ControllerRegistry.class);
// noinspection unchecked
when(controllerRegistry.getController(any(JsonPath.class), anyString())).thenThrow(IllegalStateException.class);
QuerySpecAdapterBuilder queryAdapterBuilder = new QuerySpecAdapterBuilder(new DefaultQuerySpecDeserializer(), moduleRegistry);
RequestDispatcher requestDispatcher = new HttpRequestProcessorImpl(moduleRegistry, controllerRegistry, ExceptionMapperRegistryTest.exceptionMapperRegistry, queryAdapterBuilder);
Response response = requestDispatcher.dispatchRequest("tasks", null, null, null, null);
assertThat(response).isNotNull();
assertThat(response.getHttpStatus()).isEqualTo(HttpStatus.BAD_REQUEST_400);
}
use of io.crnk.core.queryspec.DefaultQuerySpecDeserializer in project crnk-framework by crnk-project.
the class CrnkBootTest method testDiscoverDeserializer.
@Test
public void testDiscoverDeserializer() {
CrnkBoot boot = new CrnkBoot();
boot.setServiceDiscovery(serviceDiscovery);
DefaultQuerySpecDeserializer instance = new DefaultQuerySpecDeserializer();
Mockito.when(serviceDiscovery.getInstancesByType(eq(QuerySpecDeserializer.class))).thenReturn(Arrays.<QuerySpecDeserializer>asList(instance));
boot.boot();
Assert.assertSame(instance, boot.getQuerySpecDeserializer());
}
Aggregations