mardi 13 novembre 2018

Testing endpoint with MultiValueMap as param

I've got an endpoint as:

@RequestMapping(value = "/topics/{topicId}")
public class TopicGateway {
    @PostMapping
    public void generate(@RequestParam MultiValueMap params, HttpServletResponse response) {
        reportFacade.generate(params, response);
    }

I would've like to create integration test for this method. I use rest-assured, but example with default mockMvc usage would've help me too.

What I did right now is just:

given()
    .pathParam("topicId", 1)
    // here I need to add those MultiValueMap.
    .get(BASE_PATH)
    .then()
    .statusCode(200);

private MultiValueMap<String, String> params(){
    MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
    params.add("param1", "Test");
    params.add("param2", "Another test");
    params.add("param3", "123");
    params.add("param4", "456");
    return params;
}

I tried: .formParameters(params()) , but seems not working.

Aucun commentaire:

Enregistrer un commentaire