Unverified Commit de1a36e8 authored by Jay Billings's avatar Jay Billings Committed by GitHub

Merge pull request #483 from marshallmcdonnell/marshall/bats_unit_tests_and_delete

Adds unit tests and delete method to BATS
parents 49c5006b dbdaa3bf
......@@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Initial API and implementation and/or initial documentation -
* Jay Jay Billings
* Jay Jay Billings - Initial API and implementation and/or initial docs
* Marshall McDonnell - Added delete method
*****************************************************************************/
package org.eclipse.ice.bats;
......@@ -20,6 +20,7 @@ import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;
......@@ -83,6 +84,7 @@ public class DataSet {
*/
private String name = DEFAULT_NAME;
/**
* This operation sets the name of the data set. The name of the data set is the
* name recognized by the host, not the local machine. It must be set prior to
......@@ -151,6 +153,19 @@ public class DataSet {
return getHost() + ":" + getPort() + "/" + getName();
}
/**
* This operation returns the full URI of the Fuseki Data API location
* for this data set on the remote server
* using the hostname, port, and set name.
*
* @return the Fuseki Data API location
*/
public String getFusekiDatasetsURI() {
String fusekiLocation = host + ":" + port + "/";
String fusekiDataAPILoc = "$/datasets";
return getHost() + ":" + getPort() + "/$/datasets";
}
/**
* This operation creates a dataset with the given name. If no name is provided
* to setName(), the default name with a UUID appended to it will be used such
......@@ -176,9 +191,8 @@ public class DataSet {
// Connect the HTTP client
HttpClient client = HttpClientBuilder.create().build();
String fusekiLocation = host + ":" + port + "/";
String fusekiDataAPILoc = "$/datasets";
HttpPost post = new HttpPost((fusekiLocation + fusekiDataAPILoc));
String fusekiDataLocation = getFusekiDatasetsURI();
HttpPost post = new HttpPost(fusekiDataLocation);
// Add the database parameters into the form with UTF_8 encoding.
List<NameValuePair> form = new ArrayList<NameValuePair>();
......@@ -194,6 +208,24 @@ public class DataSet {
return;
}
/**
* This operation deletes the data set with the given name.
*
* @throws Exception
*/
public void delete() throws Exception {
// Connect the HTTP client
HttpClient client = HttpClientBuilder.create().build();
String fusekiDataLocation = getFusekiDatasetsURI();
HttpDelete delete = new HttpDelete(fusekiDataLocation + "/" + name);
// Delete the data set
HttpResponse response = client.execute(delete);
logger.debug(response.toString());
return;
}
/**
* This operation directs the data set to update and persist any remotely stored
* versions of this model with this version of the model. This action is a
......
/******************************************************************************
* Copyright (c) 2019- UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0,
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Marshall McDonnell - Added initial unit tests
*****************************************************************************/
package org.eclipse.ice.tests.bats;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.eclipse.ice.bats.DataSet;
/**
* These are the unit tests of the BATS Dataset class.
*
* @author Marshall McDonnell
*
*/
public class DataSetTest {
/**
* This operation checks for proper default DataSet object construction
*/
@Test
public void testConstruction() {
DataSet dataset = new DataSet();
assertEquals(dataset.getName(), "unnamed-dataset");
assertEquals(dataset.getHost(), "http://localhost");
assertEquals(dataset.getPort(), 3030);
assertEquals(dataset.getFullURI(), "http://localhost:3030/unnamed-dataset");
}
/**
* This operation checks we can set the dataset name
*/
@Test
public void testSetName() {
DataSet dataset = new DataSet();
dataset.setName("foo");
assertEquals(dataset.getName(), "foo");
}
/**
* This operation checks we can set the hostname
*/
@Test
public void testSetHost() {
DataSet dataset = new DataSet();
dataset.setHost("http://foo.com");
assertEquals(dataset.getHost(), "http://foo.com");
}
/**
* This operation checks we can set the port
*/
@Test
public void testSetPort() {
DataSet dataset = new DataSet();
dataset.setPort(8080);
assertEquals(dataset.getPort(), 8080);
}
/**
* This operation checks we get the correct Fuseki Data API URL
*/
@Test
public void testGetFusekiDatasetsURI() {
DataSet dataset = new DataSet();
assertEquals(
dataset.getFusekiDatasetsURI(),
"http://localhost:3030/$/datasets");
}
}
......@@ -6,12 +6,16 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Initial API and implementation and/or initial documentation -
* Jay Jay Billings
* Jay Jay Billings - Initial API and implementation and/or initial docs
* Marshall McDonnell - Added delete method integration test
*****************************************************************************/
package org.eclipse.ice.tests.bats;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import java.util.UUID;
......@@ -29,9 +33,15 @@ import org.junit.Test;
import org.eclipse.ice.bats.DataSet;
/**
* This is a simple test of the BATS Dataset class. It requires that the Fuseki
* is running locally on port 3030. The simplest way to do this is to execute
* the docker-compose.yml file that is in the directory root BATS directory.
* These are the integration tests of the BATS Dataset class.
* They requires that the Fuseki is running locally on port 3030.
*
* 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
*
......@@ -115,6 +125,27 @@ public class ITDataSet {
return;
}
/**
* This operation checks data set deletion
*
* @throws Exception this exception is thrown from getJenaDataset since
* we are unable to find the dataset after we delete it
*/
@Test
public void testDelete() throws Exception {
// Create a default, empty data set with the default name
DataSet dataSet = new DataSet();
// Check the data set creation
checkDataSetCreationOnServer(dataSet);
// Delete the dataset
dataSet.delete();
// Check that we get null back from the dataset
Dataset contents = dataSet.getJenaDataset();
assertNull(contents);
}
/**
* This operation tries to pull some models from the data set
*/
......
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