17
17
package com .linecorp .centraldogma .server .internal .api .converter ;
18
18
19
19
import static org .assertj .core .api .Assertions .assertThat ;
20
- import static org .mockito .Mockito .mock ;
21
- import static org .mockito .Mockito .when ;
22
20
23
21
import javax .annotation .Nullable ;
24
22
25
23
import org .junit .jupiter .api .Test ;
26
24
27
25
import com .linecorp .armeria .common .AggregatedHttpRequest ;
28
- import com .linecorp .armeria .common .HttpHeaderNames ;
29
26
import com .linecorp .armeria .common .HttpMethod ;
30
27
import com .linecorp .armeria .common .RequestHeaders ;
31
28
import com .linecorp .armeria .server .ServiceRequestContext ;
32
- import com .linecorp .centraldogma .common .Revision ;
33
29
import com .linecorp .centraldogma .server .internal .api .converter .WatchRequestConverter .WatchRequest ;
34
30
35
31
class WatchRequestConverterTest {
36
32
37
33
private static final WatchRequestConverter converter = new WatchRequestConverter ();
38
34
39
35
@ Test
40
- void convertWatchRequest () throws Exception {
41
- final ServiceRequestContext ctx = mock (ServiceRequestContext .class );
42
- final AggregatedHttpRequest request = mock (AggregatedHttpRequest .class );
43
- final RequestHeaders headers = RequestHeaders .of (HttpMethod .GET , "/" ,
44
- HttpHeaderNames .IF_NONE_MATCH , "-1" ,
45
- HttpHeaderNames .PREFER , "wait=10" );
46
- when (request .headers ()).thenReturn (headers );
36
+ void extractValidRevision () {
37
+ final String firstIfNoneMatch = "-1" ;
38
+ final String firstRevision = converter .extractRevision (firstIfNoneMatch );
39
+ assertThat (firstRevision ).isEqualTo (firstIfNoneMatch );
47
40
48
- final WatchRequest watchRequest = convert (ctx , request );
49
- assertThat (watchRequest ).isNotNull ();
50
- assertThat (watchRequest .lastKnownRevision ()).isEqualTo (Revision .HEAD );
51
- assertThat (watchRequest .timeoutMillis ()).isEqualTo (10000 ); // 10 seconds
41
+ final String secondIfNoneMatch = "\" -1\" " ;
42
+ final String secondRevision = converter .extractRevision (secondIfNoneMatch );
43
+ assertThat (secondRevision ).isEqualTo ("-1" );
44
+
45
+ final String thirdIfNoneMatch = "W/\" -1\" " ;
46
+ final String thirdRevision = converter .extractRevision (thirdIfNoneMatch );
47
+ assertThat (thirdRevision ).isEqualTo ("-1" );
48
+ }
49
+
50
+ @ Test
51
+ void extractInvalidRevision () {
52
+ final String firstIfNoneMatch = "w/\" -1\" " ;
53
+ final String firstRevision = converter .extractRevision (firstIfNoneMatch );
54
+ assertThat (firstRevision ).isEqualTo (firstIfNoneMatch );
55
+
56
+ final String secondIfNoneMatch = "W\" -1\" " ;
57
+ final String secondRevision = converter .extractRevision (secondIfNoneMatch );
58
+ assertThat (secondRevision ).isEqualTo (secondIfNoneMatch );
59
+
60
+ final String thirdIfNoneMatch = "/\" -1\" " ;
61
+ final String thirdRevision = converter .extractRevision (thirdIfNoneMatch );
62
+ assertThat (thirdRevision ).isEqualTo (thirdIfNoneMatch );
63
+
64
+ final String fourthIfNoneMatch = "-1\" " ;
65
+ final String fourthRevision = converter .extractRevision (fourthIfNoneMatch );
66
+ assertThat (fourthRevision ).isEqualTo (fourthIfNoneMatch );
67
+
68
+ final String fifthIfNoneMatch = "\" -1" ;
69
+ final String fifthRevision = converter .extractRevision (fifthIfNoneMatch );
70
+ assertThat (fifthRevision ).isEqualTo (fifthIfNoneMatch );
71
+
72
+ final String sixthIfNoneMatch = "W/\" " ;
73
+ final String sixthRevision = converter .extractRevision (sixthIfNoneMatch );
74
+ assertThat (sixthRevision ).isEqualTo (sixthIfNoneMatch );
75
+
76
+ final String seventhIfNoneMatch = "\" " ;
77
+ final String seventhRevision = converter .extractRevision (seventhIfNoneMatch );
78
+ assertThat (seventhRevision ).isEqualTo (seventhIfNoneMatch );
79
+
80
+ final String eighthIfNoneMatch = "\" \" " ;
81
+ final String eighthRevision = converter .extractRevision (eighthIfNoneMatch );
82
+ assertThat (eighthRevision ).isEqualTo (eighthIfNoneMatch );
52
83
}
53
84
54
85
@ Test
55
86
void emptyHeader () throws Exception {
56
- final ServiceRequestContext ctx = mock (ServiceRequestContext .class );
57
- final AggregatedHttpRequest request = mock (AggregatedHttpRequest .class );
58
87
final RequestHeaders headers = RequestHeaders .of (HttpMethod .GET , "/" );
59
-
60
- when (request .headers ()). thenReturn ( headers );
88
+ final AggregatedHttpRequest request = AggregatedHttpRequest . of ( headers );
89
+ final ServiceRequestContext ctx = ServiceRequestContext . of (request .toHttpRequest () );
61
90
62
91
final WatchRequest watchRequest = convert (ctx , request );
63
92
assertThat (watchRequest ).isNull ();
@@ -66,6 +95,6 @@ void emptyHeader() throws Exception {
66
95
@ Nullable
67
96
private static WatchRequest convert (
68
97
ServiceRequestContext ctx , AggregatedHttpRequest request ) throws Exception {
69
- return ( WatchRequest ) converter .convertRequest (ctx , request , null , null );
98
+ return converter .convertRequest (ctx , request , null , null );
70
99
}
71
100
}
0 commit comments