简体   繁体   中英

Java rest testing with rest-assured multiple GET requests

I have a Spring-boot application and it's a REST service for my AngularJS app. I'm trying to write some unit tests for it, and this is sample code from one of it.

    given().
            auth().basic(USER_LOGIN, "X").
            get("http://myservice/login").
            then().assertThat().statusCode(HttpStatus.UNAUTHORIZED.value());
    given().
            auth().basic(USER_LOGIN, PASSWORD).
            get("http://myservice/login").
            then().assertThat().statusCode(HttpStatus.OK.value());

The problem is that my second assertion is not passed. But when I'm trying to swap their places, assertion with UNAUTHORIZED status not passing. If I'll try to reproduce this test case with SoapUI, it will work fine, both assertions are done. Probably, it's caching results of requests somehow?

ps The security provider I'm using is Spring security.

You can reset to the standard baseURI (localhost), basePath (empty), standard port (8080), default authentication scheme (none) and default root path (empty string) using: RestAssured.reset();

https://rest-assured.googlecode.com/svn/tags/1.2.3/apidocs/index.html?com/jayway/restassured/RestAssured.html - Search for reset method in documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM