Skip to content

Instantly share code, notes, and snippets.

@harschware
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harschware/e59aac939aaa46b404e9 to your computer and use it in GitHub Desktop.
Save harschware/e59aac939aaa46b404e9 to your computer and use it in GitHub Desktop.
package com.hp.hpl.jena.sparql.path;
import static org.junit.Assert.assertEquals;
import java.io.File;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.hp.hpl.jena.update.UpdateFactory;
import com.hp.hpl.jena.update.UpdateRequest;
/**
* @see https://issues.apache.org/jira/browse/JENA-712
*
* @author tharsch
*
*/
public class TestJena712 {
// @SuppressWarnings("unused")
private static final Logger LOGGER = LoggerFactory
.getLogger(TestJena712.class);
@Test
public void testFullPathNoBaseUri() {
// test a contrived path, using the current working directory as a base.
String cwd = System.getProperty("user.dir");
String testPath = cwd + File.separator + "fileDoesNotExist.txt";
String expected = "DROP GRAPH <file://" + testPath + ">\n";
LOGGER.debug(expected);
UpdateRequest actual = UpdateFactory.create(expected);
LOGGER.debug(actual.toString());
assertEquals(expected, actual.toString());
// Also test a file that acutally exists on the file system, result
// should be the same.
File file = getAFile(cwd);
testPath = file.getAbsolutePath();
expected = "DROP GRAPH <file://" + testPath + ">\n";
LOGGER.debug(expected);
actual = UpdateFactory.create(expected);
LOGGER.debug(actual.toString());
assertEquals(expected, actual.toString());
} // end test
private File getAFile(String path) {
File dir = new File(path);
File[] directoryListing = dir.listFiles();
return directoryListing[0];
} // end method
@Test
public void testFullPathWithBaseUri() {
String testPath = System.getProperty("user.dir") + File.separator
+ "fileDoesNotExist.txt";
LOGGER.debug(testPath);
File fPath = new File(testPath);
String parent = fPath.getParent();
String fName = fPath.getName();
String cmd = "BASE <file://" + parent + File.separator
+ ">\n\nDROP GRAPH <" + testPath + ">\n";
LOGGER.debug(cmd);
UpdateRequest actual = UpdateFactory.create(cmd);
LOGGER.debug(actual.toString());
String expected = "BASE <file://" + parent + File.separator
+ ">\n\nDROP GRAPH <" + fName + ">\n";
LOGGER.debug(expected);
assertEquals(expected, actual.toString());
} // end test
@Test
public void testRelativePathNoBaseUri() {
String name = "fileDoesNotExist.txt";
String testPath = System.getProperty("user.dir") + File.separator
+ name;
LOGGER.debug(testPath);
String expected = "DROP GRAPH <file://" + testPath + ">\n";
LOGGER.debug(expected);
String cmd = "DROP GRAPH <" + name + ">\n";
LOGGER.debug(cmd);
UpdateRequest actual = UpdateFactory.create(cmd);
LOGGER.debug(actual.toString());
assertEquals(expected, actual.toString());
} // end test
@Test
public void testRelativePathWithBaseUri() {
String parent = System.getProperty("user.dir");
String name = "fileDoesNotExist.txt";
String testPath = parent + File.separator + name;
LOGGER.debug(testPath);
String cmd = "BASE <file://" + parent + File.separator
+ ">\n\nDROP GRAPH <" + testPath + ">\n";
LOGGER.debug(cmd);
UpdateRequest actual = UpdateFactory.create(cmd);
LOGGER.debug(actual.toString());
String expected = "BASE <file://" + parent + File.separator
+ ">\n\nDROP GRAPH <" + name + ">\n";
LOGGER.debug(expected);
assertEquals(expected, actual.toString());
} // end test
} // end test class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment