Skip to content

Commit 80a52d6

Browse files
carycheng77iamharish
authored andcommitted
Additional test in response for Batch Api (#474)
1 parent bd3f2e1 commit 80a52d6

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

src/main/java/com/box/sdk/BatchAPIRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected List<BoxAPIResponse> parseResponse(BoxJSONResponse batchResponse) {
111111
// Construct a BoxAPIResponse when response is null, or a BoxJSONResponse when there's a response
112112
// (not anticipating any other response as per current APIs.
113113
// Ideally we should do it based on response header)
114-
if (jsonResponse.get("response") == null) {
114+
if (jsonResponse.get("response") == null || jsonResponse.get("response").isNull()) {
115115
response =
116116
new BoxAPIResponse(jsonResponse.get("status").asInt(), responseHeaders);
117117
} else {

src/test/java/com/box/sdk/BatchAPIRequestTest.java

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,54 @@ public void testTheParsingResponseWorksAsIntended() {
110110
+ "\t\t\t\t\"type\": \"collaboration\",\n"
111111
+ "\t\t\t\t\"id\": \"456\"\n"
112112
+ "\t\t\t}\n"
113-
+ "\t\t}\n"
113+
+ "\t\t},\n"
114+
+ " {\n"
115+
+ " \t\"status\": 200,\n"
116+
+ " \t\"headers\": {},\n"
117+
+ " \t\"response\": {\n"
118+
+ " \t\t\"chunk_size\": 1,\n"
119+
+ " \t\t\"next_stream_position\": \"1152922980411393698\",\n"
120+
+ " \t\t\"entries\": [{\n"
121+
+ " \t\t\t\"source\": {\n"
122+
+ " \t\t\t\t\"type\": \"user\",\n"
123+
+ " \t\t\t\t\"id\": \"235699372\",\n"
124+
+ " \t\t\t\t\"name\": \"Cary Cheng\",\n"
125+
+ " \t\t\t\t\"login\": \"[email protected]\"\n"
126+
+ " \t\t\t},\n"
127+
+ " \t\t\t\"created_by\": {\n"
128+
+ " \t\t\t\t\"type\": \"user\",\n"
129+
+ " \t\t\t\t\"id\": \"235699372\",\n"
130+
+ " \t\t\t\t\"name\": \"Cary Cheng\",\n"
131+
+ " \t\t\t\t\"login\": \"[email protected]\"\n"
132+
+ " \t\t\t},\n"
133+
+ " \t\t\t\"created_at\": \"2016-10-06T18:42:26-07:00\",\n"
134+
+ " \t\t\t\"event_id\": \"f7369670-cc87-495f-af43-85287fd4d288\",\n"
135+
+ " \t\t\t\"event_type\": \"ADD_LOGIN_ACTIVITY_DEVICE\",\n"
136+
+ " \t\t\t\"ip_address\": \"24.130.143.167\",\n"
137+
+ " \t\t\t\"type\": \"event\",\n"
138+
+ " \t\t\t\"session_id\": null,\n"
139+
+ " \t\t\t\"additional_details\": null\n"
140+
+ " \t\t}]\n"
141+
+ " \t}\n"
142+
+ " },"
143+
+ " {\n"
144+
+ " \"status\": 404,\n"
145+
+ " \"headers\": {},\n"
146+
+ " \"response\": null\n"
147+
+ " }\n"
114148
+ "\t]\n"
115149
+ "}";
116150
JsonObject responseJson = JsonObject.readFrom(stringResponse);
117151
BoxJSONResponse batchResponse = new BoxJSONResponse(200, null, responseJson);
118152
List<BoxAPIResponse> responses = batchRequest.parseResponse(batchResponse);
119153

120-
assertTrue("There should be three responses", responses.size() == 3);
154+
assertTrue("There should be three responses", responses.size() == 5);
121155
for (BoxAPIResponse response: responses) {
122-
assertTrue("Always has response body", ((BoxJSONResponse) response).getJsonObject() != null);
156+
if (response.getResponseCode() == 404) {
157+
assertTrue("Always has response body", response != null);
158+
} else {
159+
assertTrue("Always has JSON response body", ((BoxJSONResponse) response).getJsonObject() != null);
160+
}
123161
}
124162

125163
} catch (Exception e) {

src/test/java/com/box/sdk/BoxAPIConnectionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public String getJSON() {
131131

132132
@Test
133133
@Category(UnitTest.class)
134-
public void getAuthorizetionURLSuccess() throws Exception {
134+
public void getAuthorizationURLSuccess() throws Exception {
135135
List<String> scopes = new ArrayList<String>();
136136
scopes.add("root_readwrite");
137137
scopes.add("manage_groups");

0 commit comments

Comments
 (0)