0

I'm exploring rest-assured (Java) with cucumber based Framework. There is a method written to handle query parameters, it expects a map of<String,?> as below-

protected Response **getByQueryParams**(final String url, Map<String, ?> queryParams) {
        setRootApiUrl();
        return given()
                .queryParams(queryParams)
                .contentType(ContentType.JSON)
                .accept(ContentType.JSON).get(url)
                .thenReturn();
    }

My Get Req. End point is:** http://localHost:8088/state-names?countryCode=IND**

I've a cucumber step for same as below-

   Given I perform Get operation for "/state-names" with below query params
    |countryCode|
    |IND        |

My Step Def code: using above (getByQueryParams) method >

@Given("I perform Get operation for {string} with below query params")
    public void getAllStatesWithCountryCode(String uri,Map<String,String> table) {
        var queryParMap=new HashMap<>();

        for (Map.Entry<String, String> data : table.entrySet()) {
            queryParMap.put(data.getKey(),data.getValue()); 
        }
        response = getByQueryParams(uri,queryParMap);

    }

this is throwing an error- Required type: Map<String,?> Provided:HashMap<Object,Object>

Error seems obvious but I'm not that good in java so unable to understand how to use this method with defined Map<String,?> in my scenario by avoiding above error. Plz help.

saTya
  • 305
  • 1
  • 5
  • 15
  • Thanks for accepting it as answered, but I think you should consider changing the question/description as the problem statement here is something else. – Satyendra Sharma Oct 25 '20 at 10:56

1 Answers1

1

Your method-getByQueryParams(final String url, Map<String, ?> queryParams) seems to be fine as this designed to hold any generic type of value against String Key. I'm not sure about the way your FW forming the endpoint api url.

But this error should be resolved by declaring your local map of type <String, String> rather than using default- Map<> i.e. Map<Obj,Obj>. I was able to get it fixed with either of below:

var queryParMap = new HashMap<String,String>(); or Map<String, String> queryParMap = new HashMap<>();

Hope this helps.

Satyendra Sharma
  • 1,436
  • 13
  • 19