This repository was archived by the owner on Jan 6, 2026. It is now read-only.
forked from microsoftgraph/msgraph-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOneDriveTests.java
More file actions
81 lines (68 loc) · 2.42 KB
/
Copy pathOneDriveTests.java
File metadata and controls
81 lines (68 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.microsoft.graph.functional;
import java.io.IOException;
import java.io.InputStream;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import com.microsoft.graph.concurrency.ChunkedUploadProvider;
import com.microsoft.graph.concurrency.IProgressCallback;
import com.microsoft.graph.core.ClientException;
import com.microsoft.graph.models.extensions.DriveItem;
import com.microsoft.graph.models.extensions.DriveItemUploadableProperties;
import com.microsoft.graph.models.extensions.UploadSession;
@Ignore
public class OneDriveTests {
private TestBase testBase;
@Before
public void setUp() {
testBase = new TestBase();
}
/**
* Test large file upload.
* https://github.com/OneDrive/onedrive-sdk-csharp/blob/master/docs/chunked-uploads.md
*
* @throws IOException if the input file is not found
* @throws InterruptedException if the chunked upload fails
*/
@Test
public void testLargeFileUpload() throws IOException, InterruptedException {
String itemId = "01BQHXQL5GQVAGCFJLYRH3EAG2YHGERMQA"; //Test upload folder
//Get resource file from file system
InputStream uploadFile = OneDriveTests.class.getClassLoader().getResourceAsStream("hamilton.jpg");
int fileSize = uploadFile.available();
IProgressCallback<DriveItem> callback = new IProgressCallback<DriveItem> () {
@Override
public void progress(final long current, final long max) {
//Check progress
}
@Override
public void success(final DriveItem result) {
//Handle the successful response
String finishedItemId = result.id;
Assert.assertNotNull(finishedItemId);
}
@Override
public void failure(final ClientException ex) {
//Handle the failed upload
Assert.fail("Upload session failed");
}
};
UploadSession uploadSession = testBase
.graphClient
.me()
.drive()
.items(itemId)
.itemWithPath("_hamilton.jpg")
.createUploadSession(new DriveItemUploadableProperties())
.buildRequest()
.post();
ChunkedUploadProvider<DriveItem> chunkedUploadProvider = new ChunkedUploadProvider<DriveItem>(
uploadSession,
testBase.graphClient,
uploadFile,
fileSize,
DriveItem.class);
chunkedUploadProvider.upload(callback);
}
}