@Test
public void testGetUgiDuringStartup() throws Exception {

  conf.set(DFSConfigKeys.FS_DEFAULT_NAME_KEY, "hdfs://localhost:4321/");
  ServletContext context = mock(ServletContext.class);
  String realUser = "TheDoctor";
  String user = "TheNurse";
  conf.set(DFSConfigKeys.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
  UserGroupInformation.setConfiguration(conf);
  HttpServletRequest request;
  Text ownerText = new Text(user);
  DelegationTokenIdentifier dtId = new DelegationTokenIdentifier(
      ownerText, ownerText, new Text(realUser));
  Token<DelegationTokenIdentifier> token =
      new Token<DelegationTokenIdentifier>(dtId,
          new DummySecretManager(0, 0, 0, 0));
  String tokenString = token.encodeToUrlString();
  // token with auth-ed user
  request = getMockRequest(realUser, null, null);
  when(request.getParameter(JspHelper.DELEGATION_PARAMETER_NAME)).thenReturn(
      tokenString);
  NameNode mockNN = mock(NameNode.class);
  Mockito.doCallRealMethod().when(mockNN)
      .verifyToken(Mockito.any(), Mockito.any());
  when(context.getAttribute("name.node")).thenReturn(mockNN);
  LambdaTestUtils.intercept(RetriableException.class,
      "Namenode is in startup mode",
      () -> JspHelper.getUGI(context, request, conf));
}