Skip to content

Commit

Permalink
Additional test in response for Batch Api (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
carycheng77 authored and iamharish committed Oct 5, 2017
1 parent bd3f2e1 commit 80a52d6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
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\": \"[email protected]\"\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\": \"[email protected]\"\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

0 comments on commit 80a52d6

Please sign in to comment.