kshitizmittal / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

RestAssured.enableLoggingOfRequestAndResponseIfValidationFails() does not work if failure occurs in a ResponseSpec. #350

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
 Do a test like that:
    private void requestResponse_notLogged_onSpecFailure() {
        RestAssured.config = newConfig().sslConfig(sslConfig().relaxedHTTPSValidation());
        RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
        RestAssured.baseURI = baseUri;

        RestAssured.given()
            .auth().preemptive().basic("admin", "admin")
        .when()
            .get("/endpoint-that-does-not-exists")
        .then()
            .spec(new ResponseSpecBuilder().expectStatusCode(200).build());
    }

What is the expected output? What do you see instead?
 In addition to the expected failure of the test (a 404 is returned instead of the expected 200), I expect the log to contain both the request and the response. But I do not get either.

The log:
java.lang.AssertionError: 1 expectation failed.
Expected status code <200> doesn't match actual status code <404>.

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_20]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_20]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_20]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408) ~[na:1.8.0_20]
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77) ~[groovy-2.3.2.jar:2.3.2]
    at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:71) ~[groovy-2.3.2.jar:2.3.2]
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:81) ~[groovy-2.3.2.jar:2.3.2]
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57) ~[groovy-2.3.2.jar:2.3.2]
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182) ~[groovy-2.3.2.jar:2.3.2]
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190) ~[groovy-2.3.2.jar:2.3.2]
    at com.jayway.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure.validate(ResponseSpecificationImpl.groovy:577) ~[rest-assured-2.3.2.jar:na]
    at com.jayway.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure$validate$1.call(Unknown Source) ~[na:na]
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45) ~[groovy-2.3.2.jar:2.3.2]
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) ~[groovy-2.3.2.jar:2.3.2]
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) ~[groovy-2.3.2.jar:2.3.2]
    at com.jayway.restassured.internal.ResponseSpecificationImpl.validate(ResponseSpecificationImpl.groovy:86) ~[rest-assured-2.3.2.jar:na]
    at com.jayway.restassured.internal.ValidatableResponseOptionsImpl.specification(ValidatableResponseOptionsImpl.java:287) ~[rest-assured-2.3.2.jar:na]
    at com.jayway.restassured.internal.ValidatableResponseOptionsImpl.spec(ValidatableResponseOptionsImpl.java:280) ~[rest-assured-2.3.2.jar:na]
    at controller.AdvertiserTest.requestResponse_notLogged_onSpecFailure(AdvertiserTest.java:108) ~[bin/:na]
    ... // irrelevant frames (junit launcher)

What version of the product are you using?
I am using v2.3.2.

Note: while opening this issue, I stumbled upon issue #323 that seems similar, 
but not exactly the same, to this issue. #323 is marked as fixed. Maybe this 
fix is already done and will be in v2.3.3?

Original issue reported on code.google.com by gabriel....@gmail.com on 25 Aug 2014 at 7:10

GoogleCodeExporter commented 8 years ago

Original comment by johan.ha...@gmail.com on 29 Aug 2014 at 9:32

GoogleCodeExporter commented 8 years ago

Original comment by johan.ha...@gmail.com on 29 Aug 2014 at 10:58