Andrey Saleba
Andrey Saleba

Reputation: 2197

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?

p.s. The security provider I'm using is Spring security.

Upvotes: 0

Views: 2341

Answers (1)

parishodak
parishodak

Reputation: 4666

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.

Upvotes: 1

Related Questions