You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2014/07/03 14:55:07 UTC

svn commit: r1607624 - in /jena/Experimental/jena-fuseki2/src: main/java/org/apache/jena/fuseki/servlets/REST_Quads_RW.java test/java/org/apache/jena/fuseki/http/TestHttpOp.java

Author: andy
Date: Thu Jul  3 12:55:07 2014
New Revision: 1607624

URL: http://svn.apache.org/r1607624
Log:
JENA-738 : PUT quads to replace the dataset contents

Modified:
    jena/Experimental/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads_RW.java
    jena/Experimental/jena-fuseki2/src/test/java/org/apache/jena/fuseki/http/TestHttpOp.java

Modified: jena/Experimental/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads_RW.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads_RW.java?rev=1607624&r1=1607623&r2=1607624&view=diff
==============================================================================
--- jena/Experimental/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads_RW.java (original)
+++ jena/Experimental/jena-fuseki2/src/main/java/org/apache/jena/fuseki/servlets/REST_Quads_RW.java Thu Jul  3 12:55:07 2014
@@ -57,9 +57,9 @@ public class REST_Quads_RW extends REST_
             ServletOps.errorMethodNotAllowed("POST") ;
 
         if ( action.isTransactional() )
-            doPutPostTxn(action, false) ;
+            doPutPostTxn(action, true) ;
         else
-            doPutPostNonTxn(action, false) ;
+            doPutPostNonTxn(action, true) ;
     }
 
     // These are very similar to SPARQL_REST_RW.addDataIntoTxn/nonTxn
