Skip to content

Commit f22b9dd

Browse files
committed
- adds a unit test to validate onedrive path encoding
1 parent 8428170 commit f22b9dd

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/test/java/com/microsoft/graph/functional/OneDriveTests.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.microsoft.graph.functional;
22

3+
import static org.junit.jupiter.api.Assertions.assertEquals;
34
import static org.junit.jupiter.api.Assertions.assertFalse;
45
import static org.junit.jupiter.api.Assertions.assertNotNull;
56
import static org.junit.jupiter.api.Assertions.assertTrue;
67

78
import java.io.ByteArrayInputStream;
89
import java.io.IOException;
910
import java.io.InputStream;
11+
import java.net.URL;
1012
import java.nio.charset.StandardCharsets;
1113

1214
import org.junit.jupiter.api.BeforeEach;
@@ -24,13 +26,13 @@
2426
import com.microsoft.graph.models.UploadSession;
2527
import com.microsoft.graph.models.DriveItemCreateUploadSessionParameterSet;
2628

27-
@Disabled
2829
public class OneDriveTests {
2930
private TestBase testBase;
3031

31-
@BeforeEach
3232
public void setUp() {
33-
testBase = new TestBase();
33+
if(testBase == null) {
34+
testBase = new TestBase();
35+
}
3436
}
3537

3638
final IProgressCallback callback = new IProgressCallback () {
@@ -39,6 +41,17 @@ public void progress(final long current, final long max) {
3941
//Check progress
4042
}
4143
};
44+
/**
45+
* Tests that paths are properly encoded acording to ODSP's expectations
46+
* - everything is encoded to the application/x-www-form-urlencoded MIME format
47+
* - spaces are encoded with %20
48+
*/
49+
@Test
50+
public void itemWithPathEncodesSpecialCharacters() {
51+
final URL requestURL = new TestBase(false).graphClient.me().drive().root().itemWithPath("some folder/some name with a + and a #777.docx").buildRequest().getRequestUrl();
52+
assertEquals("/me/drive/root:/some%20folder%2Fsome%20name%20with%20a%20%2B%20and%20a%20%23777.docx:", requestURL.getPath().replace("/v1.0", "").replace("/beta", ""));
53+
// version replacement so the test is version agnostic
54+
}
4255
/**
4356
* Test large file upload.
4457
* https://github.com/OneDrive/onedrive-sdk-csharp/blob/master/docs/chunked-uploads.md
@@ -47,8 +60,10 @@ public void progress(final long current, final long max) {
4760
* @throws InterruptedException if the chunked upload fails
4861
*/
4962
@Test
63+
@Disabled
5064
public void testLargeFileUpload() throws IOException, InterruptedException {
51-
//Get resource file from file system
65+
setUp();
66+
//Get resource file from file system
5267
InputStream uploadFile = OneDriveTests.class.getClassLoader().getResourceAsStream("largefile10M.blob");
5368
long fileSize = (long) uploadFile.available();
5469

@@ -72,14 +87,18 @@ public void testLargeFileUpload() throws IOException, InterruptedException {
7287
assertNotNull(result);
7388
}
7489
@Test
90+
@Disabled
7591
public void testDownloadWithCustomRequest() throws IOException {
92+
setUp();
7693
final String testDownloadFileId = "01RWFXFJG3UYRHE75RZVFYWKNUEBB53H7A";
7794
try (final InputStream stream = testBase.graphClient.customRequest("/me/drive/items/"+testDownloadFileId+"/content", InputStream.class).buildRequest().get()) {
7895
assertFalse(stream.read() == -1, "stream should not be empty");
7996
}
8097
}
8198
@Test
99+
@Disabled
82100
public void downloadJsonFileFromOneDrive() throws Exception {
101+
setUp();
83102
final DriveItemUploadableProperties item = new DriveItemUploadableProperties();
84103
item.name = "test.json";
85104
item.additionalDataManager().put("@microsoft.graph.conflictBehavior", new JsonPrimitive("replace"));

0 commit comments

Comments
 (0)