@Test
public void testGetApplicationReport() throws Exception {

  ResourceScheduler scheduler = mock(ResourceScheduler.class);
  RMContext rmContext = mock(RMContext.class);
  mockRMContext(scheduler, rmContext);
  ApplicationId appId1 = getApplicationId(1);
  ApplicationACLsManager mockAclsManager = mock(ApplicationACLsManager.class);
  when(
      mockAclsManager.checkAccess(UserGroupInformation.getCurrentUser(),
          ApplicationAccessType.VIEW_APP, null, appId1)).thenReturn(true);
  ClientRMService rmService = new ClientRMService(rmContext, scheduler,
      null, mockAclsManager, null, null);
  try {
    RecordFactory recordFactory = RecordFactoryProvider.getRecordFactory(null);
    GetApplicationReportRequest request = recordFactory
        .newRecordInstance(GetApplicationReportRequest.class);
    request.setApplicationId(appId1);
    GetApplicationReportResponse response = 
        rmService.getApplicationReport(request);
    ApplicationReport report = response.getApplicationReport();
    ApplicationResourceUsageReport usageReport = 
        report.getApplicationResourceUsageReport();
    Assert.assertEquals(10, usageReport.getMemorySeconds());
    Assert.assertEquals(3, usageReport.getVcoreSeconds());
    Assert.assertEquals("<Not set>", report.getAmNodeLabelExpression());
    Assert.assertEquals("<Not set>", report.getAppNodeLabelExpression());
    // if application has am node label set to blank
    ApplicationId appId2 = getApplicationId(2);
    when(mockAclsManager.checkAccess(UserGroupInformation.getCurrentUser(),
        ApplicationAccessType.VIEW_APP, null, appId2)).thenReturn(true);
    request.setApplicationId(appId2);
    response = rmService.getApplicationReport(request);
    report = response.getApplicationReport();
    Assert.assertEquals(NodeLabel.DEFAULT_NODE_LABEL_PARTITION,
        report.getAmNodeLabelExpression());
    Assert.assertEquals(NodeLabel.NODE_LABEL_EXPRESSION_NOT_SET,
        report.getAppNodeLabelExpression());
    // if application has am node label set to blank
    ApplicationId appId3 = getApplicationId(3);
    when(mockAclsManager.checkAccess(UserGroupInformation.getCurrentUser(),
        ApplicationAccessType.VIEW_APP, null, appId3)).thenReturn(true);
    request.setApplicationId(appId3);
    response = rmService.getApplicationReport(request);
    report = response.getApplicationReport();
    Assert.assertEquals("high-mem", report.getAmNodeLabelExpression());
    Assert.assertEquals("high-mem", report.getAppNodeLabelExpression());
    // if application id is null
    GetApplicationReportRequest invalidRequest = recordFactory
        .newRecordInstance(GetApplicationReportRequest.class);
    invalidRequest.setApplicationId(null);
    try {
      rmService.getApplicationReport(invalidRequest);
    } catch (YarnException e) {
      // rmService should return a ApplicationNotFoundException
      // when a null application id is provided
      Assert.assertTrue(e instanceof ApplicationNotFoundException);
    }
  } finally {
    rmService.close();
  }
}