public void doNotFollowRedirectsToDirIndex()
throws ProtocolException
{
when(response.getStatusLine()).thenReturn(statusLine);
final RedirectStrategy underTest = new NexusRedirectStrategy();
HttpContext httpContext;
// no location header
request = new HttpGet("http://localhost/dir/fileA");
httpContext = new BasicHttpContext();
httpContext.setAttribute(NexusRedirectStrategy.CONTENT_RETRIEVAL_MARKER_KEY, Boolean.TRUE);
when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_OK);
assertThat(underTest.isRedirected(request, response, httpContext), is(false));
// redirect to file
request = new HttpGet("http://localhost/dir/fileA");
httpContext = new BasicHttpContext();
httpContext.setAttribute(NexusRedirectStrategy.CONTENT_RETRIEVAL_MARKER_KEY, Boolean.TRUE);
when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_MOVED_TEMPORARILY);
when(response.getFirstHeader("location")).thenReturn(
new BasicHeader("location", "http://localhost/dir/fileB"));
assertThat(underTest.isRedirected(request, response, httpContext), is(true));
// redirect to dir
request = new HttpGet("http://localhost/dir");
httpContext = new BasicHttpContext();
httpContext.setAttribute(NexusRedirectStrategy.CONTENT_RETRIEVAL_MARKER_KEY, Boolean.TRUE);
when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_MOVED_TEMPORARILY);
when(response.getFirstHeader("location")).thenReturn(new BasicHeader("location", "http://localhost/dir/"));
assertThat(underTest.isRedirected(request, response, httpContext), is(false));
}