-
Notifications
You must be signed in to change notification settings - Fork 4
/
WebFluxResponseStatusExceptionHandlerSpec.groovy
52 lines (40 loc) · 1.58 KB
/
WebFluxResponseStatusExceptionHandlerSpec.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package org.opal
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.web.server.LocalServerPort
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.annotation.Order
import org.springframework.web.reactive.handler.WebFluxResponseStatusExceptionHandler
import org.springframework.web.server.WebExceptionHandler
import spock.lang.Specification
import static groovy.json.JsonOutput.toJson
import static jodd.net.HttpMethod.POST
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT
import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY
@SpringBootTest(
webEnvironment = RANDOM_PORT,
classes = [SampleApp, ExceptionHandlerConfiguration],
properties = ['createWebfluxExceptionHandler=true']
)
class WebFluxResponseStatusExceptionHandlerSpec extends Specification implements HTTPHelper {
@LocalServerPort
int port
def 'should return 422 on annotated with @ResponseStatus exception'() {
when:
def response = request().method(POST).body(toJson([name: 'Tom'])).send()
then:
response.statusCode() == UNPROCESSABLE_ENTITY.value()
and:
response.bodyBytes() == null
}
}
@Configuration
class ExceptionHandlerConfiguration {
@Bean
@Order(-2)
@ConditionalOnProperty("createWebfluxExceptionHandler")
WebExceptionHandler webExceptionHandler() {
new WebFluxResponseStatusExceptionHandler()
}
}