use of com.microsoft.graph.serializer.DefaultSerializer in project msgraph-sdk-java-core by microsoftgraph.
the class BatchResponseStep method getDeserializedBody.
/**
* Returned the deserialized response body of the current step
* @param <T2> type of the response body
* @param resultClass class of the resulting response body
* @return the deserialized response body
* @throws GraphServiceException when a bad request was sent
* @throws GraphFatalServiceException when the service did not complete the operation as expected because of an internal error
*/
@Nullable
public <T2> T2 getDeserializedBody(@Nonnull final Class<T2> resultClass) throws GraphServiceException, GraphFatalServiceException {
Objects.requireNonNull(resultClass, "parameter resultClass cannot be null");
if (serializer == null || body == null || !(body instanceof JsonElement))
return null;
final GraphErrorResponse error = serializer.deserializeObject((JsonElement) body, GraphErrorResponse.class);
if (error == null || error.error == null) {
return serializer.deserializeObject((JsonElement) body, resultClass);
} else {
boolean verboseError = false;
if (serializer instanceof DefaultSerializer) {
final ILogger logger = ((DefaultSerializer) serializer).getLogger();
verboseError = logger != null && logger.getLoggingLevel() == LoggerLevel.DEBUG;
}
throw GraphServiceException.createFromResponse("", "", new ArrayList<>(), "", headers, "", status, error, verboseError);
}
}
use of com.microsoft.graph.serializer.DefaultSerializer in project msgraph-sdk-java-core by microsoftgraph.
the class CoreHttpProviderTests method setCoreHttpProvider.
/**
* Configures the http provider for test cases
* @param toSerialize The object to serialize
*/
private void setCoreHttpProvider(final Object toSerialize) throws IOException {
final OkHttpClient mClient = mock(OkHttpClient.class);
final Call mCall = mock(Call.class);
when(mClient.newCall(any(Request.class))).thenReturn(mCall);
when(mCall.execute()).thenReturn(new Response.Builder().code(503).message("Service Unavailable").protocol(Protocol.HTTP_1_1).request(new Request.Builder().url("https://graph.microsoft.com/v1.0/me").build()).addHeader("Content-type", "application/json").body(ResponseBody.create(new GsonBuilder().setPrettyPrinting().create().toJson(toSerialize), MediaType.parse("application/json"))).build());
mProvider = new CoreHttpProvider(new DefaultSerializer(mock(ILogger.class)), mock(ILogger.class), mClient);
}
use of com.microsoft.graph.serializer.DefaultSerializer in project msgraph-sdk-java-core by microsoftgraph.
the class BatchRequestContentTest method testRemoveBatchRequesStepWithId.
@Test
void testRemoveBatchRequesStepWithId() throws MalformedURLException {
IHttpRequest requestStep = mock(IHttpRequest.class);
when(requestStep.getRequestUrl()).thenReturn(new URL(testurl));
BatchRequestContent requestContent = new BatchRequestContent();
String stepId = requestContent.addBatchRequestStep(requestStep);
requestContent.removeBatchRequestStepWithId(stepId);
String content = new DefaultSerializer(mock(ILogger.class)).serializeObject(requestContent);
String expectedContent = "{\"requests\":[]}";
assertEquals(expectedContent, content);
}
use of com.microsoft.graph.serializer.DefaultSerializer in project msgraph-sdk-java-core by microsoftgraph.
the class BatchRequestContentTest method testGetBatchRequestContent.
@Test
void testGetBatchRequestContent() throws MalformedURLException {
IHttpRequest requestStep = mock(IHttpRequest.class);
when(requestStep.getRequestUrl()).thenReturn(new URL(testurl));
BatchRequestContent requestContent = new BatchRequestContent();
String stepId = requestContent.addBatchRequestStep(requestStep);
String content = new DefaultSerializer(mock(ILogger.class)).serializeObject(requestContent);
String expectedContent = "{\"requests\":[{\"url\":\"/me\",\"method\":\"GET\",\"id\":\"" + stepId + "\"}]}";
assertEquals(expectedContent, content);
}
use of com.microsoft.graph.serializer.DefaultSerializer in project msgraph-sdk-java-core by microsoftgraph.
the class BatchRequestContentTest method testRemoveBatchRequesStepWithIdByAddingMultipleBatchSteps.
@Test
void testRemoveBatchRequesStepWithIdByAddingMultipleBatchSteps() throws MalformedURLException {
IHttpRequest requestStep = mock(IHttpRequest.class);
when(requestStep.getRequestUrl()).thenReturn(new URL(testurl));
BatchRequestContent requestContent = new BatchRequestContent();
String stepId = requestContent.addBatchRequestStep(requestStep);
IHttpRequest requestStep1 = mock(IHttpRequest.class);
when(requestStep1.getRequestUrl()).thenReturn(new URL(testurl));
String step1Id = requestContent.addBatchRequestStep(requestStep1, HttpMethod.GET, null, stepId);
requestContent.removeBatchRequestStepWithId(stepId);
String content = new DefaultSerializer(mock(ILogger.class)).serializeObject(requestContent);
String expectedContent = "{\"requests\":[{\"url\":\"/me\",\"method\":\"GET\",\"id\":\"" + step1Id + "\"}]}";
assertEquals(expectedContent, content);
}
Aggregations