diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 000000000..f7681bdfe
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,41 @@
+# Contributing to the Microsoft Graph Core SDK for Java
+
+The Microsoft Graph Core SDK for Java is available for all manner of contribution. There are a couple of different recommended paths to get contributions into the released version of this SDK.
+
+__NOTE__ A signed a contribution license agreement is required for all contributions, and is checked automatically on new pull requests. Please read and sign the agreement https://cla.microsoft.com/ before starting any work for this repository.
+
+## File issues
+
+The best way to get started with a contribution is to start a dialog with the owners of this repository. Sometimes features will be under development or out of scope for this SDK and it's best to check before starting work on contribution.
+
+## Submit pull requests for trivial changes
+
+If you are making a change that does not affect the interface components and does not affect other downstream callers, feel free to make a pull request against the __dev__ branch. The dev branch will be updated frequently.
+
+Revisions of this nature will result in a 0.0.X change of the version number.
+
+## Submit pull requests for features
+
+If major functionality is being added, or there will need to be gestation time for a change, it should be submitted against the __feature__ branch.
+
+Revisions of this nature will result in a 0.X.X change of the version number.
+
+## Add yourself as a contributor
+
+This project follows the [all contributors](https://github.com/kentcdodds/all-contributors) specification. When making a contribution, please add yourself to the table of contributors:
+
+ 1. In section 5. of the [README.md](https://github.com/microsoftgraph/msgraph-sdk-java-core/blob/dev/readme.md), after the last "|", copy and paste a new blank contributor element
+ ```html
+ [
+ Your Name](your website or github page)
+ [emoji](link "alt-text") |
+ ```
+
+ You can get your GitHub UID by inspecting your GitHub avatar image.
+
+2. For each contribution type (see [emoji key](https://github.com/kentcdodds/all-contributors#emoji-key) for a list of contribution types), add an emoji and a relevant link and alt-text.
+
+ For example, if you write a blogpost on how to use the SDK, you would include:
+
+ ```html
+ [??]("https://myblog.com/using-the-java-sdk" "Blog Post")
\ No newline at end of file
diff --git a/THIRD PARTY NOTICES b/THIRD PARTY NOTICES
new file mode 100644
index 000000000..4c6ff0a5a
--- /dev/null
+++ b/THIRD PARTY NOTICES
@@ -0,0 +1,26 @@
+This file is based on or incorporates material from the projects listed below
+(Third Party IP). The original copyright notice and the license under which
+Microsoft received such Third Party IP, are set forth below. Such licenses and
+notices are provided for informational purposes only. Microsoft licenses the
+Third Party IP to you under the licensing terms for the Microsoft product.
+Microsoft reserves all other rights not expressly granted under this agreement,
+whether by implication, estoppel or otherwise.
+
+Gson
+Copyright 2008-2011 Google Inc.
+
+Provided for Informational Purposes Only
+
+Apache 2.0 License
+
+Licensed under the Apache License, Version 2.0 (the "License"); you may not use
+this file except in compliance with the License. You may obtain a copy of the
+License at http://www.apache.org/licenses/LICENSE-2.0
+
+THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
+ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
+WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
+MERCHANTABLITY OR NON-INFRINGEMENT.
+
+See the Apache Version 2.0 License for specific language governing permissions
+and limitations under the License.
\ No newline at end of file
diff --git a/gradle.properties b/gradle.properties
index eb7f41cfc..77dfc55e9 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -21,12 +21,12 @@
## linux requires 10G, OSX requires 11G
org.gradle.jvmargs=-XX:MaxPermSize=512m -Xmx2g
-mavenRepoUrl = https://api.bintray.com/content/microsoftgraph/Maven/microsoft-graph
+mavenRepoUrl = https://api.bintray.com/content/microsoftgraph/Maven/microsoft-graph-core
mavenBintraySnapshotUrl = http://oss.jfrog.org/artifactory/oss-snapshot-local
mavenGroupId = com.microsoft.graph
mavenArtifactId = microsoft-graph-core
-mavenMajorVersion = 0
-mavenMinorVersion = 1
+mavenMajorVersion = 1
+mavenMinorVersion = 0
mavenPatchVersion = 0
mavenArtifactSuffix =
nightliesUrl = http://dl.bintray.com/MicrosoftGraph/Maven
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..e28513376
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/readme.md b/readme.md
index e29c95a24..eaf78529e 100644
--- a/readme.md
+++ b/readme.md
@@ -1,9 +1,10 @@
-# Microsoft Graph Core Preview SDK for Java
+# Microsoft Graph Core SDK for Java
-Get started with the Microsoft Graph Core SDK for Java by integrating the [Microsoft Graph API](https://graph.microsoft.io/en-us/getting-started) into your Java application!
+Get started with the Microsoft Graph Core SDK for Java by integrating the [Microsoft Graph API](https://graph.microsoft.io/en-us/getting-started) into your Java and Android application!
-## Important Note about the Microsoft Graph Core Java Preview
-During the preview we may make changes to the API, and other mechanisms of this library, which you will be required to take along with bug fixes or feature improvements. This may impact your application. An API change may require you to update your code. When we provide the General Availability release we will require you to update to the General Availability version within six months, as applications written using a preview version of library may no longer work.
+## Samples and usage guide
+[Middleware usage](https://github.com/microsoftgraph/msgraph-sdk-java-core/wiki)
+[Batching](https://github.com/microsoftgraph/msgraph-sdk-java-core/wiki/Batching)
## 1. Installation
@@ -14,14 +15,11 @@ Add the repository and a compile dependency for `microsoft-graph-core` to your p
```gradle
repository {
jcenter()
- jcenter{
- url 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
- }
}
dependency {
// Include the sdk as a dependency
- compile('com.microsoft.graph:microsoft-graph-core:0.1.0-SNAPSHOT')
+ compile('com.microsoft.graph:microsoft-graph-core:1.0.0')
}
```
@@ -31,34 +29,10 @@ Add the dependency in `dependencies` in pom.xml
com.microsoft.graph
microsoft-graph-core
- 0.1.0-SNAPSHOT
+ 1.0.0
```
-Add `profiles` in `project` to download Snapshot release binary:
-```
-
-
- allow-snapshots
-
- true
-
-
-
- snapshots-repo
- https://oss.sonatype.org/content/repositories/snapshots
-
- false
-
-
- true
-
-
-
-
-
-```
-
### 1.3 Enable ProGuard (Android)
The nature of the Graph API is such that the SDK needs quite a large set of classes to describe its functionality. You need to ensure that [ProGuard](https://developer.android.com/studio/build/shrink-code.html) is enabled on your project. Otherwise, you will incur long build times for functionality that is not necessarily relevant to your particular application. If you are still hitting the 64K method limit, you can also enable [multidexing](https://developer.android.com/studio/build/multidex.html).
@@ -70,7 +44,11 @@ Register your application by following the steps at [Register your app with the
### 2.2 Create an IAuthenticationProvider object
-An instance of the **HttpClients** class handles building client. To create a new instance of this class, you need to provide an instance of `ICoreAuthenticationProvider`, which can authenticate requests to Microsoft Graph.
+An instance of the **HttpClients** class handles building client. To create a new instance of this class, you need to provide an instance of `ICoreAuthenticationProvider`, which can authenticate requests to Microsoft Graph.
+### To get instance of HttpClients
+Auth in Java app [here](https://github.com/microsoftgraph/msgraph-sdk-java-auth)
+
+Auth in Android app [here](https://github.com/microsoftgraph/msgraph-sdk-android-auth)
### 2.3 Get a HttpClients object
You must get a **HttpClients** object to make requests against the service.
diff --git a/src/main/java/com/microsoft/graph/content/MSBatchRequestStep.java b/src/main/java/com/microsoft/graph/content/MSBatchRequestStep.java
index 7386decf8..ac13bb0ab 100644
--- a/src/main/java/com/microsoft/graph/content/MSBatchRequestStep.java
+++ b/src/main/java/com/microsoft/graph/content/MSBatchRequestStep.java
@@ -12,6 +12,8 @@ public class MSBatchRequestStep {
public MSBatchRequestStep(String requestId, Request request, List arrayOfDependsOnIds) {
if(requestId == null)
throw new IllegalArgumentException("Request Id cannot be null.");
+ if(requestId.length() == 0)
+ throw new IllegalArgumentException("Request Id cannot be empty.");
if(request == null)
new IllegalArgumentException("Request cannot be null.");
diff --git a/src/main/java/com/microsoft/graph/content/MSBatchResponseContent.java b/src/main/java/com/microsoft/graph/content/MSBatchResponseContent.java
index ed10d1da1..f640880f4 100644
--- a/src/main/java/com/microsoft/graph/content/MSBatchResponseContent.java
+++ b/src/main/java/com/microsoft/graph/content/MSBatchResponseContent.java
@@ -2,6 +2,7 @@
import java.io.IOException;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import org.json.simple.JSONArray;
@@ -18,33 +19,17 @@
public class MSBatchResponseContent {
- private JSONObject batchResponseObj;
private Response batchResponse;
private Map batchRequestsHashMap;
private JSONArray batchResponseArray;
+ private String nextLink;
/*
* @param batchResponse OkHttp batch response on execution of batch requests
*/
public MSBatchResponseContent(Response batchResponse) {
- if(batchResponse == null)
- throw new IllegalArgumentException("Batch Response cannot be null");
-
- this.batchRequestsHashMap = createBatchRequestsHashMap(batchResponse);
this.batchResponse = batchResponse;
- if(batchResponse.body() != null) {
- try {
- String batchResponseData = batchResponse.body().string();
- if(batchResponseData != null) {
- batchResponseObj = stringToJSONObject(batchResponseData);
- if(batchResponseObj != null) {
- batchResponseArray = (JSONArray)batchResponseObj.get("responses");
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
+ update(batchResponse);
}
/*
@@ -54,12 +39,9 @@ public MSBatchResponseContent(Response batchResponse) {
* @return OkHttp Response corresponding to requestId
*/
public Response getResponseById(String requestId) {
- if(batchResponseObj == null)
- return null;
+ if(batchResponseArray == null) return null;
- JSONArray responses = (JSONArray)batchResponseObj.get("responses");
- if(responses == null)
- return null;
+ JSONArray responses = batchResponseArray;
for(Object response : responses) {
JSONObject jsonresponse = (JSONObject)response;
@@ -104,20 +86,71 @@ public Response getResponseById(String requestId) {
return null;
}
- /*
- * @return responses as a string
+ /**
+ * Get map of id and responses
+ *
+ * @return responses in Map of id and response
*/
- public String getResponses() {
- return batchResponseArray != null ? batchResponseArray.toJSONString() : null;
+ public Map getResponses() {
+ if(batchResponseArray == null)
+ return null;
+ Map responsesMap = new HashMap<>();
+ for(String id : batchRequestsHashMap.keySet()) {
+ responsesMap.put(id, getResponseById(id));
+ }
+ return responsesMap;
+ }
+
+ /**
+ * Get iterator over the responses
+ *
+ * @return iterator for responses
+ */
+ public Iterator> getResponsesIterator() {
+ Map responsesMap = getResponses();
+ return responsesMap != null ? responsesMap.entrySet().iterator() : null;
+ }
+
+ public void update(Response batchResponse) {
+ if(batchResponse == null)
+ throw new IllegalArgumentException("Batch Response cannot be null");
+
+ Map requestMap = createBatchRequestsHashMap(batchResponse);
+ if(batchRequestsHashMap == null)
+ batchRequestsHashMap = new HashMap<>();
+ if(requestMap != null)
+ batchRequestsHashMap.putAll(requestMap);
+
+ if(batchResponse.body() != null) {
+ try {
+ String batchResponseData = batchResponse.body().string();
+ if(batchResponseData != null) {
+ JSONObject batchResponseObj = stringToJSONObject(batchResponseData);
+ if(batchResponseObj != null) {
+
+ JSONObject nextLinkObject = (JSONObject) batchResponseObj.get("@odata.nextLink");
+ if(nextLinkObject!=null)
+ nextLink = nextLinkObject.toString();
+
+ if(batchResponseArray == null)
+ batchResponseArray = new JSONArray();
+
+ JSONArray responseArray = (JSONArray)batchResponseObj.get("responses");
+ if(responseArray!=null)
+ batchResponseArray.addAll(responseArray);
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
/*
* @return nextLink of batch response
*/
public String nextLink() {
- if(batchResponseObj == null) return null;
- Object nextLinkObject = batchResponseObj.get("nextLink");
- return nextLinkObject != null ? ((JSONObject)nextLinkObject).toString() : null;
+ return nextLink;
}
private Map createBatchRequestsHashMap(Response batchResponse) {
diff --git a/src/main/java/com/microsoft/graph/httpcore/AuthenticationHandler.java b/src/main/java/com/microsoft/graph/httpcore/AuthenticationHandler.java
index 42e9fe304..b48b8b337 100644
--- a/src/main/java/com/microsoft/graph/httpcore/AuthenticationHandler.java
+++ b/src/main/java/com/microsoft/graph/httpcore/AuthenticationHandler.java
@@ -3,6 +3,7 @@
import java.io.IOException;
import com.microsoft.graph.httpcore.middlewareoption.MiddlewareType;
+import com.microsoft.graph.httpcore.middlewareoption.TelemetryOptions;
import okhttp3.Interceptor;
import okhttp3.Request;
@@ -21,6 +22,11 @@ public AuthenticationHandler(ICoreAuthenticationProvider authProvider) {
@Override
public Response intercept(Chain chain) throws IOException {
Request originalRequest = chain.request();
+
+ if(originalRequest.tag(TelemetryOptions.class) == null)
+ originalRequest = originalRequest.newBuilder().tag(TelemetryOptions.class, new TelemetryOptions()).build();
+ originalRequest.tag(TelemetryOptions.class).setFeatureUsage(TelemetryOptions.AUTH_HANDLER_ENABLED_FLAG);
+
Request authenticatedRequest = authProvider.authenticateRequest(originalRequest);
return chain.proceed(authenticatedRequest);
}
diff --git a/src/main/java/com/microsoft/graph/httpcore/HttpClients.java b/src/main/java/com/microsoft/graph/httpcore/HttpClients.java
index 4084ae91d..a85acc7de 100644
--- a/src/main/java/com/microsoft/graph/httpcore/HttpClients.java
+++ b/src/main/java/com/microsoft/graph/httpcore/HttpClients.java
@@ -1,5 +1,6 @@
package com.microsoft.graph.httpcore;
+import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.OkHttpClient.Builder;
@@ -15,7 +16,7 @@ private HttpClients() {
* @return OkHttpClient.Builder() custom builder for developer to add its own interceptors to it
*/
public static Builder custom() {
- return new OkHttpClient.Builder();
+ return new OkHttpClient.Builder().addInterceptor(new TelemetryHandler());
}
/**
@@ -30,6 +31,24 @@ public static OkHttpClient createDefault(ICoreAuthenticationProvider auth) {
.followRedirects(false)
.addInterceptor(new RetryHandler())
.addInterceptor(new RedirectHandler())
+ .addInterceptor(new TelemetryHandler())
.build();
}
+
+ /**
+ * Creates {@link OkHttpClient} instance with interceptors
+ *
+ * @param interceptors Use interceptors provided while constructing http client
+ * @return OkHttpClient build with interceptors provided
+ */
+ public static OkHttpClient createFromInterceptors(Interceptor[] interceptors) {
+ OkHttpClient.Builder builder = new OkHttpClient.Builder();
+ if(interceptors != null)
+ for(Interceptor interceptor : interceptors) {
+ if(interceptor != null)
+ builder.addInterceptor(interceptor);
+ }
+ builder.addInterceptor(new TelemetryHandler());
+ return builder.build();
+ }
}
diff --git a/src/main/java/com/microsoft/graph/httpcore/RedirectHandler.java b/src/main/java/com/microsoft/graph/httpcore/RedirectHandler.java
index dbc866990..b04d774c7 100644
--- a/src/main/java/com/microsoft/graph/httpcore/RedirectHandler.java
+++ b/src/main/java/com/microsoft/graph/httpcore/RedirectHandler.java
@@ -11,6 +11,7 @@
import com.microsoft.graph.httpcore.middlewareoption.MiddlewareType;
import com.microsoft.graph.httpcore.middlewareoption.RedirectOptions;
+import com.microsoft.graph.httpcore.middlewareoption.TelemetryOptions;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
@@ -65,9 +66,15 @@ Request getRedirect(
final Request request,
final Response userResponse) throws ProtocolException {
String location = userResponse.header("Location");
- if (location == null) return null;
+ if (location == null || location.length() == 0) return null;
- // TODO: If Location header is relative reference then final URL should be relative to original target URL.
+ // For relative URL in location header, the new url to redirect is relative to original request
+ if(location.startsWith("/")) {
+ if(request.url().toString().endsWith("/")) {
+ location = location.substring(1);
+ }
+ location = request.url() + location;
+ }
HttpUrl requestUrl = userResponse.request().url();
@@ -100,6 +107,11 @@ Request getRedirect(
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
+
+ if(request.tag(TelemetryOptions.class) == null)
+ request = request.newBuilder().tag(TelemetryOptions.class, new TelemetryOptions()).build();
+ request.tag(TelemetryOptions.class).setFeatureUsage(TelemetryOptions.REDIRECT_HANDLER_ENABLED_FLAG);
+
Response response = null;
int requestsCount = 1;
diff --git a/src/main/java/com/microsoft/graph/httpcore/RetryHandler.java b/src/main/java/com/microsoft/graph/httpcore/RetryHandler.java
index 5d8b18fc8..987f7bf7b 100644
--- a/src/main/java/com/microsoft/graph/httpcore/RetryHandler.java
+++ b/src/main/java/com/microsoft/graph/httpcore/RetryHandler.java
@@ -5,6 +5,7 @@
import com.microsoft.graph.httpcore.middlewareoption.IShouldRetry;
import com.microsoft.graph.httpcore.middlewareoption.MiddlewareType;
import com.microsoft.graph.httpcore.middlewareoption.RetryOptions;
+import com.microsoft.graph.httpcore.middlewareoption.TelemetryOptions;
import okhttp3.Interceptor;
import okhttp3.Request;
@@ -80,17 +81,24 @@ && checkStatus(statusCode) && isBuffered(response, request)
return shouldRetry;
}
+ /**
+ * Get retry after in milliseconds
+ * @param response Response
+ * @param delay Delay in seconds
+ * @param executionCount Execution count of retries
+ * @return Retry interval in milliseconds
+ */
long getRetryAfter(Response response, long delay, int executionCount) {
String retryAfterHeader = response.header(RETRY_AFTER);
- long retryDelay = RetryOptions.DEFAULT_DELAY;
+ double retryDelay = RetryOptions.DEFAULT_DELAY * DELAY_MILLISECONDS;
if(retryAfterHeader != null) {
- retryDelay = Long.parseLong(retryAfterHeader);
+ retryDelay = Long.parseLong(retryAfterHeader) * DELAY_MILLISECONDS;
} else {
- retryDelay = (long)((Math.pow(2.0, (double)executionCount)-1)*0.5);
- retryDelay = executionCount < 2 ? retryDelay : retryDelay + delay + (long)Math.random();
+ retryDelay = (double)((Math.pow(2.0, (double)executionCount)-1)*0.5);
+ retryDelay = (executionCount < 2 ? delay : retryDelay + delay) + (double)Math.random();
retryDelay *= DELAY_MILLISECONDS;
}
- return Math.min(retryDelay, RetryOptions.MAX_DELAY);
+ return (long)Math.min(retryDelay, RetryOptions.MAX_DELAY * DELAY_MILLISECONDS);
}
boolean checkStatus(int statusCode) {
@@ -124,6 +132,11 @@ boolean isBuffered(Response response, Request request) {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
+
+ if(request.tag(TelemetryOptions.class) == null)
+ request = request.newBuilder().tag(TelemetryOptions.class, new TelemetryOptions()).build();
+ request.tag(TelemetryOptions.class).setFeatureUsage(TelemetryOptions.RETRY_HANDLER_ENABLED_FLAG);
+
Response response = chain.proceed(request);
// Use should retry pass along with this request
diff --git a/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java b/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java
new file mode 100644
index 000000000..3e0b8ec06
--- /dev/null
+++ b/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java
@@ -0,0 +1,38 @@
+package com.microsoft.graph.httpcore;
+
+import java.io.IOException;
+
+import com.microsoft.graph.httpcore.middlewareoption.TelemetryOptions;
+
+import okhttp3.Interceptor;
+import okhttp3.Request;
+import okhttp3.Response;
+
+public class TelemetryHandler implements Interceptor{
+
+ public static final String SDK_VERSION = "SdkVersion";
+ public static final String VERSION = "v1.0.0";
+ public static final String GRAPH_VERSION_PREFIX = "graph-java-core";
+ public static final String CLIENT_REQUEST_ID = "client-request-id";
+
+ @Override
+ public Response intercept(Chain chain) throws IOException {
+ Request request = chain.request();
+ Request.Builder telemetryAddedBuilder = request.newBuilder();
+
+ TelemetryOptions telemetryOptions = request.tag(TelemetryOptions.class);
+ if(telemetryOptions == null)
+ telemetryOptions = new TelemetryOptions();
+
+ String featureUsage = "(featureUsage=" + telemetryOptions.getFeatureUsage() + ")";
+ String sdkversion_value = GRAPH_VERSION_PREFIX + "/" + VERSION + " " + featureUsage;
+ telemetryAddedBuilder.addHeader(SDK_VERSION, sdkversion_value);
+
+ if(request.header(CLIENT_REQUEST_ID) == null) {
+ telemetryAddedBuilder.addHeader(CLIENT_REQUEST_ID, telemetryOptions.getClientRequestId());
+ }
+
+ return chain.proceed(telemetryAddedBuilder.build());
+ }
+
+}
diff --git a/src/main/java/com/microsoft/graph/httpcore/middlewareoption/TelemetryOptions.java b/src/main/java/com/microsoft/graph/httpcore/middlewareoption/TelemetryOptions.java
new file mode 100644
index 000000000..60def57d8
--- /dev/null
+++ b/src/main/java/com/microsoft/graph/httpcore/middlewareoption/TelemetryOptions.java
@@ -0,0 +1,36 @@
+package com.microsoft.graph.httpcore.middlewareoption;
+
+import java.util.UUID;
+
+public class TelemetryOptions {
+
+ public static final int NONE_FLAG = 0;
+ public static final int REDIRECT_HANDLER_ENABLED_FLAG = 1;
+ public static final int RETRY_HANDLER_ENABLED_FLAG = 2;
+ public static final int AUTH_HANDLER_ENABLED_FLAG = 4;
+ public static final int DEFAULT_HTTPROVIDER_ENABLED_FLAG = 8;
+ public static final int LOGGING_HANDLER_ENABLED_FLAG = 16;
+
+ private int featureUsage = NONE_FLAG;
+ private String clientRequestId;
+
+ public void setFeatureUsage(int flag) {
+ featureUsage = featureUsage | flag;
+ }
+
+ public String getFeatureUsage() {
+ return Integer.toHexString(featureUsage);
+ }
+
+ public void setClientRequestId(String clientRequestId) {
+ this.clientRequestId = clientRequestId;
+ }
+
+ public String getClientRequestId() {
+ if(clientRequestId == null) {
+ clientRequestId = UUID.randomUUID().toString();
+ }
+ return clientRequestId;
+ }
+
+}
diff --git a/src/test/java/com/microsoft/graph/content/MSBatchResponseContentTest.java b/src/test/java/com/microsoft/graph/content/MSBatchResponseContentTest.java
index 87ac0ae7e..a7772aab9 100644
--- a/src/test/java/com/microsoft/graph/content/MSBatchResponseContentTest.java
+++ b/src/test/java/com/microsoft/graph/content/MSBatchResponseContentTest.java
@@ -4,6 +4,8 @@
import static org.junit.Assert.assertTrue;
import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map;
import org.junit.Test;
@@ -73,6 +75,44 @@ public void testGetMSBatchResponseContentByID() throws IOException {
assertTrue(response != null);
}
+ @Test
+ public void testGetMSBatchResponseContentIteratorOverResponse() throws IOException {
+ String responsebody = "{\"responses\": [{\"id\": \"1\",\"status\":200,\"headers\" : {\"Cache-Control\":\"no-cache\",\"OData-Version\":\"4.0\",\"Content-Type\":\"application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8\"},\"body\":{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#users/$entity\",\"businessPhones\":[\"8006427676\"],\"displayName\":\"MOD Administrator\",\"givenName\":\"MOD\",\"jobTitle\":null,\"mail\":\"admin@M365x751487.OnMicrosoft.com\",\"mobilePhone\":\"425-882-1032\",\"officeLocation\":null,\"preferredLanguage\":\"en-US\",\"surname\":\"Administrator\",\"userPrincipalName\":\"admin@M365x751487.onmicrosoft.com\",\"id\":\"6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c\"}},{\"id\": \"2\",\"status\":200,\"headers\" : {\"Cache-Control\":\"no-store, no-cache\",\"OData-Version\":\"4.0\",\"Content-Type\":\"application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8\"},\"body\":{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#drives/$entity\",\"createdDateTime\":\"2019-01-12T09:05:38Z\",\"description\":\"\",\"id\":\"b!nlu9o5I9g0y8gsHXfUM_bPTZ0oM_wVNArHM5R4-VkHLlnxx5SpqHRJledwfICP9f\",\"lastModifiedDateTime\":\"2019-03-06T06:59:04Z\",\"name\":\"OneDrive\",\"webUrl\":\"https://m365x751487-my.sharepoint.com/personal/admin_m365x751487_onmicrosoft_com/Documents\",\"driveType\":\"business\",\"createdBy\":{\"user\":{\"displayName\":\"System Account\"}},\"lastModifiedBy\":{\"user\":{\"displayName\":\"System Account\"}},\"owner\":{\"user\":{\"email\":\"admin@M365x751487.OnMicrosoft.com\",\"id\":\"6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c\",\"displayName\":\"MOD Administrator\"}},\"quota\":{\"deleted\":0,\"remaining\":1099509670098,\"state\":\"normal\",\"total\":1099511627776,\"used\":30324}}},{\"id\": \"3\",\"status\":201,\"headers\" : {\"Location\":\"https://graph.microsoft.com/v1.0/users/6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c/onenote/notebooks/1-94e4376a-a1c1-441a-8b41-af5c86ee39d0\",\"Preference-Applied\":\"odata.include-annotations=*\",\"Cache-Control\":\"no-cache\",\"OData-Version\":\"4.0\",\"Content-Type\":\"application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8\"},\"body\":{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#users('6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c')/onenote/notebooks/$entity\",\"id\":\"1-94e4376a-a1c1-441a-8b41-af5c86ee39d0\",\"self\":\"https://graph.microsoft.com/v1.0/users/6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c/onenote/notebooks/1-94e4376a-a1c1-441a-8b41-af5c86ee39d0\",\"createdDateTime\":\"2019-03-06T08:08:09Z\",\"displayName\":\"My Notebook -442293399\",\"lastModifiedDateTime\":\"2019-03-06T08:08:09Z\",\"isDefault\":false,\"userRole\":\"Owner\",\"isShared\":false,\"sectionsUrl\":\"https://graph.microsoft.com/v1.0/users/6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c/onenote/notebooks/1-94e4376a-a1c1-441a-8b41-af5c86ee39d0/sections\",\"sectionGroupsUrl\":\"https://graph.microsoft.com/v1.0/users/6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c/onenote/notebooks/1-94e4376a-a1c1-441a-8b41-af5c86ee39d0/sectionGroups\",\"createdBy\":{\"user\":{\"id\":\"6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c\",\"displayName\":\"MOD Administrator\"}},\"lastModifiedBy\":{\"user\":{\"id\":\"6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c\",\"displayName\":\"MOD Administrator\"}},\"links\":{\"oneNoteClientUrl\":{\"href\":\"onenote:https://m365x751487-my.sharepoint.com/personal/admin_m365x751487_onmicrosoft_com/Documents/Notebooks/My%20Notebook%20-442293399\"},\"oneNoteWebUrl\":{\"href\":\"https://m365x751487-my.sharepoint.com/personal/admin_m365x751487_onmicrosoft_com/Documents/Notebooks/My%20Notebook%20-442293399\"}}}}]}";
+ String requestbody = "{\"requests\":[{\"method\":\"GET\",\"dependsOn\":[],\"id\":\"1\",\"url\":\"me\"},{\"method\":\"GET\",\"dependsOn\":[],\"id\":\"2\",\"url\":\"me\\/drive\"},{\"headers\":{\"content-type\":\"application\\/json\"},\"method\":\"POST\",\"dependsOn\":[],\"id\":\"3\",\"body\":{\"displayName\":\"My Notebook -1263732088\"},\"url\":\"me\\/onenote\\/notebooks\"}]}";
+ Response responsedata = TestResponse(responsebody,requestbody);
+ MSBatchResponseContent batchresponse = new MSBatchResponseContent(responsedata);
+ Iterator> it = batchresponse.getResponsesIterator();
+ while(it.hasNext()) {
+ Map.Entry entry = it.next();
+ assertTrue(entry.getKey()!=null && entry.getValue()!=null);
+ }
+ }
+
+ @Test
+ public void testGetMSBatchResponseContentMapResponse() throws IOException {
+ String responsebody = "{\"responses\": [{\"id\": \"1\",\"status\":200,\"headers\" : {\"Cache-Control\":\"no-cache\",\"OData-Version\":\"4.0\",\"Content-Type\":\"application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8\"},\"body\":{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#users/$entity\",\"businessPhones\":[\"8006427676\"],\"displayName\":\"MOD Administrator\",\"givenName\":\"MOD\",\"jobTitle\":null,\"mail\":\"admin@M365x751487.OnMicrosoft.com\",\"mobilePhone\":\"425-882-1032\",\"officeLocation\":null,\"preferredLanguage\":\"en-US\",\"surname\":\"Administrator\",\"userPrincipalName\":\"admin@M365x751487.onmicrosoft.com\",\"id\":\"6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c\"}},{\"id\": \"2\",\"status\":200,\"headers\" : {\"Cache-Control\":\"no-store, no-cache\",\"OData-Version\":\"4.0\",\"Content-Type\":\"application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8\"},\"body\":{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#drives/$entity\",\"createdDateTime\":\"2019-01-12T09:05:38Z\",\"description\":\"\",\"id\":\"b!nlu9o5I9g0y8gsHXfUM_bPTZ0oM_wVNArHM5R4-VkHLlnxx5SpqHRJledwfICP9f\",\"lastModifiedDateTime\":\"2019-03-06T06:59:04Z\",\"name\":\"OneDrive\",\"webUrl\":\"https://m365x751487-my.sharepoint.com/personal/admin_m365x751487_onmicrosoft_com/Documents\",\"driveType\":\"business\",\"createdBy\":{\"user\":{\"displayName\":\"System Account\"}},\"lastModifiedBy\":{\"user\":{\"displayName\":\"System Account\"}},\"owner\":{\"user\":{\"email\":\"admin@M365x751487.OnMicrosoft.com\",\"id\":\"6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c\",\"displayName\":\"MOD Administrator\"}},\"quota\":{\"deleted\":0,\"remaining\":1099509670098,\"state\":\"normal\",\"total\":1099511627776,\"used\":30324}}},{\"id\": \"3\",\"status\":201,\"headers\" : {\"Location\":\"https://graph.microsoft.com/v1.0/users/6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c/onenote/notebooks/1-94e4376a-a1c1-441a-8b41-af5c86ee39d0\",\"Preference-Applied\":\"odata.include-annotations=*\",\"Cache-Control\":\"no-cache\",\"OData-Version\":\"4.0\",\"Content-Type\":\"application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8\"},\"body\":{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#users('6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c')/onenote/notebooks/$entity\",\"id\":\"1-94e4376a-a1c1-441a-8b41-af5c86ee39d0\",\"self\":\"https://graph.microsoft.com/v1.0/users/6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c/onenote/notebooks/1-94e4376a-a1c1-441a-8b41-af5c86ee39d0\",\"createdDateTime\":\"2019-03-06T08:08:09Z\",\"displayName\":\"My Notebook -442293399\",\"lastModifiedDateTime\":\"2019-03-06T08:08:09Z\",\"isDefault\":false,\"userRole\":\"Owner\",\"isShared\":false,\"sectionsUrl\":\"https://graph.microsoft.com/v1.0/users/6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c/onenote/notebooks/1-94e4376a-a1c1-441a-8b41-af5c86ee39d0/sections\",\"sectionGroupsUrl\":\"https://graph.microsoft.com/v1.0/users/6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c/onenote/notebooks/1-94e4376a-a1c1-441a-8b41-af5c86ee39d0/sectionGroups\",\"createdBy\":{\"user\":{\"id\":\"6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c\",\"displayName\":\"MOD Administrator\"}},\"lastModifiedBy\":{\"user\":{\"id\":\"6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c\",\"displayName\":\"MOD Administrator\"}},\"links\":{\"oneNoteClientUrl\":{\"href\":\"onenote:https://m365x751487-my.sharepoint.com/personal/admin_m365x751487_onmicrosoft_com/Documents/Notebooks/My%20Notebook%20-442293399\"},\"oneNoteWebUrl\":{\"href\":\"https://m365x751487-my.sharepoint.com/personal/admin_m365x751487_onmicrosoft_com/Documents/Notebooks/My%20Notebook%20-442293399\"}}}}]}";
+ String requestbody = "{\"requests\":[{\"method\":\"GET\",\"dependsOn\":[],\"id\":\"1\",\"url\":\"me\"},{\"method\":\"GET\",\"dependsOn\":[],\"id\":\"2\",\"url\":\"me\\/drive\"},{\"headers\":{\"content-type\":\"application\\/json\"},\"method\":\"POST\",\"dependsOn\":[],\"id\":\"3\",\"body\":{\"displayName\":\"My Notebook -1263732088\"},\"url\":\"me\\/onenote\\/notebooks\"}]}";
+ Response responsedata = TestResponse(responsebody,requestbody);
+ MSBatchResponseContent batchresponse = new MSBatchResponseContent(responsedata);
+ for(Map.Entry entry: batchresponse.getResponses().entrySet()) {
+ assertTrue(entry.getKey() != null && entry.getValue() != null);
+ }
+ }
+
+ @Test
+ public void testGetMSBatchResponseContentUpdate() throws IOException {
+ String responsebody = "{\"responses\": [{\"id\": \"1\",\"status\":200,\"headers\" : {\"Cache-Control\":\"no-cache\",\"OData-Version\":\"4.0\",\"Content-Type\":\"application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8\"},\"body\":{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#users/$entity\",\"businessPhones\":[\"8006427676\"],\"displayName\":\"MOD Administrator\",\"givenName\":\"MOD\",\"jobTitle\":null,\"mail\":\"admin@M365x751487.OnMicrosoft.com\",\"mobilePhone\":\"425-882-1032\",\"officeLocation\":null,\"preferredLanguage\":\"en-US\",\"surname\":\"Administrator\",\"userPrincipalName\":\"admin@M365x751487.onmicrosoft.com\",\"id\":\"6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c\"}},{\"id\": \"2\",\"status\":200,\"headers\" : {\"Cache-Control\":\"no-store, no-cache\",\"OData-Version\":\"4.0\",\"Content-Type\":\"application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8\"},\"body\":{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#drives/$entity\",\"createdDateTime\":\"2019-01-12T09:05:38Z\",\"description\":\"\",\"id\":\"b!nlu9o5I9g0y8gsHXfUM_bPTZ0oM_wVNArHM5R4-VkHLlnxx5SpqHRJledwfICP9f\",\"lastModifiedDateTime\":\"2019-03-06T06:59:04Z\",\"name\":\"OneDrive\",\"webUrl\":\"https://m365x751487-my.sharepoint.com/personal/admin_m365x751487_onmicrosoft_com/Documents\",\"driveType\":\"business\",\"createdBy\":{\"user\":{\"displayName\":\"System Account\"}},\"lastModifiedBy\":{\"user\":{\"displayName\":\"System Account\"}},\"owner\":{\"user\":{\"email\":\"admin@M365x751487.OnMicrosoft.com\",\"id\":\"6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c\",\"displayName\":\"MOD Administrator\"}},\"quota\":{\"deleted\":0,\"remaining\":1099509670098,\"state\":\"normal\",\"total\":1099511627776,\"used\":30324}}},{\"id\": \"3\",\"status\":201,\"headers\" : {\"Location\":\"https://graph.microsoft.com/v1.0/users/6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c/onenote/notebooks/1-94e4376a-a1c1-441a-8b41-af5c86ee39d0\",\"Preference-Applied\":\"odata.include-annotations=*\",\"Cache-Control\":\"no-cache\",\"OData-Version\":\"4.0\",\"Content-Type\":\"application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8\"},\"body\":{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#users('6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c')/onenote/notebooks/$entity\",\"id\":\"1-94e4376a-a1c1-441a-8b41-af5c86ee39d0\",\"self\":\"https://graph.microsoft.com/v1.0/users/6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c/onenote/notebooks/1-94e4376a-a1c1-441a-8b41-af5c86ee39d0\",\"createdDateTime\":\"2019-03-06T08:08:09Z\",\"displayName\":\"My Notebook -442293399\",\"lastModifiedDateTime\":\"2019-03-06T08:08:09Z\",\"isDefault\":false,\"userRole\":\"Owner\",\"isShared\":false,\"sectionsUrl\":\"https://graph.microsoft.com/v1.0/users/6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c/onenote/notebooks/1-94e4376a-a1c1-441a-8b41-af5c86ee39d0/sections\",\"sectionGroupsUrl\":\"https://graph.microsoft.com/v1.0/users/6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c/onenote/notebooks/1-94e4376a-a1c1-441a-8b41-af5c86ee39d0/sectionGroups\",\"createdBy\":{\"user\":{\"id\":\"6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c\",\"displayName\":\"MOD Administrator\"}},\"lastModifiedBy\":{\"user\":{\"id\":\"6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c\",\"displayName\":\"MOD Administrator\"}},\"links\":{\"oneNoteClientUrl\":{\"href\":\"onenote:https://m365x751487-my.sharepoint.com/personal/admin_m365x751487_onmicrosoft_com/Documents/Notebooks/My%20Notebook%20-442293399\"},\"oneNoteWebUrl\":{\"href\":\"https://m365x751487-my.sharepoint.com/personal/admin_m365x751487_onmicrosoft_com/Documents/Notebooks/My%20Notebook%20-442293399\"}}}}]}";
+ String requestbody = "{\"requests\":[{\"method\":\"GET\",\"dependsOn\":[],\"id\":\"1\",\"url\":\"me\"},{\"method\":\"GET\",\"dependsOn\":[],\"id\":\"2\",\"url\":\"me\\/drive\"},{\"headers\":{\"content-type\":\"application\\/json\"},\"method\":\"POST\",\"dependsOn\":[],\"id\":\"3\",\"body\":{\"displayName\":\"My Notebook -1263732088\"},\"url\":\"me\\/onenote\\/notebooks\"}]}";
+ Response responsedata = TestResponse(responsebody,requestbody);
+ MSBatchResponseContent batchresponse = new MSBatchResponseContent(responsedata);
+ assertTrue(batchresponse.getResponses().size() == 3);
+ String responsebody2 = "{\"responses\": [{\"id\": \"4\",\"status\":200,\"headers\" : {\"Cache-Control\":\"no-cache\",\"OData-Version\":\"4.0\",\"Content-Type\":\"application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8\"},\"body\":{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#users/$entity\",\"businessPhones\":[\"8006427676\"],\"displayName\":\"MOD Administrator\",\"givenName\":\"MOD\",\"jobTitle\":null,\"mail\":\"admin@M365x751487.OnMicrosoft.com\",\"mobilePhone\":\"425-882-1032\",\"officeLocation\":null,\"preferredLanguage\":\"en-US\",\"surname\":\"Administrator\",\"userPrincipalName\":\"admin@M365x751487.onmicrosoft.com\",\"id\":\"6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c\"}},{\"id\": \"5\",\"status\":200,\"headers\" : {\"Cache-Control\":\"no-store, no-cache\",\"OData-Version\":\"4.0\",\"Content-Type\":\"application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8\"},\"body\":{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#drives/$entity\",\"createdDateTime\":\"2019-01-12T09:05:38Z\",\"description\":\"\",\"id\":\"b!nlu9o5I9g0y8gsHXfUM_bPTZ0oM_wVNArHM5R4-VkHLlnxx5SpqHRJledwfICP9f\",\"lastModifiedDateTime\":\"2019-03-06T06:59:04Z\",\"name\":\"OneDrive\",\"webUrl\":\"https://m365x751487-my.sharepoint.com/personal/admin_m365x751487_onmicrosoft_com/Documents\",\"driveType\":\"business\",\"createdBy\":{\"user\":{\"displayName\":\"System Account\"}},\"lastModifiedBy\":{\"user\":{\"displayName\":\"System Account\"}},\"owner\":{\"user\":{\"email\":\"admin@M365x751487.OnMicrosoft.com\",\"id\":\"6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c\",\"displayName\":\"MOD Administrator\"}},\"quota\":{\"deleted\":0,\"remaining\":1099509670098,\"state\":\"normal\",\"total\":1099511627776,\"used\":30324}}},{\"id\": \"6\",\"status\":201,\"headers\" : {\"Location\":\"https://graph.microsoft.com/v1.0/users/6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c/onenote/notebooks/1-94e4376a-a1c1-441a-8b41-af5c86ee39d0\",\"Preference-Applied\":\"odata.include-annotations=*\",\"Cache-Control\":\"no-cache\",\"OData-Version\":\"4.0\",\"Content-Type\":\"application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8\"},\"body\":{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#users('6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c')/onenote/notebooks/$entity\",\"id\":\"1-94e4376a-a1c1-441a-8b41-af5c86ee39d0\",\"self\":\"https://graph.microsoft.com/v1.0/users/6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c/onenote/notebooks/1-94e4376a-a1c1-441a-8b41-af5c86ee39d0\",\"createdDateTime\":\"2019-03-06T08:08:09Z\",\"displayName\":\"My Notebook -442293399\",\"lastModifiedDateTime\":\"2019-03-06T08:08:09Z\",\"isDefault\":false,\"userRole\":\"Owner\",\"isShared\":false,\"sectionsUrl\":\"https://graph.microsoft.com/v1.0/users/6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c/onenote/notebooks/1-94e4376a-a1c1-441a-8b41-af5c86ee39d0/sections\",\"sectionGroupsUrl\":\"https://graph.microsoft.com/v1.0/users/6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c/onenote/notebooks/1-94e4376a-a1c1-441a-8b41-af5c86ee39d0/sectionGroups\",\"createdBy\":{\"user\":{\"id\":\"6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c\",\"displayName\":\"MOD Administrator\"}},\"lastModifiedBy\":{\"user\":{\"id\":\"6b4fa8ea-7e6e-486e-a8f4-d00a5b23488c\",\"displayName\":\"MOD Administrator\"}},\"links\":{\"oneNoteClientUrl\":{\"href\":\"onenote:https://m365x751487-my.sharepoint.com/personal/admin_m365x751487_onmicrosoft_com/Documents/Notebooks/My%20Notebook%20-442293399\"},\"oneNoteWebUrl\":{\"href\":\"https://m365x751487-my.sharepoint.com/personal/admin_m365x751487_onmicrosoft_com/Documents/Notebooks/My%20Notebook%20-442293399\"}}}}]}";
+ String requestbody2 = "{\"requests\":[{\"method\":\"GET\",\"dependsOn\":[],\"id\":\"4\",\"url\":\"me\"},{\"method\":\"GET\",\"dependsOn\":[],\"id\":\"5\",\"url\":\"me\\/drive\"},{\"headers\":{\"content-type\":\"application\\/json\"},\"method\":\"POST\",\"dependsOn\":[],\"id\":\"6\",\"body\":{\"displayName\":\"My Notebook -1263732088\"},\"url\":\"me\\/onenote\\/notebooks\"}]}";
+ Response responsedata2 = TestResponse(responsebody2,requestbody2);
+ batchresponse.update(responsedata2);
+ assertTrue(batchresponse.getResponses().size() == 6);
+ }
+
private Response TestResponse(String responsebody, String requestbody) {
Response.Builder builder = new Response.Builder();
builder.body(ResponseBody.create(MediaType.parse("application/json"), responsebody));
diff --git a/src/test/java/com/microsoft/graph/httpcore/HttpClientsTest.java b/src/test/java/com/microsoft/graph/httpcore/HttpClientsTest.java
index 85bb76fd5..6043c432d 100644
--- a/src/test/java/com/microsoft/graph/httpcore/HttpClientsTest.java
+++ b/src/test/java/com/microsoft/graph/httpcore/HttpClientsTest.java
@@ -4,6 +4,7 @@
import org.junit.Test;
+import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
@@ -21,5 +22,18 @@ public Request authenticateRequest(Request request) {
OkHttpClient httpclient = HttpClients.createDefault(authprovider);
assertTrue(httpclient != null);
}
+
+ @Test
+ public void arrayInterceptorsTest() {
+ AuthenticationHandler authenticationHandler = new AuthenticationHandler(new ICoreAuthenticationProvider() {
+ @Override
+ public Request authenticateRequest(Request request) {
+ return request;
+ }
+ });
+ Interceptor[] interceptors = {new RetryHandler(), new RedirectHandler(), authenticationHandler};
+ OkHttpClient client = HttpClients.createFromInterceptors(interceptors);
+ assertTrue(client.interceptors().size()==4);
+ }
}
diff --git a/src/test/java/com/microsoft/graph/httpcore/RedirectHandlerTest.java b/src/test/java/com/microsoft/graph/httpcore/RedirectHandlerTest.java
index 3182b850f..6eed2b7ad 100644
--- a/src/test/java/com/microsoft/graph/httpcore/RedirectHandlerTest.java
+++ b/src/test/java/com/microsoft/graph/httpcore/RedirectHandlerTest.java
@@ -21,7 +21,7 @@
public class RedirectHandlerTest {
String testmeurl = "https://graph.microsoft.com/v1.0/me/";
- String testurl = "https://graph.microsoft.com/v1.0/";
+ String testurl = "https://graph.microsoft.com/v1.0";
String differenthosturl = "https://graph.abc.com/v1.0/";
@Test
@@ -228,5 +228,39 @@ public void testGetRedirectForPostMethodWithStatusCodeSeeOther() {
fail("Redirect handler testGetRedirectForPostMethod1 failure");
}
}
+
+ @Test
+ public void testGetRedirectForRelativeURL() throws ProtocolException {
+ RedirectHandler redirectHandler = new RedirectHandler();
+ Request httppost = new Request.Builder().url(testurl).build();
+
+ Response response = new Response.Builder()
+ .protocol(Protocol.HTTP_1_1)
+ .code(HttpURLConnection.HTTP_SEE_OTHER)
+ .message("See Other")
+ .addHeader("location", "/testrelativeurl")
+ .request(httppost)
+ .build();
+
+ Request request = redirectHandler.getRedirect(httppost, response);
+ assertTrue(request.url().toString().compareTo(testurl+"/testrelativeurl") == 0);
+ }
+
+ @Test
+ public void testGetRedirectRelativeLocationRequestURLwithSlash() throws ProtocolException {
+ RedirectHandler redirectHandler = new RedirectHandler();
+ Request httppost = new Request.Builder().url(testmeurl).build();
+
+ Response response = new Response.Builder()
+ .protocol(Protocol.HTTP_1_1)
+ .code(HttpURLConnection.HTTP_SEE_OTHER)
+ .message("See Other")
+ .addHeader("location", "/testrelativeurl")
+ .request(httppost)
+ .build();
+ Request request = redirectHandler.getRedirect(httppost, response);
+ String expected = "https://graph.microsoft.com/v1.0/me/testrelativeurl";
+ assertTrue(request.url().toString().compareTo(expected) == 0);
+ }
}
diff --git a/src/test/java/com/microsoft/graph/httpcore/RetryHandlerTest.java b/src/test/java/com/microsoft/graph/httpcore/RetryHandlerTest.java
index 1411eb94a..d5ddc3915 100644
--- a/src/test/java/com/microsoft/graph/httpcore/RetryHandlerTest.java
+++ b/src/test/java/com/microsoft/graph/httpcore/RetryHandlerTest.java
@@ -122,4 +122,37 @@ public void testRetryRequestWithExponentialBackOff() {
assertTrue(retryhandler.retryRequest(response, 1, httppost, new RetryOptions()));
}
+
+ @Test
+ public void testGetRetryAfterWithHeader() {
+ RetryHandler retryHandler = new RetryHandler();
+ long delay = retryHandler.getRetryAfter(TestResponse().newBuilder().addHeader("Retry-After", "60").build(), 1, 1);
+ assertTrue(delay == 60000);
+ delay = retryHandler.getRetryAfter(TestResponse().newBuilder().addHeader("Retry-After", "1").build(), 2, 3);
+ assertTrue(delay == 1000);
+ }
+
+ @Test
+ public void testGetRetryAfterOnFirstExecution() {
+ RetryHandler retryHandler = new RetryHandler();
+ long delay = retryHandler.getRetryAfter(TestResponse(), 3, 1);
+ assertTrue(delay > 3000);
+ delay = retryHandler.getRetryAfter(TestResponse(), 3, 2);
+ assertTrue(delay > 3100);
+ }
+
+ @Test
+ public void testGetRetryAfterMaxExceed() {
+ RetryHandler retryHandler = new RetryHandler();
+ long delay = retryHandler.getRetryAfter(TestResponse(), 190, 1);
+ assertTrue(delay == 180000);
+ }
+
+ Response TestResponse() {
+ return new Response.Builder()
+ .code(429)
+ .message("message")
+ .request(new Request.Builder().url("https://localhost").build())
+ .protocol(Protocol.HTTP_1_0).build();
+ }
}
diff --git a/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java b/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java
new file mode 100644
index 000000000..deab260a4
--- /dev/null
+++ b/src/test/java/com/microsoft/graph/httpcore/TelemetryHandlerTest.java
@@ -0,0 +1,72 @@
+package com.microsoft.graph.httpcore;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+import okhttp3.Interceptor;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
+
+@Ignore
+public class TelemetryHandlerTest {
+ @Test
+ public void telemetryInitTest() {
+ TelemetryHandler telemetryHandler = new TelemetryHandler();
+ assertNotNull(telemetryHandler);
+ }
+
+ @Test
+ public void interceptTest() throws IOException {
+ String expectedHeader = TelemetryHandler.SDK_VERSION + TelemetryHandler.GRAPH_VERSION_PREFIX +"/"
+ +TelemetryHandler.VERSION;
+ OkHttpClient client = HttpClients.createDefault(new ICoreAuthenticationProvider() {
+ @Override
+ public Request authenticateRequest(Request request) {
+ return request;
+ }
+ });
+ Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build();
+ Response response = client.newCall(request).execute();
+ assertNotNull(response);
+ assertTrue(response.request().header("SdkVersion").contains(expectedHeader));
+ }
+
+ @Test
+ public void arrayInterceptorsTest() throws IOException {
+
+ AuthenticationHandler authenticationHandler = new AuthenticationHandler(new ICoreAuthenticationProvider() {
+
+ @Override
+ public Request authenticateRequest(Request request) {
+ return request;
+ }
+ });
+ Interceptor[] interceptors = {new RetryHandler(), new RedirectHandler(), authenticationHandler};
+ OkHttpClient client = HttpClients.createFromInterceptors(interceptors);
+ String expectedHeader = TelemetryHandler.SDK_VERSION + TelemetryHandler.GRAPH_VERSION_PREFIX +"/"
+ +TelemetryHandler.VERSION;
+ Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build();
+ Response response = client.newCall(request).execute();
+ assertNotNull(response);
+ assertTrue(response.request().header("SdkVersion").contains(expectedHeader));
+ }
+
+ @Test
+ public void arrayInterceptorEmptyTest() throws IOException {
+ Interceptor[] interceptors = null;
+ OkHttpClient client = HttpClients.createFromInterceptors(interceptors);
+ String expectedHeader = TelemetryHandler.SDK_VERSION + TelemetryHandler.GRAPH_VERSION_PREFIX +"/"
+ +TelemetryHandler.VERSION;
+ Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/users/").build();
+ Response response = client.newCall(request).execute();
+ assertNotNull(response);
+ assertTrue(response.request().header("SdkVersion").contains(expectedHeader));
+ }
+
+}
diff --git a/src/test/java/com/microsoft/graph/httpcore/TelemetryOptionsTest.java b/src/test/java/com/microsoft/graph/httpcore/TelemetryOptionsTest.java
new file mode 100644
index 000000000..dece2ef55
--- /dev/null
+++ b/src/test/java/com/microsoft/graph/httpcore/TelemetryOptionsTest.java
@@ -0,0 +1,53 @@
+package com.microsoft.graph.httpcore;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.microsoft.graph.httpcore.middlewareoption.TelemetryOptions;
+
+public class TelemetryOptionsTest {
+
+ @Test
+ public void createTelemetryOptionsTest() {
+ TelemetryOptions telemetryOptions = new TelemetryOptions();
+ assertNotNull(telemetryOptions);
+ assertNotNull(telemetryOptions.getClientRequestId());
+ }
+
+ @Test
+ public void setFeatureUsageTest() {
+ TelemetryOptions telemetryOptions = new TelemetryOptions();
+ telemetryOptions.setFeatureUsage(TelemetryOptions.AUTH_HANDLER_ENABLED_FLAG);
+ telemetryOptions.setFeatureUsage(TelemetryOptions.REDIRECT_HANDLER_ENABLED_FLAG);
+ assertTrue(telemetryOptions.getFeatureUsage().compareTo("5")==0);
+ }
+
+ @Test
+ public void getFeatureUsageTest() {
+ TelemetryOptions telemetryOptions = new TelemetryOptions();
+ telemetryOptions.setFeatureUsage(TelemetryOptions.AUTH_HANDLER_ENABLED_FLAG);
+ telemetryOptions.setFeatureUsage(TelemetryOptions.REDIRECT_HANDLER_ENABLED_FLAG);
+ telemetryOptions.setFeatureUsage(TelemetryOptions.RETRY_HANDLER_ENABLED_FLAG);
+ assertTrue(telemetryOptions.getFeatureUsage().compareTo("7")==0);
+ }
+
+ @Test
+ public void setClientRequestIdTest() {
+ TelemetryOptions telemetryOptions = new TelemetryOptions();
+ telemetryOptions.setClientRequestId("test id");
+ assertTrue(telemetryOptions.getClientRequestId().compareTo("test id")==0);
+ }
+
+ @Test
+ public void getClientRequestIdTest() {
+ TelemetryOptions telemetryOptions = new TelemetryOptions();
+ assertNotNull(telemetryOptions.getClientRequestId());
+ telemetryOptions.setClientRequestId("test id 1");
+ assertTrue(telemetryOptions.getClientRequestId().compareTo("test id 1")==0);
+ telemetryOptions.setClientRequestId("test id 2");
+ assertTrue(telemetryOptions.getClientRequestId().compareTo("test id 2")==0);
+ }
+
+}