-
Notifications
You must be signed in to change notification settings - Fork 19
/
TestCases.java
131 lines (104 loc) · 4.26 KB
/
TestCases.java
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package com.bhyoo.onedrive;
import com.bhyoo.onedrive.client.Client;
import com.bhyoo.onedrive.container.AsyncJobMonitor;
import com.bhyoo.onedrive.container.AsyncJobStatus;
import com.bhyoo.onedrive.container.items.DriveItem;
import com.bhyoo.onedrive.container.items.FileItem;
import com.bhyoo.onedrive.container.items.FolderItem;
import com.bhyoo.onedrive.container.items.pointer.PathPointer;
import com.bhyoo.onedrive.exceptions.ErrorResponseException;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import static org.junit.jupiter.api.Assertions.*;
class TestCases {
private static final String TEST_DIR_NAME = "___for_test";
private static Client client;
@BeforeAll
static void getClient() {
assertNull(client);
final String clientId = "0c4b69a8-adac-4ec1-b310-6c28ff9fa263";
final String[] scope = {"files.readwrite.all", "offline_access"};
final String redirectURL = "http://localhost:8080/";
final String clientSecret = "iqggDGYW25$;#$otqVUH024";
client = new Client(clientId, scope, redirectURL, clientSecret);
assertNotNull(client);
assertTrue(client.isLogin());
assertFalse(client.isExpired());
System.out.println(client.getFullToken());
assertNotNull(client.getAccessToken());
assertNotNull(client.getAuthCode());
assertNotNull(client.getClientId());
assertNotNull(client.getClientSecret());
assertNotNull(client.getFullToken());
assertNotNull(client.getRedirectURL());
assertNotNull(client.getRefreshToken());
assertNotNull(client.getTokenType());
assertArrayEquals(client.getScopes(), scope);
assertNotEquals(client.getExpirationTime(), 0L);
}
@AfterAll
static void logout() throws ErrorResponseException {
assertNotNull(client);
assertTrue(client.isLogin());
client.deleteItem(PathPointer.root.resolve(TEST_DIR_NAME));
client.logout();
assertFalse(client.isLogin());
}
/**
* Scenario:
* <p>
* 1. create a directory on root dir
* 2. upload an audio file to the dir
* 3. rename the file
* 4. copy the file to same directory with another name
*/
@Test
void createDirAndUpload() throws ErrorResponseException, URISyntaxException {
// Create directory '___for_test' in root directory of default drive of current account
FolderItem testDir = client.createFolder(PathPointer.root, TEST_DIR_NAME);
assertEquals(TEST_DIR_NAME, testDir.getName());
assertEquals(
new PathPointer("/" + TEST_DIR_NAME, testDir.getDriveId()).toASCIIApi(),
testDir.getPathPointer().toASCIIApi());
assertEquals(0L, testDir.getSize().longValue());
assertFalse(testDir.isDeleted());
assertFalse(testDir.isRoot());
assertFalse(testDir.isSpecial());
assertArrayEquals(new DriveItem[0], testDir.allChildren());
URL resource = ClassLoader.getSystemClassLoader().getResource("SampleAudio_0.7mb.mp3");
assertNotNull(resource);
Path path = Paths.get(resource.toURI());
// Upload local file to '___for_test' asynchronously
FileItem uploaded = (FileItem) testDir.simpleUploadFileAsync(path).awaitUninterruptibly().getNow();
assertNotNull(uploaded);
assertEquals("SampleAudio_0.7mb.mp3", uploaded.getName());
assertEquals(TEST_DIR_NAME, uploaded.getParentReference().getPathPointer().getName());
// Rename the uploaded file to 'modified.mp3'
uploaded.rename("modified.mp3");
assertNotNull(uploaded);
assertEquals("modified.mp3", uploaded.getName());
// Copy the uploaded file to same directory with another name 'copied.mp3'
@NotNull AsyncJobMonitor monitor = uploaded.copyTo(testDir, "copied.mp3");
System.out.println(monitor.getPercentageComplete());
// Wait until copy job is done
while (monitor.getStatus() != AsyncJobStatus.COMPLETED) {
monitor.update();
System.out.println(monitor.getPercentageComplete());
}
assertTrue(testDir.isChildrenFetched());
assertEquals(0, testDir.childCount());
// Update children info `testDir`
testDir.fetchChildren();
assertTrue(testDir.isChildrenFetched());
assertEquals(2, testDir.allChildren().length);
for (DriveItem item : testDir.allChildren()) {
assertTrue(item.getName().equals("copied.mp3") || item.getName().equals("modified.mp3"));
}
}
}