Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if the get query param list has only one element then hoist the element out of the list #92

Merged
merged 1 commit into from
Nov 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public Map<String, Object> asJson() {
values.put("params", params);
}
if (get != null) {
values.put("get", get);
values.put("get", processGetParams(get));
}
if (queryString != null) {
values.put("query_string", queryString);
Expand All @@ -144,6 +144,20 @@ public Map<String, Object> asJson() {
return values;
}

private Map<String, Object> processGetParams(Map<String, List<String>> map) {
Map<String, Object> result = new HashMap<>();
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
String k = entry.getKey();
List<String> v = entry.getValue();
if (v.size() == 1) {
result.put(k, v.get(0));
} else {
result.put(k, v);
}
}
return result;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.rollbar.api.payload.data;

import static java.util.Arrays.asList;

import static com.rollbar.test.Factory.request;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import java.util.HashMap;
import java.util.Map;
import java.util.List;
import org.junit.Test;

public class RequestTest {
Expand All @@ -20,7 +23,14 @@ public void shouldBeEqual() {

@Test
public void shouldReturnAsJson() {
Request request = request();
Map<String, List<String>> get = new HashMap<>();
get.put("param1", asList("value1.1", "value1.2"));
get.put("param2", asList("value2.1"));
Map<String, Object> expectedGet = new HashMap<>();
expectedGet.put("param1", get.get("param1"));
expectedGet.put("param2", "value2.1");

Request request = request(get);

Map<String, Object> expected = new HashMap<>();

Expand All @@ -34,7 +44,7 @@ public void shouldReturnAsJson() {
expected.put("params", request.getParams());
}
if (request.getGet() != null) {
expected.put("get", request.getGet());
expected.put("get", expectedGet);
}
if (request.getQueryString() != null) {
expected.put("query_string", request.getQueryString());
Expand All @@ -51,4 +61,4 @@ public void shouldReturnAsJson() {

assertThat(request.asJson(), is(expected));
}
}
}
12 changes: 8 additions & 4 deletions rollbar-api/src/test/java/com/rollbar/test/Factory.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,18 @@ public static Person person() {
}

public static Request request() {
Map<String, String> headers = new HashMap<>();
headers.put("Accept", "text/html");
headers.put("Referer", "https://rollbar.com/");

Map<String, List<String>> get = new HashMap<>();
get.put("param1", asList("value1.1", "value1.2"));
get.put("param2", asList("value2.1"));

return request(get);
}

public static Request request(Map<String, List<String>> get) {
Map<String, String> headers = new HashMap<>();
headers.put("Accept", "text/html");
headers.put("Referer", "https://rollbar.com/");

return new Request.Builder()
.url("https://rollbar.com/project/1")
.method("GET")
Expand Down