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.
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)));
.get(getRestOperationPath())
returns Response
.
You can .getStatusCode()
and compare it. Closed.
Answer just to close question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With