|
1 | 1 | package com.microsoft.graph.functional; |
2 | 2 |
|
3 | 3 | import static org.junit.Assert.assertEquals; |
| 4 | +import static org.junit.Assert.assertNotNull; |
4 | 5 |
|
5 | 6 | import org.junit.Before; |
6 | 7 | import org.junit.Ignore; |
7 | 8 | import org.junit.Test; |
8 | 9 |
|
9 | 10 | import com.google.gson.JsonObject; |
| 11 | +import com.google.gson.JsonParser; |
| 12 | +import com.microsoft.graph.logger.DefaultLogger; |
10 | 13 | import com.microsoft.graph.models.extensions.User; |
| 14 | +import com.microsoft.graph.models.extensions.UserActivity; |
| 15 | +import com.microsoft.graph.serializer.DefaultSerializer; |
11 | 16 |
|
12 | 17 | /** |
13 | 18 | * Tests for sending custom requests using the SDK |
@@ -41,4 +46,34 @@ public void testCustomGet() { |
41 | 46 | assertEquals(meGraphService.displayName, meOriginal.displayName); |
42 | 47 | assertEquals(meJson.get("displayName").getAsString(), meOriginal.displayName); |
43 | 48 | } |
| 49 | + |
| 50 | + /** |
| 51 | + * Test PUT with a custom request for both serialized and JSON content |
| 52 | + */ |
| 53 | + @Test |
| 54 | + public void testCustomPut() { |
| 55 | + JsonParser parser = new JsonParser(); |
| 56 | + DefaultSerializer serializer = new DefaultSerializer(new DefaultLogger()); |
| 57 | + String str = "{ \"appActivityId\": \"/article?12345\", \"activitySourceHost\": \"https://www.contoso.com\", \"userTimezone\": \"Africa/Casablanca\"," |
| 58 | + + " \"appDisplayName\": \"Contoso, Ltd.\", \"activationUrl\": \"https://www.contoso.com/article?id=12345\", \"contentUrl\": \"https://www.contoso.com/article?id=12345\", " |
| 59 | + + "\"fallbackUrl\": \"https://www.contoso.com/article?id=12345\", \"contentInfo\": { \"@context\": \"https://schema.org\", \"@type\": \"Article\", \"author\": \"Jennifer Booth\", " |
| 60 | + + "\"name\": \"How to Tie a Reef Knot\" }, \"visualElements\": { \"attribution\": { \"iconUrl\": \"https://www.contoso.com/icon\", \"alternateText\": \"Contoso, Ltd.\", " |
| 61 | + + "\"addImageQuery\": false }, \"description\": \"How to Tie a Reef Knot. A step-by-step visual guide to the art of nautical knot-tying.\", \"backgroundColor\": \"#ff0000\"," |
| 62 | + + " \"displayText\": \"Contoso How-To: How to Tie a Reef Knot\", \"content\": { \"$schema\": \"https://adaptivecards.io/schemas/adaptive-card.json\", \"type\": \"AdaptiveCard\"," |
| 63 | + + " \"body\": [{ \"type\": \"TextBlock\", \"text\": \"Contoso MainPage\" }] } } }"; |
| 64 | + |
| 65 | + JsonObject response = testBase.graphClient. |
| 66 | + customRequest("/me/activities/%2Farticle%3F12346"). |
| 67 | + buildRequest(). |
| 68 | + put(parser.parse(str).getAsJsonObject()); |
| 69 | + |
| 70 | + UserActivity userActivity = serializer.deserializeObject(str, UserActivity.class); |
| 71 | + UserActivity responseWithClass = testBase.graphClient. |
| 72 | + customRequest("/me/activities/2", UserActivity.class). |
| 73 | + buildRequest(). |
| 74 | + put(userActivity); |
| 75 | + |
| 76 | + assertNotNull(response); |
| 77 | + assertNotNull(responseWithClass); |
| 78 | + } |
44 | 79 | } |
0 commit comments