Skip to content

Commit 0fd72e6

Browse files
authored
Merge pull request #206 from microsoftgraph/custom-request-fix
Put added in custom request.
2 parents 0716af4 + cbbfbf6 commit 0fd72e6

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/main/java/com/microsoft/graph/http/CustomRequest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,27 @@ public void post(final T newObject, final ICallback<T> callback) {
105105
public T post(final T newObject) throws ClientException {
106106
return send(HttpMethod.POST, newObject);
107107
}
108+
109+
/**
110+
* Creates a new object
111+
*
112+
* @param putObject the new object to create
113+
* @param callback the callback to be called after success or failure
114+
*/
115+
public void put(final T putObject, final ICallback<T> callback) {
116+
send(HttpMethod.PUT, callback, putObject);
117+
}
118+
119+
/**
120+
* Creates a new object
121+
*
122+
* @param putObject the new object to create
123+
* @return the created object
124+
* @throws ClientException this exception occurs if the request was unable to complete for any reason
125+
*/
126+
public T put(final T putObject) throws ClientException {
127+
return send(HttpMethod.PUT, putObject);
128+
}
108129

109130
/**
110131
* Sets the select clause for the request

src/test/java/com/microsoft/graph/functional/CustomRequestTests.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package com.microsoft.graph.functional;
22

33
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNotNull;
45

56
import org.junit.Before;
67
import org.junit.Ignore;
78
import org.junit.Test;
89

910
import com.google.gson.JsonObject;
11+
import com.google.gson.JsonParser;
12+
import com.microsoft.graph.logger.DefaultLogger;
1013
import com.microsoft.graph.models.extensions.User;
14+
import com.microsoft.graph.models.extensions.UserActivity;
15+
import com.microsoft.graph.serializer.DefaultSerializer;
1116

1217
/**
1318
* Tests for sending custom requests using the SDK
@@ -41,4 +46,34 @@ public void testCustomGet() {
4146
assertEquals(meGraphService.displayName, meOriginal.displayName);
4247
assertEquals(meJson.get("displayName").getAsString(), meOriginal.displayName);
4348
}
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+
}
4479
}

0 commit comments

Comments
 (0)