|
5 | 5 |
|
6 | 6 | import java.io.IOException; |
7 | 7 |
|
8 | | -import com.microsoft.graph.content.MSBatchRequestContent; |
9 | | -import com.microsoft.graph.content.MSBatchResponseContent; |
| 8 | +import com.microsoft.graph.content.BatchRequestContent; |
| 9 | +import com.microsoft.graph.content.BatchResponseContent; |
10 | 10 | import com.microsoft.graph.http.HttpMethod; |
11 | 11 | import com.microsoft.graph.httpcore.HttpClients; |
12 | 12 | import com.microsoft.graph.requests.GraphServiceClient; |
|
17 | 17 | import org.junit.jupiter.api.Disabled; |
18 | 18 | import org.junit.jupiter.api.Test; |
19 | 19 |
|
20 | | -import okhttp3.MediaType; |
21 | | -import okhttp3.OkHttpClient; |
22 | | -import okhttp3.Request; |
23 | | -import okhttp3.RequestBody; |
24 | | -import okhttp3.Response; |
25 | | - |
26 | 20 | @Disabled |
27 | 21 | public class BatchTests { |
28 | 22 | @Test |
29 | 23 | public void GetsABatchFromRequests() throws IOException{ |
30 | 24 | final TestBase testBase = new TestBase(); |
31 | | - final GraphServiceClient graphServiceClient = testBase.graphClient; |
32 | | - final MSBatchRequestContent batchContent = new MSBatchRequestContent(); |
| 25 | + final GraphServiceClient graphServiceClient = testBase.graphClient; |
| 26 | + final BatchRequestContent batchContent = new BatchRequestContent(); |
33 | 27 | final String meGetId = batchContent.addBatchRequestStep(graphServiceClient.me() |
34 | | - .buildRequest() |
35 | | - .withHttpMethod(HttpMethod.GET) |
36 | | - .getHttpRequest()); |
| 28 | + .buildRequest()); |
37 | 29 | assertNotNull(meGetId); |
38 | 30 | final String usersGetId = batchContent.addBatchRequestStep(graphServiceClient.users() |
39 | 31 | .buildRequest() |
40 | 32 | .filter("accountEnabled eq true") |
41 | 33 | .expand("manager") |
42 | | - .top(5) |
43 | | - .withHttpMethod(HttpMethod.GET) |
44 | | - .getHttpRequest(), |
| 34 | + .top(5), |
| 35 | + HttpMethod.GET, |
| 36 | + null, |
45 | 37 | meGetId); |
46 | 38 | final User userToAdd = new User(); |
47 | 39 | userToAdd.givenName = "Darrel"; |
48 | 40 | final String userPostId = batchContent.addBatchRequestStep(graphServiceClient.users() |
49 | | - .buildRequest() |
50 | | - .withHttpMethod(HttpMethod.POST) |
51 | | - .getHttpRequest(userToAdd), usersGetId); |
52 | | - |
53 | | - final String serializedBatchContent = batchContent.getBatchRequestContent(); |
54 | | - |
55 | | - final Request batchRequest = new Request.Builder() |
56 | | - .url("https://graph.microsoft.com/v1.0/$batch") |
57 | | - .post(RequestBody.create(serializedBatchContent, MediaType.parse("application/json"))) |
58 | | - .build(); |
59 | | - |
60 | | - final OkHttpClient client = HttpClients.createDefault(testBase.getAuthenticationProvider()); |
61 | | - try (final Response batchResponse = client.newCall(batchRequest).execute()) { |
62 | | - assertEquals(200, batchResponse.code()); |
63 | | - |
64 | | - final MSBatchResponseContent responseContent = new MSBatchResponseContent(batchResponse); |
65 | | - assertEquals(400, responseContent.getResponseById(userPostId).code()); //400:we're not providing enough properties for the call to go through |
66 | | - assertEquals(200, responseContent.getResponseById(meGetId).code()); |
67 | | - assertEquals(200, responseContent.getResponseById(usersGetId).code()); |
68 | | - } |
| 41 | + .buildRequest(), |
| 42 | + HttpMethod.POST, |
| 43 | + userToAdd, |
| 44 | + usersGetId); |
| 45 | + |
| 46 | + final BatchResponseContent responseContent = testBase.graphClient.batch().buildRequest().post(batchContent); |
| 47 | + assertEquals(400, responseContent.getResponseById(userPostId).status); //400:we're not providing enough properties for the call to go through |
| 48 | + assertEquals(200, responseContent.getResponseById(meGetId).status); |
| 49 | + assertEquals(200, responseContent.getResponseById(usersGetId).status); |
| 50 | + final User me = responseContent.getResponseById(meGetId).getDeserializedBody(User.class); |
| 51 | + assertNotNull(me.displayName); |
69 | 52 | } |
70 | 53 | } |
0 commit comments