Search in sources :

Example 1 with CountFilter

use of com.linkedin.restli.internal.server.filter.testfilters.CountFilter in project rest.li by linkedin.

the class TestRestLiFilterChain method testFilterInvocationSuccess.

@SuppressWarnings(value = "unchecked")
@Test
public void testFilterInvocationSuccess() throws Exception {
    _restLiFilterChain = new RestLiFilterChain(Arrays.asList(_filters), _mockFilterChainDispatcher, _mockFilterChainCallback);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            _restLiFilterChain.onResponse(_mockFilterRequestContext, _mockFilterResponseContext);
            return null;
        }
    }).when(_mockFilterChainDispatcher).onRequestSuccess(eq(_mockRestLiRequestData), any(RestLiCallback.class));
    when(_mockFilterRequestContext.getRequestData()).thenReturn(_mockRestLiRequestData);
    when(_mockFilterResponseContext.getResponseData()).thenReturn(_mockRestLiResponseData);
    when(_mockFilterResponseContextFactory.fromThrowable(any(Throwable.class))).thenReturn(_mockFilterResponseContext);
    _restLiFilterChain.onRequest(_mockFilterRequestContext, _mockFilterResponseContextFactory);
    for (CountFilter filter : _filters) {
        assertEquals(filter.getNumRequests(), 1);
        assertEquals(filter.getNumResponses(), 1);
        assertEquals(filter.getNumErrors(), 0);
    }
    verify(_mockFilterRequestContext).getRequestData();
    verify(_mockFilterChainDispatcher).onRequestSuccess(eq(_mockRestLiRequestData), any(RestLiCallback.class));
    verify(_mockFilterChainCallback).onResponseSuccess(_mockRestLiResponseData);
    verifyNoMoreInteractions(_mockFilterChainCallback, _mockFilterRequestContext, _mockRestLiRequestData);
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) RestLiCallback(com.linkedin.restli.internal.server.RestLiCallback) CountFilter(com.linkedin.restli.internal.server.filter.testfilters.CountFilter) Test(org.testng.annotations.Test)

Example 2 with CountFilter

use of com.linkedin.restli.internal.server.filter.testfilters.CountFilter in project rest.li by linkedin.

the class TestRestLiFilterChain method resetMocks.

@AfterMethod
protected void resetMocks() {
    reset(_mockFilterChainDispatcher, _mockFilterChainCallback, _mockFilterRequestContext, _mockFilterResponseContext, _mockRestLiRequestData, _mockRestLiResponseData);
    _filters = new CountFilter[] { new CountFilter(), new CountFilter(), new CountFilter() };
}
Also used : CountFilter(com.linkedin.restli.internal.server.filter.testfilters.CountFilter) AfterMethod(org.testng.annotations.AfterMethod)

Example 3 with CountFilter

use of com.linkedin.restli.internal.server.filter.testfilters.CountFilter in project rest.li by linkedin.

the class TestRestLiFilterChain method init.

@BeforeMethod
protected void init() {
    _filters = new CountFilter[] { new CountFilter(), new CountFilter(), new CountFilter() };
    when(_mockFilterResponseContextFactory.getRequestContext()).thenAnswer(invocation -> new RequestContext());
    when(_method.getContext()).thenAnswer(invocation -> new ResourceContextImpl());
}
Also used : FilterRequestContext(com.linkedin.restli.server.filter.FilterRequestContext) RequestContext(com.linkedin.r2.message.RequestContext) CountFilter(com.linkedin.restli.internal.server.filter.testfilters.CountFilter) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

CountFilter (com.linkedin.restli.internal.server.filter.testfilters.CountFilter)3 RequestContext (com.linkedin.r2.message.RequestContext)1 ResourceContextImpl (com.linkedin.restli.internal.server.ResourceContextImpl)1 RestLiCallback (com.linkedin.restli.internal.server.RestLiCallback)1 FilterRequestContext (com.linkedin.restli.server.filter.FilterRequestContext)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 AfterMethod (org.testng.annotations.AfterMethod)1 BeforeMethod (org.testng.annotations.BeforeMethod)1 Test (org.testng.annotations.Test)1