Search in sources :

Example 1 with CountFilterResponseErrorOnError

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

the class TestRestLiFilterChain method testFilterInvocationResponseErrorOnError.

@SuppressWarnings("unchecked")
@Test
public void testFilterInvocationResponseErrorOnError() throws Exception {
    _restLiFilterChain = new RestLiFilterChain(Arrays.asList(_filters), _mockFilterChainCallback);
    _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);
    when(_responseHandler.buildExceptionResponseData(eq(_request), eq(_method), any(Object.class), anyMap(), anyList())).thenReturn(_mockRestLiResponseData);
    when(_mockFilterResponseContextFactory.fromThrowable(any(Throwable.class))).thenReturn(_mockFilterResponseContext);
    _restLiFilterChain.onRequest(_mockFilterRequestContext, _mockFilterResponseContextFactory);
    verifySecondFilterResponseException();
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) RestLiCallback(com.linkedin.restli.internal.server.RestLiCallback) CountFilterResponseErrorOnError(com.linkedin.restli.internal.server.filter.testfilters.CountFilterResponseErrorOnError) Test(org.testng.annotations.Test)

Example 2 with CountFilterResponseErrorOnError

use of com.linkedin.restli.internal.server.filter.testfilters.CountFilterResponseErrorOnError 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 3 with CountFilterResponseErrorOnError

use of com.linkedin.restli.internal.server.filter.testfilters.CountFilterResponseErrorOnError 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)3 CountFilterResponseErrorOnError (com.linkedin.restli.internal.server.filter.testfilters.CountFilterResponseErrorOnError)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Test (org.testng.annotations.Test)3 CountFilterResponseErrorFixesError (com.linkedin.restli.internal.server.filter.testfilters.CountFilterResponseErrorFixesError)2