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 2018/09/21 10:15:28 UTC
[17/70] [abbrv] [partial] jena git commit: JENA-1597: separate
jena-fuseki-webapp module
http://git-wip-us.apache.org/repos/asf/jena/blob/e8abcbb6/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestAuth.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestAuth.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestAuth.java
deleted file mode 100644
index 5e19f01..0000000
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestAuth.java
+++ /dev/null
@@ -1,380 +0,0 @@
-/*
- * 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.fuseki;
-
-import static org.apache.http.auth.AuthScope.ANY;
-
-import java.io.File ;
-import java.io.FileWriter ;
-import java.io.IOException ;
-import java.net.URISyntaxException ;
-import java.util.HashMap ;
-import java.util.Map ;
-
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.client.HttpClient;
-import org.apache.http.impl.client.BasicCredentialsProvider;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.jena.atlas.logging.LogCtl ;
-import org.apache.jena.atlas.web.HttpException ;
-import org.apache.jena.fuseki.Fuseki;
-import org.apache.jena.fuseki.FusekiLib;
-import org.apache.jena.query.DatasetAccessor ;
-import org.apache.jena.query.DatasetAccessorFactory ;
-import org.apache.jena.query.QueryExecutionFactory ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.sparql.engine.http.QueryEngineHTTP ;
-import org.apache.jena.sparql.engine.http.QueryExceptionHTTP ;
-import org.apache.jena.sparql.engine.http.Service ;
-import org.apache.jena.sparql.modify.UpdateProcessRemoteBase ;
-import org.apache.jena.sparql.util.Context ;
-import org.apache.jena.update.UpdateExecutionFactory ;
-import org.apache.jena.update.UpdateFactory ;
-import org.apache.jena.update.UpdateRequest ;
-import org.junit.AfterClass ;
-import org.junit.Assert ;
-import org.junit.BeforeClass ;
-import org.junit.Test ;
-
-/**
- * Tests Fuseki operation with authentication enabled.
- * This is as much a test of the Jena client libraries handling authentication.
- * These tests use Jetty-supplied authentication, not Apache Shiro.
- */
-public class TestAuth {
-
- // Use different port etc because sometimes the previous testing servers
- // don't release ports fast enough (OS issue / Linux)
- public static final int authPort = FusekiLib.choosePort() ;
- public static final String authUrlRoot = "http://localhost:"+authPort+"/" ;
- public static final String authDatasetPath = "/dataset" ;
- public static final String authServiceUpdate = "http://localhost:"+authPort+authDatasetPath+"/update" ;
- public static final String authServiceQuery = "http://localhost:"+authPort+authDatasetPath+"/query" ;
- public static final String authServiceREST = "http://localhost:"+authPort+authDatasetPath+"/data" ;
- private static File realmFile;
-
- /**
- * Sets up the authentication for tests
- * @throws IOException
- */
- @BeforeClass
- public static void setup() throws IOException {
- realmFile = File.createTempFile("realm", ".properties");
-
- try ( FileWriter writer = new FileWriter(realmFile); ) {
- writer.write("allowed: password, fuseki\n");
- writer.write("forbidden: password, other");
- }
-
- LogCtl.setLevel(Fuseki.serverLogName, "warn");
- LogCtl.setLevel(Fuseki.actionLogName, "warn") ;
- LogCtl.setLevel("org.eclipse.jetty", "warn") ;
-
- ServerCtl.setupServer(authPort, realmFile.getAbsolutePath(), authDatasetPath, true);
- }
-
- /**
- * Tears down authentication test setup
- */
- @AfterClass
- public static void teardown() {
- ServerCtl.teardownServer();
- realmFile.delete();
- }
-
- @Test(expected = QueryExceptionHTTP.class)
- public void query_with_auth_01() {
- QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
- // No auth credentials should result in an error
- qe.execAsk();
- }
-
- private static HttpClient withBasicAuth(AuthScope scope, String user, String passwd) {
- BasicCredentialsProvider provider = new BasicCredentialsProvider();
- UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(user, passwd);
- provider.setCredentials(scope, credentials);
- return HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
- }
-
- @Test(expected = QueryExceptionHTTP.class)
- public void query_with_auth_02() {
- QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
- // Auth credentials for valid user with bad password
- qe.setClient(withBasicAuth(ANY, "allowed", "incorrect"));
- qe.execAsk();
- }
-
- @Test
- public void query_with_auth_03() {
- QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
- // Auth credentials for valid user with correct password
- qe.setClient(withBasicAuth(ANY, "allowed", "password"));
- Assert.assertTrue(qe.execAsk());
- }
-
- @Test(expected = QueryExceptionHTTP.class)
- public void query_with_auth_04() {
- QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
- // Auth credentials for valid user with correct password BUT not in
- // correct role
- qe.setClient(withBasicAuth(ANY, "forbidden", "password"));
- qe.execAsk();
- }
-
- @Test
- public void query_with_auth_05() {
- // Uses auth and enables compression
- QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
- qe.setAllowCompression(true);
-
- // Auth credentials for valid user with correct password
- qe.setClient(withBasicAuth(ANY, "allowed", "password"));
- Assert.assertTrue(qe.execAsk());
- }
-
- @Test(expected = QueryExceptionHTTP.class)
- public void query_with_auth_06() {
- // Uses auth and enables compression
- QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
- qe.setAllowCompression(true);
-
- // Auth credentials for valid user with bad password
- qe.setClient(withBasicAuth(ANY, "allowed", "incorrect"));
- qe.execAsk();
- }
-
- @Test(expected = QueryExceptionHTTP.class)
- public void query_with_auth_07() throws URISyntaxException {
- QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
-
- // Auth credentials for valid user with correct password but scoped to
- // wrong URI
- qe.setClient(withBasicAuth(new AuthScope("example", authPort), "allowed", "password"));
- qe.execAsk();
- }
-
- @Test
- public void query_with_auth_08() throws URISyntaxException {
- QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
-
- // Auth credentials for valid user with correct password and scoped to
- // correct URI
- qe.setClient(withBasicAuth(new AuthScope("localhost", authPort), "allowed", "password"));
- Assert.assertTrue(qe.execAsk());
- }
-
- @Test
- public void query_with_auth_09() throws URISyntaxException {
- QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
-
- // Auth credentials for valid user with correct password
- qe.setClient(withBasicAuth(new AuthScope("localhost", authPort), "allowed", "password"));
- Assert.assertTrue(qe.execAsk());
- }
-
- @Test
- public void query_with_auth_10() {
- QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
-
- // Auth credentials for valid user with correct password and scoped
- // to correct URI
- // Provided via Service Context and its associated authenticator
- Map<String, Context> serviceContext = new HashMap<>();
- Context authContext = new Context();
-
- HttpClient client = withBasicAuth(ANY, "allowed", "password");
- authContext.put(Service.queryClient, client);
- serviceContext.put(authServiceQuery, authContext);
- qe.getContext().put(Service.serviceContext, serviceContext);
- Assert.assertTrue(qe.execAsk());
- }
-
- @Test
- public void query_with_auth_11() {
- QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
-
- // Auth credentials for valid user with correct password and scoped
- // to base URI of the actual service URL
- // Provided via Service Context and its associated authenticator
- Map<String, Context> serviceContext = new HashMap<>();
- Context authContext = new Context();
-
- HttpClient client = withBasicAuth(ANY, "allowed", "password");
- authContext.put(Service.queryClient, client);
- serviceContext.put(authServiceQuery, authContext);
- qe.getContext().put(Service.serviceContext, serviceContext);
- Assert.assertTrue(qe.execAsk());
- }
-
- @Test
- public void query_with_auth_13() throws URISyntaxException {
- QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
-
- // Auth credentials for valid user with correct password and scoped to
- // base URI of the actual service URL
- qe.setClient(withBasicAuth(new AuthScope("localhost" , authPort),"allowed", "password"));
- Assert.assertTrue(qe.execAsk());
- }
-
- @Test
- public void query_with_auth_14() throws URISyntaxException {
- QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
-
- // Auth credentials for valid user with correct password and scoped to
- // base URI of the actual service URL
- qe.setClient(withBasicAuth(new AuthScope("localhost" , authPort),"allowed", "password"));
- Assert.assertTrue(qe.execAsk());
- }
-
- @Test(expected = HttpException.class)
- public void update_with_auth_01() {
- UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
- UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate);
- // No auth credentials should result in an error
- ue.execute();
- }
-
- @Test(expected = HttpException.class)
- public void update_with_auth_02() {
- UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
- UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate);
- // Auth credentials for valid user with bad password
- ue.setClient(withBasicAuth(ANY, "allowed", "incorrect"));
- ue.execute();
- }
-
- @Test
- public void update_with_auth_03() {
- UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
- UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate);
- // Auth credentials for valid user with correct password
- ue.setClient(withBasicAuth(ANY, "allowed", "password"));
- ue.execute();
- }
-
- @Test(expected = HttpException.class)
- public void update_with_auth_04() {
- UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
- UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate);
- // Auth credentials for valid user with correct password BUT not in
- // correct role
- ue.setClient(withBasicAuth(ANY, "forbidden", "password"));
- ue.execute();
- }
-
- @Test(expected = HttpException.class)
- public void update_with_auth_05() {
- UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
- UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, authServiceUpdate);
- // No auth credentials should result in an error
- ue.execute();
- }
-
- @Test(expected = HttpException.class)
- public void update_with_auth_06() {
- UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
- UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, authServiceUpdate);
- // Auth credentials for valid user with bad password
- ue.setClient(withBasicAuth(ANY, "allowed", "incorrect"));
- ue.execute();
- }
-
- @Test
- public void update_with_auth_07() {
- UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
- UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, authServiceUpdate);
- // Auth credentials for valid user with correct password
- ue.setClient(withBasicAuth(ANY, "allowed", "password"));
- ue.execute();
- }
-
- @Test(expected = HttpException.class)
- public void update_with_auth_08() {
- UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
- UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, authServiceUpdate);
- // Auth credentials for valid user with correct password BUT not in
- // correct role
- ue.setClient(withBasicAuth(ANY, "forbidden", "password"));
- ue.execute();
- }
-
- @Test(expected = HttpException.class)
- public void update_with_auth_09() throws URISyntaxException {
- UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
- UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate);
-
- // Auth credentials for valid user with correct password but scoped to
- // wrong URI
- ue.setClient(withBasicAuth(new AuthScope("example" , authPort),"allowed", "password"));
- ue.execute();
- }
-
- @Test
- public void update_with_auth_10() throws URISyntaxException {
- UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
- UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate);
-
- // Auth credentials for valid user with correct password scoped to
- // correct URI
- ue.setClient(withBasicAuth(new AuthScope("localhost" , authPort),"allowed", "password"));
- ue.execute();
- }
-
- @Test(expected = HttpException.class)
- public void graphstore_with_auth_01() {
- // No auth credentials
- DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(authServiceREST);
- accessor.getModel();
- }
-
- @Test(expected = HttpException.class)
- public void graphstore_with_auth_02() {
- // Incorrect auth credentials
- DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(authServiceREST,
- withBasicAuth(ANY, "allowed", "incorrect"));
- accessor.getModel();
- }
-
- @Test
- public void graphstore_with_auth_03() {
- // Correct auth credentials
- DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(authServiceREST,
- withBasicAuth(ANY, "allowed", "password"));
- Model m = accessor.getModel();
- Assert.assertTrue(m.isEmpty());
- }
-
- @Test(expected = HttpException.class)
- public void graphstore_with_auth_04() throws URISyntaxException {
- // Correct auth credentials scoped to wrong URI
- DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(authServiceREST,
- withBasicAuth(new AuthScope("example.org", authPort), "allowed", "password"));
- accessor.getModel();
- }
-
- @Test
- public void graphstore_with_auth_05() throws URISyntaxException {
- // Correct auth credentials scoped to correct URI
- DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(authServiceREST,
- withBasicAuth(new AuthScope("localhost", authPort), "allowed", "password"));
- accessor.getModel();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/e8abcbb6/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestBuilder.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestBuilder.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestBuilder.java
deleted file mode 100644
index 7041498..0000000
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestBuilder.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- * 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.fuseki;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-
-import org.apache.jena.fuseki.build.DatasetDescriptionRegistry;
-import org.apache.jena.fuseki.build.FusekiBuilder;
-import org.apache.jena.query.Dataset;
-import org.apache.jena.rdf.model.Model;
-import org.apache.jena.rdf.model.ModelFactory;
-import org.apache.jena.rdf.model.Resource;
-import org.apache.jena.tdb.assembler.VocabTDB;
-import org.apache.jena.vocabulary.RDF;
-import org.junit.Test;
-
-public class TestBuilder {
-
- private static final Model dsModel;
- private static final Resource dsDesc1;
- private static final Resource dsDesc2;
- private DatasetDescriptionRegistry registry = new DatasetDescriptionRegistry() ;
-
- @Test
- public void testVerifySameDatasetObjectForSameDescription() {
-
- Dataset ds1 = FusekiBuilder.getDataset(dsDesc1, registry);
- Dataset ds2 = FusekiBuilder.getDataset(dsDesc1, registry);
- assertEquals(ds1, ds2);
- }
-
- @Test
- public void testVerifyDifferentDatasetObjectsForDifferentDescriptions() {
-
- Dataset ds1 = FusekiBuilder.getDataset(dsDesc1, registry);
- Dataset ds2 = FusekiBuilder.getDataset(dsDesc2, registry);
- assertNotEquals(ds1, ds2);
- }
-
- static {
- dsModel = ModelFactory.createDefaultModel();
- dsDesc1 = dsModel.createResource()
- .addProperty(RDF.type, VocabTDB.tDatasetTDB)
- .addProperty(VocabTDB.pLocation, "--mem--")
- ;
- dsDesc2 = dsModel.createResource()
- .addProperty(RDF.type, VocabTDB.tDatasetTDB)
- .addProperty(VocabTDB.pLocation, "--mem--")
- ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/e8abcbb6/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestDatasetAccessorHTTP.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestDatasetAccessorHTTP.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestDatasetAccessorHTTP.java
deleted file mode 100644
index d26b23f..0000000
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestDatasetAccessorHTTP.java
+++ /dev/null
@@ -1,318 +0,0 @@
-/*
- * 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.fuseki;
-
-import static org.apache.jena.fuseki.ServerCtl.datasetPath ;
-import static org.apache.jena.fuseki.ServerCtl.port ;
-import static org.apache.jena.fuseki.ServerCtl.serviceGSP ;
-import static org.apache.jena.fuseki.ServerCtl.urlDataset ;
-import static org.apache.jena.fuseki.ServerTest.gn1 ;
-import static org.apache.jena.fuseki.ServerTest.gn2 ;
-import static org.apache.jena.fuseki.ServerTest.gn99 ;
-import static org.apache.jena.fuseki.ServerTest.model1 ;
-import static org.apache.jena.fuseki.ServerTest.model2 ;
-
-import org.apache.jena.atlas.web.HttpException ;
-import org.apache.jena.query.DatasetAccessor ;
-import org.apache.jena.query.DatasetAccessorFactory ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.rdf.model.ModelFactory ;
-import org.apache.jena.riot.web.HttpOp ;
-import org.apache.jena.web.HttpSC ;
-import org.junit.Test ;
-
-
-public class TestDatasetAccessorHTTP extends AbstractFusekiTest
-{
- //Model level testing.
-
- static final String datasetURI_not_1 = "http://localhost:"+port()+"/junk" ;
- static final String datasetURI_not_2 = serviceGSP()+"/not" ;
- static final String datasetURI_not_3 = "http://localhost:"+port()+datasetPath()+"/not/data" ;
-
- @Test
- public void test_ds_1()
- {
- // Can GET the dataset service.
- try {
- HttpOp.execHttpGet(serviceGSP()) ;
- } catch (HttpException ex) {
- assertTrue(HttpSC.isClientError(ex.getResponseCode())) ;
- throw ex ;
- }
- }
-
- @Test
- public void test_ds_2()
- {
- FusekiTest.exec404(()->HttpOp.execHttpGet(datasetURI_not_1)) ;
- }
-
- @Test
- public void test_ds_3()
- {
- FusekiTest.exec404(()->HttpOp.execHttpGet(datasetURI_not_2)) ;
- }
-
- @Test
- public void test_404_1()
- {
- // Not the right service.
- DatasetAccessor du = DatasetAccessorFactory.createHTTP(datasetURI_not_1) ;
- Model graph = du.getModel(gn99) ;
- assertNull(graph) ;
- }
-
- @Test
- public void test_404_2()
- {
- DatasetAccessor du = DatasetAccessorFactory.createHTTP(datasetURI_not_2) ;
- Model graph = du.getModel(gn99) ;
- assertNull(graph) ;
- }
-
- @Test
- public void test_404_3()
- {
- // Right service, wrong graph
- DatasetAccessor du = DatasetAccessorFactory.createHTTP(serviceGSP()) ;
- Model graph = du.getModel(gn99) ;
- assertNull(graph) ;
- }
-
- @Test public void head_01()
- {
- DatasetAccessor du = connectToService() ;
- boolean b = du.containsModel(gn1) ;
- assertFalse("Blank remote dataset as a named graph", b) ;
- }
-
- @Test public void head_02()
- {
- DatasetAccessor du = connectToService() ;
- du.putModel(gn1, model1) ;
- boolean exists = du.containsModel(gn1) ;
- assertTrue(exists) ;
- exists = du.containsModel(gn2) ;
- assertFalse("Expected gn2 not to exist (1)", exists) ;
-
- exists = du.containsModel(gn2) ;
- assertFalse("Expected gn2 not to exist (2)", exists) ;
- // Clearup
- du.deleteModel(gn1) ;
- }
-
- @Test public void get_01()
- {
- DatasetAccessor du = connectToService() ;
- Model graph = du.getModel() ;
- assertTrue(graph.isEmpty()) ;
- }
-
- @Test public void get_02()
- {
- DatasetAccessor du = connectToService() ;
- Model graph = du.getModel(gn1) ;
- assertNull(graph) ;
- }
-
- // Dataset direct, not using the service endpoint.
- @Test public void get_03()
- {
- DatasetAccessor du = connectToDataset() ;
- Model graph = du.getModel() ;
- assertTrue(graph.isEmpty()) ;
- }
-
- @Test public void get_04()
- {
- DatasetAccessor du = connectToDataset() ;
- Model graph = du.getModel(gn1) ;
- assertNull(graph) ;
- }
-
- @Test public void delete_01()
- {
- DatasetAccessor du = connectToService() ;
- du.deleteDefault() ;
- }
-
- @Test public void delete_02()
- {
- DatasetAccessor du = connectToService() ;
- du.deleteModel(gn1) ;
- boolean exists = du.containsModel(gn1) ;
- assertFalse("Expected gn1 not to exist", exists) ;
- }
-
- @Test public void delete_03()
- {
- DatasetAccessor du = connectToDataset() ;
- du.deleteDefault() ;
- }
-
- @Test public void delete_04()
- {
- DatasetAccessor du = connectToDataset() ;
- du.deleteModel(gn1) ;
- boolean exists = du.containsModel(gn1) ;
- assertFalse("Expected gn1 not to exist", exists) ;
- }
-
- @Test public void put_01()
- {
- DatasetAccessor du = connectToService() ;
- du.putModel(model1) ;
- Model graph = du.getModel() ;
- assertTrue(graph.isIsomorphicWith(model1)) ;
- // Empty it.
- du.deleteDefault() ;
- graph = du.getModel() ;
- assertTrue(graph.isEmpty()) ;
- }
-
- @Test public void put_02()
- {
- DatasetAccessor du = connectToService() ;
- du.putModel(gn1, model1) ;
- boolean exists = du.containsModel(gn1) ;
- assertTrue(exists) ;
- exists = du.containsModel(gn2) ;
- assertFalse("Expected gn2 not to exist", exists) ;
-
- Model graph = du.getModel() ;
- assertTrue(graph.isEmpty()) ;
- graph = du.getModel(gn1) ;
- assertTrue(graph.isIsomorphicWith(model1)) ;
-
- du.deleteModel(gn1) ;
- exists = du.containsModel(gn1) ;
- assertFalse("Expected gn1 not to exist", exists) ;
-
- graph = du.getModel(gn1) ;
- assertNull(graph) ;
- }
-
- @Test public void put_03()
- {
- DatasetAccessor du = connectToService() ;
- du.putModel(model1) ;
- du.putModel(model2) ; // PUT overwrites
- Model graph = du.getModel() ;
- assertFalse(graph.isIsomorphicWith(model1)) ;
- assertTrue(graph.isIsomorphicWith(model2)) ;
- // Empty it.
- du.deleteDefault() ;
- graph = du.getModel() ;
- assertTrue(graph.isEmpty()) ;
- }
-
- @Test public void put_04()
- {
- DatasetAccessor du = connectToDataset() ;
- du.putModel(model1) ;
- Model graph = du.getModel() ;
- assertTrue(graph.isIsomorphicWith(model1)) ;
- // Empty it.
- du.deleteDefault() ;
- graph = du.getModel() ;
- assertTrue(graph.isEmpty()) ;
- }
-
-
- @Test public void post_01()
- {
- DatasetAccessor du = connectToService() ;
- du.putModel(model1) ;
- du.add(model2) ; // POST appends
- Model graph = du.getModel() ;
-
- Model graph3 = ModelFactory.createDefaultModel() ;
- graph3.add(model1) ;
- graph3.add(model2) ;
-
- assertFalse(graph.isIsomorphicWith(model1)) ;
- assertFalse(graph.isIsomorphicWith(model2)) ;
- assertTrue(graph.isIsomorphicWith(graph3)) ;
- // Empty it.
- du.deleteDefault() ;
- graph = du.getModel() ;
- assertTrue(graph.isEmpty()) ;
- }
-
- @Test public void post_02()
- {
- DatasetAccessor du = connectToService() ;
- du.add(model1) ;
- du.add(model2) ;
- Model graph = du.getModel() ;
-
- Model graph3 = ModelFactory.createDefaultModel() ;
- graph3.add(model1) ;
- graph3.add(model2) ;
-
- assertFalse(graph.isIsomorphicWith(model1)) ;
- assertFalse(graph.isIsomorphicWith(model2)) ;
- assertTrue(graph.isIsomorphicWith(graph3)) ;
- // Empty it.
- du.deleteDefault() ;
- graph = du.getModel() ;
- assertTrue(graph.isEmpty()) ;
- }
-
- @Test public void post_03()
- {
- DatasetAccessor du = connectToDataset() ;
- du.putModel(model1) ;
- du.add(model2) ; // POST appends
- Model graph = du.getModel() ;
-
- Model graph3 = ModelFactory.createDefaultModel() ;
- graph3.add(model1) ;
- graph3.add(model2) ;
-
- assertFalse(graph.isIsomorphicWith(model1)) ;
- assertFalse(graph.isIsomorphicWith(model2)) ;
- assertTrue(graph.isIsomorphicWith(graph3)) ;
- // Empty it.
- du.deleteDefault() ;
- graph = du.getModel() ;
- assertTrue(graph.isEmpty()) ;
- }
-
- @Test public void clearup_1()
- {
- DatasetAccessor du = connectToService() ;
- du.deleteDefault() ;
- du.deleteModel(gn1) ;
- du.deleteModel(gn2) ;
- du.deleteModel(gn99) ;
- }
-
- static DatasetAccessor connectToService()
- {
- return DatasetAccessorFactory.createHTTP(serviceGSP()) ;
- }
-
- static DatasetAccessor connectToDataset()
- {
- return DatasetAccessorFactory.createHTTP(urlDataset()) ;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/e8abcbb6/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestDatasetGraphAccessorHTTP.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestDatasetGraphAccessorHTTP.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestDatasetGraphAccessorHTTP.java
deleted file mode 100644
index cfcd9d7..0000000
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestDatasetGraphAccessorHTTP.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.fuseki;
-
-import org.apache.jena.web.AbstractTestDatasetGraphAccessor ;
-import org.apache.jena.web.DatasetGraphAccessor ;
-import org.apache.jena.web.DatasetGraphAccessorHTTP ;
-import org.junit.After ;
-import org.junit.AfterClass ;
-import org.junit.Before ;
-import org.junit.BeforeClass ;
-
-public class TestDatasetGraphAccessorHTTP extends AbstractTestDatasetGraphAccessor
-{
- @BeforeClass public static void ctlBeforeClass() { ServerCtl.ctlBeforeClass(); }
- @AfterClass public static void ctlAfterClass() { ServerCtl.ctlAfterClass(); }
- @Before public void ctlBeforeTest() { ServerCtl.ctlBeforeTest(); }
- @After public void ctlAfterTest() { ServerCtl.ctlAfterTest(); }
-
- @Override
- protected DatasetGraphAccessor getDatasetUpdater() {
- return new DatasetGraphAccessorHTTP(ServerCtl.serviceGSP()) ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/e8abcbb6/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestDatasetOps.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestDatasetOps.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestDatasetOps.java
deleted file mode 100644
index affeb89..0000000
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestDatasetOps.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * 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.fuseki;
-
-import static org.apache.jena.fuseki.ServerCtl.* ;
-import org.apache.http.HttpEntity ;
-import org.apache.http.entity.EntityTemplate ;
-import org.apache.jena.atlas.lib.StrUtils ;
-import org.apache.jena.atlas.web.HttpException ;
-import org.apache.jena.atlas.web.TypedInputStream ;
-import org.apache.jena.riot.* ;
-import org.apache.jena.riot.system.StreamRDF ;
-import org.apache.jena.riot.system.StreamRDFLib ;
-import org.apache.jena.riot.web.HttpOp ;
-import org.apache.jena.sparql.core.DatasetGraph ;
-import org.apache.jena.sparql.core.DatasetGraphFactory ;
-import org.apache.jena.sparql.sse.SSE ;
-import org.apache.jena.web.HttpSC ;
-import org.junit.Test ;
-
-/** TestDatasetAccessorHTTP does most of the GSP testing.
- * This class adds the testing of Jena Fuseki extras - whole dataset HTTP.
- */
-public class TestDatasetOps extends AbstractFusekiTest
-{
- static DatasetGraph data = SSE.parseDatasetGraph(StrUtils.strjoinNL
- ("(prefix ((: <http://example/>))",
- " (dataset",
- " (graph (_:x :p 1) (_:x :p 2))" ,
- " (graph :g (_:x :p 3))",
- "))"
- )) ;
-
- /** Create an HttpEntity for the graph */
- protected HttpEntity datasetToHttpEntity(final DatasetGraph dsg) {
- final RDFFormat syntax = RDFFormat.NQUADS ;
- EntityTemplate entity = new EntityTemplate((out) -> RDFDataMgr.write(out, dsg, syntax)) ;
- String ct = syntax.getLang().getContentType().getContentType() ;
- entity.setContentType(ct) ;
- return entity ;
- }
-
- @Test public void gsp_x_01() {
- gsp_x(urlDataset(), urlDataset()) ;
- }
-
- @Test public void gsp_x_02() {
- gsp_x(urlDataset(), serviceGSP()) ;
- }
-
- @Test public void gsp_x_03() {
- gsp_x(serviceGSP(), urlDataset()) ;
- }
-
- private void gsp_x(String outward, String inward) {
- HttpEntity e = datasetToHttpEntity(data) ;
- int expectedSize = data.getDefaultGraph().size();
- HttpOp.execHttpPut(outward, e);
- DatasetGraph dsg = DatasetGraphFactory.create() ;
- RDFDataMgr.read(dsg, inward, Lang.NQUADS);
- assertEquals(expectedSize, dsg.getDefaultGraph().size()) ;
- }
-
- // Get dataset. Tests conneg.
- @Test
- public void gsp_x_10() {
- gsp_x_ct(urlDataset(), WebContent.contentTypeNQuads, WebContent.contentTypeNQuads) ;
- }
-
- @Test
- public void gsp_x_11() {
- gsp_x_ct(urlDataset(), WebContent.contentTypeNQuadsAlt1, WebContent.contentTypeNQuads) ;
- }
-
- @Test
- public void gsp_x_12() {
- gsp_x_ct(urlDataset(), WebContent.contentTypeTriG, WebContent.contentTypeTriG) ;
- }
-
- @Test
- public void gsp_x_13() {
- gsp_x_ct(urlDataset(), WebContent.contentTypeTriGAlt1, WebContent.contentTypeTriG) ;
- }
-
- @Test
- public void gsp_x_14() {
- gsp_x_ct(urlDataset(), WebContent.defaultDatasetAcceptHeader, WebContent.contentTypeTriG) ;
- }
-
- @Test
- public void gsp_x_15() {
- // Anything!
- gsp_x_ct(urlDataset(), WebContent.defaultRDFAcceptHeader, WebContent.contentTypeTriG) ;
- }
-
- private void gsp_x_ct(String urlDataset, String acceptheader, String contentTypeResponse) {
- HttpEntity e = datasetToHttpEntity(data) ;
- HttpOp.execHttpPut(urlDataset(), e);
-
- // Do manually so the test can validate the expected ContentType
- try ( TypedInputStream in = HttpOp.execHttpGet(urlDataset, acceptheader) ) {
- assertEqualsIgnoreCase(contentTypeResponse, in.getContentType()) ;
- Lang lang = RDFLanguages.contentTypeToLang(in.getContentType());
- DatasetGraph dsg = DatasetGraphFactory.create() ;
- StreamRDF dest = StreamRDFLib.dataset(dsg) ;
- RDFParser.source(in).lang(lang).parse(dest);
- }
- }
-
- @Test
- public void gsp_x_20()
- {
- HttpEntity e = datasetToHttpEntity(data) ;
- try {
- HttpOp.execHttpPost(serviceQuery(), e);
- } catch (HttpException ex) {
- assertTrue(HttpSC.isClientError(ex.getResponseCode())) ;
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/e8abcbb6/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestFileUpload.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestFileUpload.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestFileUpload.java
deleted file mode 100644
index 4b772f9..0000000
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestFileUpload.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * 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.fuseki;
-
-import org.apache.jena.atlas.web.TypedInputStream ;
-import org.apache.jena.query.DatasetAccessor ;
-import org.apache.jena.query.DatasetAccessorFactory ;
-import org.apache.jena.rdf.model.Model ;
-import org.apache.jena.rdf.model.ModelFactory ;
-import org.apache.jena.riot.RDFDataMgr ;
-import org.apache.jena.riot.RDFLanguages ;
-import org.apache.jena.riot.web.HttpOp ;
-import org.junit.Test ;
-
-/** Additional tests for the SPARQL Graph Store protocol,
- * mainly for HTTP file upload. See {@linkplain TestDatasetAccessorHTTP}
- * and {@linkplain TestHttpOp} for tests that exercise direct GSp functionality
- *
- * @see TestDatasetAccessorHTTP
- * @see TestHttpOp
- */
-public class TestFileUpload extends AbstractFusekiTest
-{
- @Test public void upload_gsp_01()
- {
- FileSender x = new FileSender(ServerCtl.serviceGSP()+"?default") ;
- x.add("D.ttl", "<http://example/s> <http://example/p> <http://example/o> .", "text/turtle") ;
- x.send("POST") ;
-
- Model m = ModelFactory.createDefaultModel() ;
- TypedInputStream in = HttpOp.execHttpGet(ServerCtl.serviceGSP(), "text/turtle") ;
- RDFDataMgr.read(m, in, RDFLanguages.contentTypeToLang(in.getMediaType()) ) ;
- // which is is effectively :
-// DatasetAccessor du = DatasetAccessorFactory.createHTTP(serviceREST) ;
-// Model m = du.getModel() ;
- assertEquals(1, m.size()) ;
- }
-
- @Test public void upload_gsp_02()
- {
- FileSender x = new FileSender(ServerCtl.serviceGSP()+"?default") ;
- x.add("D.ttl", "<http://example/s> <http://example/p> 123 .", "text/turtle") ;
- x.add("D.nt", "<http://example/s> <http://example/p> <http://example/o-456> .", "application/n-triples") ;
- x.send("PUT") ;
-
- // BUG
- DatasetAccessor du = DatasetAccessorFactory.createHTTP(ServerCtl.serviceGSP()) ;
- Model m = du.getModel() ;
- assertEquals(2, m.size()) ;
- }
-
- // Extension of GSP - no graph selector => dataset
- @Test public void upload_gsp_03()
- {
- FileSender x = new FileSender(ServerCtl.serviceGSP()) ;
- x.add("D.ttl", "<http://example/s> <http://example/p> <http://example/o> .", "text/turtle") ;
- x.add("D.trig", "<http://example/g> { <http://example/s> <http://example/p> <http://example/o> }", "text/trig") ;
- x.send("POST") ;
-
- DatasetAccessor du = DatasetAccessorFactory.createHTTP(ServerCtl.serviceGSP()) ;
- Model m = du.getModel() ;
- assertEquals(1, m.size()) ;
- }
-
- @Test public void upload_gsp_04()
- {
- {
- DatasetAccessor du = DatasetAccessorFactory.createHTTP(ServerCtl.serviceGSP()) ;
- Model m = du.getModel() ;
- assertEquals(0, m.size()) ;
- }
- FileSender x = new FileSender(ServerCtl.urlDataset()) ;
- x.add("D.ttl", "<http://example/s> <http://example/p> <http://example/o> .", "text/plain") ;
- x.add("D.trig", "<http://example/g> { <http://example/s> <http://example/p> 123,456 }", "text/plain") ;
- x.send("POST") ;
-
- DatasetAccessor du = DatasetAccessorFactory.createHTTP(ServerCtl.serviceGSP()) ;
- Model m = du.getModel() ;
- assertEquals(1, m.size()) ;
- m = du.getModel("http://example/g") ;
- assertEquals(2, m.size()) ;
- }
-
- // Via DatasetAccessor
-
- @Test public void dataset_accessor_01() {
- FileSender x = new FileSender(ServerCtl.urlDataset()) ;
- x.add("D.nq", "", "application/-n-quads") ;
- x.send("PUT") ;
-
- DatasetAccessor du = DatasetAccessorFactory.createHTTP(ServerCtl.serviceGSP()) ;
- Model m = du.getModel() ;
- assertEquals(0, m.size()) ;
- }
-
- @Test public void dataset_accessor_02() {
- FileSender x = new FileSender(ServerCtl.urlDataset()) ;
- x.add("D.nq", "<http://example/s> <http://example/p> <http://example/o-456> <http://example/g> .", "application/n-quads") ;
- x.send("PUT") ;
-
- DatasetAccessor du = DatasetAccessorFactory.createHTTP(ServerCtl.serviceGSP()) ;
- Model m = du.getModel("http://example/g") ;
- assertEquals(1, m.size()) ;
- m = du.getModel() ;
- assertEquals(0, m.size()) ;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/e8abcbb6/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestHttpOp.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestHttpOp.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestHttpOp.java
deleted file mode 100644
index 05d523f..0000000
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestHttpOp.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/**
- * 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.fuseki;
-
-import static org.apache.jena.fuseki.FusekiTest.exec404;
-import static org.apache.jena.fuseki.FusekiTest.execWithHttpException;
-import static org.apache.jena.fuseki.ServerCtl.serviceGSP ;
-import static org.apache.jena.fuseki.ServerCtl.serviceQuery ;
-import static org.apache.jena.fuseki.ServerCtl.serviceUpdate ;
-import static org.apache.jena.fuseki.ServerCtl.urlRoot ;
-import static org.apache.jena.riot.web.HttpOp.initialDefaultHttpClient;
-
-import org.apache.http.client.HttpClient;
-import org.apache.jena.atlas.lib.IRILib ;
-import org.apache.jena.atlas.web.TypedInputStream ;
-import org.apache.jena.riot.WebContent ;
-import org.apache.jena.riot.web.HttpOp ;
-import org.apache.jena.sparql.engine.http.Params ;
-import org.apache.jena.web.HttpSC ;
-import org.junit.Test ;
-
-// This a mixture of testing HttpOp and testing basic operation of the SPARQL server
-// especially error cases abnd unusual usage that the higher level APIs don't use.
-public class TestHttpOp extends AbstractFusekiTest {
-
- static String pingURL = urlRoot()+"$/ping" ;
- static String gspServiceURL = serviceGSP() ;
- static String defaultGraphURL = serviceGSP()+"?default" ;
- static String namedGraphURL = serviceGSP()+"?graph=http://example/g" ;
- static String queryURL = serviceQuery() ;
- static String updateURL = serviceUpdate() ;
-
- static String simpleQuery = queryURL+"?query="+IRILib.encodeUriComponent("ASK{}") ;
-
- @Test public void correctDefaultResetBehavior() {
- HttpClient defaultClient = HttpOp.getDefaultHttpClient();
- HttpOp.setDefaultHttpClient(null);
- assertSame("Failed to reset to initial client!", initialDefaultHttpClient, HttpOp.getDefaultHttpClient());
- HttpOp.setDefaultHttpClient(defaultClient);
- }
-
- // Basic operations
-
- @Test public void httpGet_01() {
- assertNotNull(HttpOp.execHttpGetString(pingURL));
- }
-
- @Test
- public void httpGet_02() {
- exec404(() -> HttpOp.execHttpGet(urlRoot() + "does-not-exist"));
- }
-
- @Test public void httpGet_03() {
- assertNotNull(HttpOp.execHttpGetString(pingURL));
- }
-
- @Test public void httpGet_04() {
- String x = HttpOp.execHttpGetString(urlRoot()+"does-not-exist") ;
- assertNull(x) ;
- }
-
- @Test public void httpGet_05() {
- assertNotNull(HttpOp.execHttpGetString(simpleQuery));
- }
-
- // SPARQL Query
-
- @Test public void queryGet_01() {
- assertNotNull(HttpOp.execHttpGetString(simpleQuery));
- }
-
- public void queryGet_02() {
- // No query.
- execWithHttpException(HttpSC.BAD_REQUEST_400, () -> HttpOp.execHttpGetString(queryURL + "?query="));
- }
-
- public void httpPost_01() {
- execWithHttpException(HttpSC.UNSUPPORTED_MEDIA_TYPE_415,
- () -> HttpOp.execHttpPost(queryURL, "ASK{}", "text/plain"));
- }
-
- public void httpPost_02() {
- execWithHttpException(HttpSC.UNSUPPORTED_MEDIA_TYPE_415,
- () -> HttpOp.execHttpPost(queryURL, "ASK{}", WebContent.contentTypeSPARQLQuery));
- }
-
- public void httpPost_03() {
- execWithHttpException(HttpSC.UNSUPPORTED_MEDIA_TYPE_415,
- () -> HttpOp.execHttpPost(queryURL, "ASK{}", WebContent.contentTypeOctets));
- }
-
- @Test public void httpPost_04() {
- Params params = new Params().addParam("query", "ASK{}") ;
- try ( TypedInputStream in = HttpOp.execHttpPostFormStream(queryURL, params, WebContent.contentTypeResultsJSON) ) {}
- }
-
- public void httpPost_05() {
- Params params = new Params().addParam("query", "ASK{}") ;
- // Query to Update
- execWithHttpException(HttpSC.BAD_REQUEST_400,
- () -> HttpOp.execHttpPostFormStream(updateURL, params, WebContent.contentTypeResultsJSON));
- }
-
- @Test public void httpPost_06() {
- Params params = new Params().addParam("request", "CLEAR ALL") ;
- HttpOp.execHttpPostForm(updateURL, params) ;
- }
-
- // GSP
- @Test public void gsp_01() {
- String x = HttpOp.execHttpGetString(defaultGraphURL, "application/rdf+xml") ;
- assertTrue(x.contains("</")) ;
- assertTrue(x.contains(":RDF")) ;
- }
-
- @Test public void gsp_02() {
- 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(defaultGraphURL, WebContent.contentTypeTurtle, graphString) ;
- }
-
- @Test public void gsp_04() {
- HttpOp.execHttpPut(defaultGraphURL, WebContent.contentTypeTurtle, graphString) ;
- String s1 = HttpOp.execHttpGetString(defaultGraphURL, WebContent.contentTypeNTriples) ;
- assertFalse(s1.isEmpty()) ;
- HttpOp.execHttpDelete(defaultGraphURL) ;
- String s2 = HttpOp.execHttpGetString(defaultGraphURL, WebContent.contentTypeNTriples) ;
- assertTrue(s2.isEmpty()) ;
- }
-
- @Test public void gsp_05() {
- HttpOp.execHttpDelete(defaultGraphURL) ;
-
- HttpOp.execHttpPost(defaultGraphURL, WebContent.contentTypeTurtle, graphString) ;
- String s1 = HttpOp.execHttpGetString(defaultGraphURL, WebContent.contentTypeNTriples) ;
- assertFalse(s1.isEmpty()) ;
- HttpOp.execHttpDelete(defaultGraphURL) ;
- String s2 = HttpOp.execHttpGetString(defaultGraphURL, WebContent.contentTypeNTriples) ;
- assertTrue(s2.isEmpty()) ;
- }
-
- @Test public void gsp_06() {
- //HttpOp.execHttpDelete(namedGraphURL) ; -- would 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()) ;
-
- exec404(()->HttpOp.execHttpDelete(namedGraphURL)) ;
- }
-
- // Extended GSP - no ?default, no ?graph acts on the datasets as a whole.
-
- @Test public void gsp_10() {
- execWithHttpException(HttpSC.METHOD_NOT_ALLOWED_405, () -> HttpOp.execHttpDelete(gspServiceURL));
- }
-
- @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()) ;
- }
-}
-
http://git-wip-us.apache.org/repos/asf/jena/blob/e8abcbb6/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestHttpOperations.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestHttpOperations.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestHttpOperations.java
deleted file mode 100644
index 09d1391..0000000
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestHttpOperations.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * 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.fuseki ;
-
-import static org.apache.jena.fuseki.ServerCtl.serviceQuery ;
-import static org.apache.jena.fuseki.ServerCtl.serviceUpdate ;
-
-import org.apache.jena.atlas.web.HttpException ;
-import org.apache.jena.atlas.web.TypedInputStream ;
-import org.apache.jena.riot.WebContent ;
-import org.apache.jena.riot.web.HttpOp ;
-import org.apache.jena.sparql.engine.http.Params ;
-import org.apache.jena.sparql.util.Convert ;
-import org.junit.Assert ;
-import org.junit.Test ;
-
-/** Operation by HTTP - test dispatch - lower level than TestSPARQLProtocol */
-public class TestHttpOperations extends AbstractFusekiTest {
-
- @Test
- public void query_by_get_1() {
- String qs = Convert.encWWWForm("ASK{}") ;
- String u = serviceQuery()+"?query=" + qs ;
- try (TypedInputStream in = HttpOp.execHttpGet(u)) {
- Assert.assertNotNull(in);
- }
- }
-
- @Test
- public void query_by_post_1() {
- try (TypedInputStream in = HttpOp.execHttpPostStream(serviceQuery(), WebContent.contentTypeSPARQLQuery, "ASK{}", "*")) {
- Assert.assertNotNull(in);
- }
- }
-
- @Test
- public void query_by_post_2() {
- String qs = Convert.encWWWForm("ASK{}") ;
- String u = serviceQuery()+"?query=" + qs ;
- try (TypedInputStream in = HttpOp.execHttpPostStream(u, null, null)) {
- Assert.assertNotNull(in);
- }
- }
-
- @Test
- public void query_by_form_1() {
- Params params = new Params().addParam("query", "ASK{}") ;
- try (TypedInputStream in = HttpOp.execHttpPostFormStream(serviceQuery(), params, "*") ) {
- Assert.assertNotNull(in);
- }
- }
-
- @Test(expected=HttpException.class)
- public void query_by_form_2() {
- Params params = new Params().addParam("foobar", "ASK{}") ; // Wrong.
- try (TypedInputStream in = HttpOp.execHttpPostFormStream(serviceQuery(), params, "*") ) {
- Assert.assertNotNull(in);
- }
- }
-
- @Test
- public void update_by_post_1() {
- HttpOp.execHttpPost(serviceUpdate(), WebContent.contentTypeSPARQLUpdate, "INSERT DATA{}") ;
- }
-
- // POST ?request= :: Not supported.
-// @Test
-// public void update_by_post_2() {
-// String us = Convert.encWWWForm("INSERT DATA {}") ;
-// String u = serviceUpdate+"?update=" + us ;
-// try (TypedInputStream in = HttpOp.execHttpPostStream(u, null, null)) {
-// Assert.assertNotNull(in);
-// }
-// }
-
- @Test
- public void update_by_form_1() {
- Params params = new Params().addParam("update", "INSERT DATA{}") ;
- try (TypedInputStream in = HttpOp.execHttpPostFormStream(serviceUpdate(), params, "*") ) {
- Assert.assertNotNull(in);
- }
- }
-
- @Test(expected=HttpException.class)
- public void update_by_form_2() {
- Params params = new Params().addParam("query", "INSERT DATA{}") ; // Wrong paramater
- try (TypedInputStream in = HttpOp.execHttpPostFormStream(serviceUpdate(), params, "*") ) {
- Assert.assertNotNull(in);
- }
- }
-
- // ---- Dataset direct, with content type.
-
- @Test
- public void ds_fetch_by_get_1() {
- String u = ServerCtl.urlDataset() ;
- try (TypedInputStream in = HttpOp.execHttpGet(u)) {
- Assert.assertNotNull(in);
- }
- }
-
- @Test
- public void ds_query_by_post_1() {
- String u = ServerCtl.urlDataset() ;
- try (TypedInputStream in = HttpOp.execHttpPostStream(u, WebContent.contentTypeSPARQLQuery, "ASK{}", "*")) {
- Assert.assertNotNull(in);
- }
- }
-
- @Test
- public void ds_update_by_post_1() {
- String u = ServerCtl.urlDataset() ;
- HttpOp.execHttpPost(u, WebContent.contentTypeSPARQLUpdate, "INSERT DATA{}") ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/e8abcbb6/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestHttpOptions.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestHttpOptions.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestHttpOptions.java
deleted file mode 100644
index 7c6d4cd..0000000
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestHttpOptions.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * 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.fuseki;
-
-import org.junit.Test ;
-
-public class TestHttpOptions extends AbstractFusekiTest
-{
- @Test
- public void options_query() {
- String v = FusekiTest.execOptions(ServerCtl.serviceQuery()) ;
- FusekiTest.assertStringList(v, "GET", "OPTIONS", "POST") ;
- }
-
- @Test
- public void options_update() {
- String v = FusekiTest.execOptions(ServerCtl.serviceUpdate()) ;
- FusekiTest.assertStringList(v, "OPTIONS", "POST") ;
- }
-
- @Test
- public void options_dataset_01() {
- String v = FusekiTest.execOptions(ServerCtl.urlDataset()) ;
- // Not DELETE
- FusekiTest.assertStringList(v, "HEAD", "GET", "OPTIONS", "POST", "PUT") ;
- }
-
- @Test
- public void options_dataset_02() {
- //"quads"
- }
-
- @Test
- public void options_gsp_rw() {
- String v = FusekiTest.execOptions(ServerCtl.serviceGSP()+"?default") ;
- FusekiTest.assertStringList(v, "GET", "OPTIONS", "HEAD", "POST", "PUT", "DELETE") ;
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/jena/blob/e8abcbb6/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
deleted file mode 100644
index 9439342..0000000
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestQuery.java
+++ /dev/null
@@ -1,322 +0,0 @@
-/*
- * 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.fuseki ;
-
-import static org.apache.jena.fuseki.ServerCtl.serviceGSP ;
-import static org.apache.jena.fuseki.ServerCtl.serviceQuery ;
-import static org.apache.jena.fuseki.ServerTest.gn1;
-import static org.apache.jena.fuseki.ServerTest.gn2;
-import static org.apache.jena.fuseki.ServerTest.model1 ;
-import static org.apache.jena.fuseki.ServerTest.model2 ;
-
-import java.io.*;
-import java.net.HttpURLConnection ;
-import java.net.URL ;
-import java.util.Iterator ;
-
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.jena.atlas.json.JsonArray;
-import org.apache.jena.atlas.web.AcceptList ;
-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.rdf.model.Model ;
-import org.apache.jena.riot.web.HttpOp;
-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.SSE ;
-import org.apache.jena.sparql.util.Convert ;
-import org.junit.Assert ;
-import org.junit.Before ;
-import org.junit.Test ;
-
-public class TestQuery extends AbstractFusekiTest {
-
- @Before
- public void before() {
- DatasetAccessor du = DatasetAccessorFactory.createHTTP(serviceGSP()) ;
- du.putModel(model1) ;
- du.putModel(gn1, model2) ;
- }
-
- private static final AcceptList quadsOfferTest = DEF.quadsOffer ;
- private static final AcceptList rdfOfferTest = DEF.rdfOffer ;
-
- @Test
- public void query_01() {
- execQuery("SELECT * {?s ?p ?o}", 1) ;
- }
-
- @Test
- public void query_recursive_01() {
- String query = "SELECT * WHERE { SERVICE <" + serviceQuery() + "> { ?s ?p ?o . BIND(?o AS ?x) } }" ;
- try (QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery(), query)) {
- ResultSet rs = qExec.execSelect() ;
- Var x = Var.alloc("x") ;
- while (rs.hasNext()) {
- Binding b = rs.nextBinding() ;
- Assert.assertNotNull(b.get(x)) ;
- }
- }
- }
-
- @Test
- public void query_with_params_01() {
- String query = "ASK { }" ;
- try (QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery() + "?output=json", query)) {
- boolean result = qExec.execAsk() ;
- Assert.assertTrue(result) ;
- }
- }
-
- @Test
- public void request_id_header_01() throws IOException {
- String qs = Convert.encWWWForm("ASK{}") ;
- URL u = new URL(serviceQuery() + "?query=" + qs) ;
- HttpURLConnection conn = (HttpURLConnection)u.openConnection() ;
- Assert.assertTrue(conn.getHeaderField("Fuseki-Request-ID") != null) ;
- }
-
- @Test
- public void query_dynamic_dataset_01() {
- DatasetAccessor du = DatasetAccessorFactory.createHTTP(serviceGSP()) ;
- du.putModel(model1);
- du.putModel(gn1, model2);
- {
- String query = "SELECT * { ?s ?p ?o }" ;
- try (QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery() + "?output=json", query)) {
- ResultSet rs = qExec.execSelect() ;
- Node o = rs.next().getLiteral("o").asNode() ;
- Node n = SSE.parseNode("1") ;
- assertEquals(n, o) ;
- }
- }
- {
- String query = "SELECT * FROM <" + gn1 + "> { ?s ?p ?o }" ;
- try (QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery() + "?output=json", query)) {
- ResultSet rs = qExec.execSelect() ;
- Node o = rs.next().getLiteral("o").asNode() ;
- Node n = SSE.parseNode("2") ;
- assertEquals(n, o) ;
- }
- }
- }
-
- @Test
- public void query_dynamic_dataset_02() {
- DatasetAccessor du = DatasetAccessorFactory.createHTTP(serviceGSP()) ;
- du.putModel(model1);
- du.putModel(gn1, model1);
- du.putModel(gn2, model2);
- String query = "SELECT * FROM <"+gn1+"> FROM <"+gn2+"> { ?s ?p ?o }" ;
- try (QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery() + "?output=json", query)) {
- ResultSet rs = qExec.execSelect() ;
- int n = ResultSetFormatter.consume(rs) ;
- assertEquals(2, n) ;
- }
- }
-
- @Test
- public void query_construct_quad_01()
- {
- String queryString = " CONSTRUCT { GRAPH <http://eg/g> {?s ?p ?oq} } WHERE {?s ?p ?oq}" ;
- Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
-
- try ( QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery(), query) ) {
- Iterator<Quad> result = qExec.execConstructQuads();
- Assert.assertTrue(result.hasNext());
- Assert.assertEquals( "http://eg/g", result.next().getGraph().getURI());
-
- }
- }
-
- @Test
- public void query_construct_quad_02()
- {
- String queryString = " CONSTRUCT { GRAPH <http://eg/g> {?s ?p ?oq} } WHERE {?s ?p ?oq}" ;
- Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
-
- try ( QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery(), query) ) {
- Dataset result = qExec.execConstructDataset();
- Assert.assertTrue(result.asDatasetGraph().find().hasNext());
- Assert.assertEquals( "http://eg/g", result.asDatasetGraph().find().next().getGraph().getURI());
- }
- }
-
- @Test
- public void query_construct_01()
- {
- String query = " CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}" ;
- try ( QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery(), query) ) {
- Iterator<Triple> result = qExec.execConstructTriples();
- Assert.assertTrue(result.hasNext());
- }
- }
-
- @Test
- public void query_construct_02()
- {
- String query = " CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}" ;
- try ( QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery(), query) ) {
- Model result = qExec.execConstruct();
- assertEquals(1, result.size());
- }
- }
-
- @Test
- public void query_describe_01() {
- String query = "DESCRIBE ?s WHERE {?s ?p ?o}" ;
- try ( QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery(), query) ) {
- Model result = qExec.execDescribe();
- assertFalse(result.isEmpty()) ;
- }
- }
-
- @Test
- public void query_describe_02() {
- String query = "DESCRIBE <http://example/somethingelse> WHERE { }" ;
- try ( QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery(), query) ) {
- Model result = qExec.execDescribe();
- assertTrue(result.isEmpty()) ;
- }
- }
-
- // Conneg tests:
- // These use independent connection pooling.
- // Sharing pooling too much leads to lock up if the list is long (contentTypeTriXxml seems significant)
- // Hence: try (CloseableHttpClient client = HttpOp.createPoolingHttpClient()) { ... qExec.setClient(client); ... }
-
-
- @Test
- public void query_construct_conneg() throws IOException {
- try (CloseableHttpClient client = HttpOp.createPoolingHttpClient()) {
- String query = " CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}";
- for (MediaType type : rdfOfferTest.entries()) {
-
- String contentType = type.toHeaderString();
- try (QueryEngineHTTP qExec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery(),
- query)) {
- qExec.setModelContentType(contentType);
- qExec.setClient(client);
- Iterator<Triple> iter = qExec.execConstructTriples();
- assertTrue(iter.hasNext());
- String x = qExec.getHttpResponseContentType();
- assertEquals(contentType, x);
- }
- }
- }
- }
-
- @Test
- public void query_construct_quad_conneg() throws IOException {
- try (CloseableHttpClient client = HttpOp.createPoolingHttpClient()) {
- String queryString = " CONSTRUCT { GRAPH ?g {?s ?p ?o} } WHERE { GRAPH ?g {?s ?p ?o}}";
- Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
- for (MediaType type : quadsOfferTest.entries()) {
- String contentType = type.toHeaderString();
- try (QueryEngineHTTP qExec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery(),
- query)) {
- qExec.setDatasetContentType(contentType);
- qExec.setClient(client);
- Iterator<Quad> iter = qExec.execConstructQuads();
- assertTrue(iter.hasNext());
- String x = qExec.getHttpResponseContentType();
- assertEquals(contentType, x);
- }
- }
- }
- }
-
- @Test
- public void query_describe_conneg() throws IOException {
- try (CloseableHttpClient client = HttpOp.createPoolingHttpClient()) {
- String query = "DESCRIBE ?s WHERE {?s ?p ?o}";
- for (MediaType type : rdfOfferTest.entries()) {
- String contentType = type.toHeaderString();
- try (QueryEngineHTTP qExec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery(),
- query)) {
- qExec.setModelContentType(contentType);
- qExec.setClient(client);
- Model m = qExec.execDescribe();
- String x = qExec.getHttpResponseContentType();
- assertEquals(contentType, x);
- assertFalse(m.isEmpty());
- }
- }
- }
- }
-
- public void query_json_01() throws IOException {
- Query query = QueryFactory.create("JSON { \"s\": ?s , \"p\": ?p , \"o\" : ?o } "
- + "WHERE { ?s ?p ?o }", Syntax.syntaxARQ);
- query.toString();
- try ( QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery(), query) ) {
- JsonArray result = qExec.execJson();
- assertEquals(1, result.size());
- }
- }
-
- @Test
- public void query_json_02() throws IOException {
- String qs = Convert.encWWWForm("JSON { \"s\": ?s , \"p\": ?p , \"o\" : ?o } "
- + "WHERE { ?s ?p ?o }") ;
- URL u = new URL(serviceQuery() + "?query=" + qs) ;
- HttpURLConnection conn = (HttpURLConnection)u.openConnection() ;
- String result = null;
- StringBuffer sb = new StringBuffer();
- InputStream is = null;
- try {
- is = new BufferedInputStream(conn.getInputStream());
- BufferedReader br = new BufferedReader(new InputStreamReader(is));
- String inputLine = "";
- while ((inputLine = br.readLine()) != null) {
- sb.append(inputLine);
- }
- result = sb.toString();
- }
- finally {
- if (is != null) {
- is.close();
- }
- }
- Assert.assertNotNull(result);
- Assert.assertTrue(result.contains("http://example/x"));
- }
-
- private static void execQuery(String queryString, int exceptedRowCount) {
- try ( QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery(), queryString) ) {
- ResultSet rs = qExec.execSelect() ;
- int x = ResultSetFormatter.consume(rs) ;
- assertEquals(exceptedRowCount, x) ;
- }
- }
-
- private static void execQuery(String queryString, ResultSet expectedResultSet) {
- try ( QueryExecution qExec = QueryExecutionFactory.sparqlService(serviceQuery(), queryString) ) {
- ResultSet rs = qExec.execSelect() ;
- boolean b = ResultSetCompare.equalsByTerm(rs, expectedResultSet) ;
- assertTrue("Result sets different", b) ;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/e8abcbb6/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestSPARQLProtocol.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestSPARQLProtocol.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestSPARQLProtocol.java
deleted file mode 100644
index a5a5be3..0000000
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestSPARQLProtocol.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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.fuseki;
-
-import static org.apache.jena.fuseki.ServerCtl.serviceQuery ;
-import static org.apache.jena.fuseki.ServerCtl.serviceUpdate ;
-import static org.apache.jena.fuseki.ServerTest.gn1 ;
-import static org.apache.jena.fuseki.ServerTest.model1 ;
-import static org.apache.jena.fuseki.ServerTest.model2 ;
-
-import org.apache.jena.query.*;
-import org.apache.jena.riot.WebContent;
-import org.apache.jena.sparql.engine.http.QueryEngineHTTP;
-import org.apache.jena.sparql.util.Convert;
-import org.apache.jena.update.UpdateExecutionFactory;
-import org.apache.jena.update.UpdateFactory;
-import org.apache.jena.update.UpdateProcessor;
-import org.apache.jena.update.UpdateRequest;
-import org.junit.Before ;
-import org.junit.Test;
-
-public class TestSPARQLProtocol extends AbstractFusekiTest
-{
- @Before
- public void before() {
- // Load some data.
- DatasetAccessor du = DatasetAccessorFactory.createHTTP(ServerCtl.serviceGSP());
- du.putModel(model1);
- du.putModel(gn1, model2);
- }
-
- static String query(String base, String queryString) {
- return base + "?query=" + Convert.encWWWForm(queryString);
- }
-
- @Test
- public void query_01() {
- Query query = QueryFactory.create("SELECT * { ?s ?p ?o }");
- QueryExecution qexec = QueryExecutionFactory.sparqlService(serviceQuery(), query);
- ResultSet rs = qexec.execSelect();
- int x = ResultSetFormatter.consume(rs);
- assertTrue(x != 0);
- }
-
- @Test
- public void query_02() {
- Query query = QueryFactory.create("SELECT * { ?s ?p ?o }");
- QueryEngineHTTP engine = QueryExecutionFactory.createServiceRequest(serviceQuery(), query);
- engine.setSelectContentType(WebContent.contentTypeResultsJSON);
- ResultSet rs = engine.execSelect();
- int x = ResultSetFormatter.consume(rs);
- assertTrue(x != 0);
- }
-
- @Test
- public void update_01() {
- UpdateRequest update = UpdateFactory.create("INSERT DATA {}");
- UpdateProcessor proc = UpdateExecutionFactory.createRemote(update, serviceUpdate());
- proc.execute();
- }
-
- @Test
- public void update_02() {
- UpdateRequest update = UpdateFactory.create("INSERT DATA {}");
- UpdateProcessor proc = UpdateExecutionFactory.createRemoteForm(update, serviceUpdate());
- proc.execute();
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/e8abcbb6/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestServerReadOnly.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestServerReadOnly.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestServerReadOnly.java
deleted file mode 100644
index 225279f..0000000
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestServerReadOnly.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/**
- * 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.fuseki;
-
-import static org.apache.jena.fuseki.ServerCtl.serviceQuery ;
-import static org.apache.jena.fuseki.ServerCtl.serviceUpdate ;
-
-import java.nio.charset.StandardCharsets ;
-
-import org.apache.http.HttpEntity ;
-import org.apache.http.entity.StringEntity ;
-import org.apache.jena.query.Query ;
-import org.apache.jena.query.QueryExecution ;
-import org.apache.jena.query.QueryExecutionFactory ;
-import org.apache.jena.query.QueryFactory ;
-import org.apache.jena.riot.web.HttpOp ;
-import org.apache.jena.update.UpdateExecutionFactory ;
-import org.apache.jena.update.UpdateFactory ;
-import org.apache.jena.update.UpdateProcessor ;
-import org.apache.jena.update.UpdateRequest ;
-import org.apache.jena.web.HttpSC ;
-import org.junit.AfterClass ;
-import org.junit.BeforeClass ;
-import org.junit.Test ;
-
-/** Tests on a read only server. */
-public class TestServerReadOnly
-{
- // readonly server.
- @BeforeClass
- public static void allocServerForSuite() {
- ServerCtl.freeServer();
- //Manage ourselves.
- ServerCtl.setupServer(false) ;
- }
-
- @AfterClass
- public static void freeServerForSuite() {
- ServerCtl.freeServer() ;
- }
-
- @Test
- public void query_readonly() {
- Query query = QueryFactory.create("ASK{}");
- QueryExecution qexec = QueryExecutionFactory.sparqlService(serviceQuery(), query);
- qexec.execAsk() ;
- }
-
- @Test()
- public void update_readonly() {
- FusekiTest.exec404( () -> {
- UpdateRequest update = UpdateFactory.create("INSERT DATA {}");
- UpdateProcessor proc = UpdateExecutionFactory.createRemote(update, serviceUpdate());
- proc.execute();
- });
- }
-
-
- @Test
- public void gsp_w_readonly_POST() {
- // Try to write
- FusekiTest.execWithHttpException(HttpSC.METHOD_NOT_ALLOWED_405, ()->{
- HttpEntity e = new StringEntity("", StandardCharsets.UTF_8) ;
- HttpOp.execHttpPost(ServerCtl.serviceGSP()+"?default", e);
- }) ;
- }
-
- @Test
- public void gsp_w_readonly_PUT() {
- // Try to write
- FusekiTest.execWithHttpException(HttpSC.METHOD_NOT_ALLOWED_405, ()->{
- HttpEntity e = new StringEntity("", StandardCharsets.UTF_8) ;
- HttpOp.execHttpPut(ServerCtl.serviceGSP()+"?default", e);
- }) ;
- }
-
- @Test
- public void gsp_w_readonly_DELETE() {
- // Try to write
- FusekiTest.execWithHttpException(HttpSC.METHOD_NOT_ALLOWED_405, ()->{
- HttpOp.execHttpDelete(ServerCtl.serviceGSP()+"?default");
- }) ;
- }
-
- @Test
- public void dataset_w_readonly_POST() {
- // Try to write
- FusekiTest.execWithHttpException(HttpSC.METHOD_NOT_ALLOWED_405, ()->{
- HttpEntity e = new StringEntity("", StandardCharsets.UTF_8) ;
- HttpOp.execHttpPost(ServerCtl.urlDataset(), e) ;
- }) ;
- }
-
- @Test
- public void dataset_w_readonly_PUT() {
- // Try to write
- FusekiTest.execWithHttpException(HttpSC.METHOD_NOT_ALLOWED_405, ()->{
- HttpEntity e = new StringEntity("", StandardCharsets.UTF_8) ;
- HttpOp.execHttpPut(ServerCtl.urlDataset(), e) ;
- }) ;
- }
-
- @Test
- public void dataset_w_readonly_DELETE() {
- // Try to write
- FusekiTest.execWithHttpException(HttpSC.METHOD_NOT_ALLOWED_405, ()->{
- HttpOp.execHttpDelete(ServerCtl.urlDataset()) ;
- }) ;
- }
-
- @Test
- public void options_gsp_readonly() {
- String v = FusekiTest.execOptions(ServerCtl.serviceGSP()+"?default") ;
- FusekiTest.assertStringList(v, "GET", "OPTIONS", "HEAD") ;
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/jena/blob/e8abcbb6/jena-fuseki2/jena-fuseki-embedded/src/main/java/org/apache/jena/fuseki/embedded/FusekiServer.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-embedded/src/main/java/org/apache/jena/fuseki/embedded/FusekiServer.java b/jena-fuseki2/jena-fuseki-embedded/src/main/java/org/apache/jena/fuseki/embedded/FusekiServer.java
index 6a67f84..d8cc3f0 100644
--- a/jena-fuseki2/jena-fuseki-embedded/src/main/java/org/apache/jena/fuseki/embedded/FusekiServer.java
+++ b/jena-fuseki2/jena-fuseki-embedded/src/main/java/org/apache/jena/fuseki/embedded/FusekiServer.java
@@ -389,7 +389,7 @@ public class FusekiServer {
if ( dataAccessPoints.isRegistered(name) )
throw new FusekiConfigException("Data service name already registered: "+name);
DataAccessPoint dap = new DataAccessPoint(name, dataService);
- dataAccessPoints.register(name, dap);
+ dataAccessPoints.register(dap);
return this;
}
http://git-wip-us.apache.org/repos/asf/jena/blob/e8abcbb6/jena-fuseki2/jena-fuseki-server/pom.xml
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-server/pom.xml b/jena-fuseki2/jena-fuseki-server/pom.xml
index 89ff40e..5eef6cc 100644
--- a/jena-fuseki2/jena-fuseki-server/pom.xml
+++ b/jena-fuseki2/jena-fuseki-server/pom.xml
@@ -36,7 +36,7 @@
<dependency>
<groupId>org.apache.jena</groupId>
- <artifactId>jena-fuseki-core</artifactId>
+ <artifactId>jena-fuseki-webapp</artifactId>
<version>${project.version}</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/jena/blob/e8abcbb6/jena-fuseki2/jena-fuseki-war/pom.xml
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-war/pom.xml b/jena-fuseki2/jena-fuseki-war/pom.xml
index 9f05c05..be0b3ed 100644
--- a/jena-fuseki2/jena-fuseki-war/pom.xml
+++ b/jena-fuseki2/jena-fuseki-war/pom.xml
@@ -35,7 +35,7 @@
<dependency>
<groupId>org.apache.jena</groupId>
- <artifactId>jena-fuseki-core</artifactId>
+ <artifactId>jena-fuseki-webapp</artifactId>
<version>${project.version}</version>
</dependency>
@@ -67,8 +67,8 @@
</execution>
</executions>
<configuration>
- <warSourceDirectory>../jena-fuseki-core/src/main/webapp</warSourceDirectory>
- <webXml>../jena-fuseki-core/src/main/webapp/WEB-INF/web.xml</webXml>
+ <warSourceDirectory>../jena-fuseki-webapp/src/main/webapp</warSourceDirectory>
+ <webXml>../jena-fuseki-webapp/src/main/webapp/WEB-INF/web.xml</webXml>
<!-- Safe: Don't put in the Jetty dependency nor javax.servlet -->
<packagingExcludes>WEB-INF/lib/jetty-*,WEB-INF/lib/javax.servlet*</packagingExcludes>
</configuration>