Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ sourceSets {
repositories {
// You can declare any Maven/Ivy/file repository here.
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/" // Added for SonarQube
}
}

apply from: "gradle/dependencies.gradle"
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/microsoft/graph/CoreConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,27 @@ private Serialization(){}
public static final String ODATA_TYPE = "@odata.type";
/** OData nextLink property */
public static final String ODATA_NEXT_LINK = "@nextLink";
}

/**
* Odata Instance Annotation Constants
*/
public static class OdataInstanceAnnotations {
private OdataInstanceAnnotations(){}
/** NextLink odata instance annotation */
public static final String NEXT_LINK = "@odata.nextLink";
/** DeltaLink odata instance annotation */
public static final String DELTA_LINK = "@odata.deltaLink";
}

/**
* Collection Response Method Name Constants
*/
public static class CollectionResponseMethods {
private CollectionResponseMethods(){}
/** Method name constant for getOdataDeltaLink in collection responses*/
public static final String GET_ODATA_DELTA_LINK = "getOdataDeltaLink";
/** Method name constant for getOdataNextLink in collection responses*/
public static final String GET_ODATA_NEXT_LINK = "getOdataNextLink";
}
}
494 changes: 494 additions & 0 deletions src/main/java/com/microsoft/graph/tasks/PageIterator.java

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions src/main/java/com/microsoft/graph/tasks/PageIteratorBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.microsoft.graph.tasks;

import com.microsoft.graph.requests.IBaseClient;
import com.microsoft.kiota.RequestAdapter;
import com.microsoft.kiota.RequestInformation;
import com.microsoft.kiota.serialization.AdditionalDataHolder;
import com.microsoft.kiota.serialization.Parsable;
import com.microsoft.kiota.serialization.ParsableFactory;

import javax.annotation.Nonnull;
import java.lang.reflect.InvocationTargetException;
import java.util.function.UnaryOperator;

