9
9
import com .getyourguide .openapi .validation .api .exclusions .ViolationExclusions ;
10
10
import com .getyourguide .openapi .validation .api .model .Direction ;
11
11
import com .getyourguide .openapi .validation .api .model .OpenApiViolation ;
12
- import java .util .Optional ;
13
12
import org .junit .jupiter .api .BeforeEach ;
14
13
import org .junit .jupiter .api .Test ;
15
14
@@ -24,7 +23,7 @@ public void setup() {
24
23
}
25
24
26
25
@ Test
27
- public void testWhenViolationThenViolationNotExcluded () {
26
+ public void whenViolationThenViolationNotExcluded () {
28
27
when (customViolationExclusions .isExcluded (any ())).thenReturn (false );
29
28
30
29
checkViolationNotExcluded (buildSimpleViolation (Direction .RESPONSE , 404 ));
@@ -38,20 +37,20 @@ private static OpenApiViolation buildSimpleViolation(Direction direction, Intege
38
37
return OpenApiViolation .builder ()
39
38
.direction (direction )
40
39
.rule ("validation." + (direction == Direction .REQUEST ? "request" : "response" ) + ".something" )
41
- .responseStatus (responseStatus != null ? Optional . of ( responseStatus ) : Optional . empty () )
40
+ .responseStatus (responseStatus )
42
41
.message ("Some violation message" )
43
42
.build ();
44
43
}
45
44
46
45
@ Test
47
- public void testWhenCustomViolationExclusionThenViolationExcluded () {
46
+ public void whenCustomViolationExclusionThenViolationExcluded () {
48
47
when (customViolationExclusions .isExcluded (any ())).thenReturn (true );
49
48
50
49
checkViolationExcluded (OpenApiViolation .builder ().build ());
51
50
}
52
51
53
52
@ Test
54
- public void testWhenInstanceFailedToMatchExactlyOneThenViolationExcluded () {
53
+ public void whenInstanceFailedToMatchExactlyOneThenViolationExcluded () {
55
54
when (customViolationExclusions .isExcluded (any ())).thenReturn (false );
56
55
57
56
checkViolationExcluded (OpenApiViolation .builder ()
@@ -60,7 +59,7 @@ public void testWhenInstanceFailedToMatchExactlyOneThenViolationExcluded() {
60
59
}
61
60
62
61
@ Test
63
- public void testWhenInstanceFailedToMatchExactlyOneWithOneOf24ThenViolationExcluded () {
62
+ public void whenInstanceFailedToMatchExactlyOneWithOneOf24ThenViolationExcluded () {
64
63
when (customViolationExclusions .isExcluded (any ())).thenReturn (false );
65
64
66
65
checkViolationExcluded (OpenApiViolation .builder ()
@@ -70,36 +69,55 @@ public void testWhenInstanceFailedToMatchExactlyOneWithOneOf24ThenViolationExclu
70
69
}
71
70
72
71
@ Test
73
- public void testWhen404ResponseWithApiPathNotSpecifiedThenViolationExcluded () {
72
+ public void when404ResponseWithApiPathNotSpecifiedThenViolationExcluded () {
74
73
when (customViolationExclusions .isExcluded (any ())).thenReturn (false );
75
74
76
75
checkViolationExcluded (OpenApiViolation .builder ()
77
76
.direction (Direction .RESPONSE )
78
77
.rule ("validation.request.path.missing" )
79
- .responseStatus (Optional . of ( 404 ) )
78
+ .responseStatus (404 )
80
79
.message ("No API path found that matches request '/nothing'" )
81
80
.build ());
82
81
}
83
82
84
83
@ Test
85
- public void testWhenRequestWithApiPathNotSpecifiedThenViolationExcluded () {
84
+ public void whenRequestWithApiPathNotSpecifiedThenViolationExcluded () {
86
85
when (customViolationExclusions .isExcluded (any ())).thenReturn (false );
87
86
88
87
checkViolationExcluded (OpenApiViolation .builder ()
89
88
.direction (Direction .REQUEST )
90
89
.rule ("validation.request.path.missing" )
91
- .responseStatus (Optional . empty () )
90
+ .responseStatus (null )
92
91
.message ("No API path found that matches request '/nothing'" )
93
92
.build ());
94
93
}
95
94
96
95
@ Test
97
- public void testWhenRequestViolationsAnd400ThenViolationExcluded () {
96
+ public void whenRequestViolationsAnd400ThenViolationExcluded () {
98
97
when (customViolationExclusions .isExcluded (any ())).thenReturn (false );
99
98
100
99
checkViolationExcluded (OpenApiViolation .builder ()
101
100
.direction (Direction .REQUEST )
102
- .responseStatus (Optional .of (400 ))
101
+ .responseStatus (400 )
102
+ .message ("" )
103
+ .build ());
104
+ }
105
+
106
+ @ Test
107
+ public void when405ResponseCodeWithOperationNotAllowedViolationThenViolationExcluded () {
108
+ when (customViolationExclusions .isExcluded (any ())).thenReturn (false );
109
+
110
+ checkViolationExcluded (OpenApiViolation .builder ()
111
+ .direction (Direction .REQUEST )
112
+ .rule ("validation.request.operation.notAllowed" )
113
+ .responseStatus (405 )
114
+ .message ("" )
115
+ .build ());
116
+
117
+ checkViolationExcluded (OpenApiViolation .builder ()
118
+ .direction (Direction .RESPONSE )
119
+ .rule ("validation.request.operation.notAllowed" )
120
+ .responseStatus (405 )
103
121
.message ("" )
104
122
.build ());
105
123
}
0 commit comments