@@ -80,6 +80,8 @@ public class REST_Quads_RW extends REST_
         action.beginWrite() ;
         try {
             DatasetGraph dsg = action.getActiveDSG() ;
+            if ( clearFirst )
+                dsg.clear() ;
             StreamRDF dest = StreamRDFLib.dataset(dsg) ;
             details = Upload.incomingData(action, dest) ;
             action.commit() ;
@@ -112,7 +114,10 @@ public class REST_Quads_RW extends REST_
         // Now insert into dataset
         action.beginWrite() ;
         try {
-            FusekiLib.addDataInto(dsgTmp, action.getActiveDSG()) ;
+            DatasetGraph dsg = action.getActiveDSG() ;
+            if ( clearFirst )
+                dsg.clear() ;
+            FusekiLib.addDataInto(dsgTmp, dsg) ;
             action.commit() ;
             ServletOps.success(action) ;
         } catch (Exception ex) {

Modified: jena/Experimental/jena-fuseki2/src/test/java/org/apache/jena/fuseki/http/TestHttpOp.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-fuseki2/src/test/java/org/apache/jena/fuseki/http/TestHttpOp.java?rev=1607624&r1=1607623&r2=1607624&view=diff
==============================================================================
--- jena/Experimental/jena-fuseki2/src/test/java/org/apache/jena/fuseki/http/TestHttpOp.java (original)
+++ jena/Experimental/jena-fuseki2/src/test/java/org/apache/jena/fuseki/http/TestHttpOp.java Thu Jul  3 12:55:07 2014
@@ -40,9 +40,11 @@ public class TestHttpOp extends BaseTest
     @BeforeClass public static void beforeClass() { ServerTest.allocServer() ; }
     @AfterClass  public static void afterClass()  { ServerTest.freeServer() ; }
     
-    static String graphURL = ServerTest.serviceREST+"?default" ;
-    static String queryURL = ServerTest.serviceQuery ;
-    static String updateURL = ServerTest.serviceUpdate ;
+    static String gspServiceURL     = ServerTest.serviceREST ;
+    static String defaultGraphURL   = ServerTest.serviceREST+"?default" ;
+    static String namedGraphURL     = ServerTest.serviceREST+"?graph=http://example/g" ;
+    static String queryURL          = ServerTest.serviceQuery ;
+    static String updateURL         = ServerTest.serviceUpdate ;
     
     static String simpleQuery = queryURL+"?query="+IRILib.encodeUriComponent("ASK{}") ;
     
@@ -146,40 +148,86 @@ public class TestHttpOp extends BaseTest
     
     // GSP
     @Test public void gsp_01() {
-        String x = HttpOp.execHttpGetString(graphURL, "application/rdf+xml") ;
+        String x = HttpOp.execHttpGetString(defaultGraphURL, "application/rdf+xml") ;
         assertTrue(x.contains("</")) ;
         assertTrue(x.contains(":RDF")) ;
     }
 
     @Test public void gsp_02() {
-        String x = HttpOp.execHttpGetString(graphURL, "application/n-triples") ;
+        String x = HttpOp.execHttpGetString(defaultGraphURL, "application/n-triples") ;
         assertTrue(x.isEmpty()) ;
     }
     
     static String graphString = "@prefix : <http://example/> . :s :p :o ." ;
+    static String datasetString = "@prefix : <http://example/> . :s :p :o . :g { :sg :pg :og }" ;
     
     @Test public void gsp_03() {
-        HttpOp.execHttpPut(graphURL, WebContent.contentTypeTurtle, graphString) ;
+        HttpOp.execHttpPut(defaultGraphURL, WebContent.contentTypeTurtle, graphString) ;
     }
     
     @Test public void gsp_04() {
-        HttpOp.execHttpPut(graphURL, WebContent.contentTypeTurtle, graphString) ;
-        String s1 = HttpOp.execHttpGetString(graphURL, WebContent.contentTypeNTriples) ;
+        HttpOp.execHttpPut(defaultGraphURL, WebContent.contentTypeTurtle, graphString) ;
+        String s1 = HttpOp.execHttpGetString(defaultGraphURL, WebContent.contentTypeNTriples) ;
         assertFalse(s1.isEmpty()) ;
-        HttpOp.execHttpDelete(graphURL) ;
-        String s2 = HttpOp.execHttpGetString(graphURL, WebContent.contentTypeNTriples) ;
+        HttpOp.execHttpDelete(defaultGraphURL) ;
+        String s2 = HttpOp.execHttpGetString(defaultGraphURL, WebContent.contentTypeNTriples) ;
         assertTrue(s2.isEmpty()) ;
     }
     
     @Test public void gsp_05() {
-        HttpOp.execHttpDelete(graphURL) ;
+        HttpOp.execHttpDelete(defaultGraphURL) ;
         
-        HttpOp.execHttpPost(graphURL, WebContent.contentTypeTurtle, graphString) ;
-        String s1 = HttpOp.execHttpGetString(graphURL, WebContent.contentTypeNTriples) ;
+        HttpOp.execHttpPost(defaultGraphURL, WebContent.contentTypeTurtle, graphString) ;
+        String s1 = HttpOp.execHttpGetString(defaultGraphURL, WebContent.contentTypeNTriples) ;
         assertFalse(s1.isEmpty()) ;
-        HttpOp.execHttpDelete(graphURL) ;
-        String s2 = HttpOp.execHttpGetString(graphURL, WebContent.contentTypeNTriples) ;
+        HttpOp.execHttpDelete(defaultGraphURL) ;
+        String s2 = HttpOp.execHttpGetString(defaultGraphURL, WebContent.contentTypeNTriples) ;
         assertTrue(s2.isEmpty()) ;
     }
+    
+    @Test public void gsp_06() {
+        //HttpOp.execHttpDelete(namedGraphURL) ; -- woudl be 404.
+        
+        HttpOp.execHttpPost(namedGraphURL, WebContent.contentTypeTurtle, graphString) ;
+        String s1 = HttpOp.execHttpGetString(namedGraphURL, WebContent.contentTypeNTriples) ;
+        assertFalse(s1.isEmpty()) ;
+        String s2 = HttpOp.execHttpGetString(defaultGraphURL, WebContent.contentTypeNTriples) ;
+        assertTrue(s2.isEmpty()) ;
+        HttpOp.execHttpDelete(namedGraphURL) ;
+        String s3 = HttpOp.execHttpGetString(defaultGraphURL, WebContent.contentTypeNTriples) ;
+        assertTrue(s3.isEmpty()) ;
+        
+        try {
+            HttpOp.execHttpDelete(namedGraphURL) ;
+            fail("Expected 404") ;
+        } catch (HttpException ex) {
+            assertEquals(ex.getResponseCode(), HttpSC.NOT_FOUND_404) ;
+        }
+        
+    }
+
+    // Extended GSP - no ?default, no ?graph acts on the datasets as a whole.  
+   
+    @Test public void gsp_10() {
+        try {
+            HttpOp.execHttpDelete(gspServiceURL) ;
+            fail("Expected 405") ;
+        } catch (HttpException ex) {
+            assertEquals(ex.getResponseCode(), HttpSC.METHOD_NOT_ALLOWED_405) ;
+        }
+    }
+        
+    @Test public void gsp_11() {
+        
+        String s1 = HttpOp.execHttpGetString(gspServiceURL, WebContent.contentTypeNQuads) ;
+        assertTrue(s1.isEmpty()) ;
+        
+        HttpOp.execHttpPost(gspServiceURL, WebContent.contentTypeTriG, datasetString) ;
+        String s2 = HttpOp.execHttpGetString(gspServiceURL, WebContent.contentTypeNQuads) ;
+        assertFalse(s2.isEmpty()) ;
+        
+        String s4 = HttpOp.execHttpGetString(defaultGraphURL, WebContent.contentTypeNTriples) ;
+        assertFalse(s4.isEmpty()) ;
+    }
 }