|
22 | 22 |
|
23 | 23 | package com.microsoft.graph.http; |
24 | 24 |
|
| 25 | +import com.google.gson.JsonObject; |
| 26 | +import com.google.gson.JsonPrimitive; |
25 | 27 | import com.microsoft.graph.authentication.MockAuthenticationProvider; |
26 | 28 | import com.microsoft.graph.concurrency.IProgressCallback; |
27 | 29 | import com.microsoft.graph.concurrency.MockExecutors; |
28 | 30 | import com.microsoft.graph.core.ClientException; |
29 | 31 | import com.microsoft.graph.core.GraphErrorCodes; |
30 | 32 | import com.microsoft.graph.models.extensions.Drive; |
31 | 33 | import com.microsoft.graph.models.extensions.DriveItem; |
| 34 | +import com.microsoft.graph.logger.LoggerLevel; |
32 | 35 | import com.microsoft.graph.logger.MockLogger; |
33 | 36 | import com.microsoft.graph.serializer.MockSerializer; |
34 | 37 |
|
@@ -259,9 +262,58 @@ public Map<String, String> getHeaders() { |
259 | 262 | mProvider.send(new MockHttpRequest(), DriveItem.class, null); |
260 | 263 | fail("Expected exception in previous statement"); |
261 | 264 | } catch (final GraphServiceException e) { |
| 265 | + assertTrue(e.getMessage().indexOf("truncated") > 0); |
262 | 266 | assertEquals(expectedMessage, e.getServiceError().message); |
263 | 267 | } |
264 | 268 | } |
| 269 | + |
| 270 | + @Test |
| 271 | + public void testVerboseErrorResponse() throws Exception { |
| 272 | + final GraphErrorCodes expectedErrorCode = GraphErrorCodes.INVALID_REQUEST; |
| 273 | + final String expectedMessage = "Test error!"; |
| 274 | + final GraphErrorResponse toSerialize = new GraphErrorResponse(); |
| 275 | + toSerialize.error = new GraphError(); |
| 276 | + toSerialize.error.code = expectedErrorCode.toString(); |
| 277 | + toSerialize.error.message = expectedMessage; |
| 278 | + toSerialize.error.innererror = null; |
| 279 | + JsonObject raw = new JsonObject(); |
| 280 | + raw.add("response", new JsonPrimitive("The raw request was invalid")); |
| 281 | + toSerialize.rawObject = raw; |
| 282 | + |
| 283 | + MockLogger logger = new MockLogger(); |
| 284 | + logger.setLoggingLevel(LoggerLevel.DEBUG); |
| 285 | + |
| 286 | + mProvider = new DefaultHttpProvider(new MockSerializer(toSerialize, ""), |
| 287 | + mAuthenticationProvider = new MockAuthenticationProvider(), |
| 288 | + new MockExecutors(), |
| 289 | + logger); |
| 290 | + |
| 291 | + final ITestConnectionData data = new ITestConnectionData() { |
| 292 | + @Override |
| 293 | + public int getRequestCode() { |
| 294 | + return 415; |
| 295 | + } |
| 296 | + |
| 297 | + @Override |
| 298 | + public String getJsonResponse() { |
| 299 | + return "{}"; |
| 300 | + } |
| 301 | + |
| 302 | + @Override |
| 303 | + public Map<String, String> getHeaders() { |
| 304 | + return new HashMap<>(); |
| 305 | + } |
| 306 | + }; |
| 307 | + mProvider.setConnectionFactory(new MockConnectionFactory(new MockConnection(data))); |
| 308 | + |
| 309 | + try { |
| 310 | + mProvider.send(new MockHttpRequest(), DriveItem.class, null); |
| 311 | + fail("Expected exception in previous statement"); |
| 312 | + } catch (final GraphServiceException e) { |
| 313 | + assertFalse(e.getMessage().indexOf("truncated") > 0); |
| 314 | + assertTrue(e.getMessage().indexOf("The raw request was invalid") > 0); |
| 315 | + } |
| 316 | + } |
265 | 317 |
|
266 | 318 | @Test |
267 | 319 | public void testBodyLessResponse() throws Exception { |
|
0 commit comments