@Test
  public void testFindContextPaths() {
    ContextPolicy policy = manager.getContextPolicy("/search/standard/user");

    Assert.assertEquals("/search/standard", policy.getContextPath());

    policy = manager.getContextPolicy("/search/standard");

    Assert.assertEquals("/search/standard", policy.getContextPath());

    policy = manager.getContextPolicy("/search/endpoint");

    Assert.assertEquals("/search", policy.getContextPath());

    policy = manager.getContextPolicy("/random/other/endpoint");

    Assert.assertEquals("/", policy.getContextPath());

    policy = manager.getContextPolicy("/aaaaab");

    Assert.assertEquals("/", policy.getContextPath());

    policy = manager.getContextPolicy("/aaa/aab");

    Assert.assertEquals("/aaa", policy.getContextPath());

    policy = manager.getContextPolicy("/");

    Assert.assertEquals("/", policy.getContextPath());

    policy = manager.getContextPolicy("blah");

    Assert.assertEquals("/", policy.getContextPath());

    policy = manager.getContextPolicy("/foo/bar");

    Assert.assertEquals("/foo/bar", policy.getContextPath());

    policy = manager.getContextPolicy("/foo/bar/foobar");

    Assert.assertEquals("/foo/bar", policy.getContextPath());

    policy = manager.getContextPolicy("/foo");

    Assert.assertEquals(null, policy);

    Assert.assertTrue(manager.isWhiteListed("/foo"));

    Assert.assertTrue(!manager.isWhiteListed("/foo/bar"));
  }
  private void testAllPolicies() {
    // check search policy
    ContextPolicy policy = manager.getContextPolicy("/search");
    Assert.assertEquals("/search", policy.getContextPath());
    Iterator<String> authIter = policy.getAuthenticationMethods().iterator();
    int i = 0;
    while (authIter.hasNext()) {
      if (i == 0) {
        Assert.assertEquals("SAML", authIter.next());
      } else if (i == 1) {
        Assert.assertEquals("BASIC", authIter.next());
      } else if (i == 2) {
        Assert.assertEquals("ANON", authIter.next());
      }

      i++;
    }

    Iterator<CollectionPermission> permIter = policy.getAllowedAttributePermissions().iterator();
    i = 0;
    while (authIter.hasNext()) {
      if (i == 0) {
        Assert.assertEquals("role : user", permIter.next().getPermissionList().get(0).toString());
      } else if (i == 1) {
        Assert.assertEquals("control : foo", permIter.next().getPermissionList().get(0).toString());
        Assert.assertEquals("control : bar", permIter.next().getPermissionList().get(1).toString());
      }

      i++;
    }

    // check admin policy
    policy = manager.getContextPolicy("/admin");
    Assert.assertEquals("/admin", policy.getContextPath());
    authIter = policy.getAuthenticationMethods().iterator();
    i = 0;
    while (authIter.hasNext()) {
      if (i == 0) {
        Assert.assertEquals("SAML", authIter.next());
      } else if (i == 1) {
        Assert.assertEquals("BASIC", authIter.next());
      }

      i++;
    }

    // check foo policy
    policy = manager.getContextPolicy("/foo");
    Assert.assertEquals("/foo", policy.getContextPath());
    authIter = policy.getAuthenticationMethods().iterator();
    i = 0;
    while (authIter.hasNext()) {
      if (i == 0) {
        Assert.assertEquals("BASIC", authIter.next());
      }

      i++;
    }

    // make sure some random context points to /
    policy = manager.getContextPolicy("/random");
    Assert.assertEquals("/", policy.getContextPath());
    authIter = policy.getAuthenticationMethods().iterator();
    i = 0;
    while (authIter.hasNext()) {
      if (i == 0) {
        Assert.assertEquals("SAML", authIter.next());
      } else if (i == 1) {
        Assert.assertEquals("BASIC", authIter.next());
      }

      i++;
    }

    // check unprotected contexts
    policy = manager.getContextPolicy("/unprotected");
    Assert.assertEquals("/unprotected", policy.getContextPath());
    authIter = policy.getAuthenticationMethods().iterator();
    Assert.assertEquals(false, authIter.hasNext());

    policy = manager.getContextPolicy("/unprotected2");
    Assert.assertEquals("/unprotected2", policy.getContextPath());
    authIter = policy.getAuthenticationMethods().iterator();
    Assert.assertEquals(false, authIter.hasNext());
  }