@Test
public void testResolvePort() throws Exception {

  MetricDefinition metricDefinition = createNiceMock(MetricDefinition.class);
  expect(metricDefinition.getMetrics()).andReturn(componentMetrics);
  expect(metricDefinition.getType()).andReturn("org.apache.ambari.server.controller.metrics.RestMetricsPropertyProvider");
  expect(metricDefinition.getProperties()).andReturn(metricsProperties);
  replay(metricDefinition);
  Map<String, PropertyInfo> metrics = StackDefinedPropertyProvider.getPropertyInfo(metricDefinition);
  HashMap<String, Map<String, PropertyInfo>> componentMetrics = new HashMap<String, Map<String, PropertyInfo>>();
  componentMetrics.put(WRAPPED_METRICS_KEY, metrics);
  TestStreamProvider streamProvider = new TestStreamProvider();
  TestMetricsHostProvider metricsHostProvider = new TestMetricsHostProvider();
  RestMetricsPropertyProvider restMetricsPropertyProvider = createRestMetricsPropertyProvider(metricDefinition, componentMetrics, streamProvider,
      metricsHostProvider);
  // a property with a port doesn't exist, should return a default
  Map<String, String> customMetricsProperties = new HashMap<>(metricsProperties);
  customMetricsProperties.put("port_property_name", "wrong_property");
  String resolvedPort = restMetricsPropertyProvider.resolvePort(c1, "domu-12-31-39-0e-34-e1.compute-1.internal",
      "STORM_REST_API", customMetricsProperties, "http");
  Assert.assertEquals(DEFAULT_STORM_UI_PORT, resolvedPort);
  // a port property exists (8745). Should return it, not a default_port (8746)
  customMetricsProperties = new HashMap<>(metricsProperties);
  // custom default
  customMetricsProperties.put("default_port", "8746");
  resolvedPort = restMetricsPropertyProvider.resolvePort(c1, "domu-12-31-39-0e-34-e1.compute-1.internal",
      "STORM_REST_API", customMetricsProperties, "http");
  Assert.assertEquals(DEFAULT_STORM_UI_PORT, resolvedPort);
}