Commit b2e7358d authored by Marshall McDonnell's avatar Marshall McDonnell

Switch tabs for spaces in BATS ITDataSet

Signed-off-by: default avatarMarshall McDonnell <mcdonnellmt@ornl.gov>
parent 44597ca1
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Initial API and implementation and/or initial documentation - * Jay Jay Billings - Initial API and implementation and/or initial docs
* Jay Jay Billings * Marshall McDonnell - Added delete method integration test
*****************************************************************************/ *****************************************************************************/
package org.eclipse.ice.tests.bats; package org.eclipse.ice.tests.bats;
...@@ -33,186 +33,191 @@ import org.junit.Test; ...@@ -33,186 +33,191 @@ import org.junit.Test;
import org.eclipse.ice.bats.DataSet; import org.eclipse.ice.bats.DataSet;
/** /**
* This is a simple test of the BATS Dataset class. It requires that the Fuseki * These are the integration tests of the BATS Dataset class.
* is running locally on port 3030. The simplest way to do this is to execute * They requires that the Fuseki is running locally on port 3030.
* the docker-compose.yml file that is in the directory root BATS directory. *
* A Fuseki docker container is integrated into this project's Maven build
* via the fabric8io docker-maven-plugin:
* https://github.com/fabric8io/docker-maven-plugin
*
* The simplest way to do this is to execute:
* $ mvn clean docker:build verify
* *
* @author Jay Jay Billings * @author Jay Jay Billings
* *
*/ */
public class ITDataSet { public class ITDataSet {
/** /**
* @throws java.lang.Exception * @throws java.lang.Exception
*/ */
@BeforeClass @BeforeClass
public static void setUpBeforeClass() throws Exception { public static void setUpBeforeClass() throws Exception {
} }
/** /**
* This is a utility operation for checking if data sets correctly created * This is a utility operation for checking if data sets correctly created
* themselves on the remote server. * themselves on the remote server.
* *
* @param dataSet the dataset to check * @param dataSet the dataset to check
*/ */
private void checkDataSetCreationOnServer(final DataSet dataSet) { private void checkDataSetCreationOnServer(final DataSet dataSet) {
// Create the dataset // Create the dataset
try { try {
dataSet.create(); dataSet.create();
} catch (Exception e) { } catch (Exception e) {
// Complain // Complain
e.printStackTrace(); e.printStackTrace();
fail(); fail();
} }
// Grab the dataset directy from the server // Grab the dataset directy from the server
String name = dataSet.getName(); String name = dataSet.getName();
String fusekiURI = dataSet.getHost() + ":" + dataSet.getPort() + "/" + name; String fusekiURI = dataSet.getHost() + ":" + dataSet.getPort() + "/" + name;
String fusekiGetURI = fusekiURI + "/get"; String fusekiGetURI = fusekiURI + "/get";
RDFConnectionRemoteBuilder getConnBuilder = RDFConnectionFuseki.create().destination(fusekiGetURI); RDFConnectionRemoteBuilder getConnBuilder = RDFConnectionFuseki.create().destination(fusekiGetURI);
try (RDFConnectionFuseki getConn = (RDFConnectionFuseki) getConnBuilder.build()) { try (RDFConnectionFuseki getConn = (RDFConnectionFuseki) getConnBuilder.build()) {
System.out.println("Pulling " + dataSet.getName()); System.out.println("Pulling " + dataSet.getName());
getConn.begin(ReadWrite.READ); getConn.begin(ReadWrite.READ);
Model model = getConn.fetch(null); Model model = getConn.fetch(null);
getConn.commit(); getConn.commit();
// The only real check that exists is whether or not the exception is caught. // The only real check that exists is whether or not the exception is caught.
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
fail("Data set not found!"); fail("Data set not found!");
} }
} }
/** /**
* This operation checks data set creation. * This operation checks data set creation.
*/ */
@Test @Test
public void testCreate() { public void testCreate() {
// Create a default, empty data set with the default name // Create a default, empty data set with the default name
DataSet dataSet = new DataSet(); DataSet dataSet = new DataSet();
// Check the data set creation // Check the data set creation
checkDataSetCreationOnServer(dataSet); checkDataSetCreationOnServer(dataSet);
// Configure the name and some other details of a dataset and test that // Configure the name and some other details of a dataset and test that
// functionality // functionality
DataSet dataSet2 = new DataSet(); DataSet dataSet2 = new DataSet();
String uuidString = UUID.randomUUID().toString(); String uuidString = UUID.randomUUID().toString();
String name = "dataSetTest" + "." + uuidString; String name = "dataSetTest" + "." + uuidString;
dataSet2.setName(name); dataSet2.setName(name);
dataSet2.setHost("http://127.0.0.1"); dataSet2.setHost("http://127.0.0.1");
dataSet2.setPort(5); dataSet2.setPort(5);
// Make sure these work OK // Make sure these work OK
assertEquals(name, dataSet2.getName()); assertEquals(name, dataSet2.getName());
assertEquals("http://127.0.0.1", dataSet2.getHost()); assertEquals("http://127.0.0.1", dataSet2.getHost());
// Just check that the port is set properly since actually testing a port switch // Just check that the port is set properly since actually testing a port switch
// is too onerous // is too onerous
assertEquals(5, dataSet2.getPort()); assertEquals(5, dataSet2.getPort());
// Reset the port to avoid an error since it has been proven that it could be // Reset the port to avoid an error since it has been proven that it could be
// stored correctly. // stored correctly.
dataSet2.setPort(3030); dataSet2.setPort(3030);
// Check creating the dataset on the server with its custom args // Check creating the dataset on the server with its custom args
checkDataSetCreationOnServer(dataSet2); checkDataSetCreationOnServer(dataSet2);
return; return;
} }
/** /**
* This operation checks data set deletion * This operation checks data set deletion
* *
* @throws Exception this exception is thrown from getJenaDataset since * @throws Exception this exception is thrown from getJenaDataset since
* we are unable to find the dataset after we delete it * we are unable to find the dataset after we delete it
*/ */
@Test @Test
public void testDelete() throws Exception { public void testDelete() throws Exception {
// Create a default, empty data set with the default name // Create a default, empty data set with the default name
DataSet dataSet = new DataSet(); DataSet dataSet = new DataSet();
// Check the data set creation // Check the data set creation
checkDataSetCreationOnServer(dataSet); checkDataSetCreationOnServer(dataSet);
// Delete the dataset // Delete the dataset
dataSet.delete(); dataSet.delete();
// Check that we get null back from the dataset // Check that we get null back from the dataset
Dataset contents = dataSet.getJenaDataset(); Dataset contents = dataSet.getJenaDataset();
System.out.println(contents);
assertNull(contents); assertNull(contents);
} }
/** /**
* This operation tries to pull some models from the data set * This operation tries to pull some models from the data set
*/ */
@Test @Test
public void testModels() { public void testModels() {
// Create a new data set // Create a new data set
DataSet dataSet = new DataSet(); DataSet dataSet = new DataSet();
checkDataSetCreationOnServer(dataSet); checkDataSetCreationOnServer(dataSet);
// Put something in it // Put something in it
Model model = ModelFactory.createDefaultModel(); Model model = ModelFactory.createDefaultModel();
Resource resource = model.createResource("testModelResource"); Resource resource = model.createResource("testModelResource");
Property property = model.createProperty("none", "g"); Property property = model.createProperty("none", "g");
resource.addProperty(property, "testProp"); resource.addProperty(property, "testProp");
// Update the data set // Update the data set
dataSet.updateModel("testModel", model); dataSet.updateModel("testModel", model);
// Check the root/default model // Check the root/default model
Model rootModel = dataSet.getRootModel(); Model rootModel = dataSet.getRootModel();
assertNotNull(rootModel); assertNotNull(rootModel);
// Check the named model // Check the named model
Model namedModel = dataSet.getModel("testModel"); Model namedModel = dataSet.getModel("testModel");
assertNotNull(namedModel); assertNotNull(namedModel);
// Make sure that the model matches the original model by doing a difference and // Make sure that the model matches the original model by doing a difference and
// checking the number of statements in the difference model. // checking the number of statements in the difference model.
Model differenceModel = namedModel.difference(model); Model differenceModel = namedModel.difference(model);
assertFalse(differenceModel.listStatements().hasNext()); assertFalse(differenceModel.listStatements().hasNext());
// Try putting the model a second time to make sure that it doesn't get // Try putting the model a second time to make sure that it doesn't get
// duplicated. // duplicated.
dataSet.updateModel("testModel", model); dataSet.updateModel("testModel", model);
// Make sure the number of triples didn't change with this update. // Make sure the number of triples didn't change with this update.
Model namedModel2 = dataSet.getModel("testModel"); Model namedModel2 = dataSet.getModel("testModel");
Model differenceModel2 = namedModel2.difference(model); Model differenceModel2 = namedModel2.difference(model);
assertFalse(differenceModel2.listStatements().hasNext()); assertFalse(differenceModel2.listStatements().hasNext());
return; return;
} }
/** /**
* This operation checks loading a pre-existing data set. * This operation checks loading a pre-existing data set.
*/ */
@Test @Test
public void testJenaDataSetLoad() { public void testJenaDataSetLoad() {
// Create a new data set // Create a new data set
DataSet referenceDataSet = new DataSet(); DataSet referenceDataSet = new DataSet();
checkDataSetCreationOnServer(referenceDataSet); checkDataSetCreationOnServer(referenceDataSet);
// Put something in it // Put something in it
Model model = ModelFactory.createDefaultModel(); Model model = ModelFactory.createDefaultModel();
Resource resource = model.createResource("testModelResource"); Resource resource = model.createResource("testModelResource");
Property property = model.createProperty("none", "h"); Property property = model.createProperty("none", "h");
resource.addProperty(property, "testProp"); resource.addProperty(property, "testProp");
// Upload it to the server // Upload it to the server
referenceDataSet.updateModel("testModel", model); referenceDataSet.updateModel("testModel", model);
// Load the contents from the server into a new, empty data set // Load the contents from the server into a new, empty data set
DataSet loadedSet = new DataSet(); DataSet loadedSet = new DataSet();
loadedSet.setHost(referenceDataSet.getHost()); loadedSet.setHost(referenceDataSet.getHost());
loadedSet.setPort(referenceDataSet.getPort()); loadedSet.setPort(referenceDataSet.getPort());
loadedSet.setName(referenceDataSet.getName()); loadedSet.setName(referenceDataSet.getName());
Dataset jenaDataset = loadedSet.getJenaDataset(); Dataset jenaDataset = loadedSet.getJenaDataset();
// Check something! // Check something!
assertEquals(referenceDataSet.getJenaDataset().getDefaultModel().toString(), assertEquals(referenceDataSet.getJenaDataset().getDefaultModel().toString(),
jenaDataset.getDefaultModel().toString()); jenaDataset.getDefaultModel().toString());
return; return;
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment