Search code examples
javamultimaprest-assured

Use Multimap instead of Map for sending parameters for Rest Assured Call


I am declaring a variable

    static Multimap<String, Object> multiList = ArrayListMultimap.create();

and adding values like

    multiList.put(**key1**,value1)
    multiList.put(**key1**,value1)
    multiList.put(**key2**,value3)

Now, the request I am passing is like

    Response response = RestAssured.given().header("Cookie", SessionDetailsCedar.CSESSIONID).and().header("X-CSRFToken", SessionDetailsCedar.CSRF).and().header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8").and().header("Connection", "keep-alive").formParameters(<b>multiList</b>).when().post(<b>Some URL</b>);

My problem is that formParameters(Map) uses only Map as parameter when I would like to use Multimap instead


Solution

  • Multimap cannot be converted to Map as it is against Map's definition. In such case, I think you should use REST assured's another method formParam method as given in the example below:

     RestAssured.
        given().
                contentType("application/x-www-form-urlencoded; charset=ISO-8859-1").
                formParam("key1", value1).
                formParam("key1", value2).
                formParam("key2", value3).
        when().
                post("Some URL");