mercredi 8 juillet 2015

Spock test - RESTClient: HttpResponseException: Not Found

I would write a test that succes watch out for get query when API return 404.

My test:

   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
    }

My error:

14:24:59.294 [main] DEBUG o.a.h.impl.client.DefaultHttpClient - Connection can be kept alive indefinitely 14:24:59.305 [main] DEBUG groovyx.net.http.RESTClient - Response code: 404; found handler: org.codehaus.groovy.runtime.MethodClosure@312aa7c 14:24:59.306 [main] DEBUG groovyx.net.http.RESTClient - Parsing response as: application/json 14:24:59.443 [main] DEBUG org.apache.http.wire - << "ba[\r][\n]" 14:24:59.444 [main] DEBUG org.apache.http.wire - << "{"timestamp":1436358299234,"status":404,"error":"Not Found","exception":"com.pgssoft.exparo.web.ResourceNotFoundException","message":"No message available","path":"/api/advertisement/1"}" 14:24:59.445 [main] DEBUG org.apache.http.wire - << "[\r][\n]" 14:24:59.445 [main] DEBUG org.apache.http.wire - << "0[\r][\n]" 14:24:59.446 [main] DEBUG org.apache.http.wire - << "[\r][\n]" 14:24:59.446 [main] DEBUG o.a.h.i.c.BasicClientConnectionManager - Releasing connection org.apache.http.impl.conn.ManagedClientConnectionImpl@2ab4bc72 14:24:59.446 [main] DEBUG o.a.h.i.c.BasicClientConnectionManager - Connection can be kept alive indefinitely 14:24:59.449 [main] DEBUG groovyx.net.http.RESTClient - Parsed data to instance of: class groovy.json.internal.LazyMap

groovyx.net.http.HttpResponseException: Not Found at groovyx.net.http.RESTClient.defaultFailureHandler(RESTClient.java:263) at groovy.lang.Closure.call(Closure.java:423) at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:503) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:218) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:160) at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:515) at groovyx.net.http.RESTClient.get(RESTClient.java:119) at AdvertisementTest.Should return 404 - object delete before(AdvertisementTest.groovy:79)

Aucun commentaire:

Enregistrer un commentaire