Skip to content

Commit

Permalink
Clear stray JUnit graphs after using them
Browse files Browse the repository at this point in the history
  • Loading branch information
weisenje committed Mar 13, 2023
1 parent 2a1cc0f commit 2bb1d7c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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 );
}

Expand All @@ -87,7 +81,7 @@ public void clearGraphs() throws Exception {
seiList.addAll(this.conn.getDataInterfaces());

for (SparqlEndpointInterface sei : seiList) {
sei.clearGraph();
IntegrationTestUtility.clearGraph(sei);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -108,7 +106,6 @@ public static EndpointProperties getEndpointProperties() throws Exception {
ret.setEndpointServerUrl(sei.getServerAndPort());
ret.setEndpointUsername(sei.getUserName());
ret.setEndpointPassword(sei.getPassword());

return ret;
}

Expand Down Expand Up @@ -218,57 +215,43 @@ 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 {
SparqlGraphJson sgJson = new SparqlGraphJson(ng, getSparqlConn());
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);
}
Expand All @@ -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.
*/
Expand All @@ -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);
Expand Down Expand Up @@ -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();

Expand All @@ -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);
Expand All @@ -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(" "));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 2bb1d7c

Please sign in to comment.