diff --git a/sparqlGraphLibrary/src/main/java/com/ge/research/semtk/test/TestConnection.java b/sparqlGraphLibrary/src/main/java/com/ge/research/semtk/test/TestConnection.java index 2c5037798..dc6207161 100644 --- a/sparqlGraphLibrary/src/main/java/com/ge/research/semtk/test/TestConnection.java +++ b/sparqlGraphLibrary/src/main/java/com/ge/research/semtk/test/TestConnection.java @@ -28,10 +28,6 @@ import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; -import com.ge.research.semtk.belmont.NodeGroup; -import com.ge.research.semtk.load.DataLoader; -import com.ge.research.semtk.load.dataset.CSVDataset; -import com.ge.research.semtk.load.dataset.Dataset; import com.ge.research.semtk.load.utility.SparqlGraphJson; import com.ge.research.semtk.resultSet.GeneralResultSet; import com.ge.research.semtk.resultSet.SimpleResultSet; @@ -41,8 +37,6 @@ import com.ge.research.semtk.sparqlX.SparqlEndpointInterface; import com.ge.research.semtk.sparqlX.SparqlResultTypes; import com.ge.research.semtk.sparqlX.SparqlToXUtils; -import com.ge.research.semtk.sparqlX.VirtuosoSparqlEndpointInterface; -import com.ge.research.semtk.utility.Utility; /** * A utility class to load data to a semantic graph. Intended for use in tests. @@ -61,11 +55,11 @@ public TestConnection(int modelCount, int dataCount, String domain) throws Excep SparqlEndpointInterface sei = TestGraph.getSei(); for (int i=0; i < modelCount; i++) { - sei.setDataset(generateDatasetName(String.format("model%d", i))); + sei.setGraph(generateDatasetName(String.format("model%d", i))); conn.addModelInterface( sei ); } for (int i=0; i < dataCount; i++) { - sei.setDataset(generateDatasetName(String.format("data%d", i))); + sei.setGraph(generateDatasetName(String.format("data%d", i))); conn.addModelInterface( sei ); } @@ -87,7 +81,7 @@ public void clearGraphs() throws Exception { seiList.addAll(this.conn.getDataInterfaces()); for (SparqlEndpointInterface sei : seiList) { - sei.clearGraph(); + IntegrationTestUtility.clearGraph(sei); } } diff --git a/sparqlGraphLibrary/src/main/java/com/ge/research/semtk/test/TestGraph.java b/sparqlGraphLibrary/src/main/java/com/ge/research/semtk/test/TestGraph.java index 35a0d3623..1b1ad4165 100644 --- a/sparqlGraphLibrary/src/main/java/com/ge/research/semtk/test/TestGraph.java +++ b/sparqlGraphLibrary/src/main/java/com/ge/research/semtk/test/TestGraph.java @@ -91,11 +91,9 @@ public static SparqlEndpointInterface getSei(String graphName) throws Exception } if (sei instanceof NeptuneSparqlEndpointInterface) { - String region = IntegrationTestUtility.get("neptuneupload.s3ClientRegion"); String iamRoleArn = IntegrationTestUtility.get("neptuneupload.awsIamRoleArn"); String name = IntegrationTestUtility.get("neptuneupload.s3BucketName"); - ((NeptuneSparqlEndpointInterface) sei).setS3Config(region, name, iamRoleArn); } return sei; @@ -108,7 +106,6 @@ public static EndpointProperties getEndpointProperties() throws Exception { ret.setEndpointServerUrl(sei.getServerAndPort()); ret.setEndpointUsername(sei.getUserName()); ret.setEndpointPassword(sei.getPassword()); - return ret; } @@ -218,34 +215,34 @@ public static void execDeletionQuery(String query) throws Exception{ } } + /** + * Execute a select query + */ public static Table execTableSelect(String query) throws Exception { - // execute a select query - // exception if there's any problem - // return the table SparqlEndpointInterface sei = getSei(); TableResultSet res = (TableResultSet) sei.executeQueryAndBuildResultSet(query, SparqlResultTypes.TABLE); res.throwExceptionIfUnsuccessful(); - return res.getResults(); } public static Table execTableSelect(SparqlGraphJson sgJson) throws Exception { - // execute a select query - // exception if there's any problem - // return the table - return SparqlGraphJson.executeSelectToTable(sgJson.toJson(), getSparqlConn(), IntegrationTestUtility.getOntologyInfoClient()); } public static Table execTableSelect(JSONObject sgJsonJson, OntologyInfoClient oInfoClient) throws Exception { - // execute a select query - // exception if there's any problem - // return the table return SparqlGraphJson.executeSelectToTable(sgJsonJson, getSparqlConn(), oInfoClient); } + public static Table execSelectFromResource(Object o, String resourceName) throws Exception { + return execSelectFromResource(o.getClass(), resourceName); + } + @SuppressWarnings("rawtypes") + public static Table execSelectFromResource(Class c, String resourceName) throws Exception { + SparqlGraphJson sgjson = TestGraph.getSparqlGraphJsonFromResource(c, resourceName); + return execTableSelect(sgjson.toJson(), IntegrationTestUtility.getOntologyInfoClient()); + } + /** + * Execute a construct query + */ public static JSONArray execJsonConstruct(SparqlGraphJson sgJson) throws Exception { - // execute a construct query - // exception if there's any problem - // return the jsonArray return SparqlGraphJson.executeConstructToJson(sgJson.toJson(), getSparqlConn(), IntegrationTestUtility.getOntologyInfoClient()); } public static JSONArray execJsonConstruct(NodeGroup ng) throws Exception { @@ -253,22 +250,8 @@ public static JSONArray execJsonConstruct(NodeGroup ng) throws Exception { return SparqlGraphJson.executeConstructToJson(sgJson.toJson(), getSparqlConn(), IntegrationTestUtility.getOntologyInfoClient()); } public static JSONArray execJsonConstruct(JSONObject sgJsonJson, OntologyInfoClient oInfoClient) throws Exception { - // execute a construct query - // exception if there's any problem - // return the table return SparqlGraphJson.executeConstructToJson(sgJsonJson, getSparqlConn(), oInfoClient); } - - public static Table execSelectFromResource(Object o, String resourceName) throws Exception { - return execSelectFromResource(o.getClass(), resourceName); - } - @SuppressWarnings("rawtypes") - public static Table execSelectFromResource(Class c, String resourceName) throws Exception { - SparqlGraphJson sgjson = TestGraph.getSparqlGraphJsonFromResource(c, resourceName); - return execTableSelect(sgjson.toJson(), IntegrationTestUtility.getOntologyInfoClient()); - } - - public static JSONArray execConstructFromResource(Object o, String resourceName) throws Exception { return execConstructFromResource(o.getClass(), resourceName); } @@ -278,7 +261,6 @@ public static JSONArray execConstructFromResource(Class c, String resourceName) return execJsonConstruct(sgjson.toJson(), IntegrationTestUtility.getOntologyInfoClient()); } - /** * Get the number of triples in the test graph. */ @@ -294,7 +276,6 @@ public static int getNumTriples() throws Exception { // Use uploadOwlResource @Deprecated public static void uploadOwl(String owlFilename) throws Exception { - SparqlEndpointInterface sei = getSei(); Path path = Paths.get(owlFilename); byte[] owl = Files.readAllBytes(path); @@ -332,7 +313,6 @@ public static void syncOwlToItsGraph(String owlFilename) throws Exception { String base = Utility.getXmlBaseFromOwlRdf(new FileInputStream(owlFilename)); SparqlEndpointInterface sei = getSei(); - sei.setGraph(base); sei.clearGraph(); @@ -358,7 +338,6 @@ public static void uploadTurtleResource(Class c, String resourceName) throws Exc uploadTurtleString(Utility.getResourceAsString(c, resourceName)); } public static void uploadTurtle(String owlFilename) throws Exception { - SparqlEndpointInterface sei = getSei(); Path path = Paths.get(owlFilename); byte[] owl = Files.readAllBytes(path); @@ -368,11 +347,8 @@ public static void uploadTurtle(String owlFilename) throws Exception { } IntegrationTestUtility.getOntologyInfoClient().uncacheChangedConn(sei); } - public static void uploadTurtleString(String turtleData) throws Exception { - SparqlEndpointInterface sei = getSei(); - SimpleResultSet resultSet = SimpleResultSet.fromJson(sei.executeAuthUploadTurtle(turtleData.getBytes())); if (!resultSet.getSuccess()) { throw new Exception(resultSet.getRationaleAsString(" ")); diff --git a/sparqlGraphLibrary/src/test/java/com/ge/research/semtk/nodegroupexecution/test/NodeGroupExecutionClientTest_IT.java b/sparqlGraphLibrary/src/test/java/com/ge/research/semtk/nodegroupexecution/test/NodeGroupExecutionClientTest_IT.java index 79296e399..ee8c84d50 100755 --- a/sparqlGraphLibrary/src/test/java/com/ge/research/semtk/nodegroupexecution/test/NodeGroupExecutionClientTest_IT.java +++ b/sparqlGraphLibrary/src/test/java/com/ge/research/semtk/nodegroupexecution/test/NodeGroupExecutionClientTest_IT.java @@ -598,7 +598,7 @@ public void testCopyGraph() throws Exception{ // copy to this graph SparqlEndpointInterface toGraphSei = TestGraph.getSei(TestGraph.getDataset() + "/copy"); - toGraphSei.clearGraph(); + IntegrationTestUtility.clearGraph(toGraphSei); assertEquals(toGraphSei.getNumTriples(), 0); // assert empty before copy String statusMessage = nodeGroupExecutionClient.copyGraph( @@ -607,6 +607,7 @@ public void testCopyGraph() throws Exception{ assertTrue(statusMessage.contains("Successfully copied")); assertEquals(toGraphSei.getNumTriples(), 50); // assert populated after copy + IntegrationTestUtility.clearGraph(toGraphSei); } @Test diff --git a/sparqlGraphLibrary/src/test/java/com/ge/research/semtk/ontologyTools/test/OntologyInfoTests_IT.java b/sparqlGraphLibrary/src/test/java/com/ge/research/semtk/ontologyTools/test/OntologyInfoTests_IT.java index f9967a0a2..61b3477b7 100644 --- a/sparqlGraphLibrary/src/test/java/com/ge/research/semtk/ontologyTools/test/OntologyInfoTests_IT.java +++ b/sparqlGraphLibrary/src/test/java/com/ge/research/semtk/ontologyTools/test/OntologyInfoTests_IT.java @@ -31,7 +31,6 @@ import com.ge.research.semtk.test.TestConnection; import com.ge.research.semtk.test.TestGraph; import com.ge.research.semtk.utility.Utility; -import com.ge.research.semtk.belmont.NodeGroup; import com.ge.research.semtk.belmont.test.QueryGenTest_IT; import com.ge.research.semtk.load.DataLoader; import com.ge.research.semtk.load.dataset.CSVDataset; @@ -222,6 +221,7 @@ public void testDoubleModel() throws Exception { OntologyClass flower = oInfo.getClass("http://research.ge.com/kdl/plant#Flower"); assertTrue(cat != null); assertTrue(flower != null); + testConn.clearGraphs(); } @Test @@ -242,10 +242,12 @@ public void testDoubleModelViaQueryService() throws Exception { OntologyClass flower = oInfo.getClass("http://research.ge.com/kdl/plant#Flower"); assertTrue(cat != null); assertTrue(flower != null); + testConn.clearGraphs(); } private TestConnection setupDoubleModel() throws Exception { TestConnection conn = new TestConnection(2, 1, "http://research.ge.com/kdl/"); + conn.clearGraphs(); conn.uploadOwl(0, "src/test/resources/Pet.owl"); conn.uploadOwl(1, "src/test/resources/Plant.owl"); return conn;