Skip to content

Commit

Permalink
Add additional MetricsMvcEndpoint regex tests
Browse files Browse the repository at this point in the history
Update MetricsMvcEndpointTests to test for regular expression based
calls.

Closes spring-projectsgh-2252
  • Loading branch information
bsideup authored and philwebb committed Apr 10, 2015
1 parent 8ca5635 commit a60df81
Showing 1 changed file with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

package org.springframework.boot.actuate.endpoint.mvc;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -50,6 +51,7 @@
* Tests for {@link MetricsMvcEndpoint}
*
* @author Andy Wilkinson
* @author Sergei Egorov
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = { TestConfiguration.class })
Expand Down Expand Up @@ -96,6 +98,34 @@ public void specificMetricThatDoesNotExist() throws Exception {
this.mvc.perform(get("/metrics/bar")).andExpect(status().isNotFound());
}

@Test
public void regexAll() throws Exception {
String expected = "{\"foo\":1,\"group1.a\":1,\"group1.b\":1,\"group2.a\":1,\"group2_a\":1}";
this.mvc.perform(get("/metrics/.*")).andExpect(status().isOk())
.andExpect(content().string(expected));
}

@Test
public void regexGroupDot() throws Exception {
String expected = "{\"group1.a\":1,\"group1.b\":1,\"group2.a\":1}";
this.mvc.perform(get("/metrics/group[0-9]+\\..*")).andExpect(status().isOk())
.andExpect(content().string(expected));
}

@Test
public void regexGroup1() throws Exception {
String expected = "{\"group1.a\":1,\"group1.b\":1}";
this.mvc.perform(get("/metrics/group1\\..*")).andExpect(status().isOk())
.andExpect(content().string(expected));
}

@Test
public void specificMetricWithDot() throws Exception {
this.mvc.perform(get("/metrics/group2.a")).andExpect(status().isOk())
.andExpect(content().string("1"));

}

@Import({ EndpointWebMvcAutoConfiguration.class,
ManagementServerPropertiesAutoConfiguration.class })
@EnableWebMvc
Expand All @@ -108,7 +138,13 @@ public MetricsEndpoint endpoint() {

@Override
public Collection<Metric<?>> metrics() {
return Arrays.<Metric<?>> asList(new Metric<Integer>("foo", 1));
ArrayList<Metric<?>> metrics = new ArrayList<Metric<?>>();
metrics.add(new Metric<Integer>("foo", 1));
metrics.add(new Metric<Integer>("group1.a", 1));
metrics.add(new Metric<Integer>("group1.b", 1));
metrics.add(new Metric<Integer>("group2.a", 1));
metrics.add(new Metric<Integer>("group2_a", 1));
return Collections.unmodifiableList(metrics);
}

});
Expand Down

0 comments on commit a60df81

Please sign in to comment.