jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [35/50] jena git commit: JENA-491 Fuseki Support: Hack on QueryEngineHTTP, so that we can test the conneg of Construct Quad.
Date Mon, 24 Aug 2015 08:13:44 GMT
JENA-491 Fuseki Support: Hack on QueryEngineHTTP, so that we can test
the conneg of Construct Quad.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/602e3c02
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/602e3c02
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/602e3c02

Branch: refs/heads/master
Commit: 602e3c02779366ef9c2654aaf6bb0f1159801012
Parents: 75a7a77
Author: confidencesun <confidence.sun@gmail.com>
Authored: Wed Aug 19 21:55:56 2015 +0800
Committer: confidencesun <confidence.sun@gmail.com>
Committed: Wed Aug 19 21:55:56 2015 +0800

----------------------------------------------------------------------
 .../org/apache/jena/atlas/web/AcceptList.java   |  2 +-
 .../sparql/engine/http/QueryEngineHTTP.java     | 26 +++++++++-
 .../java/org/apache/jena/fuseki/TestQuery.java  | 52 ++++++++++++++++++++
 3 files changed, 77 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/602e3c02/jena-arq/src/main/java/org/apache/jena/atlas/web/AcceptList.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/atlas/web/AcceptList.java b/jena-arq/src/main/java/org/apache/jena/atlas/web/AcceptList.java
index 8801016..e3eb290 100644
--- a/jena-arq/src/main/java/org/apache/jena/atlas/web/AcceptList.java
+++ b/jena-arq/src/main/java/org/apache/jena/atlas/web/AcceptList.java
@@ -99,7 +99,7 @@ public class AcceptList
         return match(aItem) != null ;
     }
     
