Last active
August 29, 2015 14:05
-
-
Save harschware/e59aac939aaa46b404e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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