From ca908ec36f4fcac3b3971744eb6f3e4e07d66fec Mon Sep 17 00:00:00 2001 From: Bartosz Spyrko-Smietanko Date: Fri, 14 May 2021 14:28:37 +0100 Subject: [PATCH] Verify that HELP lines are not duplicated --- .../metrics/test/MetricAppBean.java | 10 +++++ .../metrics/test/MpMetricTest.java | 40 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/tck/rest/src/main/java/org/eclipse/microprofile/metrics/test/MetricAppBean.java b/tck/rest/src/main/java/org/eclipse/microprofile/metrics/test/MetricAppBean.java index 6af6d176..5926c82c 100644 --- a/tck/rest/src/main/java/org/eclipse/microprofile/metrics/test/MetricAppBean.java +++ b/tck/rest/src/main/java/org/eclipse/microprofile/metrics/test/MetricAppBean.java @@ -170,6 +170,16 @@ public long countMeB() { return 666666; } + @Counted(name = "counter.with.desc", tags = {"number=one"}, description = "description") + public void counterWithDesc1() { + + } + + @Counted(name = "counter.with.desc", tags = {"number=two"}, description = "description") + public void counterWithDesc2() { + + } + public void gaugeMe() { @SuppressWarnings("unchecked") diff --git a/tck/rest/src/main/java/org/eclipse/microprofile/metrics/test/MpMetricTest.java b/tck/rest/src/main/java/org/eclipse/microprofile/metrics/test/MpMetricTest.java index 22b36451..e5828033 100644 --- a/tck/rest/src/main/java/org/eclipse/microprofile/metrics/test/MpMetricTest.java +++ b/tck/rest/src/main/java/org/eclipse/microprofile/metrics/test/MpMetricTest.java @@ -29,7 +29,11 @@ import java.net.MalformedURLException; import java.net.URL; +import java.util.regex.Pattern; +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; +import org.hamcrest.Matcher; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; @@ -801,7 +805,43 @@ public void testMultipleTaggedMetricsProm() { "taggedTimer_seconds_sum{mp_scope=\"application\",number=\"two\",tier=\"integration\"} ")) .body(containsString( "taggedTimer_seconds_max{mp_scope=\"application\",number=\"two\",tier=\"integration\"} ")); + } + + @Test + @RunAsClient + public void testApplicationContainsHelpMessageOnce() { + given().header("Accept", TEXT_PLAIN).when().get("/metrics?scope=application") + .then().statusCode(200) + .and() + .body(containsLineOnce( + "HELP application_org_eclipse_microprofile_metrics_test_MetricAppBean_counter_with_desc_total description")); + } + /** + * Checks that given line appears in the body only once. + * + * @param expected + * @return + */ + private Matcher containsLineOnce(String expected) { + return new BaseMatcher() { + @Override + public void describeTo(Description description) { + description.appendText("Body should contain line [" + expected + "] only once."); + } + + @Override + public boolean matches(Object o) { + String body = (String) o; + Pattern pattern = Pattern.compile(expected); + java.util.regex.Matcher matcher = pattern.matcher(body); + int count = 0; + while (matcher.find()) { + count++; + } + return count == 1; + } + }; } }