You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by rv...@apache.org on 2013/04/09 00:44:27 UTC
svn commit: r1465816 - in /jena/Experimental/jena-jdbc:
jena-jdbc-core/src/test/java/org/apache/jena/jdbc/utils/
jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/connections/
jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/r...
Author: rvesse
Date: Mon Apr 8 22:44:27 2013
New Revision: 1465816
URL: http://svn.apache.org/r1465816
Log:
Expand remote endpoint driver tests and bug fix rename utility
Added:
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/results/TestRemoteEndpointResultsWithGraphUris.java
Modified:
jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/utils/TestUtils.java
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/connections/RemoteEndpointConnection.java
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/connections/TestRemoteEndpointConnectionWithGraphUris.java
Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/utils/TestUtils.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/utils/TestUtils.java?rev=1465816&r1=1465815&r2=1465816&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/utils/TestUtils.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/utils/TestUtils.java Mon Apr 8 22:44:27 2013
@@ -131,23 +131,39 @@ public class TestUtils {
}
/**
- * Renames a model within a dataset
+ * Renames a graph of a dataset producing a new dataset so as to not modify the original dataset
* @param ds Dataset
* @param oldUri Old URI
* @param newUri New URI
+ * @return New Dataset
*/
- public static void renameGraph(Dataset ds, String oldUri, String newUri) {
- Model m = oldUri != null ? ds.getNamedModel(oldUri) : ds.getDefaultModel();
+ public static Dataset renameGraph(Dataset ds, String oldUri, String newUri) {
+ Dataset dest = DatasetFactory.createMem();
if (oldUri == null) {
- ds.setDefaultModel(ModelFactory.createDefaultModel());
+ // Rename default graph
+ dest.addNamedModel(newUri, ds.getDefaultModel());
} else {
- ds.removeNamedModel(oldUri);
+ // Copy across default graph
+ dest.setDefaultModel(ds.getDefaultModel());
}
- if (newUri == null) {
- ds.setDefaultModel(m);
- } else {
- ds.addNamedModel(newUri, m);
+
+ Iterator<String> uris = ds.listNames();
+ while (uris.hasNext()) {
+ String uri = uris.next();
+ if (uri.equals(oldUri)) {
+ // Rename named graph
+ if (newUri == null) {
+ dest.setDefaultModel(ds.getNamedModel(oldUri));
+ } else {
+ dest.addNamedModel(newUri, ds.getNamedModel(oldUri));
+ }
+ } else {
+ // Copy across named graph
+ dest.addNamedModel(uri, ds.getNamedModel(uri));
+ }
}
+
+ return dest;
}
}
Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/connections/RemoteEndpointConnection.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/connections/RemoteEndpointConnection.java?rev=1465816&r1=1465815&r2=1465816&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/connections/RemoteEndpointConnection.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/connections/RemoteEndpointConnection.java Mon Apr 8 22:44:27 2013
@@ -96,6 +96,10 @@ public class RemoteEndpointConnection ex
this.queryService = queryEndpoint;
this.updateService = updateEndpoint;
this.readonly = this.updateService == null;
+ this.defaultGraphUris = defaultGraphUris;
+ this.namedGraphUris = namedGraphUris;
+ this.usingGraphUris = usingGraphUris;
+ this.usingNamedGraphUris = usingNamedGraphUris;
}
/**
Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/connections/TestRemoteEndpointConnectionWithGraphUris.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/connections/TestRemoteEndpointConnectionWithGraphUris.java?rev=1465816&r1=1465815&r2=1465816&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/connections/TestRemoteEndpointConnectionWithGraphUris.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/connections/TestRemoteEndpointConnectionWithGraphUris.java Mon Apr 8 22:44:27 2013
@@ -31,6 +31,7 @@ import org.apache.jena.jdbc.remote.conne
import org.apache.jena.jdbc.utils.TestUtils;
import org.junit.After;
import org.junit.AfterClass;
+import org.junit.Assert;
import org.junit.BeforeClass;
import com.hp.hpl.jena.query.Dataset;
@@ -83,7 +84,8 @@ public class TestRemoteEndpointConnectio
defaultGraphs.add(DEFAULT_GRAPH_URI);
// Set up the dataset
- TestUtils.renameGraph(ds, null, DEFAULT_GRAPH_URI);
+ ds = TestUtils.renameGraph(ds, null, DEFAULT_GRAPH_URI);
+ Assert.assertEquals(0, ds.getDefaultModel().size());
TestUtils.copyToRemoteDataset(ds, BaseServerTest.serviceREST);
return new RemoteEndpointConnection(BaseServerTest.serviceQuery, BaseServerTest.serviceUpdate, JenaConnection.DEFAULT_HOLDABILITY, JdbcCompatibility.DEFAULT);
}
Added: jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/results/TestRemoteEndpointResultsWithGraphUris.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/results/TestRemoteEndpointResultsWithGraphUris.java?rev=1465816&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/results/TestRemoteEndpointResultsWithGraphUris.java (added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/results/TestRemoteEndpointResultsWithGraphUris.java Mon Apr 8 22:44:27 2013
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.jdbc.remote.results;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.jena.fuseki.BaseServerTest;
+import org.apache.jena.fuseki.ServerTest;
+import org.apache.jena.jdbc.JdbcCompatibility;
+import org.apache.jena.jdbc.connections.JenaConnection;
+import org.apache.jena.jdbc.remote.connections.RemoteEndpointConnection;
+import org.apache.jena.jdbc.results.AbstractResultSetTests;
+import org.apache.jena.jdbc.utils.TestUtils;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+import com.hp.hpl.jena.query.Dataset;
+
+/**
+ * Tests result sets from a remote endpoint
+ *
+ */
+public class TestRemoteEndpointResultsWithGraphUris extends AbstractResultSetTests {
+
+ /**
+ * Constant for default graph URI used in these tests
+ */
+ private static final String DEFAULT_GRAPH_URI = "http://example.org/defaultGraphUri";
+
+ private static RemoteEndpointConnection connection;
+
+
+ /**
+ * Setup for the tests by allocating a Fuseki instance to work with
+ * @throws SQLException
+ */
+ @BeforeClass
+ public static void setup() throws SQLException {
+ ServerTest.allocServer();
+
+ List<String> defaultGraphUris = new ArrayList<String>();
+ defaultGraphUris.add(DEFAULT_GRAPH_URI);
+ connection = new RemoteEndpointConnection(BaseServerTest.serviceQuery, BaseServerTest.serviceUpdate, defaultGraphUris, null, null, null, JenaConnection.DEFAULT_HOLDABILITY, JdbcCompatibility.DEFAULT);
+ }
+
+ /**
+ * Clean up after each test by resetting the Fuseki instance
+ */
+ @After
+ public void cleanupTest() {
+ ServerTest.resetServer();
+ }
+
+ /**
+ * Clean up after tests by de-allocating the Fuseki instance
+ * @throws SQLException
+ */
+ @AfterClass
+ public static void cleanup() throws SQLException {
+ ServerTest.freeServer();
+
+ connection.close();
+ }
+
+ @Override
+ protected ResultSet createResults(Dataset ds, String query) throws SQLException {
+ ds = TestUtils.renameGraph(ds, null, DEFAULT_GRAPH_URI);
+ TestUtils.copyToRemoteDataset(ds, BaseServerTest.serviceREST);
+ Statement stmt = connection.createStatement();
+ return stmt.executeQuery(query);
+ }
+}