@@ -12,11 +12,11 @@ import org.assertj.core.api.BDDAssertions.thenThrownBy
12
12
import org.junit.jupiter.api.Test
13
13
14
14
class ValidatingRequestRouterWrapperTest {
15
-
16
15
@Test
17
16
fun `should return response on successful validation` () {
18
- val response = ValidatingRequestRouterWrapper (TestRequestHandler (), " openapi.yml" )
19
- .handleRequest(GET (" /tests" ).withAcceptHeader(" application/json" ), mockk())
17
+ val response =
18
+ ValidatingRequestRouterWrapper (TestRequestHandler (), " openapi.yml" )
19
+ .handleRequest(GET (" /tests" ).withAcceptHeader(" application/json" ), mockk())
20
20
21
21
then(response.statusCode).isEqualTo(200 )
22
22
}
@@ -43,8 +43,12 @@ class ValidatingRequestRouterWrapperTest {
43
43
44
44
@Test
45
45
fun `should skip validation` () {
46
- val response = ValidatingRequestRouterWrapper (InvalidTestRequestHandler (), " openapi.yml" )
47
- .handleRequestSkippingRequestAndResponseValidation(GET (" /path-not-documented" ).withAcceptHeader(" application/json" ), mockk())
46
+ val response =
47
+ ValidatingRequestRouterWrapper (InvalidTestRequestHandler (), " openapi.yml" )
48
+ .handleRequestSkippingRequestAndResponseValidation(
49
+ GET (" /path-not-documented" ).withAcceptHeader(" application/json" ),
50
+ mockk(),
51
+ )
48
52
then(response.statusCode).isEqualTo(404 )
49
53
}
50
54
@@ -54,7 +58,7 @@ class ValidatingRequestRouterWrapperTest {
54
58
ValidatingRequestRouterWrapper (
55
59
delegate = OpenApiValidatorTest .TestRequestHandler (),
56
60
specUrlOrPayload = " openapi.yml" ,
57
- additionalRequestValidationFunctions = listOf ({ _ -> throw RequestValidationFailedException () })
61
+ additionalRequestValidationFunctions = listOf ({ _ -> throw RequestValidationFailedException () }),
58
62
)
59
63
.handleRequest(GET (" /tests" ).withAcceptHeader(" application/json" ), mockk())
60
64
}
@@ -67,29 +71,32 @@ class ValidatingRequestRouterWrapperTest {
67
71
ValidatingRequestRouterWrapper (
68
72
delegate = OpenApiValidatorTest .TestRequestHandler (),
69
73
specUrlOrPayload = " openapi.yml" ,
70
- additionalResponseValidationFunctions = listOf ({ _, _ -> throw ResponseValidationFailedException () })
74
+ additionalResponseValidationFunctions = listOf ({ _, _ -> throw ResponseValidationFailedException () }),
71
75
)
72
76
.handleRequest(GET (" /tests" ).withAcceptHeader(" application/json" ), mockk())
73
77
}
74
78
.isInstanceOf(ResponseValidationFailedException ::class .java)
75
79
}
76
80
77
81
private class RequestValidationFailedException : RuntimeException (" request validation failed" )
82
+
78
83
private class ResponseValidationFailedException : RuntimeException (" request validation failed" )
79
84
80
85
private class TestRequestHandler : RequestHandler () {
81
- override val router = router {
82
- GET (" /tests" ) { _: Request <Unit > ->
83
- ResponseEntity .ok(""" {"name": "some"}""" )
86
+ override val router =
87
+ router {
88
+ GET (" /tests" ) { _: Request <Unit > ->
89
+ ResponseEntity .ok(""" {"name": "some"}""" )
90
+ }
84
91
}
85
- }
86
92
}
87
93
88
94
private class InvalidTestRequestHandler : RequestHandler () {
89
- override val router = router {
90
- GET (" /tests" ) { _: Request <Unit > ->
91
- ResponseEntity .notFound(Unit )
95
+ override val router =
96
+ router {
97
+ GET (" /tests" ) { _: Request <Unit > ->
98
+ ResponseEntity .notFound(Unit )
99
+ }
92
100
}
93
- }
94
101
}
95
102
}
0 commit comments