Skip to content

Commit 61cdf2b

Browse files
author
Nakul Sabharwal
committed
Put added in custom request.
1 parent c728b7e commit 61cdf2b

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
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;
1012
import com.microsoft.graph.models.extensions.User;
1113

1214
/**
@@ -41,4 +43,22 @@ public void testCustomGet() {
4143
assertEquals(meGraphService.displayName, meOriginal.displayName);
4244
assertEquals(meJson.get("displayName").getAsString(), meOriginal.displayName);
4345
}
46+
47+
/**
48+
* Test PUT with a custom request for both serialized and JSON content
49+
*/
50+
@Test
51+
public void testCustomPut() {
52+
JsonParser parser = new JsonParser();
53+
String str = "{ \"appActivityId\": \"/article?12345\", \"activitySourceHost\": \"https://www.contoso.com\", \"userTimezone\": \"Africa/Casablanca\","
54+
+ " \"appDisplayName\": \"Contoso, Ltd.\", \"activationUrl\": \"https://www.contoso.com/article?id=12345\", \"contentUrl\": \"https://www.contoso.com/article?id=12345\", "
55+
+ "\"fallbackUrl\": \"https://www.contoso.com/article?id=12345\", \"contentInfo\": { \"@context\": \"https://schema.org\", \"@type\": \"Article\", \"author\": \"Jennifer Booth\", "
56+
+ "\"name\": \"How to Tie a Reef Knot\" }, \"visualElements\": { \"attribution\": { \"iconUrl\": \"https://www.contoso.com/icon\", \"alternateText\": \"Contoso, Ltd.\", "
57+
+ "\"addImageQuery\": false }, \"description\": \"How to Tie a Reef Knot. A step-by-step visual guide to the art of nautical knot-tying.\", \"backgroundColor\": \"#ff0000\","
58+
+ " \"displayText\": \"Contoso How-To: How to Tie a Reef Knot\", \"content\": { \"$schema\": \"https://adaptivecards.io/schemas/adaptive-card.json\", \"type\": \"AdaptiveCard\","
59+
+ " \"body\": [{ \"type\": \"TextBlock\", \"text\": \"Contoso MainPage\" }] } } }";
60+
61+
JsonObject response = testBase.graphClient.customRequest("/me/activities/%2Farticle%3F12346").buildRequest().put(parser.parse(str).getAsJsonObject());
62+
assertNotNull(response);
63+
}
4464
}

0 commit comments

Comments
 (0)