package org.callimachusproject.restapi;

import java.net.URLEncoder;

import org.callimachusproject.test.TemporaryServerIntegrationTestCase;
import org.junit.Ignore;
import org.junit.Test;

public class SparqlEndpointIntegrationTest extends TemporaryServerIntegrationTestCase {

	private static final String QUERY = "application/sparql-query";
	private static final String UPDATE = "application/sparql-update";
	private static final String URLENCODED = "application/x-www-form-urlencoded";
	private static final String RESULTS_XML = "application/sparql-results+xml";

	@Test
	public void testGetQueryParameter() throws Exception {
		String sparql = "ASK { ?s ?p ?o }";
		String encoded = URLEncoder.encode(sparql, "UTF-8");
		String results = new String(getHomeFolder().sparqlEndpoint().ref("?query=" + encoded).get(RESULTS_XML));
		assertTrue(results.contains("true"));
	}

	@Test
	public void testPostQueryForm() throws Exception {
		String sparql = "ASK { ?s ?p ?o }";
		String encoded = URLEncoder.encode(sparql, "UTF-8");
		String form = "query=" + encoded;
		String results = new String(getHomeFolder().sparqlEndpoint().post(URLENCODED, form.getBytes(), RESULTS_XML));
		assertTrue(results.contains("true"));
	}

	@Ignore
	@Test
	public void ignore_testPostQueryDirectly() throws Exception {
		String sparql = "ASK { ?s ?p ?o }";
		String encoded = URLEncoder.encode(sparql, "UTF-8");
		String results = new String(getHomeFolder().sparqlEndpoint().post(QUERY, encoded.getBytes(), RESULTS_XML));
		assertTrue(results.contains("true"));
	}

	@Test
	public void testPostUpdateForm() throws Exception {
		String sparql = "INSERT DATA { </> a </> }";
		String encoded = URLEncoder.encode(sparql, "UTF-8");
		String form = "update=" + encoded;
		getHomeFolder().sparqlEndpoint().post(URLENCODED, form.getBytes());
	}

	@Ignore
	@Test
	public void ignore_testPostUpdateDirectly() throws Exception {
		String sparql = "INSERT DATA { </> a </> }";
		String encoded = URLEncoder.encode(sparql, "UTF-8");
		getHomeFolder().sparqlEndpoint().post(UPDATE, encoded.getBytes());
	}

}

@@ -138,33 +138,8 @@
 se;%0A
-import org.junit.Ignore;%0A
 impo
@@ -1183,33 +1183,24 @@
 rue%22));%0A%09%7D%0A%0A
-%09@Ignore%0A
 %09@Test%0A%09publ
@@ -1199,39 +1199,32 @@
 st%0A%09public void 
-ignore_
 testPostQueryDir
@@ -1292,63 +1292,8 @@
 %7D%22;%0A
-%09%09String encoded = URLEncoder.encode(sparql, %22UTF-8%22);%0A
 %09%09St
@@ -1363,23 +1363,22 @@
 (QUERY, 
-encoded
+sparql
 .getByte
@@ -1718,17 +1718,8 @@
 %09%7D%0A%0A
-%09@Ignore%0A
 %09@Te
@@ -1738,15 +1738,8 @@
 oid 
-ignore_
 test
@@ -1829,63 +1829,8 @@
 %7D%22;%0A
-%09%09String encoded = URLEncoder.encode(sparql, %22UTF-8%22);%0A
 %09%09ge
@@ -1873,23 +1873,22 @@
 UPDATE, 
-encoded
+sparql
 .getByte

Enable sparql POST direct tests