16
16
17
17
package org .springframework .boot .actuate .autoconfigure ;
18
18
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
+
19
29
import javax .servlet .Filter ;
20
30
import javax .servlet .FilterChain ;
21
31
29
39
import org .springframework .context .annotation .Configuration ;
30
40
import org .springframework .mock .web .MockHttpServletRequest ;
31
41
import 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 ;
40
46
41
47
/**
42
48
* Tests for {@link MetricFilterAutoConfiguration}.
43
49
*
44
50
* @author Phillip Webb
45
51
*/
46
52
public class MetricFilterAutoConfigurationTests {
53
+
47
54
48
55
@ Test
49
56
public void recordsHttpInteractions () throws Exception {
@@ -67,6 +74,21 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
67
74
anyDouble ());
68
75
context .close ();
69
76
}
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
+ }
70
92
71
93
@ Test
72
94
public void skipsFilterIfMissingServices () throws Exception {
@@ -88,6 +110,19 @@ public CounterService counterService() {
88
110
public GaugeService gaugeService () {
89
111
return mock (GaugeService .class );
90
112
}
113
+
91
114
}
92
115
93
116
}
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