@Test
public void testListMetrics() {

    MetricManager.getIMetricManager().clear();
    MetricManager.getCounter("product", MetricName.build("middleware.product.provider"));
    MetricManager.getMeter("test", MetricName.build("shared.carts.my_cart").level(MetricLevel.CRITICAL)).mark();
    MetricManager.getMeter("test", MetricName.build("shared.carts.my_cart")
            .level(MetricLevel.CRITICAL).tagged("source", "taobao")).mark();
    GenericType<Map<String, Object>> genericType = new GenericType<Map<String, Object>>(){};
    Map<String, Object> result = target("metrics/list").request()
            .accept(MediaType.APPLICATION_JSON_TYPE).get(genericType);
    Assert.assertEquals("success should be true", true, result.get("success"));
    Assert.assertTrue("data should be a map", result.get("data") instanceof Map);
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Set<MetricObject>> data =
            mapper.convertValue(result.get("data"), new TypeReference<Map<String, Set<MetricObject>>>(){});
    Assert.assertTrue(data.get("product").contains(MetricObject.named("middleware.product.provider.count")
            .withType(MetricObject.MetricType.COUNTER).withLevel(MetricLevel.NORMAL).build()));
    Assert.assertEquals(".count/.m1/.m5/.m15/.bucket_count/qps * 2 = 12", 12, data.get("test").size());
    Assert.assertTrue("shared.carts.my_cart.m1 should be CRITICAL level",
            data.get("test").contains(MetricObject.named("shared.carts.my_cart.m1")
            .withLevel(MetricLevel.CRITICAL).withType(MetricObject.MetricType.GAUGE).build()));
    Map<String, String> tags = new HashMap<String, String>();
    tags.put("source", "taobao");
    Assert.assertTrue(data.get("test").contains(MetricObject.named("shared.carts.my_cart.m1").withTags(tags)
            .withLevel(MetricLevel.CRITICAL).withType(MetricObject.MetricType.GAUGE).build()));
}