@Test public void testRunGracefullyHandlesRuntimeException() throws Exception { final String identifier = "foo"; final AsynchronousValidationRequest impl = new AsynchronousValidationRequest( mockParent, mockClient, route, request, context, mockExecAware, mockCacheEntry, identifier, 0); when(mockClient.revalidateCacheEntry(route, request, context, mockExecAware, mockCacheEntry)) .thenThrow(new RuntimeException()); impl.run(); verify(mockClient).revalidateCacheEntry(route, request, context, mockExecAware, mockCacheEntry); verify(mockParent).markComplete(identifier); verify(mockParent).jobFailed(identifier); }
@Test public void testRunCallsCachingClientAndRemovesIdentifier() throws Exception { final String identifier = "foo"; final AsynchronousValidationRequest impl = new AsynchronousValidationRequest( mockParent, mockClient, route, request, context, mockExecAware, mockCacheEntry, identifier, 0); when(mockClient.revalidateCacheEntry(route, request, context, mockExecAware, mockCacheEntry)) .thenReturn(mockResponse); when(mockResponse.getStatusLine()).thenReturn(mockStatusLine); when(mockStatusLine.getStatusCode()).thenReturn(200); impl.run(); verify(mockClient).revalidateCacheEntry(route, request, context, mockExecAware, mockCacheEntry); verify(mockResponse).getStatusLine(); verify(mockParent).markComplete(identifier); verify(mockParent).jobSuccessful(identifier); }
@Test public void testRunReportsJobFailedForStaleResponse() throws Exception { final String identifier = "foo"; final Header[] warning = new Header[] { new BasicHeader(HeaderConstants.WARNING, "110 localhost \"Response is stale\"") }; final AsynchronousValidationRequest impl = new AsynchronousValidationRequest( mockParent, mockClient, route, request, context, mockExecAware, mockCacheEntry, identifier, 0); when(mockClient.revalidateCacheEntry(route, request, context, mockExecAware, mockCacheEntry)) .thenReturn(mockResponse); when(mockResponse.getStatusLine()).thenReturn(mockStatusLine); when(mockStatusLine.getStatusCode()).thenReturn(200); when(mockResponse.getHeaders(HeaderConstants.WARNING)).thenReturn(warning); impl.run(); verify(mockClient).revalidateCacheEntry(route, request, context, mockExecAware, mockCacheEntry); verify(mockResponse).getStatusLine(); verify(mockStatusLine).getStatusCode(); verify(mockResponse).getHeaders(HeaderConstants.WARNING); verify(mockParent).markComplete(identifier); verify(mockParent).jobFailed(identifier); }