Below I have a url:
https://test.com/login/?response_type=code&redirect_uri=https%3A%2F%2Ftest.com&client=testclient&successUrl=https%3A%2F%2Flocalhost%3A4444%2Ftestsite%2Foauth%2Ftestendpoint%3Fresponse_type%3Dcode%26redirect_uri%3Dhttps%253A%252F%252Ftest.com%26client%3Dtestclient
I decode it so that it looks like a much tidier url string:
public void testMethod() {
final String url = URLDecoder.decode(getLastResponse().getHeaders().getFirst("location"), "UTF-8");
}
Now what I want to do is break this url apart by domain and query params and assign them. This is so I can perform asserts against them. I head the way to do this is through value key pairs but I am struggling to grasp the concept of it.
This is my attempt below but it is in a mess. Does anybody know how I can use the LinkedHashMap to help perform the key value pairs? Also, as you see in the url, some params appear twice so will need help in checking against multiple params
final Map<String, List<String>> query_pairs = new LinkedHashMap<>();
final String[] pairs = url.split("&|\\?");
for (String pair : pairs) {
final int idx = pair.indexOf("=");
final String key = idx > 0 ? url : pair;
if (!query_pairs.containsKey(key)) {
query_pairs.put(key, new LinkedList<>());
}
final String value = idx > 0 && pair.length() > idx + 1 ? url : null;
query_pairs.get(key).add(value);
}