@Test
public void testProxyUserConfiguration() {

  FilterContainer container = Mockito.mock(FilterContainer.class);
  for (int i = 0; i < 3; ++i) {
    Configuration conf = new YarnConfiguration();
    switch (i) {
      case 0:
        // hadoop.proxyuser prefix
        conf.set("hadoop.proxyuser.foo.hosts", "*");
        conf.set("hadoop.proxyuser.foo.users", "*");
        conf.set("hadoop.proxyuser.foo.groups", "*");
        break;
      case 1:
        // yarn.timeline-service.http-authentication.proxyuser prefix
        conf.set("yarn.timeline-service.http-authentication.proxyuser.foo.hosts",
            "*");
        conf.set("yarn.timeline-service.http-authentication.proxyuser.foo.users",
            "*");
        conf.set("yarn.timeline-service.http-authentication.proxyuser.foo.groups",
            "*");
        break;
      case 2:
        // hadoop.proxyuser prefix has been overwritten by
        // yarn.timeline-service.http-authentication.proxyuser prefix
        conf.set("hadoop.proxyuser.foo.hosts", "bar");
        conf.set("hadoop.proxyuser.foo.users", "bar");
        conf.set("hadoop.proxyuser.foo.groups", "bar");
        conf.set("yarn.timeline-service.http-authentication.proxyuser.foo.hosts",
            "*");
        conf.set("yarn.timeline-service.http-authentication.proxyuser.foo.users",
            "*");
        conf.set("yarn.timeline-service.http-authentication.proxyuser.foo.groups",
            "*");
        break;
      default:
        break;
    }
    TimelineAuthenticationFilterInitializer initializer =
        new TimelineAuthenticationFilterInitializer();
    initializer.initFilter(container, conf);
    Assert.assertEquals(
        "*", initializer.filterConfig.get("proxyuser.foo.hosts"));
    Assert.assertEquals(
        "*", initializer.filterConfig.get("proxyuser.foo.users"));
    Assert.assertEquals(
        "*", initializer.filterConfig.get("proxyuser.foo.groups"));
  }
}