forked from microsoftgraph/msgraph-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserTests.java
More file actions
242 lines (218 loc) · 8.21 KB
/
Copy pathUserTests.java
File metadata and controls
242 lines (218 loc) · 8.21 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
package com.microsoft.graph.functional;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import okhttp3.Request;
import com.microsoft.graph.http.HttpMethod;
import com.microsoft.graph.models.extensions.DirectoryObject;
import com.microsoft.graph.models.extensions.Drive;
import com.microsoft.graph.models.extensions.DriveItem;
import com.microsoft.graph.models.extensions.Group;
import com.microsoft.graph.models.extensions.IGraphServiceClient;
import com.microsoft.graph.models.extensions.ProfilePhoto;
import com.microsoft.graph.models.extensions.User;
import com.microsoft.graph.options.HeaderOption;
import com.microsoft.graph.options.Option;
import com.microsoft.graph.requests.extensions.IContactCollectionPage;
import com.microsoft.graph.requests.extensions.IDirectoryObjectCollectionWithReferencesPage;
import com.microsoft.graph.requests.extensions.IDriveItemCollectionPage;
import com.microsoft.graph.requests.extensions.IGroupCollectionPage;
import com.microsoft.graph.requests.extensions.IMailFolderCollectionPage;
import com.microsoft.graph.requests.extensions.IMessageCollectionPage;
import com.microsoft.graph.requests.extensions.IOrganizationCollectionPage;
import com.microsoft.graph.requests.extensions.IUsedInsightCollectionPage;
import com.microsoft.graph.requests.extensions.IUserCollectionPage;
import com.microsoft.graph.requests.extensions.IUserCollectionWithReferencesPage;
@Ignore
public class UserTests {
IGraphServiceClient graphServiceClient = null;
@Before
public void setUp() {
TestBase testBase = new TestBase();
graphServiceClient = testBase.graphClient;
}
@Test
public void getMeTest() {
//GET me
User user = graphServiceClient.me().buildRequest().get();
assertNotNull(user);
assertNotNull(user.displayName);
}
@Test
public void getMePhoto() {
//GET me/photo/$value
User user = graphServiceClient.me().buildRequest().get();
assertNotNull(user);
if(user.photo != null) {
InputStream stream = graphServiceClient.me().photo().content().buildRequest().get();
assertNotNull(stream);
}
}
@Test
public void meDriveTest() {
//GET me/drive/root/children
IDriveItemCollectionPage driveItemCollectionPage = graphServiceClient.me().drive().root().children().buildRequest().get();
assertNotNull(driveItemCollectionPage);
}
@Test
public void userKeyTest() {
//GET users('<<key>>')
IUserCollectionPage userCollectionPage = graphServiceClient.users().buildRequest().get();
assertNotNull(userCollectionPage);
assertNotNull(userCollectionPage.additionalDataManager().get("graphResponseHeaders"));
List<User> list = userCollectionPage.getCurrentPage();
if(list.size() > 0) {
User user = graphServiceClient.users(list.get(0).id).buildRequest().get();
assertNotNull(user);
}
}
@Test
public void meDriveRoot() {
//GET me/drive/root
DriveItem driveItem = graphServiceClient.me().drive().root().buildRequest().get();
assertNotNull(driveItem);
}
@Test
public void meDrive() {
//GET me/drive
Drive drive = graphServiceClient.me().drive().buildRequest().get();
assertNotNull(drive);
}
@Test
public void meDriveItems() {
//GET me/drive/items('<key>')
IDriveItemCollectionPage driveItemCollectionPage = graphServiceClient.me().drive().items().buildRequest().get();
assertNotNull(driveItemCollectionPage);
if(driveItemCollectionPage.getCurrentPage().size() > 0) {
DriveItem item = graphServiceClient.me().drive().items(driveItemCollectionPage.getCurrentPage().get(0).id).buildRequest().get();
assertNotNull(item);
}
}
@Test
public void meMessagesTest() {
//GET me/messages
IMessageCollectionPage messageCollectionPage = graphServiceClient.me().messages().buildRequest().get();
assertNotNull(messageCollectionPage);
}
@Test
public void meContactsTest() {
//GET me/contacts
IContactCollectionPage contactCollectionPage = graphServiceClient.me().contacts().buildRequest().get();
assertNotNull(contactCollectionPage);
}
@Test
public void usersKeyPhotoValueTest() {
//GET users('<<key>>')/photo/$value
IUserCollectionPage userCollectionPage = graphServiceClient.users().buildRequest().get();
for(User user:userCollectionPage.getCurrentPage()) {
if(user.photo!=null) {
InputStream stream = graphServiceClient.users(userCollectionPage.getCurrentPage().get(0).id).photo().content().buildRequest().get();
assertNotNull(stream);
break;
}
}
}
@Test
public void updateUserPhotoValueTest() throws Exception {
final File photo = new File("src/test/resources/hamilton.jpg");
final InputStream fileStream = new FileInputStream(photo);
graphServiceClient.me().photo().content().buildRequest().put(OutlookTests.getByteArray(fileStream));
}
@Test
public void getOrganization() {
//GET organization
IOrganizationCollectionPage organizationCollectionPage = graphServiceClient.organization().buildRequest().get();
assertNotNull(organizationCollectionPage);
}
@Test
public void meInsightsUsed() {
//GET me/insights/used
IUsedInsightCollectionPage usedInsightCollectionPage = graphServiceClient.me().insights().used().buildRequest().get();
assertNotNull(usedInsightCollectionPage);
}
@Test
public void mailFoldertest() {
//GET me/mailFolders
IMailFolderCollectionPage mailFolderCollectionPage = graphServiceClient.me().mailFolders().buildRequest().get();
assertNotNull(mailFolderCollectionPage);
if(mailFolderCollectionPage.getCurrentPage().size() > 0) {
String mailFolderId = mailFolderCollectionPage.getCurrentPage().get(0).id;
IMessageCollectionPage messageCollectionPage = graphServiceClient.me().mailFolders(mailFolderId).messages().buildRequest().get();
assertNotNull(messageCollectionPage);
}
}
@Test
public void meMemberof() {
IDirectoryObjectCollectionWithReferencesPage page = graphServiceClient.me().memberOf().buildRequest().get();
assertNotNull(page);
}
@Test
public void getMeAndRetryOnThrottling() throws Exception {
ExecutorService exec = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
try {
for(Integer i = 0; i < 2000; i++) {
exec.submit(new Runnable() {
@Override
public void run() {
final IUserCollectionPage users = graphServiceClient.users().buildRequest().get();
assertNotNull(users);
final List<User> currentPage = users.getCurrentPage();
assertNotNull(currentPage);
assertNotEquals(0, currentPage.size());
}
});
}
exec.awaitTermination(5L, TimeUnit.MINUTES);
} finally {
exec.shutdown();
}
}
@Test
public void emptyPostContentType() {
final String contentTypeValue = "application/json";
final HeaderOption ctype = new HeaderOption("Content-Type", contentTypeValue);
final ArrayList<Option> options = new ArrayList<>();
options.add(ctype);
final Request request = graphServiceClient.me()
.revokeSignInSessions()
.buildRequest(options)
.withHttpMethod(HttpMethod.POST)
.getHttpRequest();
assertEquals(contentTypeValue, request.body().contentType().toString());
}
@Test
public void castTest() {
final IGroupCollectionPage groups = graphServiceClient.groups().buildRequest().top(1).get();
final Group group = groups.getCurrentPage().get(0);
final IUserCollectionWithReferencesPage usersPage = graphServiceClient
.groups(group.id)
.membersAsUser()
.buildRequest()
.get();
assertNotNull(usersPage);
final IDirectoryObjectCollectionWithReferencesPage testUserCollection = graphServiceClient
.groups(group.id)
.members()
.buildRequest()
.top(1)
.get();
final DirectoryObject testUser = testUserCollection.getCurrentPage().get(0);
final User user = graphServiceClient
.groups(group.id)
.membersAsUser(testUser.id)
.buildRequest()
.get();
assertNotNull(user);
}
}