use of io.crnk.core.engine.filter.DocumentFilterContext 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.filter.DocumentFilterContext in project crnk-framework by crnk-project.
the class FilterTest method test.
@Test
public void test() throws Exception {
// WHEN
ArgumentCaptor<DocumentFilterContext> captor = ArgumentCaptor.forClass(DocumentFilterContext.class);
when(collectionGet.isAcceptable(any(JsonPath.class), eq(requestType))).thenCallRealMethod();
when(filter.filter(any(DocumentFilterContext.class), any(DocumentFilterChain.class))).thenCallRealMethod();
Map<String, Set<String>> queryParams = new HashMap<>();
RepositoryMethodParameterProvider parameterProvider = new NewInstanceRepositoryMethodParameterProvider();
Document requestBody = new Document();
dispatcher.dispatchRequest(path, requestType, queryParams, parameterProvider, requestBody);
// THEN
verify(filter).filter(captor.capture(), any(DocumentFilterChain.class));
verify(collectionGet, times(1)).handle(any(JsonPath.class), any(QueryAdapter.class), any(RepositoryMethodParameterProvider.class), any(Document.class));
verify(filter, times(1)).filter(any(DocumentFilterContext.class), any(DocumentFilterChain.class));
DocumentFilterContext value = captor.getValue();
Assert.assertEquals("tasks", value.getJsonPath().getElementName());
Assert.assertEquals(parameterProvider, value.getParameterProvider());
Assert.assertEquals(requestBody, value.getRequestBody());
Assert.assertEquals("GET", value.getMethod());
}
use of io.crnk.core.engine.filter.DocumentFilterContext in project crnk-framework by crnk-project.
the class BasicActionTest method setupFeature.
@Override
protected void setupFeature(CrnkTestFeature feature) {
filter = Mockito.spy(new DocumentFilter() {
@Override
public Response filter(DocumentFilterContext filterRequestContext, DocumentFilterChain chain) {
return chain.doFilter(filterRequestContext);
}
});
SimpleModule testModule = new SimpleModule("testFilter");
testModule.addFilter(filter);
feature.addModule(testModule);
}
use of io.crnk.core.engine.filter.DocumentFilterContext in project crnk-framework by crnk-project.
the class BasicActionTest method testInvokeResourceAction.
@Test
public void testInvokeResourceAction() {
Schedule schedule = new Schedule();
schedule.setId(1L);
schedule.setName("scheduleName");
scheduleRepo.create(schedule);
String result = scheduleRepo.resourceAction(1, "hello");
Assert.assertEquals("resource action: hello@scheduleName", result);
// check filters
ArgumentCaptor<DocumentFilterContext> contexts = ArgumentCaptor.forClass(DocumentFilterContext.class);
Mockito.verify(filter, Mockito.times(2)).filter(contexts.capture(), Mockito.any(DocumentFilterChain.class));
DocumentFilterContext actionContext = contexts.getAllValues().get(1);
Assert.assertEquals("GET", actionContext.getMethod());
Assert.assertTrue(actionContext.getJsonPath() instanceof ActionPath);
}
use of io.crnk.core.engine.filter.DocumentFilterContext in project crnk-framework by crnk-project.
the class BasicActionTest method testInvokeRepositoryAction.
@Test
@Ignore
public // The DocumentFilterContext is not invoked with this request any more
void testInvokeRepositoryAction() {
String result = scheduleRepo.repositoryAction("hello");
Assert.assertEquals("repository action: hello", result);
// check filters
ArgumentCaptor<DocumentFilterContext> contexts = ArgumentCaptor.forClass(DocumentFilterContext.class);
Mockito.verify(filter, Mockito.times(1)).filter(contexts.capture(), Mockito.any(DocumentFilterChain.class));
DocumentFilterContext actionContext = contexts.getAllValues().get(0);
Assert.assertEquals("GET", actionContext.getMethod());
Assert.assertTrue(actionContext.getJsonPath() instanceof ActionPath);
}
Aggregations