Spring Spock测试-RESTClient:HttpResponseException:未找到

Spring Spock测试-RESTClient:HttpResponseException:未找到,spring,groovy,spring-boot,spock,httpbuilder,Spring,Groovy,Spring Boot,Spock,Httpbuilder,我想在API返回404时为GET请求编写一个测试 我的测试: def "Should return 404 - object deleted before"() { setup: def advertisementEndpoint = new RESTClient( 'http://localhost:8080/' ) when: def resp = advertisementEndpoint.get(

我想在API返回404时为GET请求编写一个测试

我的测试:

   def "Should return 404 - object deleted before"() {
        setup:
        def advertisementEndpoint = new RESTClient( 'http://localhost:8080/' )
        when:
        def resp = advertisementEndpoint.get(
                path: 'api/advertisement/1',
                contentType: groovyx.net.http.ContentType.JSON
        )
        then:
        resp.status == 404
    }
我的错误:

14:24:59.294[main]调试o.a.h.impl.client.DefaultHttpClient- 连接可以无限期保持活动14:24:59.305[main]调试 groovyx.net.http.RESTClient-响应代码:404;找到的处理程序: org.codehaus.groovy.runtime。MethodClosure@312aa7c14:24:59.306[主要] 调试groovyx.net.http.RESTClient-将响应解析为: application/json 14:24:59.443[main]DEBUG org.apache.http.wire-您需要底层
HTTPBuilder
的故障处理程序。从:

您还可以为任何状态代码设置调用的默认响应处理程序 399,它与特定处理程序不匹配。在请求关闭之外设置该值意味着它将应用于所有未来的请求 使用此HTTPBuilder实例:

http.handler.failure={resp->
println“意外故障:${resp.statusLine}”}

因此:

@Grapes(
    @Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1')
)

import groovyx.net.*
import groovyx.net.http.*   

def restClient = new RESTClient('http://localhost/wrong')
restClient.handler.failure = { resp -> resp.status }
def response = restClient.get([:])
assert response == 404