@Test
public void testPopulateResourceWithAggregateFunction() throws Exception {

  TestStreamProvider streamProvider = new TestStreamProvider(AGGREGATE_CLUSTER_METRICS_FILE_PATH);
  injectCacheEntryFactoryWithStreamProvider(streamProvider);
  TestMetricHostProvider metricHostProvider = new TestMetricHostProvider();
  ComponentSSLConfiguration sslConfiguration = mock(ComponentSSLConfiguration.class);
  Map<String, Map<String, PropertyInfo>> propertyIds =
    PropertyHelper.getMetricPropertyIds(Resource.Type.Cluster);
  AMSReportPropertyProvider propertyProvider =
    new AMSReportPropertyProvider(
      propertyIds,
      streamProvider,
      sslConfiguration,
      cacheProvider,
      metricHostProvider,
      CLUSTER_NAME_PROPERTY_ID
  );
  String propertyId = PropertyHelper.getPropertyId("metrics/cpu", "User._sum");
  Resource resource = new ResourceImpl(Resource.Type.Cluster);
  resource.setProperty(CLUSTER_NAME_PROPERTY_ID, "c1");
  Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();
  temporalInfoMap.put(propertyId, new TemporalInfoImpl(1432033257812L, 1432035927922L, 1L));
  Request request = PropertyHelper.getReadRequest(
    Collections.singleton(propertyId), temporalInfoMap);
  Set<Resource> resources =
    propertyProvider.populateResources(Collections.singleton(resource), request, null);
  Assert.assertEquals(1, resources.size());
  Resource res = resources.iterator().next();
  Map<String, Object> properties = PropertyHelper.getProperties(resources.iterator().next());
  Assert.assertNotNull(properties);
  URIBuilder uriBuilder = AMSPropertyProvider.getAMSUriBuilder("localhost", 6188, false);
  uriBuilder.addParameter("metricNames", "cpu_user._sum");
  uriBuilder.addParameter("appId", "HOST");
  uriBuilder.addParameter("startTime", "1432033257812");
  uriBuilder.addParameter("endTime", "1432035927922");
  Assert.assertEquals(uriBuilder.toString(), streamProvider.getLastSpec());
  Number[][] val = (Number[][]) res.getPropertyValue("metrics/cpu/User._sum");
  Assert.assertEquals(90, val.length);
}