Skip to content

Testing multipart data request along with passing path parameters fails #1673

@SergiyDyrda

Description

@SergiyDyrda

Request handler:

@PutMapping(value = "/put-file/{requestId}",
        consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.TEXT_PLAIN_VALUE)
    @ResponseStatus(HttpStatus.ACCEPTED)
    public String putFile(@PathVariable String requestId,
        @RequestPart(value = "files") MultipartFile[] files) {
        assert StringUtils.hasText(requestId);
        assert files.length > 0;
        return "ok";
    }

Success test

@Test
    void testPutFileSucceeds() throws IOException {
        byte[] file = new ClassPathResource("img.png").getInputStream().readAllBytes();
        String result = given()
            .multiPart("files", "test.png", file, MediaType.IMAGE_PNG_VALUE)
            .contentType(ContentType.MULTIPART)
            .when()
            .put("/put-file/100")
            .then()
            .statusCode(202)
            .extract()
            .response().getBody().asString();

        assertEquals("ok", result);
    }

Failing test

@Test
    void testPutFileShouldSucceedButFails() throws IOException {
        byte[] file = new ClassPathResource("img.png").getInputStream().readAllBytes();
        String result = given()
            .multiPart("files", "test.png", file, MediaType.IMAGE_PNG_VALUE)
            .contentType(ContentType.MULTIPART)
            .when()
            .put("/put-file/{requestId}", "100")
            .then()
            .statusCode(202)
            .extract()
            .response().getBody().asString();

        assertEquals("ok", result);
    }

Expected status code <202> but was <404>

Looks like request path with path params has been parsed incorrectly
image

And the root cause somewhere in io.restassured.module.mockmvc.internal.MockMvcRequestSenderImpl#sendRequest
while invoking io.restassured.module.mockmvc.internal.MockMvcRequestSenderImpl#invokeMethod(java.lang.Object, java.lang.String, java.lang.Object...):
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions