@Test
public void testPreserveAuthHeader() throws Exception {

    HttpRequest request = new BasicHttpRequest("GET", "/");
    request.addHeader(AUTH.WWW_AUTH_RESP, "Basic c3R1ZmY6c3R1ZmY=");
    HttpContext context = new BasicHttpContext();
    BasicScheme authscheme = new BasicScheme();
    Credentials creds = new UsernamePasswordCredentials("user", "secret");
    AuthScope authscope = new AuthScope("localhost", 8080, "auth-realm", "http");
    BasicHeader challenge = new BasicHeader(AUTH.WWW_AUTH, "BASIC realm=auth-realm");
    authscheme.processChallenge(challenge);
    AuthState authstate = new AuthState();
    authstate.setAuthScheme(authscheme);
    authstate.setAuthScope(authscope);
    authstate.setCredentials(creds);
    context.setAttribute(ClientContext.TARGET_AUTH_STATE, authstate);
    HttpRequestInterceptor interceptor = new RequestTargetAuthentication();
    interceptor.process(request, context);
    Header header = request.getFirstHeader(AUTH.WWW_AUTH_RESP);
    Assert.assertNotNull(header);
    Assert.assertEquals("Basic c3R1ZmY6c3R1ZmY=", header.getValue());
}