Skip to content

Commit 253efb8

Browse files
committed
- adds unit test for batch support
1 parent a54a555 commit 253efb8

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.microsoft.graph.functional;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNotNull;
5+
6+
import java.io.IOException;
7+
8+
import com.microsoft.graph.content.MSBatchRequestContent;
9+
import com.microsoft.graph.http.HttpMethod;
10+
import com.microsoft.graph.httpcore.HttpClients;
11+
import com.microsoft.graph.httpcore.ICoreAuthenticationProvider;
12+
import com.microsoft.graph.models.extensions.IGraphServiceClient;
13+
import com.microsoft.graph.models.extensions.User;
14+
import com.microsoft.graph.requests.extensions.UserRequest;
15+
16+
import org.junit.Before;
17+
import org.junit.Ignore;
18+
import org.junit.Test;
19+
20+
import okhttp3.MediaType;
21+
import okhttp3.OkHttpClient;
22+
import okhttp3.Request;
23+
import okhttp3.RequestBody;
24+
import okhttp3.Response;
25+
26+
@Ignore
27+
public class BatchTests {
28+
IGraphServiceClient graphServiceClient = null;
29+
30+
@Before
31+
public void setUp() {
32+
final TestBase testBase = new TestBase();
33+
graphServiceClient = testBase.graphClient;
34+
}
35+
@Test
36+
public void GetsABatchFromRequests() throws IOException{
37+
final MSBatchRequestContent batchContent = new MSBatchRequestContent();
38+
final String meGetId = batchContent.addBatchRequestStep(graphServiceClient.me()
39+
.buildRequest()
40+
.withHttpMethod(HttpMethod.GET)
41+
.getHttpRequest());
42+
assertNotNull(meGetId);
43+
final String usersGetId = batchContent.addBatchRequestStep(graphServiceClient.users()
44+
.buildRequest()
45+
.filter("accountEnabled eq true")
46+
.expand("manager")
47+
.top(5)
48+
.withHttpMethod(HttpMethod.GET)
49+
.getHttpRequest(),
50+
meGetId);
51+
final User userToAdd = new User();
52+
userToAdd.givenName = "Darrel";
53+
final String userPostId = batchContent.addBatchRequestStep(graphServiceClient.users()
54+
.buildRequest()
55+
.withHttpMethod(HttpMethod.POST)
56+
.getHttpRequest(userToAdd), usersGetId);
57+
58+
final String serializedBatchContent = batchContent.getBatchRequestContent();
59+
60+
final Request batchRequest = new Request.Builder()
61+
.url("https://graph.microsoft.com/v1.0/$batch")
62+
.post(RequestBody.create(MediaType.parse("application/json"), serializedBatchContent))
63+
.build();
64+
65+
final OkHttpClient client = HttpClients.createDefault((ICoreAuthenticationProvider)graphServiceClient.getAuthenticationProvider());
66+
final Response batchResponse = client.newCall(batchRequest).execute();
67+
assertEquals(batchResponse.code(), 200);
68+
}
69+
}

0 commit comments

Comments
 (0)