Skip to content

Commit

Permalink
Merge pull request #1518 from kekolab/dev
Browse files Browse the repository at this point in the history
Fix for issue 1517 and correction of two tests not respecting the REST reference (impacted by the fix)
  • Loading branch information
baywet authored Feb 21, 2024
2 parents dde3ec2 + 9d368ce commit 93ea88a
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 20 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand All @@ -37,7 +37,7 @@ Add the dependency in `dependencies` in pom.xml
<!-- Include the sdk as a dependency -->
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph-core</artifactId>
<version>3.1.3</version>
<version>3.1.4</version>
<!-- This dependency is only needed if you are using the TokenCredentialAuthProvider -->
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> getNextExpectedRanges();
/**
* Sets the ranges that are yet to be uploaded.
* @param nextExpectedRanges the byte ranges yet to be uploaded.
*/
void setNextExpectedRanges(@Nonnull List<String> nextExpectedRanges);
void setNextExpectedRanges(@Nonnull final List<String> nextExpectedRanges);
/**
* Expiration date of the upload session
* @return the expiration date.
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> getNextExpectedRanges() {
if (nextExpectedRanges == null) {
return null;
}
return new ArrayList<>(nextExpectedRanges);
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Objects;

/**
Expand Down Expand Up @@ -76,7 +77,8 @@ public <T extends Parsable> UploadResult<T> 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<String> nextExpectedRanges = uploadSession.getNextExpectedRanges();
if (!(nextExpectedRanges == null || nextExpectedRanges.isEmpty())) {
uploadResult.uploadSession = uploadSession;
} else {
uploadResult.itemResponse = parseNode.getObjectValue(factory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TestDriveItem> 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());
Expand Down Expand Up @@ -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<TestDriveItem> result = responseHandler
.handleResponse(response, TestDriveItem::createFromDiscriminatorValue);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> result = uploadSession.getNextExpectedRanges();
assertNull(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 93ea88a

Please sign in to comment.