Strabon
changeset 1010:34a6c207f0d3
changed StrabonEndpoint to SPARQLEndpoint, added SpatialEndpoint to support KML format for all spatial endpoints (Virtuoso, Parliament, Strabon), added tests for SpatialEndpoint, tests for SPARQLEndpoint with Parliament and Virtuoso. Tests need to be added for Virtuoso endpoint to test which formats are not supported
line diff
1.1 --- a/endpoint-client/pom.xml Sat Apr 06 15:55:32 2013 +0300 1.2 +++ b/endpoint-client/pom.xml Sat Apr 06 18:05:36 2013 +0300 1.3 @@ -37,6 +37,12 @@ 1.4 <artifactId>junit</artifactId> 1.5 <scope>test</scope> 1.6 </dependency> 1.7 + <dependency> 1.8 + <groupId>org.openrdf.sesame</groupId> 1.9 + <artifactId> 1.10 + sesame-queryresultio-spatial-sparqlkml 1.11 + </artifactId> 1.12 + </dependency> 1.13 </dependencies> 1.14 1.15 <build>
2.1 --- a/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/Endpoint.java Sat Apr 06 15:55:32 2013 +0300 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,72 +0,0 @@ 2.4 -/** 2.5 - * This Source Code Form is subject to the terms of the Mozilla Public 2.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 2.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 2.8 - * 2.9 - * Copyright (C) 2013, Pyravlos Team 2.10 - * 2.11 - * http://www.strabon.di.uoa.gr/ 2.12 - */ 2.13 -package eu.earthobservatory.org.StrabonEndpoint.client; 2.14 - 2.15 -import java.io.IOException; 2.16 -import java.net.URL; 2.17 - 2.18 -import org.openrdf.query.resultio.TupleQueryResultFormat; 2.19 -import org.openrdf.rio.RDFFormat; 2.20 - 2.21 -/** 2.22 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 2.23 - * 2.24 - */ 2.25 -public interface Endpoint<T extends TupleQueryResultFormat> { 2.26 - /** 2.27 - * Executes a SPARQL query on the Endpoint and get the results 2.28 - * in the format specified by <code>T</code>. Format <code>T</code> 2.29 - * should be an instance of class (or a subclass) {@link TupleQueryResultFormat}. 2.30 - * 2.31 - * @param sparqlQuery 2.32 - * @param format 2.33 - * @return 2.34 - * @throws IOException 2.35 - */ 2.36 - public EndpointResult query(String sparqlQuery, T format) throws IOException; 2.37 - 2.38 - /** 2.39 - * Stores the RDF <code>data</code> which are in the RDF format 2.40 - * <code>format</code> in the named graph specified by the URL 2.41 - * <code>namedGraph</code>. 2.42 - * 2.43 - * @param data 2.44 - * @param format 2.45 - * @param namedGraph 2.46 - * @return <code>true</code> if store was successful, <code>false</code> otherwise 2.47 - */ 2.48 - public boolean store(String data, RDFFormat format, URL namedGraph); 2.49 - 2.50 - /** 2.51 - * Stores the RDF data located at <code>data</code> which are in the 2.52 - * RDF format <code>format</code> in the named graph specified by the 2.53 - * URL <code>namedGraph</code>. 2.54 - * 2.55 - * @param data 2.56 - * @param format 2.57 - * @param namedGraph 2.58 - * @return <code>true</code> if store was successful, <code>false</code> otherwise 2.59 - */ 2.60 - public boolean store(URL data, RDFFormat format, URL namedGraph); 2.61 - 2.62 - /** 2.63 - * Executes the SPARQL Update query specified in <code>sparqlUpdate</code>. 2.64 - * 2.65 - * @param sparqlUpdate 2.66 - * @return <code>true</code> if store was successful, <code>false</code> otherwise 2.67 - */ 2.68 - public boolean update(String sparqlUpdate); 2.69 - 2.70 - public EndpointResult describe(String sparqlDescribe); 2.71 - 2.72 - public EndpointResult construct(String sparqlConstruct); 2.73 - 2.74 - public EndpointResult ask(String sparqlAsk); 2.75 -}
3.1 --- a/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/EndpointResult.java Sat Apr 06 15:55:32 2013 +0300 3.2 +++ b/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/EndpointResult.java Sat Apr 06 18:05:36 2013 +0300 3.3 @@ -13,23 +13,27 @@ 3.4 * @author Charalampos Nikolaou <charnik@di.uoa.gr> 3.5 * 3.6 */ 3.7 -public interface EndpointResult { 3.8 +public class EndpointResult { 3.9 3.10 - /** 3.11 - * Returns the HTTP status code as returned by the endpoint. 3.12 - * @return 3.13 - */ 3.14 - public int getStatusCode(); 3.15 + private int statusCode; 3.16 + private String statusText; 3.17 + private String response; 3.18 3.19 - /** 3.20 - * Returns the status text corresponding to the status code. 3.21 - * @return 3.22 - */ 3.23 - public String getStatusText(); 3.24 + public EndpointResult(int statusCode, String statusLine, String response) { 3.25 + this.statusCode = statusCode; 3.26 + this.statusText = statusLine; 3.27 + this.response = response; 3.28 + } 3.29 3.30 - /** 3.31 - * Returns the response of the endpoint. 3.32 - * @return 3.33 - */ 3.34 - public String getResponse(); 3.35 + public int getStatusCode() { 3.36 + return statusCode; 3.37 + } 3.38 + 3.39 + public String getStatusText() { 3.40 + return statusText; 3.41 + } 3.42 + 3.43 + public String getResponse() { 3.44 + return response; 3.45 + } 3.46 }
4.1 --- a/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/HTTPClient.java Sat Apr 06 15:55:32 2013 +0300 4.2 +++ b/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/HTTPClient.java Sat Apr 06 18:05:36 2013 +0300 4.3 @@ -33,7 +33,7 @@ 4.4 /** 4.5 * The name of the endpoint. 4.6 * 4.7 - * This is useful for {@link StrabonEndpoint} instances that are usually 4.8 + * This is useful for {@link SPARQLEndpoint} instances that are usually 4.9 * deployed in a tomcat container as web applications. 4.10 */ 4.11 protected String endpointName;
5.1 --- a/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SPARQLEndpoint.java Sat Apr 06 15:55:32 2013 +0300 5.2 +++ b/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SPARQLEndpoint.java Sat Apr 06 18:05:36 2013 +0300 5.3 @@ -3,23 +3,39 @@ 5.4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5.5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5.6 * 5.7 - * Copyright (C) 2013, Pyravlos Team 5.8 + * Copyright (C) 2012, Pyravlos Team 5.9 * 5.10 * http://www.strabon.di.uoa.gr/ 5.11 */ 5.12 package eu.earthobservatory.org.StrabonEndpoint.client; 5.13 5.14 +import java.io.BufferedReader; 5.15 import java.io.IOException; 5.16 +import java.io.InputStream; 5.17 +import java.io.InputStreamReader; 5.18 import java.net.URL; 5.19 +import java.nio.charset.Charset; 5.20 +import java.util.ArrayList; 5.21 +import java.util.List; 5.22 5.23 +import org.apache.http.HttpEntity; 5.24 +import org.apache.http.HttpResponse; 5.25 +import org.apache.http.NameValuePair; 5.26 +import org.apache.http.client.entity.UrlEncodedFormEntity; 5.27 +import org.apache.http.client.methods.HttpPost; 5.28 +import org.apache.http.message.BasicNameValuePair; 5.29 import org.openrdf.query.resultio.TupleQueryResultFormat; 5.30 +import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 5.31 import org.openrdf.rio.RDFFormat; 5.32 5.33 /** 5.34 + * This class is the implementation of a java client for accessing 5.35 + * SPARQLEndpoint instances. 5.36 + * 5.37 * @author Charalampos Nikolaou <charnik@di.uoa.gr> 5.38 - * 5.39 + * @author Kallirroi Dogani <kallirroi@di.uoa.gr. 5.40 */ 5.41 -public class SPARQLEndpoint extends HTTPClient implements Endpoint<TupleQueryResultFormat> { 5.42 +public class SPARQLEndpoint extends HTTPClient{ 5.43 5.44 public SPARQLEndpoint(String host, int port) { 5.45 super(host, port); 5.46 @@ -29,38 +45,186 @@ 5.47 super(host, port, endpointName); 5.48 } 5.49 5.50 - @Override 5.51 - public EndpointResult query(String sparqlQuery, TupleQueryResultFormat format) throws IOException { 5.52 - throw new UnsupportedOperationException(); 5.53 + 5.54 + /** 5.55 + * Executes a SPARQL query on the Endpoint and get the results 5.56 + * in the format specified by stSPARQLQueryResultFormat, which is 5.57 + * an instance of class (or a subclass) {@link TupleQueryResultFormat}. 5.58 + * 5.59 + * @param sparqlQuery 5.60 + * @param format 5.61 + * @return 5.62 + * @throws IOException 5.63 + */ 5.64 + public EndpointResult query(String sparqlQuery, stSPARQLQueryResultFormat format) throws IOException { 5.65 + assert(format != null); 5.66 + 5.67 + // create a post method to execute 5.68 + HttpPost method = new HttpPost(getConnectionURL()); 5.69 + 5.70 + // set the query parameter 5.71 + List<NameValuePair> params = new ArrayList<NameValuePair>(); 5.72 + params.add(new BasicNameValuePair("query", sparqlQuery)); 5.73 + UrlEncodedFormEntity encodedEntity = new UrlEncodedFormEntity(params, Charset.defaultCharset()); 5.74 + method.setEntity(encodedEntity); 5.75 + 5.76 + // set the content type 5.77 + method.setHeader("Content-Type", "application/x-www-form-urlencoded"); 5.78 + 5.79 + // set the accept format 5.80 + method.addHeader("Accept", format.getDefaultMIMEType()); 5.81 + 5.82 + try { 5.83 + // response that will be filled next 5.84 + String responseBody = ""; 5.85 + 5.86 + // execute the method 5.87 + HttpResponse response = hc.execute(method); 5.88 + int statusCode = response.getStatusLine().getStatusCode(); 5.89 + 5.90 + // If the response does not enclose an entity, there is no need 5.91 + // to worry about connection release 5.92 + HttpEntity entity = response.getEntity(); 5.93 + if (entity != null) { 5.94 + InputStream instream = entity.getContent(); 5.95 + try { 5.96 + 5.97 + BufferedReader reader = new BufferedReader(new InputStreamReader(instream)); 5.98 + StringBuffer strBuf = new StringBuffer(); 5.99 + 5.100 + // do something useful with the response 5.101 + String nextLine; 5.102 + while ((nextLine = reader.readLine()) != null) { 5.103 + strBuf.append(nextLine + "\n"); 5.104 + } 5.105 + 5.106 + // remove last newline character 5.107 + if (strBuf.length() > 0) { 5.108 + strBuf.setLength(strBuf.length() - 1); 5.109 + } 5.110 + 5.111 + responseBody = strBuf.toString(); 5.112 + 5.113 + } catch (IOException ex) { 5.114 + // In case of an IOException the connection will be released 5.115 + // back to the connection manager automatically 5.116 + throw ex; 5.117 + 5.118 + } catch (RuntimeException ex) { 5.119 + // In case of an unexpected exception you may want to abort 5.120 + // the HTTP request in order to shut down the underlying 5.121 + // connection and release it back to the connection manager. 5.122 + method.abort(); 5.123 + throw ex; 5.124 + 5.125 + } finally { 5.126 + // Closing the input stream will trigger connection release 5.127 + instream.close(); 5.128 + } 5.129 + } 5.130 + 5.131 + return new EndpointResult(statusCode, response.getStatusLine().getReasonPhrase(), responseBody); 5.132 + 5.133 + } catch (IOException e) { 5.134 + throw e; 5.135 + 5.136 + } finally { 5.137 + // release the connection. 5.138 + method.releaseConnection(); 5.139 + } 5.140 } 5.141 5.142 - @Override 5.143 + /** 5.144 + * Stores the RDF <code>data</code> which are in the RDF format 5.145 + * <code>format</code> in the named graph specified by the URL 5.146 + * <code>namedGraph</code>. 5.147 + * 5.148 + * @param data 5.149 + * @param format 5.150 + * @param namedGraph 5.151 + * @return <code>true</code> if store was successful, <code>false</code> otherwise 5.152 + */ 5.153 + 5.154 public boolean store(String data, RDFFormat format, URL namedGraph) { 5.155 throw new UnsupportedOperationException(); 5.156 } 5.157 5.158 - @Override 5.159 + /** 5.160 + * Stores the RDF data located at <code>data</code> which are in the 5.161 + * RDF format <code>format</code> in the named graph specified by the 5.162 + * URL <code>namedGraph</code>. 5.163 + * 5.164 + * @param data 5.165 + * @param format 5.166 + * @param namedGraph 5.167 + * @return <code>true</code> if store was successful, <code>false</code> otherwise 5.168 + */ 5.169 + 5.170 public boolean store(URL data, RDFFormat format, URL namedGraph) { 5.171 throw new UnsupportedOperationException(); 5.172 } 5.173 5.174 - @Override 5.175 + /** 5.176 + * Executes the SPARQL Update query specified in <code>sparqlUpdate</code>. 5.177 + * 5.178 + * @param sparqlUpdate 5.179 + * @return <code>true</code> if store was successful, <code>false</code> otherwise 5.180 + */ 5.181 + 5.182 public boolean update(String sparqlUpdate) { 5.183 throw new UnsupportedOperationException(); 5.184 } 5.185 5.186 - @Override 5.187 public EndpointResult describe(String sparqlDescribe) { 5.188 throw new UnsupportedOperationException(); 5.189 } 5.190 5.191 - @Override 5.192 public EndpointResult construct(String sparqlConstruct) { 5.193 throw new UnsupportedOperationException(); 5.194 } 5.195 - 5.196 - @Override 5.197 + 5.198 public EndpointResult ask(String sparqlAsk) { 5.199 throw new UnsupportedOperationException(); 5.200 } 5.201 + 5.202 + 5.203 + public static void main(String args[]) { 5.204 + if (args.length < 4) { 5.205 + System.err.println("Usage: eu.earthobservatory.org.StrabonEndpoint.client.StrabonEndpoint <HOST> <PORT> <APPNAME> [<FORMAT>]"); 5.206 + System.err.println(" where <HOST> is the hostname of the Strabon Endpoint"); 5.207 + System.err.println(" <PORT> is the port to connect to on the host"); 5.208 + System.err.println(" <APPNAME> is the application name of Strabon Endpoint as deployed in the Tomcat container"); 5.209 + System.err.println(" <QUERY> is the query to execute on the endpoint"); 5.210 + System.err.println(" [<FORMAT>] is the format of your results. Should be one of XML (default), KML, KMZ, GeoJSON, TSV, or HTML."); 5.211 + System.exit(1); 5.212 + } 5.213 + 5.214 + String host = args[0]; 5.215 + Integer port = new Integer(args[1]); 5.216 + String appName = args[2]; 5.217 + String query = args[3]; 5.218 + String format = ""; 5.219 + 5.220 + if (args.length == 5) { 5.221 + format = args[4]; 5.222 + 5.223 + } else { 5.224 + format = "XML"; 5.225 + } 5.226 + 5.227 + SPARQLEndpoint endpoint = new SPARQLEndpoint(host, port, appName); 5.228 + 5.229 + try { 5.230 + EndpointResult result = endpoint.query(query, stSPARQLQueryResultFormat.valueOf(format)); 5.231 + 5.232 + System.out.println("Status code: " + result.getStatusCode()); 5.233 + System.out.println("Status text: " + result.getStatusText()); 5.234 + System.out.println("<----- Result ----->"); 5.235 + System.out.println(result.getResponse().replaceAll("\n", "\n\t")); 5.236 + System.out.println("<----- Result ----->"); 5.237 + 5.238 + } catch (IOException e) { 5.239 + e.printStackTrace(); 5.240 + } 5.241 + } 5.242 }
6.1 --- a/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SpatialEndpoint.java Sat Apr 06 15:55:32 2013 +0300 6.2 +++ b/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SpatialEndpoint.java Sat Apr 06 18:05:36 2013 +0300 6.3 @@ -9,16 +9,37 @@ 6.4 */ 6.5 package eu.earthobservatory.org.StrabonEndpoint.client; 6.6 6.7 +import java.io.ByteArrayOutputStream; 6.8 +import java.io.IOException; 6.9 +import java.io.StringReader; 6.10 +import java.util.Vector; 6.11 + 6.12 +import javax.xml.parsers.DocumentBuilder; 6.13 +import javax.xml.parsers.DocumentBuilderFactory; 6.14 + 6.15 +import org.openrdf.model.URI; 6.16 +import org.openrdf.model.impl.LiteralImpl; 6.17 +import org.openrdf.model.impl.ValueFactoryImpl; 6.18 +import org.openrdf.query.BindingSet; 6.19 +import org.openrdf.query.TupleQueryResultHandlerException; 6.20 +import org.openrdf.query.algebra.evaluation.QueryBindingSet; 6.21 import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 6.22 +import org.openrdf.query.resultio.sparqlkml.stSPARQLResultsKMLWriter; 6.23 +import org.w3c.dom.Document; 6.24 +import org.w3c.dom.Element; 6.25 +import org.w3c.dom.Node; 6.26 +import org.w3c.dom.NodeList; 6.27 +import org.xml.sax.InputSource; 6.28 6.29 /** 6.30 - * Every SPARQL endpoint that supports storing and querying of 6.31 - * spatial RDF data should extend the {@link SpatialEndpoint} 6.32 - * abstract class. 6.33 + * SpatialEndpoint is a SPARQLEndpoint which can store and 6.34 + * query for spatial data. It also supports KML format for 6.35 + * this kind of data. 6.36 * 6.37 * @author Charalampos Nikolaou <charnik@di.uoa.gr> 6.38 + * @author Kallirroi Dogani <kallirroi@di.uoa.gr> 6.39 */ 6.40 -public abstract class SpatialEndpoint extends HTTPClient implements Endpoint<stSPARQLQueryResultFormat> { 6.41 +public class SpatialEndpoint extends SPARQLEndpoint { 6.42 6.43 public SpatialEndpoint(String host, int port) { 6.44 super(host, port); 6.45 @@ -27,4 +48,99 @@ 6.46 public SpatialEndpoint(String host, int port, String endpointName) { 6.47 super(host, port, endpointName); 6.48 } 6.49 + 6.50 + public EndpointResult queryForKML(String sparqlQuery) throws IOException, TupleQueryResultHandlerException{ 6.51 + 6.52 + EndpointResult xmlResult = query(sparqlQuery, stSPARQLQueryResultFormat.XML); 6.53 + 6.54 + if (xmlResult.getStatusCode() != 200) { 6.55 + throw new RuntimeException("Failed : HTTP error code : " + xmlResult.getStatusCode() + " " + xmlResult.getStatusText()); 6.56 + } 6.57 + 6.58 + String xml = xmlResult.getResponse(); 6.59 + 6.60 + Vector<BindingSet> bindingSets = xmlToBindingSet(xml); 6.61 + 6.62 + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 6.63 + stSPARQLResultsKMLWriter kmlWriter = new stSPARQLResultsKMLWriter(outputStream); 6.64 + 6.65 + kmlWriter.startQueryResult(new Vector<String>()); 6.66 + 6.67 + for(int i=0; i<bindingSets.size(); i++){ 6.68 + 6.69 + kmlWriter.handleSolution(bindingSets.get(i)); 6.70 + } 6.71 + 6.72 + kmlWriter.endQueryResult(); 6.73 + 6.74 + 6.75 + EndpointResult kmlResult = new EndpointResult(xmlResult.getStatusCode(), xmlResult.getStatusText(), outputStream.toString()); 6.76 + return kmlResult; 6.77 + } 6.78 + 6.79 + 6.80 +private Vector<BindingSet> xmlToBindingSet(String xml){ 6.81 + 6.82 + Vector<BindingSet> bindingSetList = new Vector<BindingSet>(); 6.83 + 6.84 + try { 6.85 + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); 6.86 + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); 6.87 + Document doc = dBuilder.parse(new InputSource(new StringReader(xml))); 6.88 + 6.89 + doc.getDocumentElement().normalize(); 6.90 + 6.91 + Node resultsNode = doc.getElementsByTagName("results").item(0); 6.92 + Element resultsElement = (Element) resultsNode; 6.93 + NodeList resultsList = resultsElement.getElementsByTagName("result"); 6.94 + 6.95 + for (int i = 0; i < resultsList.getLength(); i++) { 6.96 + 6.97 + Node resultItem = resultsList.item(i); 6.98 + Element resultElement = (Element) resultItem; 6.99 + NodeList bindingNamesList = resultElement.getElementsByTagName("binding"); 6.100 + 6.101 + QueryBindingSet bindingSet = new QueryBindingSet(); 6.102 + ValueFactoryImpl valueFactImpl = new ValueFactoryImpl(); 6.103 + 6.104 + for (int j=0; j<bindingNamesList.getLength(); j++){ 6.105 + 6.106 + Node bindingNameItem = bindingNamesList.item(j); 6.107 + Element bindingNameElement = (Element) bindingNameItem; 6.108 + 6.109 + String bindingName = bindingNameElement.getAttribute("name"); 6.110 + Node child = bindingNameItem.getFirstChild(); 6.111 + Element childElement = (Element) child; 6.112 + String childName = child.getNodeName(); 6.113 + 6.114 + if(childName.equals("uri")){ 6.115 + URI uri = valueFactImpl.createURI(bindingNameElement.getElementsByTagName("uri").item(0).getTextContent()); 6.116 + bindingSet.addBinding(bindingName, uri); 6.117 + } 6.118 + else if (childName.equals("literal")){ 6.119 + URI datatype = valueFactImpl.createURI(childElement.getAttribute("datatype")); 6.120 + String value = bindingNameElement.getElementsByTagName("literal").item(0).getTextContent(); 6.121 + LiteralImpl literal= new LiteralImpl(value, datatype); 6.122 + bindingSet.addBinding(bindingName, literal); 6.123 + 6.124 + } 6.125 + else{ 6.126 + System.out.println("Parse error: Unkown xml"); 6.127 + return null; 6.128 + } 6.129 + 6.130 + } 6.131 + 6.132 + bindingSetList.add(bindingSet); 6.133 + 6.134 + } 6.135 + 6.136 + 6.137 + } 6.138 + catch (Exception e) { 6.139 + e.printStackTrace(); 6.140 + } 6.141 + 6.142 + return bindingSetList; 6.143 + } 6.144 }
7.1 --- a/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpoint.java Sat Apr 06 15:55:32 2013 +0300 7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 7.3 @@ -1,194 +0,0 @@ 7.4 -/** 7.5 - * This Source Code Form is subject to the terms of the Mozilla Public 7.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 7.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7.8 - * 7.9 - * Copyright (C) 2012, Pyravlos Team 7.10 - * 7.11 - * http://www.strabon.di.uoa.gr/ 7.12 - */ 7.13 -package eu.earthobservatory.org.StrabonEndpoint.client; 7.14 - 7.15 -import java.io.BufferedReader; 7.16 -import java.io.IOException; 7.17 -import java.io.InputStream; 7.18 -import java.io.InputStreamReader; 7.19 -import java.net.URL; 7.20 -import java.nio.charset.Charset; 7.21 -import java.util.ArrayList; 7.22 -import java.util.List; 7.23 - 7.24 -import org.apache.http.HttpEntity; 7.25 -import org.apache.http.HttpResponse; 7.26 -import org.apache.http.NameValuePair; 7.27 -import org.apache.http.client.entity.UrlEncodedFormEntity; 7.28 -import org.apache.http.client.methods.HttpPost; 7.29 -import org.apache.http.message.BasicNameValuePair; 7.30 -import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 7.31 -import org.openrdf.rio.RDFFormat; 7.32 - 7.33 -/** 7.34 - * This class is the implementation of a java client for accessing 7.35 - * StrabonEndpoint instances. 7.36 - * 7.37 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 7.38 - */ 7.39 -public class StrabonEndpoint extends SpatialEndpoint { 7.40 - 7.41 - public StrabonEndpoint(String host, int port) { 7.42 - super(host, port); 7.43 - } 7.44 - 7.45 - public StrabonEndpoint(String host, int port, String endpointName) { 7.46 - super(host, port, endpointName); 7.47 - } 7.48 - 7.49 - @Override 7.50 - public EndpointResult query(String sparqlQuery, stSPARQLQueryResultFormat format) throws IOException { 7.51 - assert(format != null); 7.52 - 7.53 - // create a post method to execute 7.54 - HttpPost method = new HttpPost(getConnectionURL() + "/Query"); 7.55 - 7.56 - // set the query parameter 7.57 - List<NameValuePair> params = new ArrayList<NameValuePair>(); 7.58 - params.add(new BasicNameValuePair("query", sparqlQuery)); 7.59 - UrlEncodedFormEntity encodedEntity = new UrlEncodedFormEntity(params, Charset.defaultCharset()); 7.60 - method.setEntity(encodedEntity); 7.61 - 7.62 - // set the content type 7.63 - method.setHeader("Content-Type", "application/x-www-form-urlencoded"); 7.64 - 7.65 - // set the accept format 7.66 - method.addHeader("Accept", format.getDefaultMIMEType()); 7.67 - 7.68 - try { 7.69 - // response that will be filled next 7.70 - String responseBody = ""; 7.71 - 7.72 - // execute the method 7.73 - HttpResponse response = hc.execute(method); 7.74 - int statusCode = response.getStatusLine().getStatusCode(); 7.75 - 7.76 - // If the response does not enclose an entity, there is no need 7.77 - // to worry about connection release 7.78 - HttpEntity entity = response.getEntity(); 7.79 - if (entity != null) { 7.80 - InputStream instream = entity.getContent(); 7.81 - try { 7.82 - 7.83 - BufferedReader reader = new BufferedReader(new InputStreamReader(instream)); 7.84 - StringBuffer strBuf = new StringBuffer(); 7.85 - 7.86 - // do something useful with the response 7.87 - String nextLine; 7.88 - while ((nextLine = reader.readLine()) != null) { 7.89 - strBuf.append(nextLine + "\n"); 7.90 - } 7.91 - 7.92 - // remove last newline character 7.93 - if (strBuf.length() > 0) { 7.94 - strBuf.setLength(strBuf.length() - 1); 7.95 - } 7.96 - 7.97 - responseBody = strBuf.toString(); 7.98 - 7.99 - } catch (IOException ex) { 7.100 - // In case of an IOException the connection will be released 7.101 - // back to the connection manager automatically 7.102 - throw ex; 7.103 - 7.104 - } catch (RuntimeException ex) { 7.105 - // In case of an unexpected exception you may want to abort 7.106 - // the HTTP request in order to shut down the underlying 7.107 - // connection and release it back to the connection manager. 7.108 - method.abort(); 7.109 - throw ex; 7.110 - 7.111 - } finally { 7.112 - // Closing the input stream will trigger connection release 7.113 - instream.close(); 7.114 - } 7.115 - } 7.116 - 7.117 - return new StrabonEndpointResult(statusCode, response.getStatusLine().getReasonPhrase(), responseBody); 7.118 - 7.119 - } catch (IOException e) { 7.120 - throw e; 7.121 - 7.122 - } finally { 7.123 - // release the connection. 7.124 - method.releaseConnection(); 7.125 - } 7.126 - } 7.127 - 7.128 - @Override 7.129 - public boolean store(String data, RDFFormat format, URL namedGraph) { 7.130 - throw new UnsupportedOperationException(); 7.131 - } 7.132 - 7.133 - @Override 7.134 - public boolean store(URL data, RDFFormat format, URL namedGraph) { 7.135 - throw new UnsupportedOperationException(); 7.136 - } 7.137 - 7.138 - @Override 7.139 - public boolean update(String sparqlUpdate) { 7.140 - throw new UnsupportedOperationException(); 7.141 - } 7.142 - 7.143 - @Override 7.144 - public EndpointResult describe(String sparqlDescribe) { 7.145 - throw new UnsupportedOperationException(); 7.146 - } 7.147 - 7.148 - @Override 7.149 - public EndpointResult construct(String sparqlConstruct) { 7.150 - throw new UnsupportedOperationException(); 7.151 - } 7.152 - 7.153 - @Override 7.154 - public EndpointResult ask(String sparqlAsk) { 7.155 - throw new UnsupportedOperationException(); 7.156 - } 7.157 - 7.158 - public static void main(String args[]) { 7.159 - if (args.length < 4) { 7.160 - System.err.println("Usage: eu.earthobservatory.org.StrabonEndpoint.client.StrabonEndpoint <HOST> <PORT> <APPNAME> [<FORMAT>]"); 7.161 - System.err.println(" where <HOST> is the hostname of the Strabon Endpoint"); 7.162 - System.err.println(" <PORT> is the port to connect to on the host"); 7.163 - System.err.println(" <APPNAME> is the application name of Strabon Endpoint as deployed in the Tomcat container"); 7.164 - System.err.println(" <QUERY> is the query to execute on the endpoint"); 7.165 - System.err.println(" [<FORMAT>] is the format of your results. Should be one of XML (default), KML, KMZ, GeoJSON, TSV, or HTML."); 7.166 - System.exit(1); 7.167 - } 7.168 - 7.169 - String host = args[0]; 7.170 - Integer port = new Integer(args[1]); 7.171 - String appName = args[2]; 7.172 - String query = args[3]; 7.173 - String format = ""; 7.174 - 7.175 - if (args.length == 5) { 7.176 - format = args[4]; 7.177 - 7.178 - } else { 7.179 - format = "XML"; 7.180 - } 7.181 - 7.182 - StrabonEndpoint endpoint = new StrabonEndpoint(host, port, appName); 7.183 - 7.184 - try { 7.185 - EndpointResult result = endpoint.query(query, stSPARQLQueryResultFormat.valueOf(format)); 7.186 - 7.187 - System.out.println("Status code: " + result.getStatusCode()); 7.188 - System.out.println("Status text: " + result.getStatusText()); 7.189 - System.out.println("<----- Result ----->"); 7.190 - System.out.println(result.getResponse().replaceAll("\n", "\n\t")); 7.191 - System.out.println("<----- Result ----->"); 7.192 - 7.193 - } catch (IOException e) { 7.194 - e.printStackTrace(); 7.195 - } 7.196 - } 7.197 -}
8.1 --- a/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpointResult.java Sat Apr 06 15:55:32 2013 +0300 8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 8.3 @@ -1,42 +0,0 @@ 8.4 -/** 8.5 - * This Source Code Form is subject to the terms of the Mozilla Public 8.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this 8.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8.8 - * 8.9 - * Copyright (C) 2012, Pyravlos Team 8.10 - * 8.11 - * http://www.strabon.di.uoa.gr/ 8.12 - */ 8.13 -package eu.earthobservatory.org.StrabonEndpoint.client; 8.14 - 8.15 -/** 8.16 - * @author Charalampos Nikolaou <charnik@di.uoa.gr> 8.17 - * 8.18 - */ 8.19 -public class StrabonEndpointResult implements EndpointResult { 8.20 - 8.21 - private int statusCode; 8.22 - private String statusText; 8.23 - private String response; 8.24 - 8.25 - public StrabonEndpointResult(int statusCode, String statusLine, String response) { 8.26 - this.statusCode = statusCode; 8.27 - this.statusText = statusLine; 8.28 - this.response = response; 8.29 - } 8.30 - 8.31 - @Override 8.32 - public int getStatusCode() { 8.33 - return statusCode; 8.34 - } 8.35 - 8.36 - @Override 8.37 - public String getStatusText() { 8.38 - return statusText; 8.39 - } 8.40 - 8.41 - @Override 8.42 - public String getResponse() { 8.43 - return response; 8.44 - } 8.45 -}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/endpoint-client/src/test/java/eu/earthobservatory/org/StrabonEndpoint/client/TestSPARQLEndpointWithParliament.java Sat Apr 06 18:05:36 2013 +0300 9.3 @@ -0,0 +1,75 @@ 9.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 9.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 9.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9.7 + * 9.8 + * Copyright (C) 2013, Pyravlos Team 9.9 + * 9.10 + * http://www.strabon.di.uoa.gr/ 9.11 + */ 9.12 +package eu.earthobservatory.org.StrabonEndpoint.client; 9.13 + 9.14 +import static org.junit.Assert.assertTrue; 9.15 + 9.16 +import java.io.IOException; 9.17 + 9.18 +import org.junit.Before; 9.19 +import org.junit.Test; 9.20 +import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 9.21 + 9.22 +/** 9.23 + * @author Kallirroi Dogani <kallirroi@di.uoa.gr> 9.24 + * 9.25 + */ 9.26 + 9.27 +public class TestSPARQLEndpointWithParliament { 9.28 + 9.29 + private SPARQLEndpoint endpoint; 9.30 + private String query; 9.31 + 9.32 + @Before 9.33 + public void init() { 9.34 + // initialize endpoint 9.35 + endpoint = new SPARQLEndpoint("luna.di.uoa.gr", 8080, "parliament/sparql"); 9.36 + 9.37 + // set query 9.38 + query = "PREFIX ex: <http://example.org/> \n" + 9.39 + "SELECT ?k ?g WHERE {\n" + 9.40 + " ex:pol1 ?k ?g\n" + 9.41 + "}" + 9.42 + "\nLIMIT 1"; 9.43 + 9.44 + } 9.45 + 9.46 + /** 9.47 + * Test method for {@link eu.earthobservatory.org.StrabonEndpoint.client.SPARQLEndpoint#query(java.lang.String, org.openrdf.query.resultio.stSPARQLQueryResultFormat)}. 9.48 + */ 9.49 + @Test 9.50 + public void testQuery() { 9.51 + try { 9.52 + EndpointResult response = endpoint.query(query, stSPARQLQueryResultFormat.XML); 9.53 + 9.54 + System.out.println(response.getResponse()); 9.55 + 9.56 + if (response.getStatusCode() != 200) { 9.57 + System.err.println("Status code ("+response.getStatusCode()+"):" + response.getStatusText()); 9.58 + 9.59 + } 9.60 + 9.61 + assertTrue(response.getStatusCode() == 200); 9.62 + 9.63 + } catch (IOException e) { 9.64 + e.printStackTrace(); 9.65 + } 9.66 + 9.67 + } 9.68 + 9.69 + /** 9.70 + * Test method for testing that method {@link eu.earthobservatory.org.StrabonEndpoint.client.SPARQLEndpoint#query(java.lang.String, org.openrdf.query.resultio.stSPARQLQueryResultFormat)}. 9.71 + * returns an IOException when it should do so. 9.72 + */ 9.73 + @Test(expected= IOException.class) 9.74 + public void testIOException() throws Exception { 9.75 + SPARQLEndpoint ep = new SPARQLEndpoint("blabla.dgr", 80, "bla"); 9.76 + ep.query(query, stSPARQLQueryResultFormat.XML); 9.77 + } 9.78 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/endpoint-client/src/test/java/eu/earthobservatory/org/StrabonEndpoint/client/TestSPARQLEndpointWithStrabon.java Sat Apr 06 18:05:36 2013 +0300 10.3 @@ -0,0 +1,91 @@ 10.4 +/** 10.5 + * This Source Code Form is subject to the terms of the Mozilla Public 10.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 10.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 10.8 + * 10.9 + * Copyright (C) 2012, Pyravlos Team 10.10 + * 10.11 + * http://www.strabon.di.uoa.gr/ 10.12 + */ 10.13 +package eu.earthobservatory.org.StrabonEndpoint.client; 10.14 + 10.15 +import static org.junit.Assert.assertTrue; 10.16 + 10.17 +import java.io.IOException; 10.18 +import java.util.Vector; 10.19 + 10.20 +import org.junit.Before; 10.21 +import org.junit.Test; 10.22 +import org.openrdf.query.resultio.TupleQueryResultFormat; 10.23 +import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 10.24 + 10.25 +/** 10.26 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 10.27 + * 10.28 + */ 10.29 +public class TestSPARQLEndpointWithStrabon { 10.30 + 10.31 + private SPARQLEndpoint endpoint; 10.32 + private String query; 10.33 + private Vector<stSPARQLQueryResultFormat> formats = new Vector<stSPARQLQueryResultFormat>(); 10.34 + 10.35 + @Before 10.36 + public void init() { 10.37 + // initialize endpoint 10.38 + endpoint = new SPARQLEndpoint("geo.linkedopendata.gr", 9090, "gag-endpoint/Query"); 10.39 + 10.40 + // set query 10.41 + query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + 10.42 + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " + 10.43 + "PREFIX gag: <http://geo.linkedopendata.gr/gag/ontology/> " + 10.44 + 10.45 + "SELECT ?geometry " + 10.46 + "WHERE {" + 10.47 + 10.48 + " ?m rdf:type gag:Δήμος . " + 10.49 + " ?m rdfs:label \"ΔΗΜΟΣ ΑΘΗΝΑΙΩΝ\" . " + 10.50 + " ?m gag:έχει_γεωμετρία ?geometry. " + 10.51 + " } " ; 10.52 + 10.53 + // initialized formats 10.54 + for (TupleQueryResultFormat format : stSPARQLQueryResultFormat.values()) { 10.55 + if (format instanceof stSPARQLQueryResultFormat) { 10.56 + formats.add((stSPARQLQueryResultFormat) format); 10.57 + } 10.58 + } 10.59 + 10.60 + } 10.61 + 10.62 + /** 10.63 + * Test method for {@link eu.earthobservatory.org.StrabonEndpoint.client.SPARQLEndpoint#query(java.lang.String, org.openrdf.query.resultio.stSPARQLQueryResultFormat)}. 10.64 + */ 10.65 + @Test 10.66 + public void testQuery() { 10.67 + for (stSPARQLQueryResultFormat format : formats) { 10.68 + try { 10.69 + EndpointResult response = endpoint.query(query, format); 10.70 + 10.71 + if (response.getStatusCode() != 200) { 10.72 + System.err.println("Status code ("+response.getStatusCode()+"):" + response.getStatusText()); 10.73 + 10.74 + } 10.75 + 10.76 + assertTrue(response.getStatusCode() == 200); 10.77 + 10.78 + } catch (IOException e) { 10.79 + e.printStackTrace(); 10.80 + } 10.81 + 10.82 + } 10.83 + } 10.84 + 10.85 + /** 10.86 + * Test method for testing that method {@link eu.earthobservatory.org.StrabonEndpoint.client.SPARQLEndpoint#query(java.lang.String, org.openrdf.query.resultio.stSPARQLQueryResultFormat)}. 10.87 + * returns an IOException when it should do so. 10.88 + */ 10.89 + @Test(expected= IOException.class) 10.90 + public void testIOException() throws Exception { 10.91 + SPARQLEndpoint ep = new SPARQLEndpoint("blabla.dgr", 80, "bla"); 10.92 + ep.query(query, formats.get(0)); 10.93 + } 10.94 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/endpoint-client/src/test/java/eu/earthobservatory/org/StrabonEndpoint/client/TestSPARQLEndpointWithVirtuoso.java Sat Apr 06 18:05:36 2013 +0300 11.3 @@ -0,0 +1,88 @@ 11.4 +/** 11.5 + * This Source Code Form is subject to the terms of the Mozilla Public 11.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 11.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 11.8 + * 11.9 + * Copyright (C) 2013, Pyravlos Team 11.10 + * 11.11 + * http://www.strabon.di.uoa.gr/ 11.12 + */ 11.13 +package eu.earthobservatory.org.StrabonEndpoint.client; 11.14 + 11.15 +import static org.junit.Assert.assertTrue; 11.16 + 11.17 +import java.io.IOException; 11.18 +import java.util.Vector; 11.19 + 11.20 +import org.junit.Before; 11.21 +import org.junit.Test; 11.22 +import org.openrdf.query.resultio.TupleQueryResultFormat; 11.23 +import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 11.24 + 11.25 +/** 11.26 + * @author Kallirroi Dogani <kallirroi@di.uoa.gr> 11.27 + * 11.28 + */ 11.29 + 11.30 +//Virtuso endpoint also needs to be tested for all formats included in stSPARQLQueryResultFormat 11.31 +//because some of them are not supported 11.32 +public class TestSPARQLEndpointWithVirtuoso { 11.33 + 11.34 + private SPARQLEndpoint endpoint; 11.35 + private String query; 11.36 + private Vector<stSPARQLQueryResultFormat> formats = new Vector<stSPARQLQueryResultFormat>(); 11.37 + 11.38 + @Before 11.39 + public void init() { 11.40 + // initialize endpoint 11.41 + endpoint = new SPARQLEndpoint("luna.di.uoa.gr", 8890, "sparql"); 11.42 + 11.43 + // set query 11.44 + query = "PREFIX ex: <http://example.org/> \n" + 11.45 + "SELECT ?k ?g WHERE {\n" + 11.46 + " ex:pol1 ?k ?g\n" + 11.47 + "}" + 11.48 + "\nLIMIT 1"; 11.49 + 11.50 + // initialized formats 11.51 + for (TupleQueryResultFormat format : stSPARQLQueryResultFormat.values()) { 11.52 + if (format instanceof stSPARQLQueryResultFormat) { 11.53 + formats.add((stSPARQLQueryResultFormat) format); 11.54 + } 11.55 + } 11.56 + 11.57 + } 11.58 + 11.59 + /** 11.60 + * Test method for {@link eu.earthobservatory.org.StrabonEndpoint.client.SPARQLEndpoint#query(java.lang.String, org.openrdf.query.resultio.stSPARQLQueryResultFormat)}. 11.61 + */ 11.62 + @Test 11.63 + public void testQuery() { 11.64 + try { 11.65 + EndpointResult response = endpoint.query(query, stSPARQLQueryResultFormat.XML); 11.66 + 11.67 + System.out.println(response.getResponse()); 11.68 + 11.69 + if (response.getStatusCode() != 200) { 11.70 + System.err.println("Status code ("+response.getStatusCode()+"):" + response.getStatusText()); 11.71 + 11.72 + } 11.73 + 11.74 + assertTrue(response.getStatusCode() == 200); 11.75 + 11.76 + } catch (IOException e) { 11.77 + e.printStackTrace(); 11.78 + } 11.79 + 11.80 + } 11.81 + 11.82 + /** 11.83 + * Test method for testing that method {@link eu.earthobservatory.org.StrabonEndpoint.client.SPARQLEndpoint#query(java.lang.String, org.openrdf.query.resultio.stSPARQLQueryResultFormat)}. 11.84 + * returns an IOException when it should do so. 11.85 + */ 11.86 + @Test(expected= IOException.class) 11.87 + public void testIOException() throws Exception { 11.88 + SPARQLEndpoint ep = new SPARQLEndpoint("blabla.dgr", 80, "bla"); 11.89 + ep.query(query, formats.get(0)); 11.90 + } 11.91 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/endpoint-client/src/test/java/eu/earthobservatory/org/StrabonEndpoint/client/TestSpatialEndpoint.java Sat Apr 06 18:05:36 2013 +0300 12.3 @@ -0,0 +1,70 @@ 12.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 12.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 12.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 12.7 + * 12.8 + * Copyright (C) 2013, Pyravlos Team 12.9 + * 12.10 + * http://www.strabon.di.uoa.gr/ 12.11 + */ 12.12 +package eu.earthobservatory.org.StrabonEndpoint.client; 12.13 + 12.14 +import static org.junit.Assert.assertTrue; 12.15 + 12.16 +import java.io.IOException; 12.17 + 12.18 +import org.junit.Before; 12.19 +import org.junit.Test; 12.20 +import org.openrdf.query.TupleQueryResultHandlerException; 12.21 + 12.22 +/** 12.23 + * @author Kallirroi Dogani <kallirroi@di.uoa.gr> 12.24 + * 12.25 + */ 12.26 + 12.27 +public class TestSpatialEndpoint { 12.28 + 12.29 + private SpatialEndpoint endpoint; 12.30 + private String query; 12.31 + 12.32 + @Before 12.33 + public void init() { 12.34 + // initialize endpoint 12.35 + endpoint = new SpatialEndpoint("luna.di.uoa.gr", 8890, "sparql"); 12.36 + 12.37 + // set query 12.38 + query = "PREFIX ex: <http://example.org/> \n" + 12.39 + "SELECT ?k ?g WHERE {\n" + 12.40 + " ?k ex:geometry ?g\n" + 12.41 + "}" + 12.42 + "\nLIMIT 1"; 12.43 + } 12.44 + 12.45 + /** 12.46 + * Test method for {@link eu.earthobservatory.org.StrabonEndpoint.client.SpatialEndpoint#query(java.lang.String, org.openrdf.query.resultio.stSPARQLQueryResultFormat)}. 12.47 + * @throws TupleQueryResultHandlerException 12.48 + */ 12.49 + @Test 12.50 + public void testQuery() { 12.51 + try { 12.52 + EndpointResult response = endpoint.queryForKML(query); 12.53 + 12.54 + System.out.println("KML format:"); 12.55 + System.out.println(response.getResponse()); 12.56 + 12.57 + if (response.getStatusCode() != 200) { 12.58 + System.err.println("Status code ("+response.getStatusCode()+"):" + response.getStatusText()); 12.59 + 12.60 + } 12.61 + 12.62 + assertTrue(response.getStatusCode() == 200); 12.63 + 12.64 + } 12.65 + catch (TupleQueryResultHandlerException e) { 12.66 + e.printStackTrace(); 12.67 + } 12.68 + catch (IOException e) { 12.69 + e.printStackTrace(); 12.70 + } 12.71 + 12.72 + } 12.73 +}
13.1 --- a/endpoint-client/src/test/java/eu/earthobservatory/org/StrabonEndpoint/client/TestStrabonEndpoint.java Sat Apr 06 15:55:32 2013 +0300 13.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 13.3 @@ -1,85 +0,0 @@ 13.4 -///** 13.5 -// * This Source Code Form is subject to the terms of the Mozilla Public 13.6 -// * License, v. 2.0. If a copy of the MPL was not distributed with this 13.7 -// * file, You can obtain one at http://mozilla.org/MPL/2.0/. 13.8 -// * 13.9 -// * Copyright (C) 2012, Pyravlos Team 13.10 -// * 13.11 -// * http://www.strabon.di.uoa.gr/ 13.12 -// */ 13.13 -//package eu.earthobservatory.org.StrabonEndpoint.client; 13.14 -// 13.15 -//import static org.junit.Assert.assertTrue; 13.16 -// 13.17 -//import java.io.IOException; 13.18 -//import java.util.Vector; 13.19 -// 13.20 -//import org.junit.Before; 13.21 -//import org.junit.Test; 13.22 -//import org.openrdf.query.resultio.TupleQueryResultFormat; 13.23 -//import org.openrdf.query.resultio.stSPARQLQueryResultFormat; 13.24 -// 13.25 -///** 13.26 -// * @author Charalampos Nikolaou <charnik@di.uoa.gr> 13.27 -// * 13.28 -// */ 13.29 -//public class TestStrabonEndpoint { 13.30 -// 13.31 -// private StrabonEndpoint endpoint; 13.32 -// private String query; 13.33 -// private Vector<stSPARQLQueryResultFormat> formats = new Vector<stSPARQLQueryResultFormat>(); 13.34 -// 13.35 -// @Before 13.36 -// public void init() { 13.37 -// // initialize endpoint 13.38 -// endpoint = new StrabonEndpoint("test.strabon.di.uoa.gr", 80, "DLR"); 13.39 -// 13.40 -// // set query 13.41 -// query = "PREFIX teleios:<http://teleios.di.uoa.gr/ontologies/noaOntology.owl#>\n" + 13.42 -// "SELECT ?s ?g WHERE {\n" + 13.43 -// " ?s teleios:hasGeometry ?g\n" + 13.44 -// "}" + 13.45 -// "\nLIMIT 1"; 13.46 -// 13.47 -// // initialized formats 13.48 -// for (TupleQueryResultFormat format : stSPARQLQueryResultFormat.values()) { 13.49 -// if (format instanceof stSPARQLQueryResultFormat) { 13.50 -// formats.add((stSPARQLQueryResultFormat) format); 13.51 -// } 13.52 -// } 13.53 -// 13.54 -// } 13.55 -// 13.56 -// /** 13.57 -// * Test method for {@link eu.earthobservatory.org.StrabonEndpoint.client.StrabonEndpoint#query(java.lang.String, org.openrdf.query.resultio.stSPARQLQueryResultFormat)}. 13.58 -// */ 13.59 -// @Test 13.60 -// public void testQuery() { 13.61 -// for (stSPARQLQueryResultFormat format : formats) { 13.62 -// try { 13.63 -// EndpointResult response = endpoint.query(query, format); 13.64 -// 13.65 -// if (response.getStatusCode() != 200) { 13.66 -// System.err.println("Status code ("+response.getStatusCode()+"):" + response.getStatusText()); 13.67 -// 13.68 -// } 13.69 -// 13.70 -// assertTrue(response.getStatusCode() == 200); 13.71 -// 13.72 -// } catch (IOException e) { 13.73 -// e.printStackTrace(); 13.74 -// } 13.75 -// 13.76 -// } 13.77 -// } 13.78 -// 13.79 -// /** 13.80 -// * Test method for testing that method {@link eu.earthobservatory.org.StrabonEndpoint.client.StrabonEndpoint#query(java.lang.String, org.openrdf.query.resultio.stSPARQLQueryResultFormat)}. 13.81 -// * returns an IOException when it should do so. 13.82 -// */ 13.83 -// @Test(expected= IOException.class) 13.84 -// public void testIOException() throws Exception { 13.85 -// StrabonEndpoint ep = new StrabonEndpoint("blabla.dgr", 80, "bla"); 13.86 -// ep.query(query, formats.get(0)); 13.87 -// } 13.88 -//}