0

I have defined a file upload method which supports multiple files upload:

 public static Result upload() {
   MultipartFormData body = request().body().asMultipartFormData();
   FilePart file1 = body.getFile("filePart1");
   FilePart file2 = body.getFile("filePart2");
   .....
   .....
 }

I would like to test this REST API and I am not sure how to do it.

Could someone help me on how to test it?

supernova
  • 1,762
  • 1
  • 14
  • 31
Kathir
  • 25
  • 1
  • 5

3 Answers3

3

download the POSTMAN plugin from chrome webstore

its going to be depercated from webstore better to download from this link

send the file to test multiple file upload

Govind Singh
  • 15,282
  • 14
  • 72
  • 106
1

In-case if you want to do the automated test from the build, please follow as below.

(I prefer automated test), which can be done with RestAssured as follows.

     io.restassured.RestAssured.given()
            .multiPart("filePart1", "filename1.txt", file1, FILE_TYPE)
            .multiPart("filePart2", "filename2.txt", file2, FILE_TYPE)
            .expect()
            .when()
            .post("/api/files")
            .then()
            .assertThat()
            .statusCode(HttpStatus.SC_CREATED)

If you are in springframework, which can be done simpler as mentioned in this blog (code a line)

Fahad
  • 749
  • 6
  • 12
1

You can test it with apitest

{
  test3: { @describe('test multi-part')
    req: {
      url: "https://httpbin.org/post",
      method: "post",
      headers: {
        'content-type': "multipart/form-data",
      },
      body: {
        filePart1: "filename1.txt", @file
        filePart2: "filename2.txt", @file
      }
    },
    res: {
      status: 200
    }
  }
}

Apitest is declarative api testing tool with JSON-like DSL.

See https://github.com/sigoden/apitest

SIGODEN
  • 11
  • 1