From dc77d1b1690bb1941b74505a2e2aa59f8b25ae12 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Thu, 3 Jun 2021 11:32:56 -0400 Subject: [PATCH 01/15] - adds worfklow dispatch event to be able to manually trigger the workflows --- .github/workflows/api-level-lint.yml | 3 ++- .github/workflows/codeql-analysis.yml | 1 + .github/workflows/conflicting-pr-label.yml | 1 + .github/workflows/sample-build-check.yml | 1 + .github/workflows/sonarcloud.yml | 1 + 5 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/api-level-lint.yml b/.github/workflows/api-level-lint.yml index cf0413555..fa711e65a 100644 --- a/.github/workflows/api-level-lint.yml +++ b/.github/workflows/api-level-lint.yml @@ -1,6 +1,7 @@ name: "Checks the SDK only using APIs from the targeted API level" -on: +on: + workflow_dispatch: push: branches: - dev diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 7d984b319..fc68b709f 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -1,6 +1,7 @@ name: "CodeQL" on: + workflow_dispatch: push: branches: [dev, master] pull_request: diff --git a/.github/workflows/conflicting-pr-label.yml b/.github/workflows/conflicting-pr-label.yml index 135603af1..c8ba2b21b 100644 --- a/.github/workflows/conflicting-pr-label.yml +++ b/.github/workflows/conflicting-pr-label.yml @@ -5,6 +5,7 @@ name: PullRequestConflicting # Controls when the action will run. Triggers the workflow on push or pull request # events but only for the master branch on: + workflow_dispatch: push: branches: [ master, dev ] pull_request: diff --git a/.github/workflows/sample-build-check.yml b/.github/workflows/sample-build-check.yml index be4146069..397ee1662 100644 --- a/.github/workflows/sample-build-check.yml +++ b/.github/workflows/sample-build-check.yml @@ -1,6 +1,7 @@ name: "samples build check" on: + workflow_dispatch: push: paths: - '**/*.java' diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 4bf6cde65..4e7b8921d 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -1,5 +1,6 @@ name: Static analysis with SonarCloud on: + workflow_dispatch: push: branches: - master From 2aebd822ea3e72179a391745a5a2e2b76632f6cc Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Thu, 3 Jun 2021 18:16:39 -0400 Subject: [PATCH 02/15] - updates sonarcloud configuration to match organization --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 504846f20..10208c4d2 100644 --- a/build.gradle +++ b/build.gradle @@ -91,8 +91,8 @@ def pomConfig = { sonarqube { properties { - property "sonar.projectKey", "msgraph-sdk-java-core" - property "sonar.organization", "microsoftgraph" + property "sonar.projectKey", "microsoftgraph_msgraph-sdk-java-core" + property "sonar.organization", "microsoftgraph2" property "sonar.host.url", "https://sonarcloud.io" } } From 070de5bdfbe4761843272bc608e469492e6915fe Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 4 Jun 2021 05:48:34 +0000 Subject: [PATCH 03/15] Bump mockito-inline from 3.10.0 to 3.11.0 Bumps [mockito-inline](https://github.com/mockito/mockito) from 3.10.0 to 3.11.0. - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v3.10.0...v3.11.0) --- updated-dependencies: - dependency-name: org.mockito:mockito-inline dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- gradle/dependencies.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index fac6a9c11..2d8b39096 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -2,7 +2,7 @@ dependencies { // Use JUnit test framework testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2' - testImplementation 'org.mockito:mockito-inline:3.10.0' + testImplementation 'org.mockito:mockito-inline:3.11.0' api 'com.squareup.okhttp3:okhttp:4.9.1' From 63b6dc305e52a18da15aa4a50e56cfd36722a9d8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 4 Jun 2021 07:27:31 +0000 Subject: [PATCH 04/15] Bump mockito-inline from 3.10.0 to 3.11.0 Bumps [mockito-inline](https://github.com/mockito/mockito) from 3.10.0 to 3.11.0. - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v3.10.0...v3.11.0) --- updated-dependencies: - dependency-name: org.mockito:mockito-inline dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7984c278d..9cc0451d8 100644 --- a/pom.xml +++ b/pom.xml @@ -46,7 +46,7 @@ org.mockito mockito-inline - 3.10.0 + 3.11.0 test From cd5e4cb71a8bea8126ddae3e0d77e2b44c6aa498 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Jun 2021 05:17:28 +0000 Subject: [PATCH 05/15] Bump azure-core from 1.16.0 to 1.17.0 Bumps [azure-core](https://github.com/Azure/azure-sdk-for-java) from 1.16.0 to 1.17.0. - [Release notes](https://github.com/Azure/azure-sdk-for-java/releases) - [Commits](https://github.com/Azure/azure-sdk-for-java/compare/azure-core_1.16.0...azure-core_1.17.0) --- updated-dependencies: - dependency-name: com.azure:azure-core dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- gradle/dependencies.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 2d8b39096..1c1ff820f 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -9,5 +9,5 @@ dependencies { implementation 'com.google.guava:guava:30.1.1-jre' implementation 'com.google.code.gson:gson:2.8.7' - api 'com.azure:azure-core:1.16.0' + api 'com.azure:azure-core:1.17.0' } \ No newline at end of file From a3b7ebcfd4d78a9b164a15972a4e13abc6c294f5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Jun 2021 06:35:22 +0000 Subject: [PATCH 06/15] Bump azure-core from 1.16.0 to 1.17.0 Bumps [azure-core](https://github.com/Azure/azure-sdk-for-java) from 1.16.0 to 1.17.0. - [Release notes](https://github.com/Azure/azure-sdk-for-java/releases) - [Commits](https://github.com/Azure/azure-sdk-for-java/compare/azure-core_1.16.0...azure-core_1.17.0) --- updated-dependencies: - dependency-name: com.azure:azure-core dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9cc0451d8..b3c9c7b3c 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ com.azure azure-core - 1.16.0 + 1.17.0 org.junit.jupiter From ec55ce4b8e4f856234e86022154ec7766dbbba8c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 11 Jun 2021 05:15:56 +0000 Subject: [PATCH 07/15] Bump org.sonarqube from 3.2.0 to 3.3 Bumps org.sonarqube from 3.2.0 to 3.3. --- updated-dependencies: - dependency-name: org.sonarqube dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 10208c4d2..e695699f5 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ plugins { id 'signing' id 'jacoco' id 'com.github.spotbugs' version '4.7.1' - id "org.sonarqube" version "3.2.0" + id "org.sonarqube" version "3.3" } java { From 739b59ea132ef579cebd6a481e6c223b73b4a59c Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 11 Jun 2021 12:13:58 -0400 Subject: [PATCH 08/15] - fixes a bug where passing null to additional data manager could lead to a null ref excep --- .../serializer/AdditionalDataManager.java | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/microsoft/graph/serializer/AdditionalDataManager.java b/src/main/java/com/microsoft/graph/serializer/AdditionalDataManager.java index 456721cdf..24489c638 100644 --- a/src/main/java/com/microsoft/graph/serializer/AdditionalDataManager.java +++ b/src/main/java/com/microsoft/graph/serializer/AdditionalDataManager.java @@ -1,16 +1,16 @@ // ------------------------------------------------------------------------------ // Copyright (c) 2017 Microsoft Corporation -// +// // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sub-license, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// +// // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -38,12 +38,12 @@ public class AdditionalDataManager extends HashMap { private static final long serialVersionUID = 8641634955796941429L; - + private final transient IJsonBackedObject jsonBackedObject; /** * Instanciates a new additional data manager from the json backed object - * + * * @param jsonBackedObject the object to read values from */ public AdditionalDataManager(@Nullable final IJsonBackedObject jsonBackedObject) { @@ -56,15 +56,15 @@ public AdditionalDataManager(@Nullable final IJsonBackedObject jsonBackedObject) * * @param json the raw JSON to set as additionalData */ - final void setAdditionalData(JsonObject json) { + final void setAdditionalData(final JsonObject json) { // Get the names of all the fields on this object's hierarchy - Set objectFields = getFields(); + final Set objectFields = getFields(); // Get the keys on this JSON - Set jsonKeys = getJsonKeys(json); + final Set jsonKeys = getJsonKeys(json); // Get all keys present in JSON and *NOT* present in fields - Set additionalDataKeys = new HashSet<>(jsonKeys); + final Set additionalDataKeys = new HashSet<>(jsonKeys); additionalDataKeys.removeAll(objectFields); // set the additionalData @@ -73,9 +73,9 @@ final void setAdditionalData(JsonObject json) { } } - private Set getJsonKeys(JsonObject json) { - Set keys = new HashSet<>(); - Set> entries = json.entrySet(); + private Set getJsonKeys(final JsonObject json) { + final Set keys = new HashSet<>(); + final Set> entries = json.entrySet(); for (Map.Entry entry : entries) { keys.add(entry.getKey()); } @@ -83,13 +83,15 @@ private Set getJsonKeys(JsonObject json) { } private Set getFields() { - Field[] fields = jsonBackedObject.getClass().getFields(); - Set serializingFields = new HashSet<>(); - for (Field field : fields) { - SerializedName serializedName; - if (null != (serializedName = field.getAnnotation(SerializedName.class)) - && null != field.getAnnotation(Expose.class)) { - serializingFields.add(serializedName.value()); + final Set serializingFields = new HashSet<>(); + if(jsonBackedObject != null ) { + final Field[] fields = jsonBackedObject.getClass().getFields(); + for (Field field : fields) { + final SerializedName serializedName = field.getAnnotation(SerializedName.class); + if (null != serializedName + && null != field.getAnnotation(Expose.class)) { + serializingFields.add(serializedName.value()); + } } } return serializingFields; From cde5553c6b2af47a83bd7f3cc4aaabddcc412c5e Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 11 Jun 2021 12:15:13 -0400 Subject: [PATCH 09/15] - fixes a bug where the serializer would only look at first level properties for additional data --- .../graph/serializer/DefaultSerializer.java | 73 +++++-------------- .../content/BatchRequestContentTest.java | 16 ++++ .../graph/content/BatchRequestTestBody.java | 30 ++++++++ 3 files changed, 65 insertions(+), 54 deletions(-) create mode 100644 src/test/java/com/microsoft/graph/content/BatchRequestTestBody.java diff --git a/src/main/java/com/microsoft/graph/serializer/DefaultSerializer.java b/src/main/java/com/microsoft/graph/serializer/DefaultSerializer.java index ec9f7999c..d901ce257 100644 --- a/src/main/java/com/microsoft/graph/serializer/DefaultSerializer.java +++ b/src/main/java/com/microsoft/graph/serializer/DefaultSerializer.java @@ -223,50 +223,13 @@ else if (fieldObject instanceof IJsonBackedObject) { public String serializeObject(@Nonnull final T serializableObject) { Objects.requireNonNull(serializableObject, "parameter serializableObject cannot be null"); logger.logDebug("Serializing type " + serializableObject.getClass().getSimpleName()); - JsonElement outJsonTree = gson.toJsonTree(serializableObject); - - if (serializableObject instanceof IJsonBackedObject) { - outJsonTree = getDataFromAdditionalDataManager(outJsonTree, serializableObject); - } else if (outJsonTree.isJsonObject()) { - final Field[] fields = serializableObject.getClass().getDeclaredFields(); - JsonObject outJson = outJsonTree.getAsJsonObject(); - for(Field field : fields) { - if(outJson.has(field.getName())) { - final Type[] interfaces = field.getType().getGenericInterfaces(); - for(Type interfaceType : interfaces) { - if(interfaceType == IJsonBackedObject.class && outJson.get(field.getName()).isJsonObject()) { - try { - final JsonElement outdatedValue = outJson.remove(field.getName()); - outJson.add(field.getName(), getDataFromAdditionalDataManager(outdatedValue.getAsJsonObject(), field.get(serializableObject))); - } catch (IllegalAccessException ex ) { - logger.logDebug("Couldn't access prop" + field.getName()); - } - break; - } - } - } - } - } - - return outJsonTree.toString(); - } - private JsonElement getDataFromAdditionalDataManager(JsonElement outJsonTree, final T serializableObject) { - final IJsonBackedObject serializableJsonObject = (IJsonBackedObject) serializableObject; - final AdditionalDataManager additionalData = serializableJsonObject.additionalDataManager(); - - // If the item is a valid Graph object, add its additional data - if (outJsonTree.isJsonObject()) { - final JsonObject outJson = outJsonTree.getAsJsonObject(); - - addAdditionalDataFromManagerToJson(additionalData, outJson); - getChildAdditionalData(serializableJsonObject, outJson); - - return outJson; - } else { - return outJsonTree; + final JsonElement outJsonTree = gson.toJsonTree(serializableObject); + if(outJsonTree != null) { + getChildAdditionalData(serializableObject, outJsonTree); + return outJsonTree.toString(); } + return ""; } - /** * Recursively populates additional data for each child object * @@ -274,14 +237,15 @@ private JsonElement getDataFromAdditionalDataManager(JsonElement outJsonTree * @param outJson the serialized output JSON to add to */ @SuppressWarnings("unchecked") - private void getChildAdditionalData(final IJsonBackedObject serializableObject, final JsonObject outJson) { - if(outJson == null) + private void getChildAdditionalData(final Object serializableObject, final JsonElement outJson) { + if(outJson == null || serializableObject == null || !outJson.isJsonObject()) return; + final JsonObject outJsonObject = outJson.getAsJsonObject(); // Use reflection to iterate through fields for eligible Graph children for (java.lang.reflect.Field field : serializableObject.getClass().getFields()) { try { final Object fieldObject = field.get(serializableObject); - final JsonElement fieldJsonElement = outJson.get(field.getName()); + final JsonElement fieldJsonElement = outJsonObject.get(field.getName()); if(fieldObject == null || fieldJsonElement == null) continue; @@ -296,7 +260,7 @@ private void getChildAdditionalData(final IJsonBackedObject serializableObject, final Object child = pair.getValue(); final JsonElement childJsonElement = fieldJsonObject.get(pair.getKey().toString()); // If the item is a valid Graph object, add its additional data - addAdditionalDataFromJsonElementToJson(child, childJsonElement); + getChildAdditionalData(child, childJsonElement); } } // If the object is a list of Graph objects, iterate through elements @@ -306,11 +270,13 @@ else if (fieldObject instanceof List && fieldJsonElement.isJsonArray()) { for (int index = 0; index < fieldObjectList.size(); index++) { final Object item = fieldObjectList.get(index); final JsonElement itemJsonElement = fieldArrayValue.get(index); - addAdditionalDataFromJsonElementToJson(item, itemJsonElement); + getChildAdditionalData(item, itemJsonElement); } - } - // If the object is a valid Graph object, add its additional data - addAdditionalDataFromJsonElementToJson(fieldObject, fieldJsonElement); + } else if(fieldJsonElement.isJsonObject()) { + // If the object is a valid Graph object, add its additional data + final JsonObject fieldJsonObject = fieldJsonElement.getAsJsonObject(); + addAdditionalDataFromJsonElementToJson(fieldObject, fieldJsonObject); + } } catch (IllegalArgumentException | IllegalAccessException e) { logger.logError("Unable to access child fields of " + serializableObject.getClass().getSimpleName(), e); } @@ -321,11 +287,10 @@ else if (fieldObject instanceof List && fieldJsonElement.isJsonArray()) { * Add each non-transient additional data property to the given JSON node * * @param item the object containing additional data - * @param itemJsonElement the JSON node to add the additional data properties to + * @param itemJsonObject the JSON node to add the additional data properties to */ - private void addAdditionalDataFromJsonElementToJson (final Object item, final JsonElement itemJsonElement) { - if (item instanceof IJsonBackedObject && itemJsonElement.isJsonObject()) { - final JsonObject itemJsonObject = itemJsonElement.getAsJsonObject(); + private void addAdditionalDataFromJsonElementToJson (final Object item, final JsonObject itemJsonObject) { + if (item instanceof IJsonBackedObject && itemJsonObject != null) { final IJsonBackedObject serializableItem = (IJsonBackedObject) item; final AdditionalDataManager itemAdditionalData = serializableItem.additionalDataManager(); addAdditionalDataFromManagerToJson(itemAdditionalData, itemJsonObject); diff --git a/src/test/java/com/microsoft/graph/content/BatchRequestContentTest.java b/src/test/java/com/microsoft/graph/content/BatchRequestContentTest.java index e6aa2a98d..54aa79676 100644 --- a/src/test/java/com/microsoft/graph/content/BatchRequestContentTest.java +++ b/src/test/java/com/microsoft/graph/content/BatchRequestContentTest.java @@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -14,6 +15,7 @@ import java.util.ArrayList; import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; import com.microsoft.graph.authentication.IAuthenticationProvider; import com.microsoft.graph.core.BaseClient; import com.microsoft.graph.core.IBaseClient; @@ -235,4 +237,18 @@ public AdditionalDataManager additionalDataManager() { assertNotNull(step4.headers); assertEquals("application/octet-stream", step4.headers.get("content-type")); } + @Test + public void serializesAdditionalData() throws MalformedURLException { + IHttpRequest requestStep = mock(IHttpRequest.class); + when(requestStep.getRequestUrl()).thenReturn(new URL(testurl)); + final BatchRequestContent batchRequest = new BatchRequestContent(); + final String bindValue = "https://somebindvalue"; + final BatchRequestTestBody body = new BatchRequestTestBody(); // using a dynamic implementation doesn't work as "this" maps to the current test class + body.additionalDataManager().put("teamsApp@odata.bind", new JsonPrimitive(bindValue)); + batchRequest.addBatchRequestStep(requestStep, HttpMethod.POST, body); + final ISerializer serializer = new DefaultSerializer(mock(ILogger.class)); + final String result = serializer.serializeObject(batchRequest); + assertNotNull(result); + assertTrue(result.contains(bindValue)); + } } diff --git a/src/test/java/com/microsoft/graph/content/BatchRequestTestBody.java b/src/test/java/com/microsoft/graph/content/BatchRequestTestBody.java new file mode 100644 index 000000000..63f7d8dca --- /dev/null +++ b/src/test/java/com/microsoft/graph/content/BatchRequestTestBody.java @@ -0,0 +1,30 @@ +package com.microsoft.graph.content; + +import javax.annotation.Nullable; + +import com.google.gson.JsonObject; +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; +import com.microsoft.graph.serializer.AdditionalDataManager; +import com.microsoft.graph.serializer.IJsonBackedObject; +import com.microsoft.graph.serializer.ISerializer; + +public class BatchRequestTestBody implements IJsonBackedObject { + @Expose + @Nullable + @SerializedName("id") + public String id; + + @Override + public void setRawObject(ISerializer serializer, JsonObject json) { + // TODO Auto-generated method stub + + } + final AdditionalDataManager manager = new AdditionalDataManager(this); + + @Override + public AdditionalDataManager additionalDataManager() { + return manager; + } + +} From 2b532c017e0f461e8ef34fbae654ae784006ffd0 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 11 Jun 2021 13:11:09 -0400 Subject: [PATCH 10/15] - code linting --- .../content/BatchRequestContentTest.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/test/java/com/microsoft/graph/content/BatchRequestContentTest.java b/src/test/java/com/microsoft/graph/content/BatchRequestContentTest.java index 54aa79676..b878853f0 100644 --- a/src/test/java/com/microsoft/graph/content/BatchRequestContentTest.java +++ b/src/test/java/com/microsoft/graph/content/BatchRequestContentTest.java @@ -39,12 +39,12 @@ import okhttp3.Response; import okhttp3.ResponseBody; -public class BatchRequestContentTest { +class BatchRequestContentTest { String testurl = "http://graph.microsoft.com/me"; @Test - public void testBatchRequestContentCreation() throws MalformedURLException { + void testBatchRequestContentCreation() throws MalformedURLException { BatchRequestContent requestContent = new BatchRequestContent(); for (int i = 0; i < 5; i++) { IHttpRequest requestStep = mock(IHttpRequest.class); @@ -55,7 +55,7 @@ public void testBatchRequestContentCreation() throws MalformedURLException { } @Test - public void testGetBatchRequestContent() throws MalformedURLException { + void testGetBatchRequestContent() throws MalformedURLException { IHttpRequest requestStep = mock(IHttpRequest.class); when(requestStep.getRequestUrl()).thenReturn(new URL(testurl)); BatchRequestContent requestContent = new BatchRequestContent(); @@ -67,7 +67,7 @@ public void testGetBatchRequestContent() throws MalformedURLException { } @Test - public void testGetBatchRequestContentWithHeader() throws MalformedURLException { + void testGetBatchRequestContentWithHeader() throws MalformedURLException { IHttpRequest requestStep = mock(IHttpRequest.class); when(requestStep.getRequestUrl()).thenReturn(new URL(testurl)); when(requestStep.getHeaders()).thenReturn(Arrays.asList(new HeaderOption("testkey", "testvalue"))); @@ -80,7 +80,7 @@ public void testGetBatchRequestContentWithHeader() throws MalformedURLException } @Test - public void testRemoveBatchRequesStepWithId() throws MalformedURLException { + void testRemoveBatchRequesStepWithId() throws MalformedURLException { IHttpRequest requestStep = mock(IHttpRequest.class); when(requestStep.getRequestUrl()).thenReturn(new URL(testurl)); BatchRequestContent requestContent = new BatchRequestContent(); @@ -92,7 +92,7 @@ public void testRemoveBatchRequesStepWithId() throws MalformedURLException { } @Test - public void testRemoveBatchRequesStepWithIdByAddingMultipleBatchSteps() throws MalformedURLException { + void testRemoveBatchRequesStepWithIdByAddingMultipleBatchSteps() throws MalformedURLException { IHttpRequest requestStep = mock(IHttpRequest.class); when(requestStep.getRequestUrl()).thenReturn(new URL(testurl)); BatchRequestContent requestContent = new BatchRequestContent(); @@ -111,7 +111,7 @@ public void testRemoveBatchRequesStepWithIdByAddingMultipleBatchSteps() throws M } @Test - public void defensiveProgrammingTests() { + void defensiveProgrammingTests() { assertThrows(NullPointerException.class, () -> { new BatchRequestContent().addBatchRequestStep(null); }, "should throw argument exception"); @@ -137,7 +137,7 @@ public void defensiveProgrammingTests() { } @Test - public void executeBatchTest() throws Throwable { + void executeBatchTest() throws Throwable { final BatchRequestContent content = new BatchRequestContent(); IHttpRequest requestStep = mock(IHttpRequest.class); when(requestStep.getRequestUrl()).thenReturn(new URL(testurl)); @@ -166,7 +166,7 @@ public void executeBatchTest() throws Throwable { } @Test - public void usesHttpMethodFromRequestIfAlreadySet() throws MalformedURLException { + void usesHttpMethodFromRequestIfAlreadySet() throws MalformedURLException { IHttpRequest requestStep = mock(IHttpRequest.class); when(requestStep.getRequestUrl()).thenReturn(new URL(testurl)); when(requestStep.getHttpMethod()).thenReturn(HttpMethod.DELETE); @@ -176,13 +176,13 @@ public void usesHttpMethodFromRequestIfAlreadySet() throws MalformedURLException } @Test - public void doesNotThrowWhenTryingToRemoveRequestFromNull() { + void doesNotThrowWhenTryingToRemoveRequestFromNull() { final BatchRequestContent batchRequest = new BatchRequestContent(); batchRequest.removeBatchRequestStepWithId("id"); } @Test - public void doesNotRemoveDependsOnWhenNotEmpty() throws MalformedURLException { + void doesNotRemoveDependsOnWhenNotEmpty() throws MalformedURLException { IHttpRequest requestStep = mock(IHttpRequest.class); when(requestStep.getRequestUrl()).thenReturn(new URL(testurl)); final BatchRequestContent batchRequest = new BatchRequestContent(); @@ -196,7 +196,7 @@ public void doesNotRemoveDependsOnWhenNotEmpty() throws MalformedURLException { } @Test - public void addsContentTypeForBodies() throws MalformedURLException { + void addsContentTypeForBodies() throws MalformedURLException { IHttpRequest requestStep = mock(IHttpRequest.class); when(requestStep.getRequestUrl()).thenReturn(new URL(testurl)); final BatchRequestContent batchRequest = new BatchRequestContent(); @@ -238,7 +238,7 @@ public AdditionalDataManager additionalDataManager() { assertEquals("application/octet-stream", step4.headers.get("content-type")); } @Test - public void serializesAdditionalData() throws MalformedURLException { + void serializesAdditionalData() throws MalformedURLException { IHttpRequest requestStep = mock(IHttpRequest.class); when(requestStep.getRequestUrl()).thenReturn(new URL(testurl)); final BatchRequestContent batchRequest = new BatchRequestContent(); From 98e44d935c229fe833d614477c041bf981758c1f Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 11 Jun 2021 13:17:17 -0400 Subject: [PATCH 11/15] - more code linting --- .../com/microsoft/graph/content/BatchRequestContentTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/com/microsoft/graph/content/BatchRequestContentTest.java b/src/test/java/com/microsoft/graph/content/BatchRequestContentTest.java index b878853f0..85ec06b49 100644 --- a/src/test/java/com/microsoft/graph/content/BatchRequestContentTest.java +++ b/src/test/java/com/microsoft/graph/content/BatchRequestContentTest.java @@ -179,6 +179,7 @@ void usesHttpMethodFromRequestIfAlreadySet() throws MalformedURLException { void doesNotThrowWhenTryingToRemoveRequestFromNull() { final BatchRequestContent batchRequest = new BatchRequestContent(); batchRequest.removeBatchRequestStepWithId("id"); + assertEquals(0, batchRequest.requests.size()); } @Test From 0f3fb83578796eb76b01b42742b5781a32425e23 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 11 Jun 2021 14:56:28 -0400 Subject: [PATCH 12/15] - pr feedback --- .../graph/serializer/DefaultSerializer.java | 82 +++++++++---------- .../content/BatchRequestContentTest.java | 2 +- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/microsoft/graph/serializer/DefaultSerializer.java b/src/main/java/com/microsoft/graph/serializer/DefaultSerializer.java index d901ce257..54a7d24ed 100644 --- a/src/main/java/com/microsoft/graph/serializer/DefaultSerializer.java +++ b/src/main/java/com/microsoft/graph/serializer/DefaultSerializer.java @@ -237,51 +237,51 @@ public String serializeObject(@Nonnull final T serializableObject) { * @param outJson the serialized output JSON to add to */ @SuppressWarnings("unchecked") - private void getChildAdditionalData(final Object serializableObject, final JsonElement outJson) { - if(outJson == null || serializableObject == null || !outJson.isJsonObject()) - return; + private void getChildAdditionalData(final Object serializableObject, final JsonElement outJson) { + if(outJson == null || serializableObject == null || !outJson.isJsonObject()) + return; final JsonObject outJsonObject = outJson.getAsJsonObject(); - // Use reflection to iterate through fields for eligible Graph children - for (java.lang.reflect.Field field : serializableObject.getClass().getFields()) { - try { - final Object fieldObject = field.get(serializableObject); - final JsonElement fieldJsonElement = outJsonObject.get(field.getName()); - if(fieldObject == null || fieldJsonElement == null) - continue; + // Use reflection to iterate through fields for eligible Graph children + for (java.lang.reflect.Field field : serializableObject.getClass().getFields()) { + try { + final Object fieldObject = field.get(serializableObject); + final JsonElement fieldJsonElement = outJsonObject.get(field.getName()); + if(fieldObject == null || fieldJsonElement == null) + continue; - // If the object is a HashMap, iterate through its children - if (fieldObject instanceof Map && fieldJsonElement.isJsonObject()) { - final Map serializableChildren = (Map) fieldObject; - final Iterator> it = serializableChildren.entrySet().iterator(); - final JsonObject fieldJsonObject = fieldJsonElement.getAsJsonObject(); + // If the object is a HashMap, iterate through its children + if (fieldObject instanceof Map && fieldJsonElement.isJsonObject()) { + final Map serializableChildren = (Map) fieldObject; + final Iterator> it = serializableChildren.entrySet().iterator(); + final JsonObject fieldJsonObject = fieldJsonElement.getAsJsonObject(); - while (it.hasNext()) { - final Map.Entry pair = (Map.Entry)it.next(); - final Object child = pair.getValue(); - final JsonElement childJsonElement = fieldJsonObject.get(pair.getKey().toString()); - // If the item is a valid Graph object, add its additional data - getChildAdditionalData(child, childJsonElement); - } - } - // If the object is a list of Graph objects, iterate through elements - else if (fieldObject instanceof List && fieldJsonElement.isJsonArray()) { - final JsonArray fieldArrayValue = fieldJsonElement.getAsJsonArray(); - final List fieldObjectList = (List) fieldObject; - for (int index = 0; index < fieldObjectList.size(); index++) { - final Object item = fieldObjectList.get(index); - final JsonElement itemJsonElement = fieldArrayValue.get(index); - getChildAdditionalData(item, itemJsonElement); - } - } else if(fieldJsonElement.isJsonObject()) { + while (it.hasNext()) { + final Map.Entry pair = (Map.Entry)it.next(); + final Object child = pair.getValue(); + final JsonElement childJsonElement = fieldJsonObject.get(pair.getKey().toString()); + // If the item is a valid Graph object, add its additional data + getChildAdditionalData(child, childJsonElement); + } + } + // If the object is a list of Graph objects, iterate through elements + else if (fieldObject instanceof List && fieldJsonElement.isJsonArray()) { + final JsonArray fieldArrayValue = fieldJsonElement.getAsJsonArray(); + final List fieldObjectList = (List) fieldObject; + for (int index = 0; index < fieldObjectList.size(); index++) { + final Object item = fieldObjectList.get(index); + final JsonElement itemJsonElement = fieldArrayValue.get(index); + getChildAdditionalData(item, itemJsonElement); + } + } else if(fieldJsonElement.isJsonObject()) { // If the object is a valid Graph object, add its additional data - final JsonObject fieldJsonObject = fieldJsonElement.getAsJsonObject(); - addAdditionalDataFromJsonElementToJson(fieldObject, fieldJsonObject); + final JsonObject fieldJsonObject = fieldJsonElement.getAsJsonObject(); + addAdditionalDataFromJsonObjectToJson(fieldObject, fieldJsonObject); } - } catch (IllegalArgumentException | IllegalAccessException e) { - logger.logError("Unable to access child fields of " + serializableObject.getClass().getSimpleName(), e); - } - } - } + } catch (IllegalArgumentException | IllegalAccessException e) { + logger.logError("Unable to access child fields of " + serializableObject.getClass().getSimpleName(), e); + } + } + } /** * Add each non-transient additional data property to the given JSON node @@ -289,7 +289,7 @@ else if (fieldObject instanceof List && fieldJsonElement.isJsonArray()) { * @param item the object containing additional data * @param itemJsonObject the JSON node to add the additional data properties to */ - private void addAdditionalDataFromJsonElementToJson (final Object item, final JsonObject itemJsonObject) { + private void addAdditionalDataFromJsonObjectToJson (final Object item, final JsonObject itemJsonObject) { if (item instanceof IJsonBackedObject && itemJsonObject != null) { final IJsonBackedObject serializableItem = (IJsonBackedObject) item; final AdditionalDataManager itemAdditionalData = serializableItem.additionalDataManager(); diff --git a/src/test/java/com/microsoft/graph/content/BatchRequestContentTest.java b/src/test/java/com/microsoft/graph/content/BatchRequestContentTest.java index 85ec06b49..176f16f4f 100644 --- a/src/test/java/com/microsoft/graph/content/BatchRequestContentTest.java +++ b/src/test/java/com/microsoft/graph/content/BatchRequestContentTest.java @@ -179,7 +179,7 @@ void usesHttpMethodFromRequestIfAlreadySet() throws MalformedURLException { void doesNotThrowWhenTryingToRemoveRequestFromNull() { final BatchRequestContent batchRequest = new BatchRequestContent(); batchRequest.removeBatchRequestStepWithId("id"); - assertEquals(0, batchRequest.requests.size()); + assertNull(batchRequest.requests); } @Test From 08f978eda4cbe79f468d7a2e5d257c8dca785f50 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 11 Jun 2021 15:01:40 -0400 Subject: [PATCH 13/15] - bumps patch version --- gradle.properties | 2 +- readme.md | 8 ++++---- .../com/microsoft/graph/httpcore/TelemetryHandler.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index 2e7cee095..6663f2b4c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,7 +25,7 @@ mavenGroupId = com.microsoft.graph mavenArtifactId = microsoft-graph-core mavenMajorVersion = 2 mavenMinorVersion = 0 -mavenPatchVersion = 4 +mavenPatchVersion = 5 mavenArtifactSuffix = #These values are used to run functional tests diff --git a/readme.md b/readme.md index 236c359b5..9da26ba4c 100644 --- a/readme.md +++ b/readme.md @@ -22,9 +22,9 @@ repositories { dependencies { // Include the sdk as a dependency - implementation 'com.microsoft.graph:microsoft-graph-core:2.0.4' + implementation 'com.microsoft.graph:microsoft-graph-core:2.0.5' // This dependency is only needed if you are using the TokenCrendentialAuthProvider - implementation 'com.azure:azure-identity:1.2.5' + implementation 'com.azure:azure-identity:1.3.1' } ``` @@ -37,11 +37,11 @@ Add the dependency in `dependencies` in pom.xml com.microsoft.graph microsoft-graph-core - 2.0.4 + 2.0.5 com.azure azure-identity - 1.2.5 + 1.3.1 ``` diff --git a/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java b/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java index ddc7ccdcf..40072fc03 100644 --- a/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java +++ b/src/main/java/com/microsoft/graph/httpcore/TelemetryHandler.java @@ -25,7 +25,7 @@ public class TelemetryHandler implements Interceptor{ /** * Current SDK version */ - public static final String VERSION = "v2.0.4"; + public static final String VERSION = "v2.0.5"; /** * Verion prefix */ From 735339e052c886815a709002925e6749962a1bcc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Jun 2021 06:25:31 +0000 Subject: [PATCH 14/15] Bump mockito-inline from 3.11.0 to 3.11.1 Bumps [mockito-inline](https://github.com/mockito/mockito) from 3.11.0 to 3.11.1. - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v3.11.0...v3.11.1) --- updated-dependencies: - dependency-name: org.mockito:mockito-inline dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- gradle/dependencies.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 1c1ff820f..38c853013 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -2,7 +2,7 @@ dependencies { // Use JUnit test framework testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2' - testImplementation 'org.mockito:mockito-inline:3.11.0' + testImplementation 'org.mockito:mockito-inline:3.11.1' api 'com.squareup.okhttp3:okhttp:4.9.1' From 8af0ccd5a39dab270f46a585fe54764e170a308d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Jun 2021 08:02:07 +0000 Subject: [PATCH 15/15] Bump mockito-inline from 3.11.0 to 3.11.1 Bumps [mockito-inline](https://github.com/mockito/mockito) from 3.11.0 to 3.11.1. - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v3.11.0...v3.11.1) --- updated-dependencies: - dependency-name: org.mockito:mockito-inline dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b3c9c7b3c..f0e1d0f8c 100644 --- a/pom.xml +++ b/pom.xml @@ -46,7 +46,7 @@ org.mockito mockito-inline - 3.11.0 + 3.11.1 test