-    private List<MediaRange> entries()
+    public List<MediaRange> entries()
     {
         return Collections.unmodifiableList(ranges) ;
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/602e3c02/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
b/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
index 84c2c10..abe4d1f 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
@@ -87,6 +87,9 @@ public class QueryEngineHTTP implements QueryExecution {
     private String selectContentType    = defaultSelectHeader();
     private String askContentType       = defaultAskHeader();
     private String modelContentType     = defaultConstructHeader();
+    private String datasetContentType   = WebContent.defaultDatasetAcceptHeader;
+    
+    private String httpResponseContentType;
     /**
      * Supported content types for SELECT queries
      */
@@ -334,7 +337,11 @@ public class QueryEngineHTTP implements QueryExecution {
         this.authenticator = authenticator;
     }
 
-    @Override
+    public String getHttpResponseContentType() {
+		return httpResponseContentType;
+	}
+
+	@Override
     public ResultSet execSelect() {
         checkNotClosed() ;
         ResultSet rs = execResultSetInner() ;
@@ -360,6 +367,7 @@ public class QueryEngineHTTP implements QueryExecution {
         // Don't assume the endpoint actually gives back the content type we
         // asked for
         String actualContentType = httpQuery.getContentType();
+        httpResponseContentType = actualContentType;
 
         // If the server fails to return a Content-Type then we will assume
         // the server returned the type we asked for
@@ -441,6 +449,7 @@ public class QueryEngineHTTP implements QueryExecution {
         // Don't assume the endpoint actually gives back the content type we
         // asked for
         String actualContentType = httpQuery.getContentType();
+        httpResponseContentType = actualContentType;
 
         // If the server fails to return a Content-Type then we will assume
         // the server returned the type we asked for
@@ -468,6 +477,7 @@ public class QueryEngineHTTP implements QueryExecution {
         // Don't assume the endpoint actually gives back the content type we
         // asked for
         String actualContentType = httpQuery.getContentType();
+        httpResponseContentType = actualContentType;
 
         // If the server fails to return a Content-Type then we will assume
         // the server returned the type we asked for
@@ -488,12 +498,13 @@ public class QueryEngineHTTP implements QueryExecution {
     private Iterator<Quad> execQuads() {
         checkNotClosed() ;
         HttpQuery httpQuery = makeHttpQuery();
-        httpQuery.setAccept(WebContent.defaultDatasetAcceptHeader);
+        httpQuery.setAccept(datasetContentType);
         InputStream in = httpQuery.exec();
         
         // Don't assume the endpoint actually gives back the content type we
         // asked for
         String actualContentType = httpQuery.getContentType();
+        httpResponseContentType = actualContentType;
 
         // If the server fails to return a Content-Type then we will assume
         // the server returned the type we asked for
@@ -520,6 +531,7 @@ public class QueryEngineHTTP implements QueryExecution {
             // Don't assume the endpoint actually gives back the content type we
             // asked for
             String actualContentType = httpQuery.getContentType();
+            httpResponseContentType = actualContentType;
 
             // If the server fails to return a Content-Type then we will assume
             // the server returned the type we asked for
@@ -795,6 +807,16 @@ public class QueryEngineHTTP implements QueryExecution {
         modelContentType = contentType;
     }
     
+    public void setDatasetContentType(String contentType) {
+        // Check that this is a valid setting
+        Lang lang = RDFLanguages.contentTypeToLang(contentType);
+        if (lang == null)
+            throw new IllegalArgumentException("Given Content Type '" + contentType + "'
is not supported by RIOT");
+        if (!RDFLanguages.isQuads(lang))
+            throw new IllegalArgumentException("Given Content Type '" + contentType + "'
is not a RDF Dataset format");
+        datasetContentType = contentType;
+    }
+    
     private static final String selectContentTypeHeader = initSelectContentTypes() ;
 
     public static String defaultSelectHeader() {

http://git-wip-us.apache.org/repos/asf/jena/blob/602e3c02/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
index e721d9d..5a57da3 100644
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
+++ b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
@@ -31,18 +31,22 @@ import java.net.URL ;
 import java.util.Iterator ;
 
 import org.apache.jena.atlas.junit.BaseTest ;
+import org.apache.jena.atlas.logging.Log;
+import org.apache.jena.atlas.web.MediaType;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.graph.Triple ;
 import org.apache.jena.query.* ;
 import org.apache.jena.sparql.core.Quad ;
 import org.apache.jena.sparql.core.Var ;
 import org.apache.jena.sparql.engine.binding.Binding ;
+import org.apache.jena.sparql.engine.http.QueryEngineHTTP ;
 import org.apache.jena.sparql.resultset.ResultSetCompare ;
 import org.apache.jena.sparql.sse.Item ;
 import org.apache.jena.sparql.sse.SSE ;
 import org.apache.jena.sparql.sse.builders.BuilderResultSet ;
 import org.apache.jena.sparql.util.Convert ;
 import org.apache.jena.rdf.model.*;
+import org.apache.jena.riot.WebContent;
 import org.junit.AfterClass ;
 import org.junit.Assert ;
 import org.junit.BeforeClass ;
@@ -192,6 +196,36 @@ public class TestQuery extends BaseTest {
             assertEquals(1, result.size());
         }
     }
+    
+    @Test
+    public void query_construct_conneg()
+    {
+        String query = " CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}" ;
+        for (MediaType type: DEF.rdfOffer.entries()){
+            String contentType = type.toHeaderString();
+            try ( QueryEngineHTTP qExec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery,
query) ) {
+                qExec.setModelContentType(initConstructContentTypes( contentType ) );
+        	    qExec.execConstruct();
+                assertEquals( contentType , qExec.getHttpResponseContentType());
+            }
+        }
+    }
+    
+    @Test
+    public void query_construct_quad_conneg()
+    {
+        String queryString = " CONSTRUCT { GRAPH ?g {?s ?p ?o} } WHERE { GRAPH ?g {?s ?p
?o}}" ;
+        Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
+        for (MediaType type: DEF.quadsOffer.entries()){
+            String contentType = type.toHeaderString();
+            try ( QueryEngineHTTP qExec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery,
query) ) {
+                qExec.setDatasetContentType(initConstructContentTypes( contentType ) );
+        	    qExec.execConstructQuads();
+                assertEquals( contentType , qExec.getHttpResponseContentType());
+            }
+        }
+    }
+   
 
     private void execQuery(String queryString, int exceptedRowCount) {
         QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery, queryString)
;
@@ -206,4 +240,22 @@ public class TestQuery extends BaseTest {
         boolean b = ResultSetCompare.equalsByTerm(rs, expectedResultSet) ;
         assertTrue("Result sets different", b) ;
     }
+    
+    private static String initConstructContentTypes(String... contentTypes) {
+        // Or use WebContent.defaultGraphAcceptHeader which is slightly
+        // narrower. Here, we have a tuned setting for SPARQL operations.
+        StringBuilder sBuff = new StringBuilder() ;
+        for (int i=0;i<contentTypes.length;i++ ){
+        	accumulateContentTypeString(sBuff, contentTypes[i], 1- i*0.1);
+        }
+        return sBuff.toString();
+    }
+
+    private static void accumulateContentTypeString(StringBuilder sBuff, String str, double
v) {
+        if ( sBuff.length() != 0 )
+            sBuff.append(", ") ;
+        sBuff.append(str) ;
+        if ( v < 1 )
+            sBuff.append(";q=").append(v) ;
+    } 
 }


Mime
View raw message