Search in sources :

Example 1 with CountFilterResponseErrorFixesError

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

the class TestRestLiFilterChain method testFilterInvocationResponseErrorFixesError.

@SuppressWarnings(value = "unchecked")
@Test
public void testFilterInvocationResponseErrorFixesError() throws Exception {
    _restLiFilterChain = new RestLiFilterChain(Arrays.asList(_filters), _mockFilterChainCallback);
    _filters[1] = new CountFilterResponseErrorFixesError();
    _filters[2] = new CountFilterResponseErrorOnError();
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            _restLiFilterChain.onResponse(_mockFilterRequestContext, _mockFilterResponseContext, _mockResponseAttachments);
            return null;
        }
    }).when(_mockFilterChainCallback).onRequestSuccess(eq(_mockRestLiRequestData), any(RestLiCallback.class));
    when(_mockFilterRequestContext.getRequestData()).thenReturn(_mockRestLiRequestData);
    when(_mockFilterResponseContext.getResponseData()).thenReturn(_mockRestLiResponseData);
    _restLiFilterChain.onRequest(_mockFilterRequestContext, _mockFilterResponseContextFactory);
    assertFilterCounts(_filters[0], 1, 1, 0);
    assertFilterCounts(_filters[1], 1, 0, 1);
    assertFilterCounts(_filters[2], 1, 1, 0);
    verify(_mockFilterChainCallback).onRequestSuccess(eq(_mockRestLiRequestData), any(RestLiCallback.class));
    verify(_mockFilterChainCallback).onResponseSuccess(eq(_mockRestLiResponseData), eq(_mockResponseAttachments));
    verify(_mockFilterRequestContext).getRequestData();
    verify(_mockFilterResponseContext, times(3)).getResponseData();
    verifyNoMoreInteractions(_mockFilterChainCallback, _mockFilterRequestContext, _mockRestLiRequestData);
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) RestLiCallback(com.linkedin.restli.internal.server.RestLiCallback) CountFilterResponseErrorOnError(com.linkedin.restli.internal.server.filter.testfilters.CountFilterResponseErrorOnError) CountFilterResponseErrorFixesError(com.linkedin.restli.internal.server.filter.testfilters.CountFilterResponseErrorFixesError) Test(org.testng.annotations.Test)

Example 2 with CountFilterResponseErrorFixesError

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

the class TestRestLiFilterChain method testFilterInvocationLastResponseErrorFixesError.

@SuppressWarnings(value = "unchecked")
@Test
public void testFilterInvocationLastResponseErrorFixesError() throws Exception {
    _restLiFilterChain = new RestLiFilterChain(Arrays.asList(_filters), _mockFilterChainCallback);
    _filters[0] = new CountFilterResponseErrorFixesError();
    _filters[1] = new CountFilterResponseErrorOnError();
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            _restLiFilterChain.onResponse(_mockFilterRequestContext, _mockFilterResponseContext, _mockResponseAttachments);
            return null;
        }
    }).when(_mockFilterChainCallback).onRequestSuccess(eq(_mockRestLiRequestData), any(RestLiCallback.class));
    when(_mockFilterRequestContext.getRequestData()).thenReturn(_mockRestLiRequestData);
    when(_mockFilterResponseContext.getResponseData()).thenReturn(_mockRestLiResponseData);
    _restLiFilterChain.onRequest(_mockFilterRequestContext, _mockFilterResponseContextFactory);
    assertFilterCounts(_filters[0], 1, 0, 1);
    assertFilterCounts(_filters[1], 1, 1, 0);
    assertFilterCounts(_filters[2], 1, 1, 0);
    verify(_mockFilterChainCallback).onRequestSuccess(eq(_mockRestLiRequestData), any(RestLiCallback.class));
    verify(_mockFilterChainCallback).onResponseSuccess(eq(_mockRestLiResponseData), eq(_mockResponseAttachments));
    verify(_mockFilterRequestContext).getRequestData();
    verify(_mockFilterResponseContext, times(3)).getResponseData();
    verifyNoMoreInteractions(_mockFilterChainCallback, _mockFilterRequestContext, _mockRestLiRequestData);
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) RestLiCallback(com.linkedin.restli.internal.server.RestLiCallback) CountFilterResponseErrorOnError(com.linkedin.restli.internal.server.filter.testfilters.CountFilterResponseErrorOnError) CountFilterResponseErrorFixesError(com.linkedin.restli.internal.server.filter.testfilters.CountFilterResponseErrorFixesError) Test(org.testng.annotations.Test)

Aggregations

RestLiCallback (com.linkedin.restli.internal.server.RestLiCallback)2 CountFilterResponseErrorFixesError (com.linkedin.restli.internal.server.filter.testfilters.CountFilterResponseErrorFixesError)2 CountFilterResponseErrorOnError (com.linkedin.restli.internal.server.filter.testfilters.CountFilterResponseErrorOnError)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Test (org.testng.annotations.Test)2