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

Additional test in response for Batch Api #474

Merged
merged 1 commit into from
Oct 5, 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
2 changes: 1 addition & 1 deletion src/main/java/com/box/sdk/BatchAPIRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected List<BoxAPIResponse> parseResponse(BoxJSONResponse batchResponse) {
// Construct a BoxAPIResponse when response is null, or a BoxJSONResponse when there's a response
// (not anticipating any other response as per current APIs.
// Ideally we should do it based on response header)
if (jsonResponse.get("response") == null) {
if (jsonResponse.get("response") == null || jsonResponse.get("response").isNull()) {
response =
new BoxAPIResponse(jsonResponse.get("status").asInt(), responseHeaders);
} else {
Expand Down
44 changes: 41 additions & 3 deletions src/test/java/com/box/sdk/BatchAPIRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,54 @@ public void testTheParsingResponseWorksAsIntended() {
+ "\t\t\t\t\"type\": \"collaboration\",\n"
+ "\t\t\t\t\"id\": \"456\"\n"
+ "\t\t\t}\n"
+ "\t\t}\n"
+ "\t\t},\n"
+ " {\n"
+ " \t\"status\": 200,\n"
+ " \t\"headers\": {},\n"
+ " \t\"response\": {\n"
+ " \t\t\"chunk_size\": 1,\n"
+ " \t\t\"next_stream_position\": \"1152922980411393698\",\n"
+ " \t\t\"entries\": [{\n"
+ " \t\t\t\"source\": {\n"
+ " \t\t\t\t\"type\": \"user\",\n"
+ " \t\t\t\t\"id\": \"235699372\",\n"
+ " \t\t\t\t\"name\": \"Cary Cheng\",\n"
+ " \t\t\t\t\"login\": \"ccheng+demo@box.com\"\n"
+ " \t\t\t},\n"
+ " \t\t\t\"created_by\": {\n"
+ " \t\t\t\t\"type\": \"user\",\n"
+ " \t\t\t\t\"id\": \"235699372\",\n"
+ " \t\t\t\t\"name\": \"Cary Cheng\",\n"
+ " \t\t\t\t\"login\": \"ccheng+demo@box.com\"\n"
+ " \t\t\t},\n"
+ " \t\t\t\"created_at\": \"2016-10-06T18:42:26-07:00\",\n"
+ " \t\t\t\"event_id\": \"f7369670-cc87-495f-af43-85287fd4d288\",\n"
+ " \t\t\t\"event_type\": \"ADD_LOGIN_ACTIVITY_DEVICE\",\n"
+ " \t\t\t\"ip_address\": \"24.130.143.167\",\n"
+ " \t\t\t\"type\": \"event\",\n"
+ " \t\t\t\"session_id\": null,\n"
+ " \t\t\t\"additional_details\": null\n"
+ " \t\t}]\n"
+ " \t}\n"
+ " },"
+ " {\n"
+ " \"status\": 404,\n"
+ " \"headers\": {},\n"
+ " \"response\": null\n"
+ " }\n"
+ "\t]\n"
+ "}";
JsonObject responseJson = JsonObject.readFrom(stringResponse);
BoxJSONResponse batchResponse = new BoxJSONResponse(200, null, responseJson);
List<BoxAPIResponse> responses = batchRequest.parseResponse(batchResponse);

assertTrue("There should be three responses", responses.size() == 3);
assertTrue("There should be three responses", responses.size() == 5);
for (BoxAPIResponse response: responses) {
assertTrue("Always has response body", ((BoxJSONResponse) response).getJsonObject() != null);
if (response.getResponseCode() == 404) {
assertTrue("Always has response body", response != null);
} else {
assertTrue("Always has JSON response body", ((BoxJSONResponse) response).getJsonObject() != null);
}
}

} catch (Exception e) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/box/sdk/BoxAPIConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public String getJSON() {

@Test
@Category(UnitTest.class)
public void getAuthorizetionURLSuccess() throws Exception {
public void getAuthorizationURLSuccess() throws Exception {
List<String> scopes = new ArrayList<String>();
scopes.add("root_readwrite");
scopes.add("manage_groups");
Expand Down