Strabon

changeset 767:3b0d9bcd9a1d

Created junit test to test the limitation of query results.
author Stella Giannakopoulou <sgian@di.uoa.gr>
date Wed Dec 05 19:11:28 2012 +0200 (2012-12-05)
parents 733b824d894f
children 6b6f0afbc89e
files endpoint-client/src/test/java/eu/earthobservatory/org/StrabonEndpoint/client/TestLimit.java
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/endpoint-client/src/test/java/eu/earthobservatory/org/StrabonEndpoint/client/TestLimit.java	Wed Dec 05 19:11:28 2012 +0200
     1.3 @@ -0,0 +1,109 @@
     1.4 +/**
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.8 + * 
     1.9 + * Copyright (C) 2012, Pyravlos Team
    1.10 + * 
    1.11 + * http://www.strabon.di.uoa.gr/
    1.12 + */
    1.13 +package eu.earthobservatory.org.StrabonEndpoint.client;
    1.14 +
    1.15 +
    1.16 +import static org.junit.Assert.assertTrue;
    1.17 +
    1.18 +import java.io.IOException;
    1.19 +import org.junit.Before;
    1.20 +import org.junit.Test;
    1.21 +import org.openrdf.query.resultio.stSPARQLQueryResultFormat;
    1.22 +
    1.23 +/**
    1.24 + * @author Stella Giannakopoulou <sgian@di.uoa.gr>
    1.25 + *
    1.26 + */
    1.27 +public class TestLimit {
    1.28 +
    1.29 +	private StrabonEndpoint endpoint; 
    1.30 +	private String [] testQueries;
    1.31 +	private stSPARQLQueryResultFormat format;			
    1.32 +	
    1.33 +	@Before
    1.34 +	public void init() {
    1.35 +		
    1.36 +		// initialize endpoint		
    1.37 +		endpoint = new StrabonEndpoint("localhost", 8080, "strabon-endpoint");		
    1.38 +		testQueries = new String[6];
    1.39 +		
    1.40 +		 // set queries
    1.41 +		 testQueries[0] = "SELECT *\n" +
    1.42 +				"WHERE\n"+							
    1.43 +				"{\n"+
    1.44 +				"	?x ?y ?z\n" +
    1.45 +				"}\n" +
    1.46 +				"limit 3";	
    1.47 +		 
    1.48 +		 testQueries[1] = "SELECT *\n" +
    1.49 +					"WHERE\n"+							
    1.50 +					"{\n"+
    1.51 +					"	?x ?limit 5\n" +
    1.52 +					"}\n" +
    1.53 +					"limit 3";
    1.54 +		 
    1.55 +		 testQueries[2] = "SELECT *\n" +
    1.56 +					"WHERE\n"+							
    1.57 +					"{\n"+
    1.58 +					"	?x ?limit 5\n" +
    1.59 +					"}\n" +
    1.60 +					"limit 3\n" +
    1.61 +					"offset 4";
    1.62 +		 
    1.63 +		 testQueries[3] = "SELECT *\n" +
    1.64 +					"WHERE\n"+							
    1.65 +					"{\n"+
    1.66 +					"	?x ?y ?z\n" +
    1.67 +					"}\n" +
    1.68 +					"limit 3000";
    1.69 +		 
    1.70 +		 testQueries[4] = "SELECT *\n" +
    1.71 +					"WHERE\n"+							
    1.72 +					"{\n"+
    1.73 +					"	?x ?y ?z\n" +
    1.74 +					"}\n" +
    1.75 +					"offset 5" +
    1.76 +					"limit 3000";
    1.77 +		 
    1.78 +		 testQueries[5] = "SELECT *\n" +
    1.79 +					"WHERE\n"+							
    1.80 +					"{\n"+
    1.81 +					"	?x ?z 5\n" +
    1.82 +					"}\n" +
    1.83 +					"limit3000\n" +
    1.84 +					"offset 2";
    1.85 +		
    1.86 +		// format does not matter for the test
    1.87 +		format = stSPARQLQueryResultFormat.HTML;								
    1.88 +	}
    1.89 +	
    1.90 +	/**
    1.91 +	 * Test method for {@link eu.earthobservatory.org.StrabonEndpoint.client.StrabonEndpoint#query(java.lang.String, org.openrdf.query.resultio.stSPARQLQueryResultFormat)}.
    1.92 +	 */
    1.93 +	@Test
    1.94 +	public void testQuery() {				
    1.95 +				 
    1.96 +		for (String query : testQueries) {			
    1.97 +			try {
    1.98 +				EndpointResult response = endpoint.query(query, format);
    1.99 +				
   1.100 +				if (response.getStatusCode() != 200) {
   1.101 +					System.err.println("Status code ("+response.getStatusCode()+"):" + response.getStatusText());
   1.102 +					
   1.103 +				}
   1.104 +				
   1.105 +				assertTrue(response.getStatusCode() == 200);
   1.106 +
   1.107 +			} catch (IOException e) {
   1.108 +				e.printStackTrace();
   1.109 +			}					
   1.110 +		}
   1.111 +	}	
   1.112 +}