|
14 | 14 | import com.google.gson.JsonElement; |
15 | 15 | import com.microsoft.graph.http.GraphErrorResponse; |
16 | 16 | import com.microsoft.graph.http.GraphServiceException; |
| 17 | +import com.microsoft.graph.logger.DefaultLogger; |
17 | 18 | import com.microsoft.graph.logger.ILogger; |
| 19 | +import com.microsoft.graph.logger.LoggerLevel; |
18 | 20 | import com.microsoft.graph.serializer.DefaultSerializer; |
19 | 21 | import com.microsoft.graph.serializer.ISerializer; |
20 | 22 |
|
@@ -114,4 +116,52 @@ public void deserializesErrorsProperly() { |
114 | 116 | } else |
115 | 117 | fail("batch response was null"); |
116 | 118 | } |
| 119 | + @Test |
| 120 | + public void includeVerboseInformation() { |
| 121 | + String responsebody = "{\"responses\":[{\"id\":\"1\",\"status\":400,\"headers\":{\"Cache-Control\":\"no-cache\",\"x-ms-resource-unit\":\"1\",\"Content-Type\":\"application/json\"},\"body\":{\"error\":{\"code\":\"Request_BadRequest\",\"message\":\"Avalueisrequiredforproperty'displayName'ofresource'User'.\",\"innerError\":{\"date\":\"2021-02-02T19:19:38\",\"request-id\":\"408b8e64-4047-4c97-95b6-46e9f212ab48\",\"client-request-id\":\"102910da-260c-3028-0fb3-7d6903a02622\"}}}}]}"; |
| 122 | + ISerializer serializer = new DefaultSerializer(new DefaultLogger() {{ |
| 123 | + setLoggingLevel(LoggerLevel.DEBUG); |
| 124 | + }}); |
| 125 | + BatchResponseContent batchresponse = serializer.deserializeObject(responsebody, BatchResponseContent.class); |
| 126 | + if(batchresponse != null) { |
| 127 | + if(batchresponse.responses != null) // this is done by the batch request in the fluent API |
| 128 | + for(final BatchResponseStep<?> step : batchresponse.responses) { |
| 129 | + step.serializer = serializer; |
| 130 | + } |
| 131 | + try { |
| 132 | + batchresponse.getResponseById("1").getDeserializedBody(BatchRequestContent.class); |
| 133 | + } catch(GraphServiceException ex) { |
| 134 | + final GraphErrorResponse response = ex.getError(); |
| 135 | + assertNotNull(response); |
| 136 | + assertNotNull(response.error); |
| 137 | + assertNotNull(response.error.message); |
| 138 | + assertEquals(ex.getMessage(true), ex.getMessage()); |
| 139 | + } |
| 140 | + } else |
| 141 | + fail("batch response was null"); |
| 142 | + } |
| 143 | + @Test |
| 144 | + public void doesNotIncludeVerboseInformation() { |
| 145 | + String responsebody = "{\"responses\":[{\"id\":\"1\",\"status\":400,\"headers\":{\"Cache-Control\":\"no-cache\",\"x-ms-resource-unit\":\"1\",\"Content-Type\":\"application/json\"},\"body\":{\"error\":{\"code\":\"Request_BadRequest\",\"message\":\"Avalueisrequiredforproperty'displayName'ofresource'User'.\",\"innerError\":{\"date\":\"2021-02-02T19:19:38\",\"request-id\":\"408b8e64-4047-4c97-95b6-46e9f212ab48\",\"client-request-id\":\"102910da-260c-3028-0fb3-7d6903a02622\"}}}}]}"; |
| 146 | + ISerializer serializer = new DefaultSerializer(new DefaultLogger() {{ |
| 147 | + setLoggingLevel(LoggerLevel.ERROR); |
| 148 | + }}); |
| 149 | + BatchResponseContent batchresponse = serializer.deserializeObject(responsebody, BatchResponseContent.class); |
| 150 | + if(batchresponse != null) { |
| 151 | + if(batchresponse.responses != null) // this is done by the batch request in the fluent API |
| 152 | + for(final BatchResponseStep<?> step : batchresponse.responses) { |
| 153 | + step.serializer = serializer; |
| 154 | + } |
| 155 | + try { |
| 156 | + batchresponse.getResponseById("1").getDeserializedBody(BatchRequestContent.class); |
| 157 | + } catch(GraphServiceException ex) { |
| 158 | + final GraphErrorResponse response = ex.getError(); |
| 159 | + assertNotNull(response); |
| 160 | + assertNotNull(response.error); |
| 161 | + assertNotNull(response.error.message); |
| 162 | + assertEquals(ex.getMessage(false), ex.getMessage()); |
| 163 | + } |
| 164 | + } else |
| 165 | + fail("batch response was null"); |
| 166 | + } |
117 | 167 | } |
0 commit comments