Skip to content

Commit 96ac49f

Browse files
committed
- adds unit tests for batch response steps exception verbosity
1 parent 859776a commit 96ac49f

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/test/java/com/microsoft/graph/content/BatchResponseContentTest.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
import com.google.gson.JsonElement;
1515
import com.microsoft.graph.http.GraphErrorResponse;
1616
import com.microsoft.graph.http.GraphServiceException;
17+
import com.microsoft.graph.logger.DefaultLogger;
1718
import com.microsoft.graph.logger.ILogger;
19+
import com.microsoft.graph.logger.LoggerLevel;
1820
import com.microsoft.graph.serializer.DefaultSerializer;
1921
import com.microsoft.graph.serializer.ISerializer;
2022

@@ -114,4 +116,52 @@ public void deserializesErrorsProperly() {
114116
} else
115117
fail("batch response was null");
116118
}
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+
}
117167
}

0 commit comments

Comments
 (0)