Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RESTAssured recieve one of two possible status codes

I have test(!) code of RESTAssured, that checks that REST endpoint returns me 0 as status code;

     given()
        .contentType(CONTENT_TYPE_APPLICATION_JSON)
    .when()
        .get(getRestOperationPath())
    .then()
        .statusCode(STATUS_CODE_OK); 

But now it is possible that it also can supply code 404, that is considered valid output. I need my test to check that status code is one of the two, but I cannot wrap my head on how to do actually do it. Can you point me as to how I can do it, or if it is impossible?

upd:

.get(getRestOperationPath()) returns Response -> you can get status code and compare it. closed.

like image 613
Andrii Plotnikov Avatar asked Aug 02 '16 07:08

Andrii Plotnikov


2 Answers

You could also do this using the Hamcrest matchers, without extracting the response into a separate variable.

You can use a combination of anyOf() and is()

import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.is;

...

given()
    .contentType(CONTENT_TYPE_APPLICATION_JSON)
.when()
    .get(getRestOperationPath())
.then()
    .statusCode(anyOf(is(STATUS_CODE_OK),is(STATUS_CODE_NOT_FOUND))); 
like image 73
user3319803 Avatar answered Sep 22 '22 17:09

user3319803


.get(getRestOperationPath()) returns Response. You can .getStatusCode() and compare it. Closed.

Answer just to close question.

like image 45
Andrii Plotnikov Avatar answered Sep 23 '22 17:09

Andrii Plotnikov