diff --git a/CHANGELOG.md b/CHANGELOG.md index d7bb7f1ae..2238b7153 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +## [3.1.4] - 2024-02-21 + +- Bumps Kiota-Java abstractions, authentication, http, and serialization components +- Fixes a test in the test suite which did not respect the REST reference [#1517](https://github.com/microsoftgraph/msgraph-sdk-java-core/issues/1517) +- Fixes a bug with LargeFileUploadTask [#1517](https://github.com/microsoftgraph/msgraph-sdk-java-core/issues/1517) + +### Changed + ## [3.1.3] - 2024-02-14 ### Changed diff --git a/gradle.properties b/gradle.properties index bb163d800..6b4f97803 100644 --- a/gradle.properties +++ b/gradle.properties @@ -25,7 +25,7 @@ mavenGroupId = com.microsoft.graph mavenArtifactId = microsoft-graph-core mavenMajorVersion = 3 mavenMinorVersion = 1 -mavenPatchVersion = 3 +mavenPatchVersion = 4 mavenArtifactSuffix = #These values are used to run functional tests diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 9a407bccb..809ce6757 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -16,11 +16,11 @@ dependencies { api 'com.squareup.okhttp3:okhttp:4.12.0' api 'com.azure:azure-core:1.46.0' - api 'com.microsoft.kiota:microsoft-kiota-abstractions:1.0.2' - implementation 'com.microsoft.kiota:microsoft-kiota-authentication-azure:1.0.2' - implementation 'com.microsoft.kiota:microsoft-kiota-http-okHttp:1.0.2' - implementation 'com.microsoft.kiota:microsoft-kiota-serialization-json:1.0.2' - implementation 'com.microsoft.kiota:microsoft-kiota-serialization-text:1.0.2' - implementation 'com.microsoft.kiota:microsoft-kiota-serialization-form:1.0.2' - implementation 'com.microsoft.kiota:microsoft-kiota-serialization-multipart:1.0.2' + api 'com.microsoft.kiota:microsoft-kiota-abstractions:1.0.3' + implementation 'com.microsoft.kiota:microsoft-kiota-authentication-azure:1.0.3' + implementation 'com.microsoft.kiota:microsoft-kiota-http-okHttp:1.0.3' + implementation 'com.microsoft.kiota:microsoft-kiota-serialization-json:1.0.3' + implementation 'com.microsoft.kiota:microsoft-kiota-serialization-text:1.0.3' + implementation 'com.microsoft.kiota:microsoft-kiota-serialization-form:1.0.3' + implementation 'com.microsoft.kiota:microsoft-kiota-serialization-multipart:1.0.3' } diff --git a/readme.md b/readme.md index ae39f1330..bfe046029 100644 --- a/readme.md +++ b/readme.md @@ -22,7 +22,7 @@ repositories { dependencies { // Include the sdk as a dependency - implementation 'com.microsoft.graph:microsoft-graph-core:3.1.3' + implementation 'com.microsoft.graph:microsoft-graph-core:3.1.4' // This dependency is only needed if you are using the TokenCredentialAuthProvider implementation 'com.azure:azure-identity:1.11.0' } @@ -37,7 +37,7 @@ Add the dependency in `dependencies` in pom.xml com.microsoft.graph microsoft-graph-core - 3.1.3 + 3.1.4 com.azure azure-identity diff --git a/src/main/java/com/microsoft/graph/core/models/IUploadSession.java b/src/main/java/com/microsoft/graph/core/models/IUploadSession.java index 072d24d02..ab9a0dd6f 100644 --- a/src/main/java/com/microsoft/graph/core/models/IUploadSession.java +++ b/src/main/java/com/microsoft/graph/core/models/IUploadSession.java @@ -23,19 +23,19 @@ public interface IUploadSession extends Parsable, AdditionalDataHolder { * Sets the Upload Url * @param url the upload Url for the session */ - void setUploadUrl(@Nonnull String url); + void setUploadUrl(@Nonnull final String url); /** * Gets the Next Expected Ranges. * A collection of byte ranges that the server is missing for the file. These ranges are zero indexed and of the format 'start-end' (e.g. '0-26' to indicate the first 27 bytes of the file). When uploading files as Outlook attachments, instead of a collection of ranges, this property always indicates a single value '{start}', the location in the file where the next upload should begin. * @return the Next Expected Ranges. */ - @Nonnull + @Nullable List getNextExpectedRanges(); /** * Sets the ranges that are yet to be uploaded. * @param nextExpectedRanges the byte ranges yet to be uploaded. */ - void setNextExpectedRanges(@Nonnull List nextExpectedRanges); + void setNextExpectedRanges(@Nonnull final List nextExpectedRanges); /** * Expiration date of the upload session * @return the expiration date. @@ -46,5 +46,5 @@ public interface IUploadSession extends Parsable, AdditionalDataHolder { * Set the expiration date of the UploadSession * @param dateTime the expiration date of the UploadSession. */ - void setExpirationDateTime(@Nonnull OffsetDateTime dateTime); + void setExpirationDateTime(@Nonnull final OffsetDateTime dateTime); } diff --git a/src/main/java/com/microsoft/graph/core/models/UploadSession.java b/src/main/java/com/microsoft/graph/core/models/UploadSession.java index 18bb54d9c..f69e14a54 100644 --- a/src/main/java/com/microsoft/graph/core/models/UploadSession.java +++ b/src/main/java/com/microsoft/graph/core/models/UploadSession.java @@ -55,9 +55,12 @@ public void setUploadUrl(@Nonnull final String uploadUrl) { * Get the next upload byte ranges to be uploaded. * @return The byte ranges to be uploaded. */ - @Nonnull + @Nullable @Override public List getNextExpectedRanges() { + if (nextExpectedRanges == null) { + return null; + } return new ArrayList<>(nextExpectedRanges); } /** diff --git a/src/main/java/com/microsoft/graph/core/requests/upload/UploadResponseHandler.java b/src/main/java/com/microsoft/graph/core/requests/upload/UploadResponseHandler.java index 6d4a2acec..8e165599a 100644 --- a/src/main/java/com/microsoft/graph/core/requests/upload/UploadResponseHandler.java +++ b/src/main/java/com/microsoft/graph/core/requests/upload/UploadResponseHandler.java @@ -18,6 +18,7 @@ import java.net.HttpURLConnection; import java.net.URI; import java.net.URISyntaxException; +import java.util.List; import java.util.Objects; /** @@ -76,7 +77,8 @@ public UploadResult handleResponse(@Nonnull final Respon } else { final ParseNode parseNode = parseNodeFactory.getParseNode(contentType, in); final UploadSession uploadSession = parseNode.getObjectValue(UploadSession::createFromDiscriminatorValue); - if (!uploadSession.getNextExpectedRanges().isEmpty()) { + final List nextExpectedRanges = uploadSession.getNextExpectedRanges(); + if (!(nextExpectedRanges == null || nextExpectedRanges.isEmpty())) { uploadResult.uploadSession = uploadSession; } else { uploadResult.itemResponse = parseNode.getObjectValue(factory); diff --git a/src/test/java/com/microsoft/graph/core/requests/upload/UploadResponseHandlerTest.java b/src/test/java/com/microsoft/graph/core/requests/upload/UploadResponseHandlerTest.java index 531383a91..f0f4105f7 100644 --- a/src/test/java/com/microsoft/graph/core/requests/upload/UploadResponseHandlerTest.java +++ b/src/test/java/com/microsoft/graph/core/requests/upload/UploadResponseHandlerTest.java @@ -51,6 +51,36 @@ void GetUploadItemOnCompletedUpload() { assertEquals("largeFile.vhd", item.name); assertEquals(33, item.size); } + + @Test + void GetUploadItemOnCompletedUpdate() { + registry.contentTypeAssociatedFactories.put(CoreConstants.MimeTypeNames.APPLICATION_JSON, new JsonParseNodeFactory()); + + UploadResponseHandler responseHandler = new UploadResponseHandler(null); + ResponseBody body = ResponseBody.create("{\n" + + " \"id\": \"912310013A123\",\n" + + " \"name\": \"largeFile.vhd\",\n" + + " \"size\": 33\n" + + "}" + , MediaType.parse(CoreConstants.MimeTypeNames.APPLICATION_JSON)); + Response response = new Response.Builder() + .request(mock(Request.class)) + .protocol(mock(Protocol.class)) + .body(body) + .code(HttpURLConnection.HTTP_OK) + .message("OK") + .build(); + UploadResult result = responseHandler + .handleResponse(response, TestDriveItem::createFromDiscriminatorValue); + responseHandler.handleResponse(response, parseNode -> {return new TestDriveItem();}); + TestDriveItem item = result.itemResponse; + assertTrue(result.isUploadSuccessful()); + assertNotNull(item); + assertEquals("912310013A123", item.id); + assertEquals("largeFile.vhd", item.name); + assertEquals(33, item.size); + } + @Test void getFileAttachmentLocationOnCompletedUpload() { registry.contentTypeAssociatedFactories.put(CoreConstants.MimeTypeNames.APPLICATION_JSON, new JsonParseNodeFactory()); @@ -89,9 +119,9 @@ void getUploadSessionOnProgressingUpload() { Response response = new Response.Builder() .request(mock(Request.class)) .protocol(mock(Protocol.class)) - .message("OK") + .message("Accepted") .body(body) - .code(HttpURLConnection.HTTP_OK) + .code(HttpURLConnection.HTTP_ACCEPTED) .build(); UploadResult result = responseHandler .handleResponse(response, TestDriveItem::createFromDiscriminatorValue); @@ -105,6 +135,7 @@ void getUploadSessionOnProgressingUpload() { assertEquals("77829-99375", session.getNextExpectedRanges().get(1)); assertEquals(2, session.getNextExpectedRanges().size()); } + @Test void throwsServiceExceptionOnErrorResponse() { UploadResponseHandler responseHandler = new UploadResponseHandler(null); diff --git a/src/test/java/com/microsoft/graph/core/requests/upload/UploadSessionTest.java b/src/test/java/com/microsoft/graph/core/requests/upload/UploadSessionTest.java new file mode 100644 index 000000000..1b29e509c --- /dev/null +++ b/src/test/java/com/microsoft/graph/core/requests/upload/UploadSessionTest.java @@ -0,0 +1,19 @@ +package com.microsoft.graph.core.requests.upload; + +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.util.List; + +import org.junit.jupiter.api.Test; + +import com.microsoft.graph.core.models.UploadSession; + +class UploadSessionTest { + @Test + void getNextExpectedRangesDoesNotFailOnDefault() + { + final UploadSession uploadSession = new UploadSession(); + final List result = uploadSession.getNextExpectedRanges(); + assertNull(result); + } +} diff --git a/src/test/java/com/microsoft/graph/core/requests/upload/UploadSliceRequestTest.java b/src/test/java/com/microsoft/graph/core/requests/upload/UploadSliceRequestTest.java index 73038109b..079521205 100644 --- a/src/test/java/com/microsoft/graph/core/requests/upload/UploadSliceRequestTest.java +++ b/src/test/java/com/microsoft/graph/core/requests/upload/UploadSliceRequestTest.java @@ -40,9 +40,9 @@ void putReturnsExpectedUploadSession() throws IOException { Response response = new Response.Builder() .request(new Request.Builder().post(mock(RequestBody.class)).url("https://a.b.c/").build()) .protocol(Protocol.HTTP_1_1) - .message("OK") + .message("Accepted") .body(body) - .code(HttpURLConnection.HTTP_OK) + .code(HttpURLConnection.HTTP_ACCEPTED) .build(); OkHttpClient mockClient = getMockClient(response);