@Test
  public void testBasicAuthenticationNoCreds() throws Exception {
    this.localServer.register("*", new AuthHandler());
    this.localServer.start();

    TestCredentialsProvider credsProvider = new TestCredentialsProvider(null);

    this.httpclient.setCredentialsProvider(credsProvider);

    HttpGet httpget = new HttpGet("/");

    HttpResponse response = this.httpclient.execute(getServerHttp(), httpget);
    HttpEntity entity = response.getEntity();
    Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode());
    Assert.assertNotNull(entity);
    EntityUtils.consume(entity);
    AuthScope authscope = credsProvider.getAuthScope();
    Assert.assertNotNull(authscope);
    Assert.assertEquals("test realm", authscope.getRealm());
  }
  @Test
  public void testBasicAuthenticationSuccess() throws Exception {
    this.serverBootstrap.registerHandler("*", new AuthHandler());

    final HttpHost target = start();

    final HttpClientContext context = HttpClientContext.create();
    final TestCredentialsProvider credsProvider =
        new TestCredentialsProvider(new UsernamePasswordCredentials("test", "test"));
    context.setCredentialsProvider(credsProvider);
    final HttpGet httpget = new HttpGet("/");

    final HttpResponse response = this.httpclient.execute(target, httpget, context);
    final HttpEntity entity = response.getEntity();
    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    Assert.assertNotNull(entity);
    EntityUtils.consume(entity);
    final AuthScope authscope = credsProvider.getAuthScope();
    Assert.assertNotNull(authscope);
    Assert.assertEquals("test realm", authscope.getRealm());
  }
  @Test
  public void testBasicAuthenticationSuccessOnRepeatablePost() throws Exception {
    this.localServer.register("*", new AuthHandler());
    this.localServer.start();

    TestCredentialsProvider credsProvider =
        new TestCredentialsProvider(new UsernamePasswordCredentials("test", "test"));

    this.httpclient.setCredentialsProvider(credsProvider);

    HttpPost httppost = new HttpPost("/");
    httppost.setEntity(new StringEntity("some important stuff", Consts.ASCII));

    HttpResponse response = this.httpclient.execute(getServerHttp(), httppost);
    HttpEntity entity = response.getEntity();
    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    Assert.assertNotNull(entity);
    EntityUtils.consume(entity);
    AuthScope authscope = credsProvider.getAuthScope();
    Assert.assertNotNull(authscope);
    Assert.assertEquals("test realm", authscope.getRealm());
  }