rest-assured icon indicating copy to clipboard operation
rest-assured copied to clipboard

current basePath settings is not used in .post() request

Open nilyin opened this issue 3 years ago • 0 comments

Hi, I am using rest-assured with quarkus.

my code is

` logger.debug("before POST item with id, using path {}", RestAssured.baseURI + RestAssured.basePath);

        given()
                .contentType("application/octet-stream")
                .body(image)
                .pathParam("id", random)
                .when()
                .post("/{id}")
                .then()
                .assertThat().spec(prepareResponseSpec(Response.Status.NOT_FOUND.getStatusCode())).log().all();`

logger shows correctly set baseURI and base Path: (main) before POST item with id, using path http://localhost:8081/images/address

actually at the test class I use these settings:

` @BeforeEach public void setURL() { baseURI = "http://localhost:8081"; RestAssured.basePath = "/images/address"; RestAssured.requestSpecification = given() .header("Content-Type", "application/json"); RestAssured.filters(new RequestLoggingFilter(), new ResponseLoggingFilter()); }

`

to set the class-wide values for both baseURI and basePath.

so the expected behavior of method .post("/{id}") is to use use endpoint address prefixed with baseURI + baseBath, i.e. "http://localhost:8081/images/address/some_number" in my case.

In reality the different basePath is used (actually http://localhost:8081/addresses/id , which is used in different test class)

my fix is to use explicit path setting before .post() call like this:

`

given() .contentType("application/octet-stream") .body(image) .pathParam("id", random) .when() .basePath(basePath) .post("/{id}") .then() .assertThat().spec(prepareResponseSpec(Response.Status.NOT_FOUND.getStatusCode())).log().all();

`

So it looks, that it is a bug or if not then please tell me what I am doing wrong...

nilyin avatar Jan 07 '22 14:01 nilyin