interface PageIteratorBuilder<TEntity extends Parsable, TCollectionPage extends Parsable & AdditionalDataHolder> {
/**
* Sets the client for the PageIteratorBuilder.
* @param client the client to set.
*/
public PageIteratorBuilder<TEntity, TCollectionPage> client(@Nonnull IBaseClient client);
/**
* Sets the request adapter for the PageIteratorBuilder.
* @param requestAdapter the request adapter to set.
*/
public PageIteratorBuilder<TEntity, TCollectionPage> requestAdapter(@Nonnull RequestAdapter requestAdapter);
/**
* Sets the page to be iterated over.
* @param collectionPage the page to be iterated over.
*/
public PageIteratorBuilder<TEntity, TCollectionPage> collectionPage(@Nonnull TCollectionPage collectionPage) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException;
/**
* Sets factory to use for creating a collection page.
* @param collectionPageFactory the factory to use for creating a collection page.
*/
public PageIteratorBuilder<TEntity, TCollectionPage> collectionPageFactory(@Nonnull ParsableFactory<TCollectionPage> collectionPageFactory);
/**
* Sets the function to configure each subsequent request.
* @param requestConfigurator function to configure each subsequent request.
*/
public PageIteratorBuilder<TEntity, TCollectionPage> requestConfigurator(@Nonnull UnaryOperator<RequestInformation> requestConfigurator);
/**
* Build the PageIterator.
* Should fail if request adapter is not set.
* Should fail if current collection page is not set.
* Should fail if collection page factory is not set.
* Should fail if process page item callback is not set.
* @return the built PageIterator.
*/
PageIterator<TEntity, TCollectionPage> build() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
import org.junit.jupiter.params.aggregator.ArgumentsAccessor;
import org.junit.jupiter.params.provider.CsvSource;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.*;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -53,9 +50,9 @@ void BatchRequestContent_InitializeWithBatchRequestSteps() {
@Test
void BatchRequestContent_InitializeWithInvalidDependsOnIds() {
BatchRequestStep requestStep = new BatchRequestStep("1", mock(Request.class));
BatchRequestStep requestStep2 = new BatchRequestStep("2", mock(Request.class), List.of("3"));
BatchRequestStep requestStep2 = new BatchRequestStep("2", mock(Request.class), Arrays.asList("3"));
try {
new BatchRequestContent(client, List.of(requestStep, requestStep2));
new BatchRequestContent(client, Arrays.asList(requestStep, requestStep2));
} catch (IllegalArgumentException ex) {
assertEquals(ErrorConstants.Messages.INVALID_DEPENDS_ON_REQUEST_ID, ex.getMessage());
}
Expand Down Expand Up @@ -84,7 +81,7 @@ void BatchRequestContent_AddBatchRequestStepToBatchRequestContentWithMaxSteps()
@Test
void BatchRequestContent_AddBatchRequestStepWithExistingRequestStep() {
BatchRequestStep batchRequestStep = new BatchRequestStep("1", mock(Request.class));
BatchRequestContent batchRequestContent = new BatchRequestContent(client, List.of(batchRequestStep));
BatchRequestContent batchRequestContent = new BatchRequestContent(client, Arrays.asList(batchRequestStep));

assertFalse(batchRequestContent.addBatchRequestStep(batchRequestStep));
assertNotNull(batchRequestContent.getBatchRequestSteps());
Expand All @@ -93,7 +90,7 @@ void BatchRequestContent_AddBatchRequestStepWithExistingRequestStep() {
@Test
void BatchRequestContent_AddBatchRequestStepWithNullRequestStep() {
BatchRequestStep batchRequestStep = new BatchRequestStep("1", mock(Request.class));
BatchRequestContent batchRequestContent = new BatchRequestContent(client, List.of(batchRequestStep));
BatchRequestContent batchRequestContent = new BatchRequestContent(client, Arrays.asList(batchRequestStep));

assertFalse(batchRequestContent.addBatchRequestStep((BatchRequestStep) null));
assertNotNull(batchRequestContent.getBatchRequestSteps());
Expand All @@ -102,8 +99,8 @@ void BatchRequestContent_AddBatchRequestStepWithNullRequestStep() {
@Test
void BatchRequestContent_RemoveBatchRequestStepWithIdForExistingId() {
BatchRequestStep batchRequestStep = new BatchRequestStep("1", mock(Request.class));
BatchRequestStep batchRequestStep2 = new BatchRequestStep("2", mock(Request.class), List.of("1", "1", "1"));
BatchRequestContent batchRequestContent = new BatchRequestContent(client, List.of(batchRequestStep, batchRequestStep2));
BatchRequestStep batchRequestStep2 = new BatchRequestStep("2", mock(Request.class), Arrays.asList("1", "1", "1"));
BatchRequestContent batchRequestContent = new BatchRequestContent(client, Arrays.asList(batchRequestStep, batchRequestStep2));

assertTrue(batchRequestContent.removeBatchRequestStepWithId("1"));
assertEquals(1, batchRequestContent.getBatchRequestSteps().size());
Expand All @@ -112,23 +109,23 @@ void BatchRequestContent_RemoveBatchRequestStepWithIdForExistingId() {
@Test
void BatchRequestContent_RemoveBatchRequestStepWithIdForNonExistingId() {
BatchRequestStep batchRequestStep = new BatchRequestStep("1", mock(Request.class));
BatchRequestStep batchRequestStep2 = new BatchRequestStep("2", mock(Request.class), List.of("1"));
BatchRequestContent batchRequestContent = new BatchRequestContent(client, List.of(batchRequestStep, batchRequestStep2));
BatchRequestStep batchRequestStep2 = new BatchRequestStep("2", mock(Request.class), Arrays.asList("1"));
BatchRequestContent batchRequestContent = new BatchRequestContent(client, Arrays.asList(batchRequestStep, batchRequestStep2));

assertFalse(batchRequestContent.removeBatchRequestStepWithId("3"));
assertEquals(2, batchRequestContent.getBatchRequestSteps().size());
assertEquals(Objects.requireNonNull(batchRequestStep2.getDependsOn()).get(0), Objects.requireNonNull(batchRequestContent.getBatchRequestSteps().get("2").getDependsOn()).get(0));
}
@Test
void BatchRequestContent_GetBatchRequestContentFromStep() throws IOException, URISyntaxException {
void BatchRequestContent_GetBatchRequestContentFromStep() throws Exception {
Request request = new Request.Builder().url(requestUrl).build();
BatchRequestStep batchRequestStep = new BatchRequestStep("1", mock(Request.class));
BatchRequestStep batchRequestStep2 = new BatchRequestStep("2", request, List.of("1"));
BatchRequestContent batchRequestContent = new BatchRequestContent(client, List.of(batchRequestStep, batchRequestStep2));
BatchRequestStep batchRequestStep2 = new BatchRequestStep("2", request, Arrays.asList("1"));
BatchRequestContent batchRequestContent = new BatchRequestContent(client, Arrays.asList(batchRequestStep, batchRequestStep2));

batchRequestContent.removeBatchRequestStepWithId("1");
InputStream requestContent = batchRequestContent.getBatchRequestContentAsync().join();
String requestContentString = new String(requestContent.readAllBytes(), StandardCharsets.UTF_8);
String requestContentString = readInputStream(requestContent);
requestContentString = requestContentString.replace("\n", "").replaceAll("\\s", "");
String expectedContent = "{\"requests\":[{\"id\":\"2\",\"url\":\"/me\",\"method\":\"GET\"}]}";

Expand All @@ -137,7 +134,7 @@ void BatchRequestContent_GetBatchRequestContentFromStep() throws IOException, UR
assertEquals(expectedContent, requestContentString);
}
@Test
void BatchRequestContent_GetBatchRequestContentFromStepAsyncDoesNotModifyDateTimes() throws IOException {
void BatchRequestContent_GetBatchRequestContentFromStepAsyncDoesNotModifyDateTimes() throws Exception {
String bodyString = "{\n" +
" \"subject\": \"Lets go for lunch\",\n" +
" \"body\": {\n \"contentType\": \"HTML\",\n" +
Expand Down Expand Up @@ -165,11 +162,11 @@ void BatchRequestContent_GetBatchRequestContentFromStepAsyncDoesNotModifyDateTim
"}";
Request eventRequest = new Request.Builder().url(requestUrl).method("POST", RequestBody.create(bodyString, MediaType.parse("application/json"))).build();
BatchRequestStep batchRequestStep = new BatchRequestStep("1", new Request.Builder().url(requestUrl).build());
BatchRequestStep batchRequestSte2 = new BatchRequestStep("2", eventRequest, List.of("1"));
BatchRequestContent batchRequestContent = new BatchRequestContent(client, List.of(batchRequestStep, batchRequestSte2));
BatchRequestStep batchRequestSte2 = new BatchRequestStep("2", eventRequest, Arrays.asList("1"));
BatchRequestContent batchRequestContent = new BatchRequestContent(client, Arrays.asList(batchRequestStep, batchRequestSte2));

InputStream stream = batchRequestContent.getBatchRequestContentAsync().join();
String requestContentString = new String(stream.readAllBytes(), StandardCharsets.UTF_8);
String requestContentString = readInputStream(stream);
String expectedJson = "{\n" +
" \"requests\": [\n" +
" {\n" +
Expand Down Expand Up @@ -272,7 +269,7 @@ void BatchRequestContent_AddBatchRequestStepWithBaseRequest() throws IOException
assertEquals(batchRequestContent.getBatchRequestSteps().get(requestId).getRequest().method(), requestInfo.httpMethod.toString());
}
@Test
void BatchRequestContent_AddBatchRequestStepWithBaseRequestWithHeaderOptions() throws IOException {
void BatchRequestContent_AddBatchRequestStepWithBaseRequestWithHeaderOptions() throws Exception {
BatchRequestContent batchRequestContent = new BatchRequestContent(client);
Request request = new Request.Builder()
.url(requestUrl)
Expand All @@ -286,7 +283,7 @@ void BatchRequestContent_AddBatchRequestStepWithBaseRequestWithHeaderOptions() t
assertNotNull(Objects.requireNonNull(batchRequestContent.getBatchRequestSteps().get(requestId).getRequest().body()).contentType());

InputStream stream = batchRequestContent.getBatchRequestContentAsync().join();
String requestContentString = new String(stream.readAllBytes(), StandardCharsets.UTF_8);
String requestContentString = readInputStream(stream);
String expectedJsonSection = " \"url\": \"/me\"," +
" \"method\": \"POST\"," +
" \"body\": {}," +
Expand Down Expand Up @@ -329,15 +326,15 @@ void BatchRequestContent_AddBatchRequestStepWithBaseRequestToBatchRequestContent
"https://graph.microsoft.com/v1.0/users?$filter=identities/any(id:id/issuer%20eq%20'$74707853-18b3-411f-ad57-2ef65f6fdeb0'%20and%20id/issuerAssignedId%20eq%20'**bobbetancourt@fakeemail.com**') , /users?$filter=identities/any(id:id/issuer%20eq%20%27$74707853-18b3-411f-ad57-2ef65f6fdeb0%27%20and%20id/issuerAssignedId%20eq%20%27**bobbetancourt@fakeemail.com**%27)" ,
"https://graph.microsoft.com/beta/users?$filter=identities/any(id:id/issuer%20eq%20'$74707853-18b3-411f-ad57-2ef65f6fdeb0'%20and%20id/issuerAssignedId%20eq%20'**bobbetancourt@fakeemail.com**')&$top=1 , /users?$filter=identities/any(id:id/issuer%20eq%20%27$74707853-18b3-411f-ad57-2ef65f6fdeb0%27%20and%20id/issuerAssignedId%20eq%20%27**bobbetancourt@fakeemail.com**%27)&$top=1" ,
})
void BatchRequestContent_AddBatchRequestStepWithBaseRequestProperlySetsVersion(ArgumentsAccessor argumentsAccessor) throws IOException {
void BatchRequestContent_AddBatchRequestStepWithBaseRequestProperlySetsVersion(ArgumentsAccessor argumentsAccessor) throws Exception {
Request request = new Request.Builder().url(argumentsAccessor.getString(0)).build();
BatchRequestStep batchRequestStep = new BatchRequestStep("1", request);
BatchRequestContent batchRequestContent = new BatchRequestContent(client);
assertTrue(batchRequestContent.getBatchRequestSteps().isEmpty());

batchRequestContent.addBatchRequestStep(batchRequestStep);
InputStream stream = batchRequestContent.getBatchRequestContentAsync().join();
String requestContentString = new String(stream.readAllBytes(), StandardCharsets.UTF_8);
String requestContentString = readInputStream(stream);
String expectedJson = "{" +
" \"requests\": [" +
" {" +
Expand All @@ -352,4 +349,14 @@ void BatchRequestContent_AddBatchRequestStepWithBaseRequestProperlySetsVersion(A
requestContentString = requestContentString.replaceAll("\\s", "").replace("\n", "");
assertEquals(expectedJson, requestContentString);
}
private static String readInputStream(InputStream stream) throws Exception {
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = stream.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
return new String(result.toByteArray(), StandardCharsets.UTF_8);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import okhttp3.RequestBody;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Arrays;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand All @@ -26,9 +26,9 @@ void BatchRequestBuilder_DefaultBuilderTest() {
RequestBody requestBody = RequestBody.create("{}", MediaType.get(CoreConstants.MimeTypeNames.APPLICATION_JSON));
Request request2 = new Request.Builder().url("https://graph.microsoft.com/v1.0/me/onenote/notebooks").post(requestBody).build();
BatchRequestStep batchRequestStep = new BatchRequestStep("1", request);
BatchRequestStep batchRequestStep2 = new BatchRequestStep("2", request2, List.of("1"));
BatchRequestStep batchRequestStep2 = new BatchRequestStep("2", request2, Arrays.asList("1"));

BatchRequestContent batchRequestContent = new BatchRequestContent(client,List.of(batchRequestStep, batchRequestStep2));
BatchRequestContent batchRequestContent = new BatchRequestContent(client,Arrays.asList(batchRequestStep, batchRequestStep2));
RequestInformation requestInformation = batchRequestBuilder.toPostRequestInformationAsync(batchRequestContent).join();

assertEquals("{+baseurl}/$batch", requestInformation.urlTemplate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class LargeFileUploadTest {
final OkHttpRequestAdapter adapter = new OkHttpRequestAdapter(mock(AuthenticationProvider.class));

@Test
void ThrowsIllegalArgumentExceptionOnEmptyStream() throws NoSuchFieldException, IllegalAccessException, IOException {
void ThrowsIllegalArgumentExceptionOnEmptyStream() throws IllegalAccessException, IOException {
UploadSession session = new UploadSession();
session.setNextExpectedRanges(Arrays.asList("0-"));
session.setUploadUrl("http://localhost");
session.setExpirationDateTime(OffsetDateTime.parse("2019-11-07T06:39:31.499Z"));

InputStream stream = InputStream.nullInputStream();
InputStream stream = new ByteArrayInputStream(new byte[0]);
int size = stream.available();
long maxSliceSize = 200*1024;

Expand Down
Loading