Search in sources :

Example 1 with CoreHttpProvider

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);
}
Also used : Call(okhttp3.Call) OkHttpClient(okhttp3.OkHttpClient) IHttpRequest(com.microsoft.graph.http.IHttpRequest) Request(okhttp3.Request) CoreHttpProvider(com.microsoft.graph.http.CoreHttpProvider) URL(java.net.URL) DefaultSerializer(com.microsoft.graph.serializer.DefaultSerializer) Response(okhttp3.Response) IHttpRequest(com.microsoft.graph.http.IHttpRequest) IAuthenticationProvider(com.microsoft.graph.authentication.IAuthenticationProvider) ILogger(com.microsoft.graph.logger.ILogger) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with CoreHttpProvider

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());
}
Also used : OkHttpClient(okhttp3.OkHttpClient) ILogger(com.microsoft.graph.logger.ILogger) CoreHttpProvider(com.microsoft.graph.http.CoreHttpProvider) ISerializer(com.microsoft.graph.serializer.ISerializer) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with CoreHttpProvider

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());
}
Also used : DefaultSerializer(com.microsoft.graph.serializer.DefaultSerializer) OkHttpClient(okhttp3.OkHttpClient) JsonElement(com.google.gson.JsonElement) Request(okhttp3.Request) CustomRequest(com.microsoft.graph.http.CustomRequest) CoreHttpProvider(com.microsoft.graph.http.CoreHttpProvider) Test(org.junit.jupiter.api.Test)

Aggregations

CoreHttpProvider (com.microsoft.graph.http.CoreHttpProvider)3 OkHttpClient (okhttp3.OkHttpClient)3 ILogger (com.microsoft.graph.logger.ILogger)2 DefaultSerializer (com.microsoft.graph.serializer.DefaultSerializer)2 Request (okhttp3.Request)2 Test (org.junit.jupiter.api.Test)2 JsonElement (com.google.gson.JsonElement)1 IAuthenticationProvider (com.microsoft.graph.authentication.IAuthenticationProvider)1 CustomRequest (com.microsoft.graph.http.CustomRequest)1 IHttpRequest (com.microsoft.graph.http.IHttpRequest)1 ISerializer (com.microsoft.graph.serializer.ISerializer)1 URL (java.net.URL)1 Call (okhttp3.Call)1 Response (okhttp3.Response)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1