Strabon

changeset 674:322e3050c7e1

added test method for testing that StrabonEndpoint.query() should return an IOException when it cannot establish a connection to the endpoint
author Babis Nikolaou <charnik@di.uoa.gr>
date Wed Oct 31 00:26:42 2012 +0200 (2012-10-31)
parents 7fda2cf3acef
children 92b2b31e150d c7aa5e7dd068 af2605b62451
files endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpoint.java endpoint/src/test/java/eu/earthobservatory/org/StrabonEndpoint/client/TestStrabonEndpoint.java
line diff
     1.1 --- a/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpoint.java	Wed Oct 31 00:06:47 2012 +0200
     1.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpoint.java	Wed Oct 31 00:26:42 2012 +0200
     1.3 @@ -34,6 +34,8 @@
     1.4  
     1.5  	@Override
     1.6  	public EndpointResult query(String sparqlQuery, stSPARQLQueryResultFormat format) throws IOException {
     1.7 +		assert(format != null);
     1.8 +		
     1.9  		// create a post method to execute
    1.10  		PostMethod method = new PostMethod(getConnectionURL() + "/Query");
    1.11  		
     2.1 --- a/endpoint/src/test/java/eu/earthobservatory/org/StrabonEndpoint/client/TestStrabonEndpoint.java	Wed Oct 31 00:06:47 2012 +0200
     2.2 +++ b/endpoint/src/test/java/eu/earthobservatory/org/StrabonEndpoint/client/TestStrabonEndpoint.java	Wed Oct 31 00:26:42 2012 +0200
     2.3 @@ -12,15 +12,13 @@
     2.4  import static org.junit.Assert.assertTrue;
     2.5  
     2.6  import java.io.IOException;
     2.7 +import java.util.Vector;
     2.8  
     2.9  import org.junit.Before;
    2.10  import org.junit.Test;
    2.11  import org.openrdf.query.resultio.TupleQueryResultFormat;
    2.12  import org.openrdf.query.resultio.stSPARQLQueryResultFormat;
    2.13  
    2.14 -import eu.earthobservatory.org.StrabonEndpoint.client.EndpointResult;
    2.15 -import eu.earthobservatory.org.StrabonEndpoint.client.StrabonEndpoint;
    2.16 -
    2.17  /**
    2.18   * @author Charalampos Nikolaou <charnik@di.uoa.gr>
    2.19   *
    2.20 @@ -28,10 +26,28 @@
    2.21  public class TestStrabonEndpoint {
    2.22  
    2.23  	private StrabonEndpoint endpoint; 
    2.24 +	private String query;
    2.25 +	private Vector<stSPARQLQueryResultFormat> formats = new Vector<stSPARQLQueryResultFormat>();
    2.26  	
    2.27  	@Before
    2.28  	public void init() {
    2.29 +		// initialize endpoint
    2.30  		endpoint = new StrabonEndpoint("test.strabon.di.uoa.gr", 80, "DLR");
    2.31 +		
    2.32 +		// set query
    2.33 +		query = "PREFIX teleios:<http://teleios.di.uoa.gr/ontologies/noaOntology.owl#>\n" +
    2.34 +				"SELECT ?s ?g WHERE {\n" +
    2.35 +				"	?s teleios:hasGeometry ?g\n" +
    2.36 +				"}" +
    2.37 +				"\nLIMIT 1";
    2.38 +		
    2.39 +		// initialized formats
    2.40 +		for (TupleQueryResultFormat format : stSPARQLQueryResultFormat.values()) {
    2.41 +				if (format instanceof stSPARQLQueryResultFormat) {
    2.42 +					formats.add((stSPARQLQueryResultFormat) format);
    2.43 +				}
    2.44 +		}
    2.45 +				
    2.46  	}
    2.47  	
    2.48  	/**
    2.49 @@ -39,32 +55,31 @@
    2.50  	 */
    2.51  	@Test
    2.52  	public void testQuery() {
    2.53 -		for (TupleQueryResultFormat format : stSPARQLQueryResultFormat.values()) {
    2.54 +		for (stSPARQLQueryResultFormat format : formats) {
    2.55  			try {
    2.56 -				String query = "" +
    2.57 -						"PREFIX teleios:<http://teleios.di.uoa.gr/ontologies/noaOntology.owl#>\n" +
    2.58 -						"SELECT ?s ?g WHERE {\n" +
    2.59 -						"	?s teleios:hasGeometry ?g\n" +
    2.60 -						"}" +
    2.61 -						"\nLIMIT 1";
    2.62 +				EndpointResult response = endpoint.query(query, format);
    2.63  				
    2.64 -				if (format instanceof stSPARQLQueryResultFormat) {
    2.65 -					EndpointResult response = endpoint.query(query, (stSPARQLQueryResultFormat) format);
    2.66 -					
    2.67 -					if (response.getStatusCode() != 200) {
    2.68 -						System.err.println("Status code ("+response.getStatusCode()+"):" + response.getStatusText());
    2.69 -						
    2.70 -					}
    2.71 -					
    2.72 -					assertTrue(response.getStatusCode() == 200);
    2.73 +				if (response.getStatusCode() != 200) {
    2.74 +					System.err.println("Status code ("+response.getStatusCode()+"):" + response.getStatusText());
    2.75  					
    2.76  				}
    2.77 +				
    2.78 +				assertTrue(response.getStatusCode() == 200);
    2.79  
    2.80  			} catch (IOException e) {
    2.81  				e.printStackTrace();
    2.82  			}
    2.83  			
    2.84  		}
    2.85 -		
    2.86 +	}
    2.87 +	
    2.88 +	/**
    2.89 +	 * Test method for testing that method {@link eu.earthobservatory.org.StrabonEndpoint.client.StrabonEndpoint#query(java.lang.String, org.openrdf.query.resultio.stSPARQLQueryResultFormat)}.
    2.90 +	 * returns an IOException when it should do so.
    2.91 +	 */
    2.92 +	@Test(expected= IOException.class)
    2.93 +	public void testIOException() throws Exception {
    2.94 +		StrabonEndpoint ep = new StrabonEndpoint("blabla.dgr", 80, "bla");
    2.95 +		ep.query(query, formats.get(0));
    2.96  	}
    2.97  }