Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 686
Madhavi Mokkapati Avatar asked Oct 30 '22 12:10

Madhavi Mokkapati


1 Answers

The bad news is that is not really acceptable:

in the RFC 3986, in section 3.4 Query, there is no definition for parameters with multiple values.

The Good news it that it seems possible:

1 a Map and Set< String > should do the job:

com.ning.http.client.FluentStringsMap map = new com.ning.http.client.FluentStringsMap();
map.add("name", "one_value");
Set<String> values= new HashSet<String>();
values.add("1");
values.add("2");
values.add("3");
values.add("4");
map.add("values", values);

see: How to send request parameters with same parameter-name

2 If you have few values, you can put by several List or varargs:

https://code.google.com/p/rest-assured/wiki/Usage#Parameters

. param("myList", "value1", "value2"). .. 

List<String> values = new ArrayList<String>();
values.add("value1");
values.add("value2");

.param("myList", values). .. 

https://code.google.com/p/rest-assured/wiki/Usage#Static_imports

3 Another solution would be to use JSON.

like image 168
guillaume girod-vitouchkina Avatar answered Nov 15 '22 03:11

guillaume girod-vitouchkina