@Before
  public void setup() throws Exception {
    httpDigest = new HTTPDigestAuthentication();

    httpDigest.setAuthManager(new PropertiesFileBasedAuthenticationManager());

    httpDigest.setRealmName("*****@*****.**");
    httpDigest.setOpaque("5ccc069c403ebaf9f0171e9517f40e41");
  }
  @Test
  public void testHttpDigest() throws Exception {
    TestServletRequest req =
        new TestServletRequest(
            new InputStream() {
              @Override
              public int read() throws IOException {
                return 0;
              }
            });

    TestServletResponse resp =
        new TestServletResponse(
            new OutputStream() {

              @Override
              public void write(int b) throws IOException {
                System.out.println(b);
              }
            });

    req.setMethod("GET");

    // Call the server to get the digest challenge
    Principal result = httpDigest.authenticate(req, resp);
    assertNull(result);

    String authorizationHeader = resp.getHeader(PicketBoxConstants.HTTP_WWW_AUTHENTICATE);
    authorizationHeader = authorizationHeader.substring(7);
    String[] tokens = HTTPDigestUtil.quoteTokenize(authorizationHeader);

    // Let us get the digest info
    DigestHolder digest = HTTPDigestUtil.digest(tokens);

    // Get Positive Authentication
    req.addHeader(PicketBoxConstants.HTTP_AUTHORIZATION_HEADER, "Digest " + getPositive(digest));
    result = httpDigest.authenticate(req, resp);

    assertNotNull(result);

    req.clearHeaders();

    // Get Negative Authentication
    req.addHeader(PicketBoxConstants.HTTP_AUTHORIZATION_HEADER, "Digest " + getNegative());
    result = httpDigest.authenticate(req, resp);
    assertNull(result);

    String digestHeader = resp.getHeader(PicketBoxConstants.HTTP_WWW_AUTHENTICATE);
    assertTrue(digestHeader.startsWith("Digest realm="));
  }