2
2
3
3
import io .prometheus .client .Collector ;
4
4
import io .prometheus .client .CollectorRegistry ;
5
+
6
+ import org .eclipse .jetty .http .HttpMethod ;
5
7
import org .junit .After ;
6
8
import org .junit .Test ;
7
9
import org .mockito .invocation .InvocationOnMock ;
8
10
import org .mockito .stubbing .Answer ;
9
11
10
- import javax .servlet .FilterChain ;
11
- import javax .servlet .FilterConfig ;
12
- import javax .servlet .ServletResponse ;
13
- import javax .servlet .http .HttpServletRequest ;
14
- import javax .servlet .http .HttpServletResponse ;
12
+ import jakarta .servlet .FilterChain ;
13
+ import jakarta .servlet .FilterConfig ;
14
+ import jakarta .servlet .ServletResponse ;
15
+ import jakarta .servlet .http .HttpServletRequest ;
16
+ import jakarta .servlet .http .HttpServletResponse ;
15
17
import java .util .Enumeration ;
16
18
17
19
import static org .junit .Assert .assertEquals ;
@@ -48,7 +50,7 @@ public void init() throws Exception {
48
50
HttpServletRequest req = mock (HttpServletRequest .class );
49
51
50
52
when (req .getRequestURI ()).thenReturn ("/foo/bar/baz/bang/zilch/zip/nada" );
51
- when (req .getMethod ()).thenReturn (HttpMethods .GET );
53
+ when (req .getMethod ()).thenReturn (HttpMethod .GET . asString () );
52
54
53
55
HttpServletResponse res = mock (HttpServletResponse .class );
54
56
FilterChain c = mock (FilterChain .class );
@@ -60,7 +62,7 @@ public void init() throws Exception {
60
62
final Double sampleValue = CollectorRegistry .defaultRegistry .getSampleValue (
61
63
metricName + "_count" ,
62
64
new String [] { "path" , "method" },
63
- new String [] { "/foo/bar/baz/bang" , HttpMethods .GET });
65
+ new String [] { "/foo/bar/baz/bang" , HttpMethod .GET . asString () });
64
66
assertNotNull (sampleValue );
65
67
assertEquals (1 , sampleValue , 0.0001 );
66
68
}
@@ -71,7 +73,7 @@ public void doFilter() throws Exception {
71
73
final String path = "/foo/bar/baz/bang/zilch/zip/nada" ;
72
74
73
75
when (req .getRequestURI ()).thenReturn (path );
74
- when (req .getMethod ()).thenReturn (HttpMethods .GET );
76
+ when (req .getMethod ()).thenReturn (HttpMethod .GET . asString () );
75
77
76
78
HttpServletResponse res = mock (HttpServletResponse .class );
77
79
FilterChain c = mock (FilterChain .class );
@@ -88,7 +90,7 @@ public void doFilter() throws Exception {
88
90
89
91
final Double sampleValue = CollectorRegistry .defaultRegistry .getSampleValue (name + "_count" ,
90
92
new String [] { "path" , "method" },
91
- new String [] { path , HttpMethods .GET });
93
+ new String [] { path , HttpMethod .GET . asString () });
92
94
assertNotNull (sampleValue );
93
95
assertEquals (1 , sampleValue , 0.0001 );
94
96
}
@@ -98,7 +100,7 @@ public void testConstructor() throws Exception {
98
100
HttpServletRequest req = mock (HttpServletRequest .class );
99
101
final String path = "/foo/bar/baz/bang" ;
100
102
when (req .getRequestURI ()).thenReturn (path );
101
- when (req .getMethod ()).thenReturn (HttpMethods .POST );
103
+ when (req .getMethod ()).thenReturn (HttpMethod .POST . asString () );
102
104
103
105
FilterChain c = mock (FilterChain .class );
104
106
doAnswer (new Answer <Void >() {
@@ -119,7 +121,7 @@ public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
119
121
final Double sum = CollectorRegistry .defaultRegistry .getSampleValue (
120
122
"foobar_baz_filter_duration_seconds_sum" ,
121
123
new String [] { "path" , "method" },
122
- new String [] { path , HttpMethods .POST });
124
+ new String [] { path , HttpMethod .POST . asString () });
123
125
assertNotNull (sum );
124
126
assertEquals (0.1 , sum , 0.01 );
125
127
}
@@ -129,7 +131,7 @@ public void testBucketsAndName() throws Exception {
129
131
HttpServletRequest req = mock (HttpServletRequest .class );
130
132
final String path = "/foo/bar/baz/bang" ;
131
133
when (req .getRequestURI ()).thenReturn (path );
132
- when (req .getMethod ()).thenReturn (HttpMethods .POST );
134
+ when (req .getMethod ()).thenReturn (HttpMethod .POST . asString () );
133
135
134
136
FilterChain c = mock (FilterChain .class );
135
137
doAnswer (new Answer <Void >() {
@@ -153,17 +155,17 @@ public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
153
155
154
156
final Double sum = CollectorRegistry .defaultRegistry .getSampleValue ("foo_sum" ,
155
157
new String [] { "path" , "method" },
156
- new String [] { "/foo" , HttpMethods .POST });
158
+ new String [] { "/foo" , HttpMethod .POST . asString () });
157
159
assertEquals (0.1 , sum , 0.01 );
158
160
159
161
final Double le05 = CollectorRegistry .defaultRegistry .getSampleValue ("foo_bucket" ,
160
162
new String [] { "path" , "method" , "le" },
161
- new String [] { "/foo" , HttpMethods .POST , "0.05" });
163
+ new String [] { "/foo" , HttpMethod .POST . asString () , "0.05" });
162
164
assertNotNull (le05 );
163
165
assertEquals (0 , le05 , 0.01 );
164
166
final Double le15 = CollectorRegistry .defaultRegistry .getSampleValue ("foo_bucket" ,
165
167
new String [] { "path" , "method" , "le" },
166
- new String [] { "/foo" , HttpMethods .POST , "0.15" });
168
+ new String [] { "/foo" , HttpMethod .POST . asString () , "0.15" });
167
169
assertNotNull (le15 );
168
170
assertEquals (1 , le15 , 0.01 );
169
171
@@ -193,7 +195,7 @@ public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
193
195
public void testStatusCode () throws Exception {
194
196
HttpServletRequest req = mock (HttpServletRequest .class );
195
197
when (req .getRequestURI ()).thenReturn ("/foo/bar/baz/bang" );
196
- when (req .getMethod ()).thenReturn (HttpMethods .GET );
198
+ when (req .getMethod ()).thenReturn (HttpMethod .GET . asString () );
197
199
198
200
HttpServletResponse res = mock (HttpServletResponse .class );
199
201
when (res .getStatus ()).thenReturn (200 );
@@ -209,7 +211,7 @@ public void testStatusCode() throws Exception {
209
211
final Double sampleValue = CollectorRegistry .defaultRegistry .getSampleValue (
210
212
"foobar_filter_status_total" ,
211
213
new String [] { "path" , "method" , "status" },
212
- new String [] { "/foo/bar" , HttpMethods .GET , "200" });
214
+ new String [] { "/foo/bar" , HttpMethod .GET . asString () , "200" });
213
215
assertNotNull (sampleValue );
214
216
assertEquals (1 , sampleValue , 0.0001 );
215
217
}
@@ -218,7 +220,7 @@ public void testStatusCode() throws Exception {
218
220
public void testStatusCodeWithNonHttpServletResponse () throws Exception {
219
221
HttpServletRequest req = mock (HttpServletRequest .class );
220
222
when (req .getRequestURI ()).thenReturn ("/foo/bar/baz/bang" );
221
- when (req .getMethod ()).thenReturn (HttpMethods .GET );
223
+ when (req .getMethod ()).thenReturn (HttpMethod .GET . asString () );
222
224
223
225
ServletResponse res = mock (ServletResponse .class );
224
226
@@ -235,7 +237,7 @@ public void testStatusCodeWithNonHttpServletResponse() throws Exception {
235
237
new String [] { "path" , "method" , "status" },
236
238
new String [] {
237
239
"/foo/bar" ,
238
- HttpMethods .GET ,
240
+ HttpMethod .GET . asString () ,
239
241
MetricsFilter .UNKNOWN_HTTP_STATUS_CODE });
240
242
assertNotNull (sampleValue );
241
243
assertEquals (1 , sampleValue , 0.0001 );
0 commit comments