use of com.microsoft.graph.http.CoreHttpProvider in project msgraph-sdk-java-core by microsoftgraph.
the class BatchRequestContentTest method executeBatchTest.
@Test
void executeBatchTest() throws Throwable {
final BatchRequestContent content = new BatchRequestContent();
IHttpRequest requestStep = mock(IHttpRequest.class);
when(requestStep.getRequestUrl()).thenReturn(new URL(testurl));
final String stepId = content.addBatchRequestStep(requestStep);
final OkHttpClient mHttpClient = mock(OkHttpClient.class);
final Call mCall = mock(Call.class);
when(mHttpClient.newCall(any(Request.class))).thenReturn(mCall);
final CoreHttpProvider mHttpProvider = new CoreHttpProvider(new DefaultSerializer(mock(ILogger.class)), mock(ILogger.class), mHttpClient);
final IBaseClient<?> mClient = BaseClient.builder().authenticationProvider(mock(IAuthenticationProvider.class)).httpProvider(mHttpProvider).buildClient();
final Response mResponse = new Response.Builder().request(new Request.Builder().url("https://graph.microsoft.com/v1.0/$batch").build()).code(200).protocol(Protocol.HTTP_1_1).message("OK").addHeader("Content-type", "application/json").body(ResponseBody.create("{\"responses\": [{\"id\": \"" + stepId + "\",\"status\": 200,\"body\": null}]}", MediaType.parse("application/json"))).build();
when(mCall.execute()).thenReturn(mResponse);
final BatchResponseContent batchResponse = mClient.batch().buildRequest().post(content);
assertNotNull(mClient.batch().buildRequest().postAsync(content));
final BatchResponseStep<?> response = batchResponse.getResponseById(stepId);
assertNotNull(response);
}
use of com.microsoft.graph.http.CoreHttpProvider in project msgraph-sdk-java-core by microsoftgraph.
the class BaseClientTests method setUp.
@BeforeEach
public void setUp() throws Exception {
baseClient = new BaseClient<>();
mLogger = mock(ILogger.class);
mSerializer = mock(ISerializer.class);
mHttpProvider = new CoreHttpProvider(mSerializer, mLogger, new OkHttpClient.Builder().build());
}
use of com.microsoft.graph.http.CoreHttpProvider in project msgraph-sdk-java-core by microsoftgraph.
the class BaseClientTests method testCustomRequest.
@Test
public void testCustomRequest() {
baseClient.setHttpProvider(new CoreHttpProvider(new DefaultSerializer(mLogger), mLogger, new OkHttpClient.Builder().build()));
final CustomRequestBuilder<JsonElement> simpleRequestBuilder = baseClient.customRequest("");
assertNotNull(simpleRequestBuilder);
final CustomRequestBuilder<String> stringRequestBuilder = baseClient.customRequest("", String.class);
assertNotNull(stringRequestBuilder);
final CustomRequest<String> abs = stringRequestBuilder.buildRequest();
abs.setHttpMethod(HttpMethod.POST);
final Request nat = abs.getHttpRequest("somestring");
assertEquals("\"somestring\"", getStringFromRequestBody(nat));
assertEquals("application", nat.body().contentType().type());
assertEquals("json", nat.body().contentType().subtype());
}
Aggregations