@Test
public void testGetAMContainer() throws Exception {

  final ApplicationAttemptId appAttemptId =
      ApplicationAttemptId.newInstance(ApplicationId.newInstance(0, 1), 1);
  ContainerReport container;
  if (callerUGI == null) {
    container = historyManager.getAMContainer(appAttemptId);
  } else {
    try {
      container =
          callerUGI.doAs(new PrivilegedExceptionAction<ContainerReport> () {
        @Override
        public ContainerReport run() throws Exception {
          return historyManager.getAMContainer(appAttemptId);
        }
      });
      if (callerUGI != null && callerUGI.getShortUserName().equals("user3")) {
        // The exception is expected
        Assert.fail();
      }
    } catch (AuthorizationException e) {
      if (callerUGI != null && callerUGI.getShortUserName().equals("user3")) {
        // The exception is expected
        return;
      }
      throw e;
    }
  }
  Assert.assertNotNull(container);
  Assert.assertEquals(appAttemptId, container.getContainerId()
      .getApplicationAttemptId());
}