package com.github.timtebeek.graphql.jpa;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;

import graphql.ExecutionResult;
import org.crygier.graphql.GraphQLExecutor;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import com.github.timtebeek.graphql.jpa.model.Book;

@RunWith(SpringRunner.class)
@SpringBootTest
public class GraphQLExecutorTest {
	private static final String	WAR_AND_PEACE	= "War and Peace";

	@Autowired
	EntityManager				em;
	@Autowired
	GraphQLExecutor				graphqlExecutor;

	@Test
	public void getBook() {
		Book book = em.find(Book.class, Long.valueOf(2));
		Assert.assertNotNull(book);
		Assert.assertEquals(WAR_AND_PEACE, book.getTitle());
	}

	@Test
	@SuppressWarnings("unchecked")
	public void query() {
		ExecutionResult result = graphqlExecutor.execute("{Book(title: \"" + WAR_AND_PEACE + "\"){title genre}}");
		Assert.assertTrue(result.getErrors().toString(), result.getErrors().isEmpty());
		Assert.assertEquals(WAR_AND_PEACE, ((Map<String, List<Map<String, Object>>>) result.getData()).get("Book").get(0).get("title"));
		Assert.assertEquals("{Book=[{title=War and Peace, genre=NOVEL}]}", result.getData().toString());
	}

	@Test
	@SuppressWarnings("unchecked")
	public void queryArguments() {
		Map<String, Object> args = new HashMap<>();
		args.put("title", WAR_AND_PEACE);
		String query = "query BookQuery($title: String!){Book(title: $title){title genre}}";
		ExecutionResult result = graphqlExecutor.execute(query, args);
		Assert.assertTrue(result.getErrors().toString(), result.getErrors().isEmpty());
		Assert.assertEquals(WAR_AND_PEACE, ((Map<String, List<Map<String, Object>>>) result.getData()).get("Book").get(0).get("title"));
		Assert.assertEquals("{Book=[{title=War and Peace, genre=NOVEL}]}", result.getData().toString());
	}

	@Test
	@SuppressWarnings("unchecked")
	public void queryArgumentsLongId() {
		Map<String, Object> args = new HashMap<>();
		args.put("bookid", Long.valueOf(2));
		String query = "query BookQuery($bookid: Long!){Book(id: $bookid){title genre}}";
		ExecutionResult result = graphqlExecutor.execute(query, args);
		Assert.assertTrue(result.getErrors().toString(), result.getErrors().isEmpty());
		Assert.assertEquals(WAR_AND_PEACE, ((Map<String, List<Map<String, Object>>>) result.getData()).get("Book").get(0).get("title"));
		Assert.assertEquals("{Book=[{title=War and Peace, genre=NOVEL}]}", result.getData().toString());
	}
}

@@ -2055,634 +2055,7 @@
 ;%0A%09%7D
-%0A%0A%09@Test%0A%09@SuppressWarnings(%22unchecked%22)%0A%09public void queryArgumentsLongId() %7B%0A%09%09Map%3CString, Object%3E args = new HashMap%3C%3E();%0A%09%09args.put(%22bookid%22, Long.valueOf(2));%0A%09%09String query = %22query BookQuery($bookid: Long!)%7BBook(id: $bookid)%7Btitle genre%7D%7D%22;%0A%09%09ExecutionResult result = graphqlExecutor.execute(query, args);%0A%09%09Assert.assertTrue(result.getErrors().toString(), result.getErrors().isEmpty());%0A%09%09Assert.assertEquals(WAR_AND_PEACE, ((Map%3CString, List%3CMap%3CString, Object%3E%3E%3E) result.getData()).get(%22Book%22).get(0).get(%22title%22));%0A%09%09Assert.assertEquals(%22%7BBook=%5B%7Btitle=War and Peace, genre=NOVEL%7D%5D%7D%22, result.getData().toString());%0A%09%7D
 %0A%7D%0A

Drop queryArgumentsLongId while issue is outstanding upstream