package com.microsoft.graph.functional;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.microsoft.graph.models.extensions.User;

/**
 * Tests for sending custom requests using the SDK
 */
@Ignore
public class CustomRequestTests {
	private TestBase testBase;

	@Before
	public void setUp() {
		testBase = new TestBase();
	}

	/**
	 * Test GET with a custom request for both serialized and JSON content
	 */
	@Test
	public void testCustomGet() {
		User meOriginal = testBase.graphClient.me().buildRequest().get();

		User meGraphService = testBase.graphClient
				.customRequest("/me", User.class)
				.buildRequest()
				.get();

		JsonObject meJson = testBase.graphClient
				.customRequest("/me")
				.buildRequest()
				.get();

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

@@ -301,28 +301,193 @@
 aph.
-models.extensions.Us
+logger.DefaultLogger;%0Aimport com.microsoft.graph.models.extensions.User;%0Aimport com.microsoft.graph.models.extensions.UserActivity;%0Aimport com.microsoft.graph.serializer.DefaultSerializ
 er;%0A
@@ -1404,16 +1404,93 @@
 rser();%0A
+%09%09DefaultSerializer serializer = new DefaultSerializer(new DefaultLogger());%0A
 %09%09String
@@ -2667,16 +2667,21 @@
 hClient.
+%0A%09%09%09%09
 customRe
@@ -2723,16 +2723,21 @@
 12346%22).
+%0A%09%09%09%09
 buildReq
@@ -2743,16 +2743,21 @@
 quest().
+%0A%09%09%09%09
 put(pars
@@ -2796,30 +2796,317 @@
 ;%0A%09%09
-assertNotNull(response
+%0A%09%09UserActivity userActivity = serializer.deserializeObject(str, UserActivity.class); %0A%09%09UserActivity responseWithClass = testBase.graphClient.%0A%09%09%09%09customRequest(%22/me/activities/2%22, UserActivity.class).%0A%09%09%09%09buildRequest().%0A%09%09%09%09put(userActivity);%0A%09%09%0A%09%09assertNotNull(response);%0A%09%09assertNotNull(responseWithClass
 );%0A%09

Test for both put functions