@Test
public void testGetUgi() throws IOException {

  conf.set(DFSConfigKeys.FS_DEFAULT_NAME_KEY, "hdfs://localhost:4321/");
  HttpServletRequest request = mock(HttpServletRequest.class);
  String user = "TheDoctor";
  Text userText = new Text(user);
  DelegationTokenIdentifier dtId = new DelegationTokenIdentifier(userText,
      userText, null);
  Token<DelegationTokenIdentifier> token = new Token<DelegationTokenIdentifier>(
      dtId, new DummySecretManager(0, 0, 0, 0));
  String tokenString = token.encodeToUrlString();
  when(request.getParameter(JspHelper.DELEGATION_PARAMETER_NAME)).thenReturn(
      tokenString);
  when(request.getRemoteUser()).thenReturn(user);
  conf.set(DFSConfigKeys.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
  UserGroupInformation.setConfiguration(conf);
  InetSocketAddress serviceAddr = NameNode.getAddress(conf);
  Text tokenService = new Text(serviceAddr.getAddress().getHostAddress()
      + ":" + serviceAddr.getPort());
  UserGroupInformation ugi = JspHelper.getUGI(request, conf);
  Token<? extends TokenIdentifier> tokenInUgi = ugi.getTokens().iterator()
      .next();
  Assert.assertEquals(tokenInUgi.getService(), tokenService);
}