@Test
public void testGetApplicationReport() throws Exception {

  for (int i = 1; i <= 2; ++i) {
    final ApplicationId appId = ApplicationId.newInstance(0, i);
    ApplicationReport app;
    if (callerUGI == null) {
      app = historyManager.getApplication(appId);
    } else {
      app =
          callerUGI.doAs(new PrivilegedExceptionAction<ApplicationReport> () {
        @Override
        public ApplicationReport run() throws Exception {
          return historyManager.getApplication(appId);
        }
      });
    }
    Assert.assertNotNull(app);
    Assert.assertEquals(appId, app.getApplicationId());
    Assert.assertEquals("test app", app.getName());
    Assert.assertEquals("test app type", app.getApplicationType());
    Assert.assertEquals("user1", app.getUser());
    Assert.assertEquals("test queue", app.getQueue());
    Assert.assertEquals(Integer.MAX_VALUE + 2L
        + app.getApplicationId().getId(), app.getStartTime());
    Assert.assertEquals(Integer.MAX_VALUE + 3L
        + +app.getApplicationId().getId(), app.getFinishTime());
    Assert.assertTrue(Math.abs(app.getProgress() - 1.0F) < 0.0001);
    // App 2 doesn't have the ACLs, such that the default ACLs " " will be used.
    // Nobody except admin and owner has access to the details of the app.
    if ((i ==  1 && callerUGI != null &&
        callerUGI.getShortUserName().equals("user3")) ||
        (i ==  2 && callerUGI != null &&
        (callerUGI.getShortUserName().equals("user2") ||
            callerUGI.getShortUserName().equals("user3")))) {
      Assert.assertEquals(ApplicationAttemptId.newInstance(appId, -1),
          app.getCurrentApplicationAttemptId());
      Assert.assertEquals(ApplicationHistoryManagerOnTimelineStore.UNAVAILABLE,
          app.getHost());
      Assert.assertEquals(-1, app.getRpcPort());
      Assert.assertEquals(ApplicationHistoryManagerOnTimelineStore.UNAVAILABLE,
          app.getTrackingUrl());
      Assert.assertEquals(ApplicationHistoryManagerOnTimelineStore.UNAVAILABLE,
          app.getOriginalTrackingUrl());
      Assert.assertEquals("", app.getDiagnostics());
    } else {
      Assert.assertEquals(ApplicationAttemptId.newInstance(appId, 1),
          app.getCurrentApplicationAttemptId());
      Assert.assertEquals("test host", app.getHost());
      Assert.assertEquals(100, app.getRpcPort());
      Assert.assertEquals("test tracking url", app.getTrackingUrl());
      Assert.assertEquals("test original tracking url",
          app.getOriginalTrackingUrl());
      Assert.assertEquals("test diagnostics info", app.getDiagnostics());
    }
    ApplicationResourceUsageReport applicationResourceUsageReport =
        app.getApplicationResourceUsageReport();
    Assert.assertEquals(123,
        applicationResourceUsageReport.getMemorySeconds());
    Assert
        .assertEquals(345, applicationResourceUsageReport.getVcoreSeconds());
    Assert.assertEquals(FinalApplicationStatus.UNDEFINED,
        app.getFinalApplicationStatus());
    Assert.assertEquals(YarnApplicationState.FINISHED,
        app.getYarnApplicationState());
  }
}