private StubResponse identifyTypeOfStubResponse(final StubHttpLifecycle assertionStubHttpLifecycle) {
if (stubHttpLifecycles.contains(assertionStubHttpLifecycle)) {
final int indexOf = stubHttpLifecycles.indexOf(assertionStubHttpLifecycle);
final StubHttpLifecycle foundStubHttpLifecycle = stubHttpLifecycles.get(indexOf);
final Map<String, String> headers = foundStubHttpLifecycle.getRequest().getHeaders();
if (headers.containsKey(StubRequest.AUTH_HEADER)) {
final String foundBasicAuthorization = headers.get(StubRequest.AUTH_HEADER);
final String givenBasicAuthorization = assertionStubHttpLifecycle.getRequest().getHeaders().get(StubRequest.AUTH_HEADER);
if (!foundBasicAuthorization.equals(givenBasicAuthorization)) {
return new UnauthorizedStubResponse();
}
}
if (foundStubHttpLifecycle.getResponse().getHeaders().containsKey("location")) {
final RedirectStubResponse redirectStubResponse = new RedirectStubResponse();
redirectStubResponse.setLatency(foundStubHttpLifecycle.getResponse().getLatency());
redirectStubResponse.setBody(foundStubHttpLifecycle.getResponse().getBody());
redirectStubResponse.setStatus(foundStubHttpLifecycle.getResponse().getStatus());
redirectStubResponse.setHeaders(foundStubHttpLifecycle.getResponse().getHeaders());
return redirectStubResponse;
}
return foundStubHttpLifecycle.getResponse();
}
return new NotFoundStubResponse();
}