1616
1717package org .springframework .boot .actuate .autoconfigure ;
1818
19+ import static org .hamcrest .Matchers .equalTo ;
20+ import static org .junit .Assert .assertThat ;
21+ import static org .mockito .BDDMockito .willAnswer ;
22+ import static org .mockito .Matchers .anyDouble ;
23+ import static org .mockito .Matchers .eq ;
24+ import static org .mockito .Mockito .mock ;
25+ import static org .mockito .Mockito .verify ;
26+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
27+ import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
28+
1929import javax .servlet .Filter ;
2030import javax .servlet .FilterChain ;
2131
2939import org .springframework .context .annotation .Configuration ;
3040import org .springframework .mock .web .MockHttpServletRequest ;
3141import org .springframework .mock .web .MockHttpServletResponse ;
32-
33- import static org .hamcrest .Matchers .equalTo ;
34- import static org .junit .Assert .assertThat ;
35- import static org .mockito .BDDMockito .willAnswer ;
36- import static org .mockito .Matchers .anyDouble ;
37- import static org .mockito .Matchers .eq ;
38- import static org .mockito .Mockito .mock ;
39- import static org .mockito .Mockito .verify ;
42+ import org .springframework .test .web .servlet .MockMvc ;
43+ import org .springframework .test .web .servlet .setup .MockMvcBuilders ;
44+ import org .springframework .web .bind .annotation .RequestMapping ;
45+ import org .springframework .web .bind .annotation .RestController ;
4046
4147/**
4248 * Tests for {@link MetricFilterAutoConfiguration}.
4349 *
4450 * @author Phillip Webb
4551 */
4652public class MetricFilterAutoConfigurationTests {
53+
4754
4855 @ Test
4956 public void recordsHttpInteractions () throws Exception {
@@ -67,6 +74,21 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
6774 anyDouble ());
6875 context .close ();
6976 }
77+
78+ @ Test
79+ public void recordsHttpInteractionsWithTemplateVariable () throws Exception {
80+ AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext (
81+ Config .class , MetricFilterAutoConfiguration .class );
82+ Filter filter = context .getBean (Filter .class );
83+ MockMvc mvc = MockMvcBuilders .standaloneSetup (new MetricFilterTestController ()).addFilter (filter ).build ();
84+ mvc .perform (get ("/templateVarTest/foo" ))
85+ .andExpect (status ().isOk ());
86+
87+ verify (context .getBean (CounterService .class )).increment ("status.200.templateVarTest.-someVariable-" );
88+ verify (context .getBean (GaugeService .class )).submit (eq ("response.templateVarTest.-someVariable-" ),
89+ anyDouble ());
90+ context .close ();
91+ }
7092
7193 @ Test
7294 public void skipsFilterIfMissingServices () throws Exception {
@@ -88,6 +110,19 @@ public CounterService counterService() {
88110 public GaugeService gaugeService () {
89111 return mock (GaugeService .class );
90112 }
113+
91114 }
92115
93116}
117+
118+
119+ @ RestController
120+ class MetricFilterTestController
121+ {
122+
123+ @ RequestMapping ("templateVarTest/{someVariable}" )
124+ public String testTemplateVariableResolution (String someVariable )
125+ {
126+ return someVariable ;
127+ }
128+ }
0 commit comments