Improve output: distinguish between failed assertions (failures) and unexpected exceptions (errors), and print a filtered stack trace for any exception.
This commit is contained in:
commit
4f2e303079
1839 changed files with 235630 additions and 0 deletions
3
webapp/test/commons-logging.properties
Normal file
3
webapp/test/commons-logging.properties
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Tell Apache Commons Logging that we want to use Log4J for the unit tests,
|
||||
# even if other logging systems are available.
|
||||
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
|
|
@ -0,0 +1,331 @@
|
|||
package edu.cornell.mannlib.vitro.testing;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintStream;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.HashSet;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import org.apache.log4j.ConsoleAppender;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.PatternLayout;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* A collection of useful routines to help when testing.
|
||||
* <ul>
|
||||
* <li>Permit tests to control the Logging levels of individual classes.</li>
|
||||
* <li>Permit tests to control system properties.</li>
|
||||
* <li>Suppress, capture or test standard output and/or error output.</li>
|
||||
* <li>Create and delete temporary files and directories.</li>
|
||||
* <li>Create URLs from Strings without throwing checked exceptions.</li>
|
||||
* <li>Compare the contents of XML documents.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author jeb228
|
||||
*/
|
||||
public abstract class AbstractTestClass {
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Control the level of logging output.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/** The layout we use for logging. */
|
||||
private static final PatternLayout patternLayout = new PatternLayout(
|
||||
"%p %d{yyyy-MM-dd' 'HH:mm:ss.SSS} [%t] (%c{1}) %m%n");
|
||||
|
||||
/**
|
||||
* Unless modified, all Logging will be done to the console at
|
||||
* {@link Level#INFO}.
|
||||
*/
|
||||
@Before
|
||||
@After
|
||||
public void initializeLogging() {
|
||||
LogManager.resetConfiguration();
|
||||
Logger.getRootLogger().addAppender(new ConsoleAppender(patternLayout));
|
||||
Logger.getRootLogger().setLevel(Level.INFO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this in a "@Before" or "@BeforeClass" method to change the logging
|
||||
* level of a particular class.
|
||||
*/
|
||||
protected static void setLoggerLevel(Class<?> clazz, Level level) {
|
||||
Logger.getLogger(clazz).setLevel(level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Same thing, but for a logger that is not named directly after a class.
|
||||
*/
|
||||
protected static void setLoggerLevel(String category, Level level) {
|
||||
Logger.getLogger(category).setLevel(level);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Control standard output or error output.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private static final PrintStream originalSysout = System.out;
|
||||
private static final PrintStream originalSyserr = System.err;
|
||||
private final ByteArrayOutputStream capturedSysout = new ByteArrayOutputStream();
|
||||
private final ByteArrayOutputStream capturedSyserr = new ByteArrayOutputStream();
|
||||
|
||||
@Before
|
||||
@After
|
||||
public void restoreOutputStreams() {
|
||||
System.setOut(originalSysout);
|
||||
System.setErr(originalSyserr);
|
||||
capturedSysout.reset();
|
||||
capturedSyserr.reset();
|
||||
}
|
||||
|
||||
protected void suppressSysout() {
|
||||
System.setOut(new PrintStream(capturedSysout, true));
|
||||
}
|
||||
|
||||
protected void suppressSyserr() {
|
||||
System.setErr(new PrintStream(capturedSyserr, true));
|
||||
}
|
||||
|
||||
protected String getSysoutForTest() {
|
||||
return capturedSysout.toString();
|
||||
}
|
||||
|
||||
protected String getSyserrForTest() {
|
||||
return capturedSyserr.toString();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Set values on System properties for individual tests.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private static Properties originalSystemProperties = (Properties) System
|
||||
.getProperties().clone();
|
||||
|
||||
@Before
|
||||
@After
|
||||
public void restoreSystemProperties() {
|
||||
System.setProperties((Properties) originalSystemProperties.clone());
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Manage temporary files.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete a file, either before or after the test. If it can't be deleted,
|
||||
* complain.
|
||||
*/
|
||||
protected static void deleteFile(File file) {
|
||||
if (file.exists()) {
|
||||
if (!file.delete()) {
|
||||
fail("Unable to delete file '" + file.getPath() + "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all of the files in a directory, and the directory itself. Will
|
||||
* not work if there are sub-directories.
|
||||
*/
|
||||
protected static void purgeDirectory(File directory) {
|
||||
if (directory.exists()) {
|
||||
File[] files = directory.listFiles();
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()) {
|
||||
fail("Directory '" + directory
|
||||
+ "' contains at least one nested directory.");
|
||||
}
|
||||
}
|
||||
for (File file : files) {
|
||||
deleteFile(file);
|
||||
}
|
||||
deleteFile(directory);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all of the files in a directory, any sub-directories, and the
|
||||
* directory itself.
|
||||
*/
|
||||
protected static void purgeDirectoryRecursively(File directory) {
|
||||
if (directory.exists()) {
|
||||
File[] files = directory.listFiles();
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()) {
|
||||
purgeDirectoryRecursively(file);
|
||||
} else {
|
||||
deleteFile(file);
|
||||
}
|
||||
}
|
||||
deleteFile(directory);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a directory of a given name inside the Temp directory. If such a
|
||||
* directory already exists, purge it and its contents and create it fresh.
|
||||
*/
|
||||
protected static File createTempDirectory(String name) throws IOException {
|
||||
File tempDirectory = new File(System.getProperty("java.io.tmpdir"),
|
||||
name);
|
||||
|
||||
// If it already exists, remove it, so we start clean.
|
||||
if (tempDirectory.exists()) {
|
||||
purgeDirectoryRecursively(tempDirectory);
|
||||
}
|
||||
|
||||
if (!tempDirectory.mkdir()) {
|
||||
throw new IOException("failed to create temp directory '"
|
||||
+ tempDirectory.getPath() + "'");
|
||||
}
|
||||
|
||||
return tempDirectory;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Other utilities.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create a file and fill it with the contents provided.
|
||||
*/
|
||||
protected File createFile(File directory, String filename, String contents)
|
||||
throws IOException {
|
||||
Writer writer = null;
|
||||
try {
|
||||
File file = new File(directory, filename);
|
||||
file.createNewFile();
|
||||
writer = new FileWriter(file);
|
||||
writer.write(contents);
|
||||
return file;
|
||||
} finally {
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the entire contents of a file, or throw an exception if it's not
|
||||
* there.
|
||||
*/
|
||||
protected static String readFile(File file) throws IOException {
|
||||
if (!file.exists()) {
|
||||
throw new IOException("file '" + file.getPath() + "' ('"
|
||||
+ file.getAbsolutePath() + "') does not exist.");
|
||||
}
|
||||
FileReader fileReader = new FileReader(file);
|
||||
String result = readAll(fileReader);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Suck all the data from a {@link Reader} into a {@link String}.
|
||||
*/
|
||||
protected static String readAll(Reader reader) throws IOException {
|
||||
StringBuilder result = new StringBuilder();
|
||||
BufferedReader buffered = new BufferedReader(reader);
|
||||
String line;
|
||||
while (null != (line = buffered.readLine())) {
|
||||
result.append(line).append('\n');
|
||||
}
|
||||
reader.close();
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Suck all the data from a {@link InputStream} into a {@link String}.
|
||||
*/
|
||||
protected static String readAll(InputStream stream) throws IOException {
|
||||
return readAll(new InputStreamReader(stream));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string to a URL without a checked exception.
|
||||
*/
|
||||
protected static URL url(String string) {
|
||||
try {
|
||||
return new URL(string);
|
||||
} catch (MalformedURLException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read each string into an XML document and then write it again. This
|
||||
* should discard any differences that are not syntactically significant.
|
||||
* Will they be identical?
|
||||
*/
|
||||
protected void assertEquivalentXmlDocs(String string1, String string2) {
|
||||
String out1 = launderXmlDocument(string1);
|
||||
String out2 = launderXmlDocument(string2);
|
||||
if (!out1.equals(out2)) {
|
||||
fail("XML documents are not equivalent: expected <" + string1
|
||||
+ "> but was <" + string2 + ">");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a string of XML into a document and write it again. This should
|
||||
* result in a canonical form that can be compared to other such strings.
|
||||
*/
|
||||
private String launderXmlDocument(String docString) {
|
||||
StringWriter result = new StringWriter();
|
||||
try {
|
||||
DocumentBuilderFactory bFactory = DocumentBuilderFactory
|
||||
.newInstance();
|
||||
DocumentBuilder builder = bFactory.newDocumentBuilder();
|
||||
|
||||
TransformerFactory xFactory = TransformerFactory.newInstance();
|
||||
Transformer xformer = xFactory.newTransformer();
|
||||
|
||||
StringReader reader = new StringReader(docString);
|
||||
Document doc = builder.parse(new InputSource(reader));
|
||||
xformer.transform(new DOMSource(doc), new StreamResult(result));
|
||||
} catch (ParserConfigurationException e) {
|
||||
fail(e.toString());
|
||||
} catch (SAXException e) {
|
||||
fail(e.toString());
|
||||
} catch (IOException e) {
|
||||
fail(e.toString());
|
||||
} catch (TransformerException e) {
|
||||
fail(e.toString());
|
||||
}
|
||||
return result.toString().replaceAll(">\\s+<", "><");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,347 @@
|
|||
package edu.cornell.mannlib.vitro.testing;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import static edu.cornell.mannlib.vitro.testing.VitroTestRunner.ReportLevel.BRIEF;
|
||||
import static edu.cornell.mannlib.vitro.testing.VitroTestRunner.ReportLevel.FULL;
|
||||
import static edu.cornell.mannlib.vitro.testing.VitroTestRunner.ReportLevel.MORE;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.runner.Description;
|
||||
import org.junit.runner.Result;
|
||||
import org.junit.runner.notification.Failure;
|
||||
import org.junit.runner.notification.RunListener;
|
||||
|
||||
import com.ibm.icu.text.SimpleDateFormat;
|
||||
|
||||
import edu.cornell.mannlib.vitro.testing.VitroTestRunner.ReportLevel;
|
||||
|
||||
/**
|
||||
* Listen to events as they come from the JUnit test runner. The events from the
|
||||
* lifecycle methods are broken down into semantic chunks and executed. Three
|
||||
* levels of output are available.
|
||||
*
|
||||
* On the surface, JUnit treats "failures" (failed assertions) the same as
|
||||
* "errors" (unexpected exceptions). We're going to distinguish between them.
|
||||
*
|
||||
* @author jeb228
|
||||
*/
|
||||
public class VitroTestRunListener extends RunListener {
|
||||
private final ReportLevel reportLevel;
|
||||
|
||||
private int classCount;
|
||||
private int testsTotal;
|
||||
private int errorsTotal;
|
||||
private int failuresTotal;
|
||||
private int ignoresTotal;
|
||||
private long overallStartTime;
|
||||
|
||||
private Class<?> currentClass;
|
||||
private int testsCurrentClass;
|
||||
private int errorsCurrentClass;
|
||||
private int failuresCurrentClass;
|
||||
private int ignoresCurrentClass;
|
||||
private long classStartTime;
|
||||
|
||||
private String currentTest;
|
||||
private boolean testHadError;
|
||||
private boolean testFailed;
|
||||
private boolean testIgnored;
|
||||
private long testStartTime;
|
||||
|
||||
public VitroTestRunListener(ReportLevel reportLevel) {
|
||||
this.reportLevel = reportLevel;
|
||||
}
|
||||
|
||||
/** Did any of the tests fail or have errors? */
|
||||
public boolean didEverythingPass() {
|
||||
return (failuresTotal == 0) && (errorsTotal == 0);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Life-cycle methods that will be called by the test runner.
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public void testRunStarted(Description description) throws Exception {
|
||||
openTestRun();
|
||||
reportTestRunStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testStarted(Description description) throws Exception {
|
||||
if (currentClass != description.getTestClass()) {
|
||||
if (currentClass != null) {
|
||||
closeCurrentClass();
|
||||
reportCurrentClass();
|
||||
}
|
||||
|
||||
openCurrentClass(description);
|
||||
reportCurrentClassStart();
|
||||
}
|
||||
|
||||
openCurrentTest(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testAssumptionFailure(Failure failure) {
|
||||
if (isError(failure)) {
|
||||
testHadError = true;
|
||||
reportError(failure);
|
||||
} else {
|
||||
testFailed = true;
|
||||
reportFailure(failure);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testFailure(Failure failure) throws Exception {
|
||||
if (isError(failure)) {
|
||||
testHadError = true;
|
||||
reportError(failure);
|
||||
} else {
|
||||
testFailed = true;
|
||||
reportFailure(failure);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testFinished(Description description) throws Exception {
|
||||
closeCurrentTest();
|
||||
reportCurrentTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testIgnored(Description description) throws Exception {
|
||||
testStarted(description);
|
||||
testIgnored = true;
|
||||
testFinished(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testRunFinished(Result result) throws Exception {
|
||||
if (currentClass != null) {
|
||||
closeCurrentClass();
|
||||
reportCurrentClass();
|
||||
}
|
||||
closeTestRun();
|
||||
reportTestRun();
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Handling the logical events.
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
private void openTestRun() {
|
||||
overallStartTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
private void closeTestRun() {
|
||||
// Nothing to close.
|
||||
}
|
||||
|
||||
private void reportTestRunStart() {
|
||||
if (reportLevel == FULL) {
|
||||
System.out
|
||||
.println("Starting test run at " + time(overallStartTime));
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
if (reportLevel == MORE) {
|
||||
System.out
|
||||
.println("Starting test run at " + time(overallStartTime));
|
||||
System.out.println();
|
||||
System.out.println("Tests Pass Error Fail Ignore Seconds");
|
||||
}
|
||||
}
|
||||
|
||||
private void reportTestRun() {
|
||||
int successes = testsTotal - errorsTotal - failuresTotal - ignoresTotal;
|
||||
|
||||
if (reportLevel != BRIEF) {
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
System.out.format(
|
||||
"Tests Pass Error Fail Ignore Seconds TOTAL (%d classes)\n",
|
||||
classCount);
|
||||
System.out.format(" %4d %4d %4d %4d %4d %6s\n", testsTotal,
|
||||
successes, errorsTotal, failuresTotal, ignoresTotal,
|
||||
elapsed(overallStartTime));
|
||||
|
||||
if (reportLevel != BRIEF) {
|
||||
System.out.println("Ending test run at "
|
||||
+ time(System.currentTimeMillis()));
|
||||
}
|
||||
}
|
||||
|
||||
private void openCurrentClass(Description description) {
|
||||
currentClass = description.getTestClass();
|
||||
classStartTime = System.currentTimeMillis();
|
||||
testsCurrentClass = 0;
|
||||
errorsCurrentClass = 0;
|
||||
failuresCurrentClass = 0;
|
||||
ignoresCurrentClass = 0;
|
||||
}
|
||||
|
||||
private void closeCurrentClass() {
|
||||
classCount++;
|
||||
testsTotal += testsCurrentClass;
|
||||
errorsTotal += errorsCurrentClass;
|
||||
failuresTotal += failuresCurrentClass;
|
||||
ignoresTotal += ignoresCurrentClass;
|
||||
}
|
||||
|
||||
private void reportCurrentClassStart() {
|
||||
if (reportLevel == FULL) {
|
||||
System.out.format("Tests Pass Error Fail Ignore Seconds %s\n",
|
||||
currentClass.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private void reportCurrentClass() {
|
||||
int successes = testsCurrentClass - errorsCurrentClass
|
||||
- failuresCurrentClass - ignoresCurrentClass;
|
||||
if (reportLevel == MORE) {
|
||||
System.out.format(" %4d %4d %4d %4d %4d %6s %s\n",
|
||||
testsCurrentClass, successes, errorsCurrentClass,
|
||||
failuresCurrentClass, ignoresCurrentClass,
|
||||
elapsed(classStartTime), currentClass.getSimpleName());
|
||||
}
|
||||
if (reportLevel == FULL) {
|
||||
System.out.println("-----------------------------------");
|
||||
System.out.format(" %4d %4d %4d %4d %4d %6s\n",
|
||||
testsCurrentClass, successes, errorsCurrentClass,
|
||||
failuresCurrentClass, ignoresCurrentClass,
|
||||
elapsed(classStartTime));
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
private void openCurrentTest(Description description) {
|
||||
currentTest = description.getMethodName();
|
||||
testHadError = false;
|
||||
testFailed = false;
|
||||
testIgnored = false;
|
||||
testStartTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
private void closeCurrentTest() {
|
||||
if (testHadError) {
|
||||
errorsCurrentClass++;
|
||||
}
|
||||
if (testFailed) {
|
||||
failuresCurrentClass++;
|
||||
}
|
||||
if (testIgnored) {
|
||||
ignoresCurrentClass++;
|
||||
}
|
||||
testsCurrentClass++;
|
||||
}
|
||||
|
||||
private boolean isError(Failure failure) {
|
||||
Throwable throwable = failure.getException();
|
||||
return (throwable != null) && !(throwable instanceof AssertionError);
|
||||
}
|
||||
|
||||
private void reportError(Failure error) {
|
||||
Description description = error.getDescription();
|
||||
String methodName = description.getMethodName();
|
||||
String className = description.getTestClass().getName();
|
||||
String message = error.getMessage();
|
||||
System.out.format("EXCEPTION: test %s() in %s: %s\n",
|
||||
methodName, className, message);
|
||||
System.out.println(formatStackTrace(error.getException()));
|
||||
}
|
||||
|
||||
private void reportFailure(Failure failure) {
|
||||
Description description = failure.getDescription();
|
||||
String methodName = description.getMethodName();
|
||||
String className = description.getTestClass().getName();
|
||||
String message = failure.getMessage();
|
||||
System.out.format("TEST FAILED: test %s() in %s: %s\n", methodName,
|
||||
className, message);
|
||||
}
|
||||
|
||||
private void reportCurrentTest() {
|
||||
if (reportLevel == FULL) {
|
||||
char passFlag = (testIgnored | testFailed | testHadError) ? ' '
|
||||
: '1';
|
||||
char errorFlag = testHadError ? '1' : ' ';
|
||||
char failFlag = testFailed ? '1' : ' ';
|
||||
char ignoreFlag = testIgnored ? '1' : ' ';
|
||||
System.out.format(
|
||||
" %c %c %c %c %6s %s()\n",
|
||||
passFlag, errorFlag, failFlag, ignoreFlag,
|
||||
elapsed(testStartTime), currentTest);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Formatting methods.
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
private final SimpleDateFormat formatter = new SimpleDateFormat(
|
||||
"HH:mm:ss 'on' MMM dd, yyyy");
|
||||
|
||||
private String time(long time) {
|
||||
return formatter.format(new Date(time));
|
||||
}
|
||||
|
||||
/** Show elapsed time in 6 columns. */
|
||||
private String elapsed(long start) {
|
||||
long interval = System.currentTimeMillis() - start;
|
||||
return String.format("%6.2f", ((float) interval) / 1000.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim the stack trace: don't show the line saying "23 more", and don't
|
||||
* show the lines about org.junit or java.lang.reflect or sun.reflect.
|
||||
*
|
||||
* Once we hit some "client code", we won't trim any futher lines even if
|
||||
* they belong to org.junit, or the others.
|
||||
*
|
||||
* If we have nested exceptions, the process repeats for each "Caused by"
|
||||
* section.
|
||||
*/
|
||||
private String formatStackTrace(Throwable throwable) {
|
||||
StringWriter w = new StringWriter();
|
||||
throwable.printStackTrace(new PrintWriter(w));
|
||||
String[] lineArray = w.toString().split("\\n");
|
||||
List<String> lines = new ArrayList<String>(Arrays.asList(lineArray));
|
||||
|
||||
boolean removing = true;
|
||||
for (int i = lines.size() - 1; i > 0; i--) {
|
||||
String line = lines.get(i);
|
||||
if (removing) {
|
||||
if (line.matches("\\s*[\\.\\s\\d]+more\\s*")
|
||||
|| line.contains("at "
|
||||
+ VitroTestRunner.class.getName())
|
||||
|| line.contains("at org.junit.")
|
||||
|| line.contains("at java.lang.reflect.")
|
||||
|| line.contains("at sun.reflect.")) {
|
||||
lines.remove(line);
|
||||
} else {
|
||||
removing = false;
|
||||
}
|
||||
} else {
|
||||
if (line.contains("Caused by: ")) {
|
||||
removing = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (String line : lines) {
|
||||
result.append(line).append('\n');
|
||||
}
|
||||
return result.toString().trim();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
package edu.cornell.mannlib.vitro.testing;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.junit.runner.JUnitCore;
|
||||
|
||||
/**
|
||||
* A Java application that will run the Vitro unit tests. It searches for unit
|
||||
* tests in the supplied source directory (any file whose name is *Test.Java).
|
||||
* It runs the tests with a variety of reporting detail, depending on the level
|
||||
* selected. If the level selector is absent or unrecognized, the medium level
|
||||
* is used.
|
||||
*
|
||||
* @author jeb228
|
||||
*/
|
||||
public class VitroTestRunner {
|
||||
public enum ReportLevel {
|
||||
/** Report only the one-line summary. */
|
||||
BRIEF,
|
||||
/** Report times and statistics for each test class. */
|
||||
MORE,
|
||||
/** Report times and statistics for each test method. */
|
||||
FULL
|
||||
}
|
||||
|
||||
private final List<Class<?>> classes;
|
||||
private final VitroTestRunListener listener;
|
||||
|
||||
/**
|
||||
* Locate the test classes. Initialize the test listener.
|
||||
*/
|
||||
public VitroTestRunner(File sourceRootDir, ReportLevel reportLevel) {
|
||||
List<String> classNames = getListOfTestClassNames(sourceRootDir);
|
||||
this.classes = getTestClasses(classNames);
|
||||
this.listener = new VitroTestRunListener(reportLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a recursive search through the source directory.
|
||||
*/
|
||||
private List<String> getListOfTestClassNames(File sourceRootDir) {
|
||||
SortedSet<String> names = new TreeSet<String>();
|
||||
searchForTestClasses(names, "", sourceRootDir);
|
||||
return new ArrayList<String>(names);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively search the directory for files in the form "*Test.java".
|
||||
* Ignore any files or directories whose names start with a "."
|
||||
*/
|
||||
private void searchForTestClasses(SortedSet<String> names, String prefix,
|
||||
File directory) {
|
||||
for (File file : directory.listFiles()) {
|
||||
String filename = file.getName();
|
||||
if (filename.startsWith(".")) {
|
||||
// ignore .svn, etc.
|
||||
} else if (file.isDirectory()) {
|
||||
searchForTestClasses(names, prefix + filename + ".", file);
|
||||
} else if (filename.endsWith("Test.java")) {
|
||||
String classname = filename.substring(0, filename.length() - 5);
|
||||
names.add(prefix + classname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate a class for each test class name.
|
||||
*/
|
||||
private List<Class<?>> getTestClasses(List<String> classNames) {
|
||||
List<Class<?>> classes = new ArrayList<Class<?>>();
|
||||
for (String classname : classNames) {
|
||||
try {
|
||||
classes.add(Class.forName(classname));
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new IllegalArgumentException("Can't load test class: "
|
||||
+ classname, e);
|
||||
}
|
||||
}
|
||||
return classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* We've located all of the test clases. Now run them.
|
||||
*/
|
||||
private void run() {
|
||||
JUnitCore junitCore = new JUnitCore();
|
||||
junitCore.addListener(this.listener);
|
||||
junitCore.run(this.classes.toArray(new Class<?>[0]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Did any of the tests fail?
|
||||
*/
|
||||
private boolean didEverythingPass() {
|
||||
return this.listener.didEverythingPass();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* You must provide a path to the source directory of the test classes.
|
||||
* </p>
|
||||
* <p>
|
||||
* You may also provide a reporting level of "BRIEF", "MORE", or "FULL". If
|
||||
* no level is provided, or if it is not recognized, "BRIEF" is used.
|
||||
* </p>
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
if ((args.length < 1) || (args.length > 2)) {
|
||||
usage("Wrong number of arguments: expecting 1 or 2, but found "
|
||||
+ args.length + ".");
|
||||
}
|
||||
File sourceRootDir = new File(args[0]);
|
||||
|
||||
if (!sourceRootDir.exists()) {
|
||||
usage(sourceRootDir + " does not exist.");
|
||||
}
|
||||
if (!sourceRootDir.isDirectory()) {
|
||||
usage(sourceRootDir + " is not a directory.");
|
||||
}
|
||||
|
||||
ReportLevel reportLevel = ReportLevel.MORE;
|
||||
if (args.length == 2) {
|
||||
for (ReportLevel level : ReportLevel.values()) {
|
||||
if (level.toString().equalsIgnoreCase(args[1])) {
|
||||
reportLevel = level;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VitroTestRunner runner = new VitroTestRunner(sourceRootDir, reportLevel);
|
||||
runner.run();
|
||||
|
||||
if (!runner.didEverythingPass()) {
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell them how it should have been done.
|
||||
*/
|
||||
private static void usage(String message) {
|
||||
System.out.println(message);
|
||||
System.out.println("usage: " + VitroTestRunner.class.getSimpleName()
|
||||
+ " sourceRootDirectory [ BRIEF | MORE | FULL ]");
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,228 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.auth.policy;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler;
|
||||
|
||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddDataPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddObjectPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.DropDataPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||
|
||||
/**
|
||||
* Simple test of JenaNetidPolicyTest that uses the ExamplePolicy.xml
|
||||
* It expects that the model will have the resource
|
||||
* <http://vivo.library.cornell.edu/abox#entity11821> will have
|
||||
* the datatype property vitro:netid of "bdc34".
|
||||
*
|
||||
* @author bdc34
|
||||
*
|
||||
*/
|
||||
|
||||
public class JenaNetidPolicyTest extends AbstractTestClass {
|
||||
static transient JenaNetidPolicy jniPolicy;
|
||||
static transient JenaNetidPolicy unAuthPolicy;
|
||||
static transient Model model;
|
||||
static IdentifierBundle idb;
|
||||
|
||||
static String onts[] ={
|
||||
"/testontologies/smallVivo-20070809.owl",
|
||||
"/testontologies/vitro1.owl",
|
||||
"/testontologies/vivo-users.owl"
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Loading files with this.getClass().getResourceAsStream()
|
||||
* Notice that / is the path seperator and strings that lack
|
||||
* a leading slash are relative to the package of the this.getClass().
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void setUpForClass() throws Exception {
|
||||
// Suppress warnings from creating default model.
|
||||
setLoggerLevel(RDFDefaultErrorHandler.class, Level.OFF);
|
||||
model = ModelFactory.createDefaultModel();
|
||||
|
||||
for( String ont : onts){
|
||||
InputStream in = JenaNetidPolicyTest.class.getResourceAsStream(ont);
|
||||
model.read(in,null);
|
||||
in.close();
|
||||
}
|
||||
OntModel ontModel = ModelFactory.createOntologyModel(ONT_MODEL_SPEC,model);
|
||||
ontModel.prepare();
|
||||
|
||||
InputStream in = JenaNetidPolicyTest.class.getResourceAsStream("resources/examplePolicy.xml");
|
||||
jniPolicy = new JenaNetidPolicy(model,in);
|
||||
in.close();
|
||||
|
||||
in = JenaNetidPolicyTest.class.getResourceAsStream("resources/examplePolicy.xml");
|
||||
unAuthPolicy = new JenaNetidPolicy(model,in, Authorization.UNAUTHORIZED);
|
||||
in.close();
|
||||
|
||||
idb = new ArrayIdentifierBundle();
|
||||
idb.add(new SelfEditingIdentifierFactory.NetId("bdc34"));
|
||||
}
|
||||
|
||||
@Test public void testOfSetupFromXml(){
|
||||
assertNotNull(model);
|
||||
JenaNetidPolicy j = jniPolicy;
|
||||
assertNotNull(j);
|
||||
assertNotNull(j.model);
|
||||
assertNotNull(j.prefixes);
|
||||
assertNotNull( j.actionToQueryStr );
|
||||
assertNotNull(j.name);
|
||||
assertEquals(j.name, "Example Policy");
|
||||
assertTrue(j.prefixes.length() > 0);
|
||||
assertTrue( j.actionToQueryStr.size() > 0);
|
||||
}
|
||||
|
||||
@Test public void testAddDataProps(){
|
||||
RequestedAction act; PolicyDecision pd;
|
||||
|
||||
act = new AddDataPropStmt(
|
||||
"http://some.non.existing.resource",
|
||||
"http://some.non.existing.dataproperty",
|
||||
"bogus value", null, null);
|
||||
pd = jniPolicy.isAuthorized(idb, act);
|
||||
assertNotNull(pd);
|
||||
assertTrue( "authorization was " + pd.getAuthorized() +
|
||||
'\n' + pd.getDebuggingInfo(),
|
||||
pd.getAuthorized() == Authorization.INCONCLUSIVE);
|
||||
|
||||
pd = unAuthPolicy.isAuthorized(idb, act);
|
||||
assertNotNull(pd);
|
||||
assertTrue( "authorization was " + pd.getAuthorized() +
|
||||
'\n' + pd.getDebuggingInfo(),
|
||||
pd.getAuthorized() == Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
@Test public void testAddDataProps2(){
|
||||
RequestedAction act; PolicyDecision pd;
|
||||
|
||||
act = new AddDataPropStmt(
|
||||
"http://vivo.library.cornell.edu/abox#entity11821",
|
||||
"vitro:description",
|
||||
"a description of some kind.", null, null);
|
||||
pd = jniPolicy.isAuthorized(idb, act);
|
||||
assertNotNull(pd);
|
||||
assertTrue("authorization was " + pd.getAuthorized() +
|
||||
'\n' + pd.getDebuggingInfo(),
|
||||
pd.getAuthorized() == Authorization.AUTHORIZED);
|
||||
|
||||
pd = unAuthPolicy.isAuthorized(idb, act);
|
||||
assertNotNull(pd);
|
||||
assertTrue( "authorization was " + pd.getAuthorized() +
|
||||
'\n' + pd.getDebuggingInfo(),
|
||||
pd.getAuthorized() == Authorization.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
@Test public void testDropDataProps1(){
|
||||
RequestedAction act; PolicyDecision pd;
|
||||
|
||||
DataPropertyStatementImpl dp = new DataPropertyStatementImpl();
|
||||
dp.setIndividualURI("http://vivo.library.cornell.edu/abox#entity11821");
|
||||
dp.setData("a description of some kind.");
|
||||
dp.setDatapropURI("vitro:description");
|
||||
act = new DropDataPropStmt( dp );
|
||||
|
||||
pd = jniPolicy.isAuthorized(idb, act);
|
||||
assertNotNull(pd);
|
||||
assertTrue("authorization was " + pd.getAuthorized() +
|
||||
'\n' + pd.getDebuggingInfo(),
|
||||
pd.getAuthorized() == Authorization.AUTHORIZED);
|
||||
|
||||
pd = unAuthPolicy.isAuthorized(idb, act);
|
||||
assertNotNull(pd);
|
||||
assertTrue( "authorization was " + pd.getAuthorized() +
|
||||
'\n' + pd.getDebuggingInfo(),
|
||||
pd.getAuthorized() == Authorization.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
@Test public void testDropDataProps2(){
|
||||
RequestedAction act; PolicyDecision pd;
|
||||
|
||||
DataPropertyStatementImpl dp = new DataPropertyStatementImpl();
|
||||
dp.setIndividualURI("http://mannlib.cornell.edu/non.existing.resource");
|
||||
dp.setData("a description of some kind.");
|
||||
dp.setDatapropURI("vitro:description");
|
||||
act = new DropDataPropStmt( dp );
|
||||
|
||||
pd = jniPolicy.isAuthorized(idb, act);
|
||||
assertNotNull(pd);
|
||||
assertTrue("authorization was " + pd.getAuthorized() +
|
||||
'\n' + pd.getDebuggingInfo(),
|
||||
pd.getAuthorized() == Authorization.INCONCLUSIVE);
|
||||
|
||||
pd = unAuthPolicy.isAuthorized(idb, act);
|
||||
assertNotNull(pd);
|
||||
assertTrue( "authorization was " + pd.getAuthorized() +
|
||||
'\n' + pd.getDebuggingInfo(),
|
||||
pd.getAuthorized() == Authorization.INCONCLUSIVE);
|
||||
|
||||
}
|
||||
|
||||
@Test public void testObjectProps(){
|
||||
RequestedAction act = new AddObjectPropStmt(
|
||||
"http://vivo.library.cornell.edu/abox#entity11821",
|
||||
"vitro:headOf",
|
||||
"http://vivo.library.cornell.edu/abox#entity1");
|
||||
PolicyDecision pd = jniPolicy.isAuthorized(idb, act);
|
||||
assertNotNull(pd);
|
||||
assertTrue("authorization was " + pd.getAuthorized(),
|
||||
pd.getAuthorized() == Authorization.AUTHORIZED);
|
||||
|
||||
pd = unAuthPolicy.isAuthorized(idb, act);
|
||||
assertNotNull(pd);
|
||||
assertTrue( "authorization was " + pd.getAuthorized() +
|
||||
'\n' + pd.getDebuggingInfo(),
|
||||
pd.getAuthorized() == Authorization.UNAUTHORIZED);
|
||||
|
||||
act = new AddObjectPropStmt(
|
||||
"http://vivo.library.cornell.edu/abox#entity123",
|
||||
"vitro:headOf",
|
||||
"http://vivo.library.cornell.edu/abox#entity1");
|
||||
pd = jniPolicy.isAuthorized(idb, act);
|
||||
assertNotNull(pd);
|
||||
assertTrue("authorization was " + pd.getAuthorized(),
|
||||
pd.getAuthorized() == Authorization.INCONCLUSIVE);
|
||||
|
||||
pd = unAuthPolicy.isAuthorized(idb, act);
|
||||
assertNotNull(pd);
|
||||
assertTrue( "authorization was " + pd.getAuthorized() +
|
||||
'\n' + pd.getDebuggingInfo(),
|
||||
pd.getAuthorized() == Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
// static String ONTOLOGY_ADDR = "http://caruso.mannlib.cornell.edu/xml/rdf/smallVivo-20070809.owl";
|
||||
// static String VITRO_ADDR = "http://ivy.mannlib.cornell.edu/ontologies/vitro/vitro1.owl";
|
||||
// static String USERS_ADDR = "http://ivy.mannlib.cornell.edu/ontologies/vivo/vivo-users.owl";
|
||||
//String ONTOLOGY_ADDR = "http://lowe.mannlib.cornell.edu/ontologies/fao/geopolitical_Ontology_v_0_2.owl";
|
||||
//String ONTOLOGY_ADDR = "http://lowe.mannlib.cornell.edu/ontologies/fao/languagecode.owl";
|
||||
//String ONTOLOGY_ADDR = "http://localhost/~bjl23/ontologies/VitroFacultyReporting.0.2.owl";
|
||||
|
||||
static OntModelSpec ONT_MODEL_SPEC = OntModelSpec.OWL_DL_MEM; // no additional entailment reasoning
|
||||
//OntModelSpec ONT_MODEL_SPEC = OntModelSpec.OWL_MEM_MICRO_RULE_INF; // some additional OWL entailment reasoning
|
||||
//OntModelSpec ONT_MODEL_SPEC = OntModelSpec.RDFS_MEM_RDFS_INF;
|
||||
|
||||
}
|
|
@ -0,0 +1,423 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.auth.policy;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddDataPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddObjectPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.DropObjectPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.EditDataPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.EditObjPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.AddNewUser;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.LoadOntology;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.RebuildTextIndex;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.RemoveUser;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.ServerStatus;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.admin.UpdateTextIndex;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ontology.CreateOwlClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ontology.DefineDataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ontology.DefineObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ontology.RemoveOwlClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
|
||||
public class SelfEditingPolicyTest extends AbstractTestClass {
|
||||
|
||||
String SAFE_NS = "http://test.mannlib.cornell.edu/ns/01#";
|
||||
String UNSAFE_NS = VitroVocabulary.vitroURI;
|
||||
|
||||
String SELFEDITOR_URI =SAFE_NS + "individual244";
|
||||
String SAFE_RESOURCE = SAFE_NS + "otherIndividual77777";
|
||||
String UNSAFE_RESOURCE = UNSAFE_NS + "otherIndividual99999";
|
||||
|
||||
String SAFE_PREDICATE= SAFE_NS + "hasHairStyle";
|
||||
String UNSAFE_PREDICATE = UNSAFE_NS + "hasSuperPowers";
|
||||
|
||||
SelfEditingPolicy policy ;
|
||||
IdentifierBundle ids;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
policy = new SelfEditingPolicy(null,null,null,null);
|
||||
|
||||
|
||||
ids = new ArrayIdentifierBundle();
|
||||
//ids.add( new NetIdIdentifierFactory.NetId("test223") );
|
||||
|
||||
IndividualImpl ind = new IndividualImpl();
|
||||
ind.setURI( SELFEDITOR_URI );
|
||||
ids.add( new SelfEditingIdentifierFactory.SelfEditing( ind, SelfEditingIdentifierFactory.NOT_BLACKLISTED ) );
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCanModifiyNs(){
|
||||
Assert.assertTrue( policy.canModifyResource("http://bobs.com#hats") );
|
||||
Assert.assertTrue( policy.canModifyResource("ftp://bobs.com#hats"));
|
||||
Assert.assertTrue( policy.canModifyResource( SAFE_RESOURCE ));
|
||||
Assert.assertTrue( policy.canModifyPredicate( SAFE_PREDICATE ));
|
||||
Assert.assertTrue( policy.canModifyResource("http://bobs.com/hats"));
|
||||
|
||||
|
||||
Assert.assertTrue( ! policy.canModifyResource(""));
|
||||
Assert.assertTrue( ! policy.canModifyResource(VitroVocabulary.vitroURI + "something"));
|
||||
Assert.assertTrue( ! policy.canModifyResource(VitroVocabulary.OWL + "Ontology"));
|
||||
Assert.assertTrue( ! policy.canModifyPredicate( UNSAFE_PREDICATE ));
|
||||
Assert.assertTrue( ! policy.canModifyResource( UNSAFE_RESOURCE ));
|
||||
Assert.assertTrue( ! policy.canModifyResource( UNSAFE_NS ));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProhibitedProperties(){
|
||||
Set<String> badProps = new HashSet<String>();
|
||||
badProps.add("http://mannlib.cornell.edu/bad#prp234");
|
||||
badProps.add("http://mannlib.cornell.edu/bad#prp999");
|
||||
badProps.add("http://mannlib.cornell.edu/bad#prp333");
|
||||
badProps.add("http://mannlib.cornell.edu/bad#prp777");
|
||||
badProps.add("http://mannlib.cornell.edu/bad#prp0020");
|
||||
SelfEditingPolicy badPropPolicy = new SelfEditingPolicy(badProps,null,null,null);
|
||||
|
||||
RequestedAction whatToAuth = new AddObjectPropStmt(
|
||||
SELFEDITOR_URI,"http://mannlib.cornell.edu/bad#prp234" ,SAFE_RESOURCE);
|
||||
PolicyDecision dec = badPropPolicy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
|
||||
whatToAuth = new AddObjectPropStmt(
|
||||
SAFE_RESOURCE ,"http://mannlib.cornell.edu/bad#prp234", SELFEDITOR_URI);
|
||||
dec = badPropPolicy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
|
||||
whatToAuth = new AddObjectPropStmt(
|
||||
SELFEDITOR_URI,"http://mannlib.cornell.edu/bad#prp999" ,SAFE_RESOURCE);
|
||||
dec = badPropPolicy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
|
||||
whatToAuth = new AddObjectPropStmt(
|
||||
SAFE_RESOURCE ,"http://mannlib.cornell.edu/bad#prp999", SELFEDITOR_URI);
|
||||
dec = badPropPolicy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
|
||||
whatToAuth = new AddObjectPropStmt(
|
||||
SAFE_RESOURCE ,SAFE_PREDICATE, SELFEDITOR_URI);
|
||||
dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, dec.getAuthorized());
|
||||
|
||||
whatToAuth = new AddObjectPropStmt(
|
||||
SELFEDITOR_URI,SAFE_PREDICATE,SAFE_RESOURCE);
|
||||
dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, dec.getAuthorized());
|
||||
|
||||
whatToAuth = new AddObjectPropStmt(
|
||||
SELFEDITOR_URI, UNSAFE_PREDICATE, SAFE_RESOURCE);
|
||||
dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
|
||||
//now with dataprop statements
|
||||
whatToAuth = new AddDataPropStmt(
|
||||
SELFEDITOR_URI,"http://mannlib.cornell.edu/bad#prp234" ,SAFE_RESOURCE, null, null);
|
||||
dec = badPropPolicy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
|
||||
whatToAuth = new AddDataPropStmt(
|
||||
SAFE_RESOURCE ,"http://mannlib.cornell.edu/bad#prp234", SELFEDITOR_URI, null, null);
|
||||
dec = badPropPolicy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
|
||||
whatToAuth = new AddDataPropStmt(
|
||||
SELFEDITOR_URI,"http://mannlib.cornell.edu/bad#prp999" ,SAFE_RESOURCE, null, null);
|
||||
dec = badPropPolicy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
|
||||
whatToAuth = new AddDataPropStmt(
|
||||
SAFE_RESOURCE ,"http://mannlib.cornell.edu/bad#prp999", SELFEDITOR_URI, null, null);
|
||||
dec = badPropPolicy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
|
||||
whatToAuth = new AddDataPropStmt(
|
||||
SAFE_RESOURCE ,SAFE_PREDICATE, SELFEDITOR_URI, null, null);
|
||||
dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
|
||||
whatToAuth = new AddDataPropStmt(
|
||||
SELFEDITOR_URI,SAFE_PREDICATE,SAFE_RESOURCE, null, null);
|
||||
dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, dec.getAuthorized());
|
||||
|
||||
whatToAuth = new AddDataPropStmt(
|
||||
SELFEDITOR_URI, UNSAFE_PREDICATE, SAFE_RESOURCE, null, null);
|
||||
dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVisitIdentifierBundleAddObjectPropStmt() {
|
||||
AddObjectPropStmt whatToAuth = new AddObjectPropStmt(
|
||||
SELFEDITOR_URI,SAFE_PREDICATE,SAFE_RESOURCE);
|
||||
PolicyDecision dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, dec.getAuthorized());
|
||||
|
||||
whatToAuth = new AddObjectPropStmt(
|
||||
SAFE_RESOURCE ,SAFE_PREDICATE, SELFEDITOR_URI);
|
||||
dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, dec.getAuthorized());
|
||||
|
||||
//this is the case where the editor is not part of the stmt
|
||||
whatToAuth = new AddObjectPropStmt(
|
||||
SAFE_RESOURCE, SAFE_PREDICATE, SAFE_RESOURCE);
|
||||
dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
|
||||
whatToAuth = new AddObjectPropStmt(
|
||||
SELFEDITOR_URI, UNSAFE_PREDICATE, SAFE_RESOURCE);
|
||||
dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
|
||||
whatToAuth = new AddObjectPropStmt(
|
||||
SELFEDITOR_URI, SAFE_PREDICATE, UNSAFE_RESOURCE);
|
||||
dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
}
|
||||
//
|
||||
// @Test
|
||||
// public void testVisitIdentifierBundleDropResource() {
|
||||
// fail("Not yet implemented");
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testVisitIdentifierBundleDropDataPropStmt() {
|
||||
// fail("Not yet implemented");
|
||||
// }
|
||||
//
|
||||
@Test
|
||||
public void testVisitIdentifierBundleDropObjectPropStmt() {
|
||||
DropObjectPropStmt whatToAuth = new DropObjectPropStmt(
|
||||
SELFEDITOR_URI,SAFE_PREDICATE,SAFE_RESOURCE);
|
||||
PolicyDecision dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, dec.getAuthorized());
|
||||
|
||||
whatToAuth = new DropObjectPropStmt(
|
||||
SAFE_RESOURCE ,SAFE_PREDICATE, SELFEDITOR_URI);
|
||||
dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, dec.getAuthorized());
|
||||
|
||||
// this is the case where the editor is not part of the stmt
|
||||
whatToAuth = new DropObjectPropStmt(
|
||||
SAFE_RESOURCE, SAFE_PREDICATE, SAFE_RESOURCE);
|
||||
dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
|
||||
whatToAuth = new DropObjectPropStmt(
|
||||
SELFEDITOR_URI, UNSAFE_PREDICATE, SAFE_RESOURCE);
|
||||
dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
|
||||
whatToAuth = new DropObjectPropStmt(
|
||||
SELFEDITOR_URI, SAFE_PREDICATE, UNSAFE_RESOURCE);
|
||||
dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
}
|
||||
//
|
||||
// @Test
|
||||
// public void testVisitIdentifierBundleAddResource() {
|
||||
// fail("Not yet implemented");
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testVisitIdentifierBundleAddDataPropStmt() {
|
||||
// fail("Not yet implemented");
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testVisitIdentifierBundleUploadFile() {
|
||||
// fail("Not yet implemented");
|
||||
// }
|
||||
//
|
||||
//
|
||||
@Test
|
||||
public void testVisitIdentifierBundleEditDataPropStmt() {
|
||||
|
||||
DataPropertyStatement dps = new DataPropertyStatementImpl();
|
||||
dps.setIndividualURI(SELFEDITOR_URI);
|
||||
dps.setDatapropURI(SAFE_PREDICATE);
|
||||
dps.setData("junk");
|
||||
EditDataPropStmt whatToAuth = new EditDataPropStmt(dps);
|
||||
PolicyDecision dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, dec.getAuthorized());
|
||||
|
||||
dps = new DataPropertyStatementImpl();
|
||||
dps.setIndividualURI(SELFEDITOR_URI);
|
||||
dps.setDatapropURI(UNSAFE_PREDICATE);
|
||||
dps.setData("junk");
|
||||
whatToAuth = new EditDataPropStmt(dps);
|
||||
dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
|
||||
dps = new DataPropertyStatementImpl();
|
||||
dps.setIndividualURI(UNSAFE_RESOURCE);
|
||||
dps.setDatapropURI(SAFE_PREDICATE);
|
||||
whatToAuth = new EditDataPropStmt(dps);
|
||||
dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
|
||||
dps = new DataPropertyStatementImpl();
|
||||
dps.setIndividualURI(SAFE_RESOURCE);
|
||||
dps.setDatapropURI(SAFE_PREDICATE);
|
||||
whatToAuth = new EditDataPropStmt(dps);
|
||||
dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
}
|
||||
//
|
||||
@Test
|
||||
public void testVisitIdentifierBundleEditObjPropStmt() {
|
||||
EditObjPropStmt whatToAuth = new EditObjPropStmt(
|
||||
SELFEDITOR_URI,SAFE_PREDICATE,SAFE_RESOURCE);
|
||||
PolicyDecision dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, dec.getAuthorized());
|
||||
|
||||
whatToAuth = new EditObjPropStmt(
|
||||
SAFE_RESOURCE ,SAFE_PREDICATE, SELFEDITOR_URI);
|
||||
dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.AUTHORIZED, dec.getAuthorized());
|
||||
|
||||
//this is the case where the editor is not part of the stmt
|
||||
whatToAuth = new EditObjPropStmt(
|
||||
SAFE_RESOURCE, SAFE_PREDICATE, SAFE_RESOURCE);
|
||||
dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
|
||||
whatToAuth = new EditObjPropStmt(
|
||||
SELFEDITOR_URI, UNSAFE_PREDICATE, SAFE_RESOURCE);
|
||||
dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
|
||||
whatToAuth = new EditObjPropStmt(
|
||||
SELFEDITOR_URI, SAFE_PREDICATE, UNSAFE_RESOURCE);
|
||||
dec = policy.isAuthorized(ids, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testVisitIdentifierBundleServerStatus() {
|
||||
PolicyDecision dec = policy.isAuthorized(ids, new ServerStatus() );
|
||||
Assert.assertTrue(dec.getAuthorized() == Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVisitIdentifierBundleCreateOwlClass() {
|
||||
CreateOwlClass a = new CreateOwlClass();
|
||||
a.setSubjectUri("http://someClass/test");
|
||||
PolicyDecision dec = policy.visit(ids, a );
|
||||
Assert.assertTrue(dec.getAuthorized() == Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVisitIdentifierBundleRemoveOwlClass() {
|
||||
RemoveOwlClass a = new RemoveOwlClass();
|
||||
a.setSubjectUri("http://someClass/test");
|
||||
PolicyDecision dec = policy.visit(ids, a );
|
||||
Assert.assertTrue(dec.getAuthorized() == Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVisitIdentifierBundleDefineDataProperty() {
|
||||
DefineDataProperty a = new DefineDataProperty();
|
||||
a.setSubjectUri("http://someClass/test");
|
||||
PolicyDecision dec = policy.visit(ids, a );
|
||||
Assert.assertTrue(dec.getAuthorized() == Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVisitIdentifierBundleDefineObjectProperty() {
|
||||
DefineObjectProperty a = new DefineObjectProperty();
|
||||
a.setSubjectUri("http://someClass/test");
|
||||
PolicyDecision dec = policy.visit(ids, a );
|
||||
Assert.assertTrue(dec.getAuthorized() == Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVisitIdentifierBundleAddNewUser() {
|
||||
AddNewUser a = new AddNewUser();
|
||||
PolicyDecision dec = policy.visit(ids, a );
|
||||
Assert.assertTrue(dec.getAuthorized() == Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVisitIdentifierBundleRemoveUser() {
|
||||
RemoveUser a = new RemoveUser();
|
||||
PolicyDecision dec = policy.visit(ids, a );
|
||||
Assert.assertTrue(dec.getAuthorized() == Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVisitIdentifierBundleLoadOntology() {
|
||||
LoadOntology a = new LoadOntology();
|
||||
PolicyDecision dec = policy.visit(ids, a );
|
||||
Assert.assertTrue(dec.getAuthorized() == Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVisitIdentifierBundleRebuildTextIndex() {
|
||||
RebuildTextIndex a = new RebuildTextIndex();
|
||||
PolicyDecision dec = policy.visit(ids, a );
|
||||
Assert.assertTrue(dec.getAuthorized() == Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVisitIdentifierBundleUpdateTextIndex() {
|
||||
UpdateTextIndex a = new UpdateTextIndex();
|
||||
PolicyDecision dec = policy.visit(ids, a );
|
||||
Assert.assertTrue(dec.getAuthorized() == Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
<edu.cornell.mannlib.vitro.webapp.auth.policy.JenaNetidPolicy>
|
||||
<name>Example Policy</name>
|
||||
<prefixes>PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
|
||||
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
|
||||
PREFIX vivoa: <http://vivo.library.cornell.edu/abox#>
|
||||
PREFIX vivo: <http://vivo.library.cornell.edu/ns/0.1#>
|
||||
PREFIX vitro: <http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#>
|
||||
</prefixes>
|
||||
|
||||
<actionToQueryStr>
|
||||
<entry>
|
||||
<string>edu.cornell.mannlib.vitro.webapp.auth.requestedAction.DropObjectPropStmt</string>
|
||||
<list>
|
||||
<string>ASK WHERE { ?subject vitro:netid ?netid }</string>
|
||||
<string>ASK WHERE { ?object vitro:netid ?netid }</string>
|
||||
</list>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddObjectPropStmt</string>
|
||||
<list>
|
||||
<string>ASK WHERE { ?subject vitro:netid ?netid }</string>
|
||||
<string>ASK WHERE { ?object vitro:netid ?netid }</string>
|
||||
</list>
|
||||
</entry>
|
||||
|
||||
<entry>
|
||||
<string>edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddDataPropStmt</string>
|
||||
<list>
|
||||
<string>ASK WHERE { ?subject vitro:netid ?netid }</string>
|
||||
</list>
|
||||
</entry>
|
||||
<entry>
|
||||
<string>edu.cornell.mannlib.vitro.webapp.auth.requestedAction.DropDataPropStmt</string>
|
||||
<list>
|
||||
<string>ASK WHERE { ?subject vitro:netid ?netid }</string>
|
||||
</list>
|
||||
</entry>
|
||||
|
||||
</actionToQueryStr>
|
||||
</edu.cornell.mannlib.vitro.webapp.auth.policy.JenaNetidPolicy>
|
|
@ -0,0 +1,312 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.auth.policy.setup;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler;
|
||||
|
||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.ArrayIdentifierBundle;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.Identifier;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.IdentifierBundle;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.identifier.SelfEditingIdentifierFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.SelfEditingPolicy;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.Authorization;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.ifaces.PolicyDecision;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.AddObjectPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.EditDataPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.EditObjPropStmt;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestedAction;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
|
||||
public class SelfEditingPolicySetupTest extends AbstractTestClass {
|
||||
private static final Logger LOG = Logger
|
||||
.getLogger(SelfEditingPolicySetupTest.class);
|
||||
|
||||
/** We may edit objects in this arbitrary namespace. */
|
||||
private static final String SAFE_NS = "http://test.mannlib.cornell.edu/ns/01#";
|
||||
|
||||
/** We are not allowed to edit objects in the administrative namespace. */
|
||||
private static final String ADMIN_NS = VitroVocabulary.vitroURI;
|
||||
|
||||
/** The URI of a SelfEditor. */
|
||||
private static final String SELFEDITOR_URI = SAFE_NS + "individual000";
|
||||
|
||||
/** Some things that are safe to edit. */
|
||||
private static final String SAFE_RESOURCE = SAFE_NS + "individual123";
|
||||
private static final String SAFE_PREDICATE = SAFE_NS + "hasHairStyle";
|
||||
|
||||
/** Some things that are not safe to edit. */
|
||||
private static final String ADMIN_RESOURCE = ADMIN_NS + "individual666";
|
||||
private static final String ADMIN_PREDICATE_1 = ADMIN_NS + "hasSuperPowers";
|
||||
private static final String ADMIN_PREDICATE_2 = ADMIN_NS + "mayPrintMoney";
|
||||
private static final String ADMIN_PREDICATE_3 = ADMIN_NS
|
||||
+ "getsOutOfJailFree";
|
||||
private static final String ADMIN_PREDICATE_4 = ADMIN_NS + "canDeleteModel";
|
||||
|
||||
/** The policy we are testing. */
|
||||
SelfEditingPolicy policy;
|
||||
|
||||
/** A SelfEditing individual identifier. */
|
||||
Individual seIndividual;
|
||||
|
||||
/** A bundle that contains a SelfEditing individual. */
|
||||
IdentifierBundle ids;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
InputStream is = getClass().getResourceAsStream(
|
||||
"./SelfEditingPolicySetupTest.xml");
|
||||
Assert.assertNotNull(is);
|
||||
|
||||
// suppress the warning messages from loading the model.
|
||||
setLoggerLevel(RDFDefaultErrorHandler.class, Level.OFF);
|
||||
|
||||
OntModel model = ModelFactory.createOntologyModel();
|
||||
model.read(is, "");
|
||||
Assert.assertNotNull(model);
|
||||
Assert.assertTrue(model.size() > 0);
|
||||
|
||||
policy = SelfEditingPolicySetup.makeSelfEditPolicyFromModel(model);
|
||||
Assert.assertNotNull(policy);
|
||||
|
||||
seIndividual = new IndividualImpl();
|
||||
seIndividual.setURI(SELFEDITOR_URI);
|
||||
|
||||
ids = new ArrayIdentifierBundle();
|
||||
ids.add(new SelfEditingIdentifierFactory.SelfEditing(seIndividual,
|
||||
SelfEditingIdentifierFactory.NOT_BLACKLISTED));
|
||||
|
||||
// setLoggerLevel(SelfEditingPolicySetupTest.class, Level.DEBUG);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// General tests
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void nullRequestedAction() {
|
||||
PolicyDecision dec = policy.isAuthorized(ids, null);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullIdentifierBundle() {
|
||||
AddObjectPropStmt whatToAuth = new AddObjectPropStmt(SELFEDITOR_URI,
|
||||
SAFE_PREDICATE, SAFE_RESOURCE);
|
||||
PolicyDecision dec = policy.isAuthorized(null, whatToAuth);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(Authorization.INCONCLUSIVE, dec.getAuthorized());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noSelfEditorIdentifier() {
|
||||
ids.clear();
|
||||
ids.add(new Identifier() {
|
||||
});
|
||||
assertAddObjectPropStmt(SELFEDITOR_URI, SAFE_PREDICATE, SAFE_RESOURCE,
|
||||
Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void blacklistedSelfEditor() {
|
||||
ids.clear();
|
||||
ids.add(new SelfEditingIdentifierFactory.SelfEditing(seIndividual,
|
||||
"Don't like this guy."));
|
||||
assertAddObjectPropStmt(SELFEDITOR_URI, SAFE_PREDICATE, SAFE_RESOURCE,
|
||||
Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Tests against AddObjectPropStmt
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void addObjectPropStmtSuccess1() {
|
||||
assertAddObjectPropStmt(SELFEDITOR_URI, SAFE_PREDICATE, SAFE_RESOURCE,
|
||||
Authorization.AUTHORIZED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addObjectPropStmtSuccess2() {
|
||||
assertAddObjectPropStmt(SAFE_RESOURCE, SAFE_PREDICATE, SELFEDITOR_URI,
|
||||
Authorization.AUTHORIZED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addObjectPropStmtUnsafePredicate1() {
|
||||
assertAddObjectPropStmt(SELFEDITOR_URI, ADMIN_PREDICATE_1,
|
||||
SAFE_RESOURCE, Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addObjectPropStmtUnsafePredicate2() {
|
||||
assertAddObjectPropStmt(SAFE_RESOURCE, ADMIN_PREDICATE_1,
|
||||
SELFEDITOR_URI, Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addObjectPropStmtUnsafePredicate3() {
|
||||
assertAddObjectPropStmt(SELFEDITOR_URI, ADMIN_PREDICATE_2,
|
||||
SAFE_RESOURCE, Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addObjectPropStmtUnsafePredicate4() {
|
||||
assertAddObjectPropStmt(SELFEDITOR_URI, ADMIN_PREDICATE_3,
|
||||
SAFE_RESOURCE, Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addObjectPropStmtUnsafePredicate5() {
|
||||
assertAddObjectPropStmt(SELFEDITOR_URI, ADMIN_PREDICATE_4,
|
||||
SAFE_RESOURCE, Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Tests against EditObjPropStmt
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void editObjectPropStmtSuccess1() {
|
||||
assertEditObjPropStmt(SELFEDITOR_URI, SAFE_PREDICATE, SAFE_RESOURCE,
|
||||
Authorization.AUTHORIZED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void editObjectPropStmtSuccess2() {
|
||||
assertEditObjPropStmt(SAFE_RESOURCE, SAFE_PREDICATE, SELFEDITOR_URI,
|
||||
Authorization.AUTHORIZED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void editObjectPropStmtEditorNotInvolved() {
|
||||
// this is the case where the editor is not part of the stmt
|
||||
assertEditObjPropStmt(SAFE_RESOURCE, SAFE_PREDICATE, SAFE_RESOURCE,
|
||||
Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void editObjectPropStmtUnsafeResource() {
|
||||
assertEditObjPropStmt(SELFEDITOR_URI, SAFE_PREDICATE, ADMIN_RESOURCE,
|
||||
Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void editObjectPropStmtUnsafePredicate1() {
|
||||
assertEditObjPropStmt(SELFEDITOR_URI, ADMIN_PREDICATE_4, SAFE_RESOURCE,
|
||||
Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void editObjectPropStmtUnsafePredicate2() {
|
||||
assertEditObjPropStmt(SAFE_RESOURCE, ADMIN_PREDICATE_4, SELFEDITOR_URI,
|
||||
Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void editObjectPropStmtUnsafeBoth() {
|
||||
assertEditObjPropStmt(SELFEDITOR_URI, ADMIN_PREDICATE_4,
|
||||
ADMIN_RESOURCE, Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Tests against EditDataPropStmt
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void editDataPropSuccess() {
|
||||
assertEditDataPropStmt(SELFEDITOR_URI, SAFE_PREDICATE, "junk",
|
||||
Authorization.AUTHORIZED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void editDataPropUnsafePredicate() {
|
||||
assertEditDataPropStmt(SELFEDITOR_URI, ADMIN_PREDICATE_1, "junk",
|
||||
Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void editDataPropUnsafeResource() {
|
||||
assertEditDataPropStmt(ADMIN_RESOURCE, SAFE_PREDICATE, null,
|
||||
Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void editDataPropNoCloseRelation() {
|
||||
assertEditDataPropStmt(SAFE_RESOURCE, SAFE_PREDICATE, null,
|
||||
Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void editDataPropModelProhibited() {
|
||||
// model prohibited
|
||||
assertEditDataPropStmt(SAFE_RESOURCE, ADMIN_PREDICATE_1, null,
|
||||
Authorization.INCONCLUSIVE);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Support methods
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create an {@link AddObjectPropStmt}, test it, and compare to expected
|
||||
* results.
|
||||
*/
|
||||
private void assertAddObjectPropStmt(String uriOfSub, String uriOfPred,
|
||||
String uriOfObj, Authorization expectedAuthorization) {
|
||||
AddObjectPropStmt whatToAuth = new AddObjectPropStmt(uriOfSub,
|
||||
uriOfPred, uriOfObj);
|
||||
PolicyDecision dec = policy.isAuthorized(ids, whatToAuth);
|
||||
LOG.debug(dec);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(expectedAuthorization, dec.getAuthorized());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an {@link EditObjPropStmt}, test it, and compare to expected
|
||||
* results.
|
||||
*/
|
||||
private void assertEditObjPropStmt(String uriOfSub, String uriOfPred,
|
||||
String uriOfObj, Authorization expectedAuthorization) {
|
||||
EditObjPropStmt whatToAuth = new EditObjPropStmt(uriOfSub, uriOfPred,
|
||||
uriOfObj);
|
||||
PolicyDecision dec = policy.isAuthorized(ids, whatToAuth);
|
||||
LOG.debug(dec);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(expectedAuthorization, dec.getAuthorized());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an {@link EditDataPropStmt}, test it, and compare to expected
|
||||
* results.
|
||||
*/
|
||||
private void assertEditDataPropStmt(String individualURI,
|
||||
String datapropURI, String data, Authorization expectedAuthorization) {
|
||||
DataPropertyStatement dps = new DataPropertyStatementImpl();
|
||||
dps.setIndividualURI(individualURI);
|
||||
dps.setDatapropURI(datapropURI);
|
||||
dps.setData(data);
|
||||
|
||||
EditDataPropStmt whatToAuth = new EditDataPropStmt(dps);
|
||||
PolicyDecision dec = policy.isAuthorized(ids, whatToAuth);
|
||||
LOG.debug(dec);
|
||||
Assert.assertNotNull(dec);
|
||||
Assert.assertEquals(expectedAuthorization, dec.getAuthorized());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?xml version='1.0' encoding='ISO-8859-1'?>
|
||||
<rdf:RDF
|
||||
xmlns:owl ="http://www.w3.org/2002/07/owl#"
|
||||
xmlns:rdf ="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:rdfs ="http://www.w3.org/2000/01/rdf-schema#"
|
||||
xmlns:xsd ="http://www.w3.org/2001/XMLSchema#"
|
||||
xmlns:vitro="http://vitro.mannlib.cornell.edu/ns/vitro/0.7#"
|
||||
xmlns =""
|
||||
>
|
||||
|
||||
<owl:Ontology rdf:about="">
|
||||
<rdfs:comment>
|
||||
An ontology with a property with a prohibited annotation for unit testing.
|
||||
</rdfs:comment>
|
||||
</owl:Ontology>
|
||||
|
||||
<owl:AnnotationProperty rdf:about="vitro:selfEditProhibitedAnnot"/>
|
||||
|
||||
<owl:ObjectProperty rdf:about="vitro:hasSuperPowers">
|
||||
<vitro:selfEditProhibitedAnnot rdf:datatype="xsd:boolean">true</vitro:selfEditProhibitedAnnot>
|
||||
</owl:ObjectProperty>
|
||||
|
||||
<owl:ObjectProperty rdf:about="vitro:mayPrintMoney">
|
||||
<vitro:selfEditProhibitedAnnot rdf:datatype="xsd:boolean">true</vitro:selfEditProhibitedAnnot>
|
||||
</owl:ObjectProperty>
|
||||
|
||||
<owl:ObjectProperty rdf:about="vitro:getsOutOfJailFree">
|
||||
<vitro:selfEditProhibitedAnnot rdf:datatype="xsd:boolean">true</vitro:selfEditProhibitedAnnot>
|
||||
</owl:ObjectProperty>
|
||||
|
||||
<owl:ObjectProperty rdf:about="vitro:canDeleteModel">
|
||||
<vitro:selfEditProhibitedAnnot rdf:datatype="xsd:boolean">true</vitro:selfEditProhibitedAnnot>
|
||||
</owl:ObjectProperty>
|
||||
|
||||
|
||||
<owl:DatatypeProperty rdf:about="vitro:felonies">
|
||||
<vitro:selfEditProhibitedAnnot rdf:datatype="xsd:boolean">true</vitro:selfEditProhibitedAnnot>
|
||||
</owl:DatatypeProperty>
|
||||
|
||||
|
||||
</rdf:RDF>
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.dao.filtering;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.sf.jga.fn.UnaryFunctor;
|
||||
import net.sf.jga.fn.comparison.ComparisonFunctors;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class BaseFilteringTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilterMethods(){
|
||||
List numbers = Arrays.asList( 1,2,3,4,5,6,7,8,9,10 );
|
||||
UnaryFunctor<Integer,Boolean> greaterThan3 =
|
||||
ComparisonFunctors.greater(3);
|
||||
|
||||
BaseFiltering b = new BaseFiltering();
|
||||
List filteredNum = b.filter(numbers,greaterThan3);
|
||||
Assert.assertNotNull(filteredNum);
|
||||
Assert.assertTrue("expected 7 found "+filteredNum.size() , filteredNum.size() == 7);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.dao.filtering;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* User: bdc34
|
||||
* Date: Oct 24, 2007
|
||||
* Time: 10:51:01 AM
|
||||
*/
|
||||
public class TabFitleringTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilteringBug1(){
|
||||
/*
|
||||
This test a bug where the vclass listing from the index
|
||||
had a different count than the listing in the auto linked
|
||||
tab.
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.dao.filtering.filters;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import net.sf.jga.fn.UnaryFunctor;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.Assert;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Tab;
|
||||
|
||||
|
||||
public class FiltersTest {
|
||||
|
||||
Boolean ACCEPTED = Boolean.TRUE;
|
||||
Boolean REJECTED = Boolean.FALSE;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTimeFiltersForFutureEvents(){
|
||||
Tab tab = new Tab();
|
||||
tab.setDayLimit( 10 );
|
||||
UnaryFunctor<Individual,Boolean> filter =
|
||||
FiltersForTabs.getTimeFilter(tab, new DateTime());
|
||||
|
||||
Individual ind = new IndividualImpl();
|
||||
DateTime timekey;
|
||||
|
||||
// Allow a slight fudge factor for the time it takes the tests to run.
|
||||
DateTime now = new DateTime().plusSeconds(1);
|
||||
|
||||
for(int i=1; i < 100 ; i++){
|
||||
timekey = now.minusDays(i);
|
||||
ind.setTimekey( timekey.toDate() );
|
||||
Assert.assertTrue("minus " + i + " days should Reject",
|
||||
filter.fn( ind ) == REJECTED);
|
||||
}
|
||||
|
||||
for(int i=0; i< 10 ; i++){
|
||||
timekey = now.plusDays(i);
|
||||
ind.setTimekey( timekey.toDate() );
|
||||
Assert.assertTrue("plus " + i + " days should Accept",
|
||||
filter.fn( ind ) == ACCEPTED);
|
||||
}
|
||||
|
||||
timekey = now.plusDays( 10 );
|
||||
ind.setTimekey( timekey.toDate() );
|
||||
Assert.assertTrue("plus 10 days should Reject",
|
||||
filter.fn( ind ) == REJECTED);
|
||||
|
||||
for(int i=10; i < 1000 ; i++){
|
||||
timekey = now.plusDays(i);
|
||||
ind.setTimekey( timekey.toDate() );
|
||||
Assert.assertTrue("plus " + i + " days should Reject",
|
||||
filter.fn( ind ) == REJECTED);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTimeFiltersForPastReleases(){
|
||||
Tab tab = new Tab();
|
||||
tab.setDayLimit( -10 );
|
||||
UnaryFunctor<Individual,Boolean> filter =
|
||||
FiltersForTabs.getTimeFilter(tab, new DateTime());
|
||||
|
||||
Individual ind = new IndividualImpl();
|
||||
DateTime sunrise;
|
||||
|
||||
// Allow a slight fudge factor for the time it takes the tests to run.
|
||||
DateTime now = new DateTime().plusSeconds(1);
|
||||
|
||||
for(int i=1; i < 1000 ; i++){
|
||||
sunrise = now.plusDays(i);
|
||||
ind.setSunrise( sunrise.toDate() );
|
||||
Assert.assertTrue("plus " + i + " days should Reject",
|
||||
filter.fn( ind ) == REJECTED);
|
||||
}
|
||||
|
||||
ind.setSunrise( now.minusMinutes(20).toDate() );
|
||||
Assert.assertTrue("minus 20 minutes should Accept",
|
||||
filter.fn( ind ) == ACCEPTED);
|
||||
|
||||
for(int i=1; i <= 10 ; i++){
|
||||
sunrise = now.minusDays(i);
|
||||
ind.setSunrise( sunrise.toDate() );
|
||||
Assert.assertTrue("minus " + i + " days should Accept",
|
||||
filter.fn( ind ) == ACCEPTED);
|
||||
}
|
||||
|
||||
for(int i=11; i < 100 ; i++){
|
||||
sunrise = now.minusDays(i);
|
||||
ind.setSunrise( sunrise.toDate() );
|
||||
Assert.assertTrue("minus " + i + " days should Reject",
|
||||
filter.fn( ind ) == REJECTED);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarkowitzCase(){
|
||||
DateTime now = new DateTime().withTime(0, 0, 0, 0);
|
||||
Date sunrise = now.minusDays(1).toDate();
|
||||
Date timeKey = now.plusDays(2).toDate();
|
||||
|
||||
Tab tab = new Tab();
|
||||
tab.setDayLimit( -10 );
|
||||
UnaryFunctor<Individual,Boolean> filter =
|
||||
FiltersForTabs.getTimeFilter(tab, new DateTime());
|
||||
|
||||
Individual ind = new IndividualImpl();
|
||||
ind.setSunrise( sunrise );
|
||||
ind.setTimekey( timeKey );
|
||||
|
||||
Assert.assertTrue("Should accept with day limit -10",
|
||||
filter.fn( ind ) == ACCEPTED);
|
||||
|
||||
tab.setDayLimit( 10 );
|
||||
filter = FiltersForTabs.getTimeFilter(tab, new DateTime());
|
||||
|
||||
Assert.assertTrue("Should accept with day limit +10",
|
||||
filter.fn( ind ) == ACCEPTED );
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.dao.filtering.filters;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.PropertyInstance;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean.RoleLevel;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
||||
|
||||
public class HiddenFromEditRoleFilterTest {
|
||||
|
||||
|
||||
OntModel testModel;
|
||||
WebappDaoFactory wdf;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Model model = ModelFactory.createDefaultModel();
|
||||
InputStream in = HiddenFromDisplayBelowRoleLevelFilter.class.getResourceAsStream("./filtertesting.rdf");
|
||||
model.read(in,null);
|
||||
testModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM,model);
|
||||
wdf = new WebappDaoFactoryJena(testModel,"http://example.org/test/1.0/",null,null);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCuratorLevelRoleFilter(){
|
||||
HiddenFromDisplayBelowRoleLevelFilter filter = new HiddenFromDisplayBelowRoleLevelFilter(RoleLevel.CURATOR, wdf);
|
||||
Assert.assertNotNull(filter);
|
||||
|
||||
Individual ind = new IndividualImpl();
|
||||
|
||||
List<VClass> vcs = new ArrayList<VClass>();
|
||||
VClass vc = new VClass() ;
|
||||
vc.setHiddenFromDisplayBelowRoleLevel(RoleLevel.PUBLIC);
|
||||
vcs.add( vc );
|
||||
ind.setVClasses(vcs, true);
|
||||
vc = new VClass() ;
|
||||
vc.setHiddenFromDisplayBelowRoleLevel(RoleLevel.PUBLIC);
|
||||
vcs.add( vc );
|
||||
ind.setVClasses(vcs, true);
|
||||
|
||||
Assert.assertTrue( filter.individualFilter.fn(ind) );
|
||||
|
||||
ind.setHiddenFromDisplayBelowRoleLevel(RoleLevel.PUBLIC);
|
||||
Assert.assertTrue( filter.individualFilter.fn(ind) );
|
||||
|
||||
ind.setHiddenFromDisplayBelowRoleLevel(RoleLevel.DB_ADMIN);
|
||||
Assert.assertFalse( filter.individualFilter.fn(ind) );
|
||||
|
||||
|
||||
//classes can force an individual to be hidden
|
||||
ind.setHiddenFromDisplayBelowRoleLevel(RoleLevel.PUBLIC);
|
||||
vc.setHiddenFromDisplayBelowRoleLevel(RoleLevel.DB_ADMIN);
|
||||
// Assert.assertFalse( filter.individualFilter.fn(ind) );
|
||||
|
||||
Assert.assertFalse( filter.classFilter.fn( vc ) );
|
||||
vc.setHiddenFromDisplayBelowRoleLevel(RoleLevel.CURATOR);
|
||||
Assert.assertTrue( filter.classFilter.fn( vc ) );
|
||||
|
||||
DataProperty dp = new DataProperty();
|
||||
Assert.assertTrue( filter.dataPropertyFilter.fn(dp) );
|
||||
dp.setHiddenFromDisplayBelowRoleLevel(RoleLevel.PUBLIC);
|
||||
Assert.assertTrue( filter.dataPropertyFilter.fn(dp) );
|
||||
dp.setHiddenFromDisplayBelowRoleLevel(RoleLevel.DB_ADMIN);
|
||||
Assert.assertFalse( filter.dataPropertyFilter.fn(dp) );
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,255 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.dao.filtering.filters;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.sf.jga.algorithms.Summarize;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.BaseFiltering;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils;
|
||||
|
||||
public class VitroFiltersFactoryTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSunsetWindowFilterOnListOfEnts() {
|
||||
DateTime easyDate = new org.joda.time.DateTime(2005,1,1,0,0,0,0); //2005-01-01
|
||||
Date givenDate = easyDate.toDate();
|
||||
|
||||
VitroFilters vf = VitroFilterUtils.getSunsetWindowFilter(givenDate);
|
||||
Assert.assertNotNull(vf);
|
||||
checkFilterForNull(vf);
|
||||
|
||||
List<Individual> ents = new LinkedList();
|
||||
for( int i = 0; i< 10; i++){
|
||||
Individual ent = new IndividualImpl();
|
||||
ent.setSunrise( null );
|
||||
ent.setSunset( null );
|
||||
ents.add(ent);
|
||||
}
|
||||
|
||||
BaseFiltering bf = new BaseFiltering();
|
||||
List filtered = bf.filter(ents,vf.getIndividualFilter());
|
||||
Assert.assertNotNull(filtered);
|
||||
Assert.assertTrue("expcted to filter no entities, filtered out " + (10-filtered.size()),
|
||||
filtered.size() == 10);
|
||||
|
||||
Individual ent = new IndividualImpl();
|
||||
ent.setSunrise( easyDate.minusDays(3).toDate() );
|
||||
ent.setSunset( easyDate.plusDays(3).toDate() );
|
||||
ents.add(ent);
|
||||
|
||||
filtered = bf.filter(ents,vf.getIndividualFilter());
|
||||
Assert.assertNotNull(filtered);
|
||||
Assert.assertTrue("expcted to filter no entities, filtered out " + (11-filtered.size()),
|
||||
filtered.size() == 11);
|
||||
|
||||
ent = new IndividualImpl();
|
||||
ent.setSunrise( easyDate.minusDays(100).toDate() );
|
||||
ent.setSunset( easyDate.minusDays(110).toDate() );
|
||||
ents.add(ent);
|
||||
|
||||
filtered = bf.filter(ents,vf.getIndividualFilter());
|
||||
Assert.assertNotNull(filtered);
|
||||
Assert.assertTrue("expcted to filter one entity, filtered out " + (12-filtered.size()),
|
||||
filtered.size() == 11);
|
||||
|
||||
long count = Summarize.count(ents,vf.getIndividualFilter());
|
||||
Assert.assertTrue("expected 12, got " + ents.size(), ents.size() == 12);
|
||||
Assert.assertTrue("expected count of 11, got " + count , count == 11);
|
||||
|
||||
long a = 20000;
|
||||
int b = (int)a;
|
||||
Assert.assertTrue( b == 20000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSunsetWindowFilter() {
|
||||
DateTime easyDate = new org.joda.time.DateTime(2005,1,1,0,0,0,0); //2005-01-01
|
||||
Date givenDate = easyDate.toDate();
|
||||
|
||||
VitroFilters vf = VitroFilterUtils.getSunsetWindowFilter(givenDate);
|
||||
Assert.assertNotNull(vf);
|
||||
checkFilterForNull(vf);
|
||||
|
||||
Individual ent = new IndividualImpl();
|
||||
ent.setSunrise( easyDate.minusDays(3).toDate() );
|
||||
ent.setSunset( easyDate.plusDays(3).toDate() );
|
||||
Assert.assertTrue(vf.getIndividualFilter().fn( ent ) );
|
||||
|
||||
ent.setSunrise( easyDate.toDate() );
|
||||
Assert.assertTrue("items should be not filtered on first sunrise day", vf.getIndividualFilter().fn(ent));
|
||||
|
||||
ent.setSunrise( easyDate.minusDays(3).toDate() );
|
||||
ent.setSunset( easyDate.minusDays( 2 ).toDate() );
|
||||
Assert.assertFalse("should be sunset and filtered out", vf.getIndividualFilter().fn( ent ));
|
||||
|
||||
ent.setSunrise( easyDate.plusDays(3).toDate() );
|
||||
ent.setSunset( easyDate.plusDays( 10 ).toDate() );
|
||||
Assert.assertFalse("should not yet be sunrised and filtered out", vf.getIndividualFilter().fn( ent ));
|
||||
|
||||
ent.setSunrise( null );
|
||||
ent.setSunset( null );
|
||||
Assert.assertTrue("nulls should not throw exceptions and and not be filtered out", vf.getIndividualFilter().fn( ent ));
|
||||
|
||||
//should work with webapp too
|
||||
Individual entwa = new IndividualImpl();
|
||||
entwa.setSunrise( easyDate.minusDays(3).toDate() );
|
||||
entwa.setSunset( easyDate.plusDays(3).toDate() );
|
||||
Assert.assertTrue(vf.getIndividualFilter().fn( entwa ) );
|
||||
|
||||
entwa.setSunrise( easyDate.toDate() );
|
||||
Assert.assertTrue("items should be not filtered on first sunrise day", vf.getIndividualFilter().fn(entwa));
|
||||
|
||||
entwa.setSunrise( easyDate.minusDays(3).toDate() );
|
||||
entwa.setSunset( easyDate.minusDays( 2 ).toDate() );
|
||||
Assert.assertFalse("should be sunset and filtered out", vf.getIndividualFilter().fn( entwa ));
|
||||
|
||||
entwa.setSunrise( easyDate.plusDays(3).toDate() );
|
||||
entwa.setSunset( easyDate.plusDays( 10 ).toDate() );
|
||||
Assert.assertFalse("should not yet be sunrised and filtered out", vf.getIndividualFilter().fn( entwa ));
|
||||
|
||||
entwa.setSunrise( null );
|
||||
entwa.setSunset( null );
|
||||
Assert.assertTrue("null should not throw exceptions and should not be filtered out", vf.getIndividualFilter().fn( entwa ));
|
||||
|
||||
//ObjectPropertyStatements
|
||||
ObjectPropertyStatement ops = new ObjectPropertyStatementImpl();
|
||||
ops.setObject(entwa);
|
||||
|
||||
entwa.setSunrise( easyDate.minusDays(3).toDate() );
|
||||
entwa.setSunset( easyDate.plusDays(3).toDate() );
|
||||
Assert.assertTrue(vf.getIndividualFilter().fn( entwa ) );
|
||||
|
||||
entwa.setSunrise( easyDate.toDate() );
|
||||
Assert.assertTrue("items should be not filtered on first sunrise day", vf.getObjectPropertyStatementFilter().fn(ops));
|
||||
|
||||
entwa.setSunrise( easyDate.minusDays(3).toDate() );
|
||||
entwa.setSunset( easyDate.minusDays( 2 ).toDate() );
|
||||
Assert.assertFalse("should be sunset and filtered out", vf.getObjectPropertyStatementFilter().fn(ops));
|
||||
|
||||
entwa.setSunrise( easyDate.plusDays(3).toDate() );
|
||||
entwa.setSunset( easyDate.plusDays( 10 ).toDate() );
|
||||
Assert.assertFalse("should not yet be sunrised and filtered out", vf.getObjectPropertyStatementFilter().fn(ops));
|
||||
|
||||
entwa.setSunrise( null );
|
||||
entwa.setSunset( null );
|
||||
Assert.assertTrue("null should not throw exceptions and should not be filtered out", vf.getObjectPropertyStatementFilter().fn(ops));
|
||||
|
||||
ops.setSunrise( null );
|
||||
ops.setSunset( null );
|
||||
Assert.assertTrue("null should not throw exceptions and should not be filtered out", vf.getObjectPropertyStatementFilter().fn( ops ) );
|
||||
|
||||
//DataPropertyStatements
|
||||
DataPropertyStatement dps = new DataPropertyStatementImpl();
|
||||
dps.setSunrise( easyDate.minusDays(3).toDate() );
|
||||
dps.setSunset( easyDate.plusDays( 3).toDate() );
|
||||
Assert.assertTrue( vf.getDataPropertyStatementFilter().fn( dps ) );
|
||||
|
||||
dps.setSunrise( easyDate.toDate() );
|
||||
dps.setSunset( easyDate.plusDays( 3).toDate() );
|
||||
Assert.assertTrue( vf.getDataPropertyStatementFilter().fn( dps ) );
|
||||
|
||||
dps.setSunrise( null );
|
||||
dps.setSunset( null );
|
||||
Assert.assertTrue("should be not throw exceptions and should not be filtered out", vf.getDataPropertyStatementFilter().fn( dps ) );
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTestFilter() {
|
||||
VitroFilters vf = VitroFilterUtils.getTestFilter();
|
||||
checkFilterForNull(vf);
|
||||
ArrayList<Individual> ents = new ArrayList<Individual>();
|
||||
|
||||
String[] names = {"Greg", "gary", "bob", "Sue", "jim" };
|
||||
for( String name : names){
|
||||
Individual ent = new IndividualImpl();
|
||||
ent.setName(name);
|
||||
ents.add(ent);
|
||||
}
|
||||
|
||||
BaseFiltering bf = new BaseFiltering();
|
||||
List<Individual> filteredEnts = bf.filter(ents,vf.getIndividualFilter());
|
||||
Assert.assertNotNull(filteredEnts);
|
||||
Assert.assertEquals("did not filter correctly", 2, filteredEnts.size());
|
||||
}
|
||||
|
||||
private int portalId2Numeric(long i) {
|
||||
return (int)FlagMathUtils.portalId2Numeric( i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCalsFilter(){
|
||||
VitroFilters vf = VitroFilterUtils.getCalsPortalFilter();
|
||||
IndividualImpl ind = new IndividualImpl();
|
||||
|
||||
ind.setFlag1Numeric(0);
|
||||
Assert.assertTrue(vf.getIndividualFilter().fn(ind) == REJECT);
|
||||
|
||||
ind.setFlag1Numeric( portalId2Numeric(1) );
|
||||
Assert.assertTrue(vf.getIndividualFilter().fn(ind) == REJECT);
|
||||
|
||||
ind.setFlag1Numeric( portalId2Numeric(2));
|
||||
Assert.assertTrue(vf.getIndividualFilter().fn(ind) == ACCEPT);
|
||||
|
||||
ind.setFlag1Numeric( portalId2Numeric(3));
|
||||
Assert.assertTrue(vf.getIndividualFilter().fn(ind) == ACCEPT);
|
||||
ind.setFlag1Numeric( portalId2Numeric(4));
|
||||
Assert.assertTrue(vf.getIndividualFilter().fn(ind) == ACCEPT);
|
||||
ind.setFlag1Numeric( portalId2Numeric(5));
|
||||
Assert.assertTrue(vf.getIndividualFilter().fn(ind) == ACCEPT);
|
||||
ind.setFlag1Numeric( portalId2Numeric(6));
|
||||
Assert.assertTrue(vf.getIndividualFilter().fn(ind) == REJECT);
|
||||
ind.setFlag1Numeric( portalId2Numeric(7));
|
||||
Assert.assertTrue(vf.getIndividualFilter().fn(ind) == REJECT);
|
||||
|
||||
ind.setFlag1Numeric( portalId2Numeric(2) + portalId2Numeric(1));
|
||||
Assert.assertTrue(vf.getIndividualFilter().fn(ind) == ACCEPT);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void checkFilterForNull(VitroFilters vf){
|
||||
Assert.assertNotNull("filter was null", vf);
|
||||
Assert.assertNotNull("getClassFilter was null", vf.getClassFilter());
|
||||
Assert.assertNotNull("getDataPropertyFilter was null", vf.getDataPropertyFilter());
|
||||
Assert.assertNotNull("getDataPropertyStatementFilter was null", vf.getDataPropertyStatementFilter());
|
||||
Assert.assertNotNull("getObjectPropertyFilter was null", vf.getObjectPropertyFilter());
|
||||
Assert.assertNotNull("getObjectPropertyStatementFilter was null", vf.getObjectPropertyStatementFilter());
|
||||
Assert.assertNotNull("getIndividualFilter was null", vf.getIndividualFilter());
|
||||
Assert.assertNotNull("getTabFilter was null", vf.getTabFilter());
|
||||
Assert.assertNotNull("getUserFilter was null", vf.getUserFilter());
|
||||
Assert.assertNotNull("getVClassGroupFilter was null", vf.getVClassGroupFilter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoleLevelFilter(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
private boolean ACCEPT= true;
|
||||
private boolean REJECT= false;
|
||||
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.dao.filtering.filters;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.flags.PortalFlag;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils;
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WebappDaoFilteringPortalTest {
|
||||
String[][] entsDef = {
|
||||
// entity name flag 1 numeric
|
||||
{"0", "only in portal 1", Long.toString( portalId2Numeric(1) )},
|
||||
{"1", "In portal 1 and 2", Long.toString( portalId2Numeric(1) + portalId2Numeric(2) )},
|
||||
{"2", "in portal 3", Long.toString( portalId2Numeric(3) )},
|
||||
{"3", "checked into no portal", "0"},
|
||||
{"4", "checked into portal 4", Long.toString( portalId2Numeric(4) )},
|
||||
{"5", "checked into 1 and 4", Long.toString( portalId2Numeric(1) + portalId2Numeric(4) )},
|
||||
{"6", "checked into 4", Long.toString( portalId2Numeric(4) )},
|
||||
{"7", "checked into 5", Long.toString( portalId2Numeric(5) )},
|
||||
|
||||
};
|
||||
|
||||
List <Individual> ents = new ArrayList (10);
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
//we need something that makes classes
|
||||
for(String entA[] : entsDef){
|
||||
Individual ent = new IndividualImpl();
|
||||
ent.setName("Item " + entA[0] + ": " + entA[1]);
|
||||
ent.setFlag1Numeric( Integer.parseInt(entA[2]) );
|
||||
ents.add(ent);
|
||||
}
|
||||
}
|
||||
|
||||
private long portalId2Numeric(long i) {
|
||||
return FlagMathUtils.portalId2Numeric( i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPortal(){
|
||||
//Is it in portal 2 (aka numeric portal 4, in vivo 'life sci' ) ?
|
||||
PortalFlag f = new PortalFlag( 2 );
|
||||
VitroFilters vf = VitroFilterUtils.getFilterFromPortalFlag(f);
|
||||
Assert.assertNotNull( vf );
|
||||
Assert.assertFalse( vf.getIndividualFilter().fn( ents.get(0) ) );
|
||||
Assert.assertTrue( vf.getIndividualFilter().fn( ents.get(1) ) );
|
||||
Assert.assertFalse( vf.getIndividualFilter().fn( ents.get(2) ) );
|
||||
Assert.assertFalse( vf.getIndividualFilter().fn( ents.get(3) ) );
|
||||
Assert.assertFalse( vf.getIndividualFilter().fn( ents.get(4) ) );
|
||||
Assert.assertFalse( vf.getIndividualFilter().fn( ents.get(5) ) );
|
||||
|
||||
//Is it in portal 1 (aka numeric portal 2, in vivo 'vivo portal' ) ?
|
||||
f = new PortalFlag(1);
|
||||
vf = VitroFilterUtils.getFilterFromPortalFlag(f);
|
||||
Assert.assertNotNull( vf );
|
||||
Assert.assertTrue( vf.getIndividualFilter().fn( ents.get(0) ) );
|
||||
Assert.assertTrue( vf.getIndividualFilter().fn( ents.get(1) ) );
|
||||
Assert.assertFalse( vf.getIndividualFilter().fn( ents.get(2) ) );
|
||||
Assert.assertFalse( vf.getIndividualFilter().fn( ents.get(3) ) );
|
||||
Assert.assertFalse( vf.getIndividualFilter().fn( ents.get(4) ) );
|
||||
Assert.assertTrue( vf.getIndividualFilter().fn( ents.get(5) ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllPorta(){
|
||||
VitroFilters vf = VitroFilterUtils.getCalsPortalFilter();
|
||||
Assert.assertNotNull( vf );
|
||||
Assert.assertFalse( vf.getIndividualFilter().fn( ents.get(0) ) );
|
||||
Assert.assertTrue( vf.getIndividualFilter().fn( ents.get(1) ) );
|
||||
Assert.assertTrue( vf.getIndividualFilter().fn( ents.get(2) ) );
|
||||
Assert.assertFalse( vf.getIndividualFilter().fn( ents.get(3) ) );
|
||||
Assert.assertTrue( vf.getIndividualFilter().fn( ents.get(4) ) );
|
||||
Assert.assertTrue( vf.getIndividualFilter().fn( ents.get(5) ) );
|
||||
Assert.assertTrue( vf.getIndividualFilter().fn( ents.get(6) ) );
|
||||
Assert.assertTrue( vf.getIndividualFilter().fn( ents.get(7) ) );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<rdf:RDF xmlns:owl="http://www.w3.org/2002/07/owl/"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema/"
|
||||
xmlns:vitro="http://vitro.mannlib.cornell.edu/ns/vitro/0.7/"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema/"
|
||||
xmlns="http://example.org/test/1.0/">
|
||||
|
||||
<owl:ObjectProperty rdf:about="http://example.org/test/1.0/hiddenProp">
|
||||
<rdfs:label>a hidden object property for testing</rdfs:label>
|
||||
<vitro:hiddenFromPublicDisplayAnnot rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</vitro:hiddenFromPublicDisplayAnnot>
|
||||
</owl:ObjectProperty>
|
||||
|
||||
<owl:ObjectProperty rdf:about="http://example.org/test/1.0/nonhiddenProp">
|
||||
<rdfs:label>a publicly visible object property for testing</rdfs:label>
|
||||
<vitro:hiddenFromPublicDisplayAnnot rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">false</vitro:hiddenFromPublicDisplayAnnot>
|
||||
</owl:ObjectProperty>
|
||||
|
||||
<owl:Class rdf:about="http://example.org/test/1.0/testType">
|
||||
</owl:Class>
|
||||
|
||||
<testType rdf:about="http://example.org/test/1.0/visibleBob">
|
||||
<vitro:hiddenFromPublicDisplayAnnot rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">false</vitro:hiddenFromPublicDisplayAnnot>
|
||||
</testType>
|
||||
|
||||
<rdf:Description rdf:about="http://example.org/test/1.0/hiddenBob">
|
||||
<ns0:type xmlns:ns0="http://www.w3.org/1999/02/22-rdf-syntax-ns/" rdf:resource="http://example.org/test/1.0/testType"/>
|
||||
<vitro:hiddenFromPublicDisplayAnnot rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</vitro:hiddenFromPublicDisplayAnnot>
|
||||
</rdf:Description>
|
||||
|
||||
<rdf:Description rdf:about="http://example.org/test/1.0/visibleKate">
|
||||
<ns0:type xmlns:ns0="http://www.w3.org/1999/02/22-rdf-syntax-ns/" rdf:resource="http://example.org/test/1.0/testType"/>
|
||||
<vitro:hiddenFromPublicDisplayAnnot rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">false</vitro:hiddenFromPublicDisplayAnnot>
|
||||
<hiddenProp rdf:resource="http://example.org/test/1.0/visibleBob"/>
|
||||
<hiddenProp rdf:resource="http://example.org/test/1.0/hiddenBob"/>
|
||||
<visibleProp rdf:resource="http://example.org/test/1.0/visibleBob"/>
|
||||
<visibleProp rdf:resource="http://example.org/test/1.0/hiddenBob"/>
|
||||
</rdf:Description>
|
||||
|
||||
<rdf:Description rdf:about="http://example.org/test/1.0/hiddenKate">
|
||||
<ns0:type xmlns:ns0="http://www.w3.org/1999/02/22-rdf-syntax-ns/" rdf:resource="http://example.org/test/1.0/testType"/>
|
||||
<vitro:hiddenFromPublicDisplayAnnot rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</vitro:hiddenFromPublicDisplayAnnot>
|
||||
<hiddenProp rdf:resource="http://example.org/test/1.0/visibleBob"/>
|
||||
<hiddenProp rdf:resource="http://example.org/test/1.0/hiddenBob"/>
|
||||
<visibleProp rdf:resource="http://example.org/test/1.0/visibleBob"/>
|
||||
<visibleProp rdf:resource="http://example.org/test/1.0/hiddenBob"/>
|
||||
</rdf:Description>
|
||||
</rdf:RDF>
|
|
@ -0,0 +1,780 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||
import com.hp.hpl.jena.rdf.model.Statement;
|
||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
|
||||
public class DependentResourceDeleteJenaTest {
|
||||
String depRes = "<" + VitroVocabulary.DEPENDENT_RESOURCE + ">";
|
||||
|
||||
void printModels(Model expected, Model result){
|
||||
System.out.println("Expected:");
|
||||
expected.write(System.out);
|
||||
System.out.println("Result:");
|
||||
result.write(System.out);
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testStmtNormalDelete() {
|
||||
String n3 =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:hasNose ex:nose1 . " ;
|
||||
|
||||
Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3");
|
||||
|
||||
List<Statement> deletes = DependentResourceDeleteJena.getDependentResourceDeleteList(
|
||||
model.createStatement(
|
||||
model.createResource("http://example.com/bob"),
|
||||
model.createProperty("http://example.com/hasNose"),
|
||||
model.createResource("http://example.com/nose1")),
|
||||
model);
|
||||
|
||||
Model resultModel = ModelFactory.createDefaultModel();
|
||||
resultModel.add(deletes);
|
||||
|
||||
//all statements should be deleted
|
||||
Assert.assertTrue(resultModel.isIsomorphicWith( model ));
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testStmtSimpleForceDelete() {
|
||||
String n3 =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:hasNose ex:nose1 . \n" +
|
||||
" ex:nose1 rdf:type " + depRes + " . \n" +
|
||||
" ex:nose1 ex:hasHair ex:hair23. \n" +
|
||||
" ex:hair23 rdf:type " + depRes + " . \n" +
|
||||
" ex:hair23 ex:hasHairCount \"23\". " ;
|
||||
|
||||
Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3");
|
||||
|
||||
List<Statement> deletes = DependentResourceDeleteJena.getDependentResourceDeleteList(
|
||||
model.createStatement(
|
||||
model.createResource("http://example.com/bob"),
|
||||
model.createProperty("http://example.com/hasNose"),
|
||||
model.createResource("http://example.com/nose1")),
|
||||
model);
|
||||
|
||||
Model resultModel = ModelFactory.createDefaultModel();
|
||||
resultModel.add(deletes);
|
||||
|
||||
//all statements should be deleted
|
||||
boolean same = resultModel.isIsomorphicWith( model );
|
||||
Assert.assertTrue( same);
|
||||
}
|
||||
|
||||
|
||||
@org.junit.Test
|
||||
public void testStmtNonForceDelete() {
|
||||
String n3 =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:hasNose ex:nose1 . \n" +
|
||||
" ex:nose1 ex:hasHair ex:hair23. \n" +
|
||||
" ex:hair23 rdf:type " + depRes + " . \n" +
|
||||
" ex:hair23 ex:hasHairCount \"23\". " ;
|
||||
|
||||
String expected =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:nose1 ex:hasHair ex:hair23. \n" +
|
||||
" ex:hair23 rdf:type " + depRes + " . \n" +
|
||||
" ex:hair23 ex:hasHairCount \"23\". " ;
|
||||
|
||||
Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3");
|
||||
|
||||
List<Statement> deletes = DependentResourceDeleteJena.getDependentResourceDeleteList(
|
||||
model.createStatement(
|
||||
model.createResource("http://example.com/bob"),
|
||||
model.createProperty("http://example.com/hasNose"),
|
||||
model.createResource("http://example.com/nose1")),
|
||||
model);
|
||||
|
||||
model.remove(deletes);
|
||||
|
||||
Model expectedModel = (ModelFactory.createDefaultModel()).read(new StringReader(expected), "", "N3");
|
||||
boolean same = expectedModel.isIsomorphicWith( model );
|
||||
if( ! same ) printModels( expectedModel, model);
|
||||
Assert.assertTrue( same );
|
||||
}
|
||||
|
||||
|
||||
@org.junit.Test
|
||||
public void testStmtForceDeleteWithLiterals() {
|
||||
String n3 =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" +
|
||||
" ex:bob ex:hasNose ex:nose1 . \n" +
|
||||
" ex:nose1 rdf:type " + depRes + " . \n" +
|
||||
" ex:nose1 ex:a \"this is a literal\". \n" +
|
||||
" ex:nose1 ex:b \"2343\" . \n" +
|
||||
" ex:nose1 ex:hasHair ex:hair23. \n" +
|
||||
" ex:hair23 rdf:type " + depRes + " . \n" +
|
||||
" ex:hair23 ex:hasHairCount \"23\". " ;
|
||||
|
||||
String expected =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" ;
|
||||
|
||||
Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3");
|
||||
|
||||
List<Statement> deletes = DependentResourceDeleteJena.getDependentResourceDeleteList(
|
||||
model.createStatement(
|
||||
model.createResource("http://example.com/bob"),
|
||||
model.createProperty("http://example.com/hasNose"),
|
||||
model.createResource("http://example.com/nose1")),
|
||||
model);
|
||||
|
||||
model.remove(deletes);
|
||||
|
||||
Model expectedModel = (ModelFactory.createDefaultModel()).read(new StringReader(expected), "", "N3");
|
||||
boolean same = expectedModel.isIsomorphicWith( model );
|
||||
if( ! same ) printModels( expectedModel, model);
|
||||
Assert.assertTrue( same );
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testStmtForceDeleteWithCycles() {
|
||||
String n3 =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" +
|
||||
" ex:bob ex:hasNose ex:nose1 . \n" +
|
||||
" ex:nose1 rdf:type " + depRes + " . \n" +
|
||||
" ex:nose1 ex:a \"this is a literal\". \n" +
|
||||
" ex:nose1 ex:b \"2343\" . \n" +
|
||||
" ex:nose1 ex:c ex:bob . \n" +
|
||||
" ex:nose1 ex:hasHair ex:hair23. \n" +
|
||||
" ex:hair23 rdf:type " + depRes + " . \n" +
|
||||
" ex:hair23 ex:c ex:bob . \n" +
|
||||
" ex:hair23 ex:hasHairCount \"23\". " ;
|
||||
|
||||
String expected =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" ;
|
||||
|
||||
Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3");
|
||||
|
||||
List<Statement> deletes = DependentResourceDeleteJena.getDependentResourceDeleteList(
|
||||
model.createStatement(
|
||||
model.createResource("http://example.com/bob"),
|
||||
model.createProperty("http://example.com/hasNose"),
|
||||
model.createResource("http://example.com/nose1")),
|
||||
model);
|
||||
|
||||
model.remove(deletes);
|
||||
|
||||
Model expectedModel = (ModelFactory.createDefaultModel()).read(new StringReader(expected), "", "N3");
|
||||
boolean same = expectedModel.isIsomorphicWith( model );
|
||||
if( ! same ) printModels( expectedModel, model);
|
||||
Assert.assertTrue( same );
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testStmtForceDeleteWithCycles2() {
|
||||
String n3 =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" +
|
||||
" ex:bob ex:hasNose ex:nose1 . \n" +
|
||||
" ex:nose1 rdf:type " + depRes + " . \n" +
|
||||
" ex:nose1 ex:a \"this is a literal\". \n" +
|
||||
" ex:nose1 ex:b \"2343\" . \n" +
|
||||
" ex:nose1 ex:c ex:nose1 . \n" +
|
||||
" ex:nose1 ex:c ex:bob . \n" ;
|
||||
|
||||
String expected =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" ;
|
||||
|
||||
Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3");
|
||||
|
||||
List<Statement> deletes = DependentResourceDeleteJena.getDependentResourceDeleteList(
|
||||
model.createStatement(
|
||||
model.createResource("http://example.com/bob"),
|
||||
model.createProperty("http://example.com/hasNose"),
|
||||
model.createResource("http://example.com/nose1")),
|
||||
model);
|
||||
|
||||
model.remove(deletes);
|
||||
|
||||
Model expectedModel = (ModelFactory.createDefaultModel()).read(new StringReader(expected), "", "N3");
|
||||
boolean same = expectedModel.isIsomorphicWith( model );
|
||||
if( ! same ) printModels( expectedModel, model);
|
||||
Assert.assertTrue( same );
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testStmtForceDeleteWithLinks() {
|
||||
String n3 =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" +
|
||||
" ex:bob ex:hasNose ex:nose1 . \n" +
|
||||
" ex:nose1 rdf:type " + depRes + " . \n" +
|
||||
" ex:nose1 ex:c ex:glasses65 . \n" +
|
||||
" ex:glasses65 ex:c ex:nose1 . \n" +
|
||||
" ex:glasses65 ex:a \"glasses 65\" ." ;
|
||||
|
||||
String expected =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" +
|
||||
" ex:glasses65 ex:a \"glasses 65\" ." ;
|
||||
|
||||
Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3");
|
||||
|
||||
List<Statement> deletes = DependentResourceDeleteJena.getDependentResourceDeleteList(
|
||||
model.createStatement(
|
||||
model.createResource("http://example.com/bob"),
|
||||
model.createProperty("http://example.com/hasNose"),
|
||||
model.createResource("http://example.com/nose1")),
|
||||
model);
|
||||
|
||||
model.remove(deletes);
|
||||
|
||||
Model expectedModel = (ModelFactory.createDefaultModel()).read(new StringReader(expected), "", "N3");
|
||||
boolean same = expectedModel.isIsomorphicWith( model );
|
||||
if( ! same ) printModels( expectedModel, model);
|
||||
Assert.assertTrue( same );
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testStmtForceDeleteWithBNodes() {
|
||||
String n3 =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" +
|
||||
" ex:bob ex:hasNose [ \n" +
|
||||
" rdf:type " + depRes + " ; \n" +
|
||||
" ex:a \"this is a bnode\"; \n" +
|
||||
" ex:c ex:glasses65 ] . \n" +
|
||||
" ex:glasses65 ex:a \"glasses 65\" ." ;
|
||||
|
||||
String expected =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" +
|
||||
" ex:glasses65 ex:a \"glasses 65\" ." ;
|
||||
|
||||
Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3");
|
||||
|
||||
StmtIterator stmtIt = model.listStatements(
|
||||
model.createResource("http://example.com/bob"),
|
||||
model.createProperty("http://example.com/hasNose"),
|
||||
(RDFNode)null);
|
||||
|
||||
List<Statement> deletes =
|
||||
DependentResourceDeleteJena.getDependentResourceDeleteList(stmtIt.nextStatement(),model);
|
||||
model.remove(deletes);
|
||||
|
||||
Model expectedModel = (ModelFactory.createDefaultModel()).read(new StringReader(expected), "", "N3");
|
||||
boolean same = expectedModel.isIsomorphicWith( model );
|
||||
if( ! same ) printModels( expectedModel, model);
|
||||
Assert.assertTrue( same );
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testStmtForceDeleteWithNestedBNodes() {
|
||||
String n3 =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" +
|
||||
" ex:bob ex:hasNose [ \n" +
|
||||
" rdf:type " + depRes + " ; \n" +
|
||||
" ex:a \"this is a bnode\"; \n" +
|
||||
" ex:c ex:glasses65 ; \n" +
|
||||
" ex:c [ rdf:type " + depRes + " ;" +
|
||||
" ex:a \"this is a nested bnode\" ] " +
|
||||
"] . \n" +
|
||||
" ex:glasses65 ex:a \"glasses 65\" ." ;
|
||||
|
||||
String expected =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" +
|
||||
" ex:glasses65 ex:a \"glasses 65\" ." ;
|
||||
|
||||
Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3");
|
||||
|
||||
StmtIterator stmtIt = model.listStatements(
|
||||
model.createResource("http://example.com/bob"),
|
||||
model.createProperty("http://example.com/hasNose"),
|
||||
(RDFNode)null);
|
||||
|
||||
List<Statement> deletes =
|
||||
DependentResourceDeleteJena.getDependentResourceDeleteList(stmtIt.nextStatement(),model);
|
||||
model.remove(deletes);
|
||||
|
||||
Model expectedModel = (ModelFactory.createDefaultModel()).read(new StringReader(expected), "", "N3");
|
||||
boolean same = expectedModel.isIsomorphicWith( model );
|
||||
if( ! same ) printModels( expectedModel, model);
|
||||
Assert.assertTrue( same );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@org.junit.Test
|
||||
public void testResNormalDelete() {
|
||||
String n3 =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:hasNose ex:nose1 . " ;
|
||||
Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3");
|
||||
List<Statement> deletes = DependentResourceDeleteJena.getDependentResourceDeleteList(
|
||||
model.createResource("http://example.com/nose1"),model);
|
||||
Assert.assertTrue( deletes != null && deletes.size() ==0 );
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testResSimpleForceDelete() {
|
||||
String n3 =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:hasNose ex:nose1 . \n" +
|
||||
" ex:nose1 rdf:type " + depRes + " . \n" +
|
||||
" ex:nose1 ex:hasHair ex:hair23. \n" +
|
||||
" ex:hair23 rdf:type " + depRes + " . \n" +
|
||||
" ex:hair23 ex:hasHairCount \"23\". " ;
|
||||
Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3");
|
||||
|
||||
List<Statement> deletes = DependentResourceDeleteJena.getDependentResourceDeleteList(
|
||||
model.createResource("http://example.com/nose1"),model);
|
||||
Model resultModel = ModelFactory.createDefaultModel();
|
||||
resultModel.add(deletes);
|
||||
|
||||
//all statements should be deleted
|
||||
boolean same = resultModel.isIsomorphicWith( model );
|
||||
Assert.assertTrue( same);
|
||||
}
|
||||
|
||||
|
||||
@org.junit.Test
|
||||
public void testResNonForceDelete() {
|
||||
String n3 =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:hasNose ex:nose1 . \n" +
|
||||
" ex:nose1 ex:hasHair ex:hair23. \n" +
|
||||
" ex:hair23 rdf:type " + depRes + " . \n" +
|
||||
" ex:hair23 ex:hasHairCount \"23\". " ;
|
||||
Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3");
|
||||
List<Statement> deletes = DependentResourceDeleteJena.getDependentResourceDeleteList(
|
||||
model.createResource("http://example.com/nose1"),model);
|
||||
Assert.assertTrue( deletes != null && deletes.size() == 0);
|
||||
}
|
||||
|
||||
|
||||
@org.junit.Test
|
||||
public void testResForceDeleteWithLiterals() {
|
||||
String n3 =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" +
|
||||
" ex:bob ex:hasNose ex:nose1 . \n" +
|
||||
" ex:nose1 rdf:type " + depRes + " . \n" +
|
||||
" ex:nose1 ex:a \"this is a literal\". \n" +
|
||||
" ex:nose1 ex:b \"2343\" . \n" +
|
||||
" ex:nose1 ex:hasHair ex:hair23. \n" +
|
||||
" ex:hair23 rdf:type " + depRes + " . \n" +
|
||||
" ex:hair23 ex:hasHairCount \"23\". " ;
|
||||
|
||||
String expected =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" ;
|
||||
Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3");
|
||||
|
||||
List<Statement> deletes = DependentResourceDeleteJena.getDependentResourceDeleteList(
|
||||
model.createResource("http://example.com/nose1"),model);
|
||||
|
||||
model.remove(deletes);
|
||||
|
||||
Model expectedModel = (ModelFactory.createDefaultModel()).read(new StringReader(expected), "", "N3");
|
||||
boolean same = expectedModel.isIsomorphicWith( model );
|
||||
if( ! same ) printModels( expectedModel, model);
|
||||
Assert.assertTrue( same );
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testResForceDeleteWithCycles() {
|
||||
String n3 =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" +
|
||||
" ex:bob ex:hasNose ex:nose1 . \n" +
|
||||
" ex:nose1 rdf:type " + depRes + " . \n" +
|
||||
" ex:nose1 ex:a \"this is a literal\". \n" +
|
||||
" ex:nose1 ex:b \"2343\" . \n" +
|
||||
" ex:nose1 ex:c ex:bob . \n" +
|
||||
" ex:nose1 ex:hasHair ex:hair23. \n" +
|
||||
" ex:hair23 rdf:type " + depRes + " . \n" +
|
||||
" ex:hair23 ex:c ex:bob . \n" +
|
||||
" ex:hair23 ex:hasHairCount \"23\". " ;
|
||||
|
||||
String expected =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" ;
|
||||
Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3");
|
||||
|
||||
List<Statement> deletes = DependentResourceDeleteJena.getDependentResourceDeleteList(
|
||||
model.createResource("http://example.com/nose1"),model);
|
||||
|
||||
model.remove(deletes);
|
||||
|
||||
Model expectedModel = (ModelFactory.createDefaultModel()).read(new StringReader(expected), "", "N3");
|
||||
boolean same = expectedModel.isIsomorphicWith( model );
|
||||
if( ! same ) printModels( expectedModel, model);
|
||||
Assert.assertTrue( same );
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testResForceDeleteWithCycles2() {
|
||||
String n3 =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" +
|
||||
" ex:bob ex:hasNose ex:nose1 . \n" +
|
||||
" ex:nose1 rdf:type " + depRes + " . \n" +
|
||||
" ex:nose1 ex:a \"this is a literal\". \n" +
|
||||
" ex:nose1 ex:b \"2343\" . \n" +
|
||||
" ex:nose1 ex:c ex:nose1 . \n" +
|
||||
" ex:nose1 ex:c ex:bob . \n" ;
|
||||
|
||||
String expected =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" ;
|
||||
Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3");
|
||||
|
||||
List<Statement> deletes = DependentResourceDeleteJena.getDependentResourceDeleteList(
|
||||
model.createResource("http://example.com/nose1"),model);
|
||||
model.remove(deletes);
|
||||
|
||||
Model expectedModel = (ModelFactory.createDefaultModel()).read(new StringReader(expected), "", "N3");
|
||||
boolean same = expectedModel.isIsomorphicWith( model );
|
||||
if( ! same ) printModels( expectedModel, model);
|
||||
Assert.assertTrue( same );
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testResForceDeleteWithLinks() {
|
||||
String n3 =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" +
|
||||
" ex:bob ex:hasNose ex:nose1 . \n" +
|
||||
" ex:nose1 rdf:type " + depRes + " . \n" +
|
||||
" ex:nose1 ex:c ex:glasses65 . \n" +
|
||||
" ex:glasses65 ex:c ex:nose1 . \n" +
|
||||
" ex:glasses65 ex:a \"glasses 65\" ." ;
|
||||
|
||||
String expected =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" +
|
||||
" ex:glasses65 ex:a \"glasses 65\" ." ;
|
||||
Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3");
|
||||
|
||||
List<Statement> deletes = DependentResourceDeleteJena.getDependentResourceDeleteList(
|
||||
model.createResource("http://example.com/nose1"),model);
|
||||
model.remove(deletes);
|
||||
|
||||
Model expectedModel = (ModelFactory.createDefaultModel()).read(new StringReader(expected), "", "N3");
|
||||
boolean same = expectedModel.isIsomorphicWith( model );
|
||||
if( ! same ) printModels( expectedModel, model);
|
||||
Assert.assertTrue( same );
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testResForceDeleteWithBNodes() {
|
||||
String n3 =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" +
|
||||
" ex:bob ex:hasNose [ \n" +
|
||||
" rdf:type " + depRes + " ; \n" +
|
||||
" ex:a \"this is a bnode\"; \n" +
|
||||
" ex:c ex:glasses65 ] . \n" +
|
||||
" ex:glasses65 ex:a \"glasses 65\" ." ;
|
||||
|
||||
String expected =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" +
|
||||
" ex:glasses65 ex:a \"glasses 65\" ." ;
|
||||
Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3");
|
||||
|
||||
StmtIterator stmtIt = model.listStatements(
|
||||
model.createResource("http://example.com/bob"),
|
||||
model.createProperty("http://example.com/hasNose"),
|
||||
(RDFNode)null);
|
||||
|
||||
RDFNode bnode = stmtIt.nextStatement().getObject();
|
||||
|
||||
List<Statement> deletes =
|
||||
DependentResourceDeleteJena.getDependentResourceDeleteList(bnode,model);
|
||||
model.remove(deletes);
|
||||
|
||||
Model expectedModel = (ModelFactory.createDefaultModel()).read(new StringReader(expected), "", "N3");
|
||||
boolean same = expectedModel.isIsomorphicWith( model );
|
||||
if( ! same ) printModels( expectedModel, model);
|
||||
Assert.assertTrue( same );
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testResForceDeleteWithNestedBNodes() {
|
||||
String n3 =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" +
|
||||
" ex:bob ex:hasNose [ \n" +
|
||||
" rdf:type " + depRes + " ; \n" +
|
||||
" ex:a \"this is a bnode\"; \n" +
|
||||
" ex:c ex:glasses65 ; \n" +
|
||||
" ex:c [ rdf:type " + depRes + " ;" +
|
||||
" ex:a \"this is a nested bnode\" ] " +
|
||||
"] . \n" +
|
||||
" ex:glasses65 ex:a \"glasses 65\" ." ;
|
||||
|
||||
String expected =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" +
|
||||
" ex:glasses65 ex:a \"glasses 65\" ." ;
|
||||
|
||||
Model model = (ModelFactory.createDefaultModel()).read(new StringReader(n3), "", "N3");
|
||||
|
||||
StmtIterator stmtIt = model.listStatements(
|
||||
model.createResource("http://example.com/bob"),
|
||||
model.createProperty("http://example.com/hasNose"),
|
||||
(RDFNode)null);
|
||||
RDFNode bnode = stmtIt.nextStatement().getObject();
|
||||
|
||||
List<Statement> deletes =
|
||||
DependentResourceDeleteJena.getDependentResourceDeleteList(bnode,model);
|
||||
model.remove(deletes);
|
||||
|
||||
Model expectedModel = (ModelFactory.createDefaultModel()).read(new StringReader(expected), "", "N3");
|
||||
boolean same = expectedModel.isIsomorphicWith( model );
|
||||
if( ! same ) printModels( expectedModel, model);
|
||||
Assert.assertTrue( same );
|
||||
}
|
||||
|
||||
|
||||
@org.junit.Test
|
||||
public void testDeleteForChange() {
|
||||
String source =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" +
|
||||
" ex:bob ex:hasNose ex:nose1 . \n" +
|
||||
" ex:nose1 rdf:type " + depRes + " . \n" +
|
||||
" ex:nose1 ex:a \"this is a literal\". \n" +
|
||||
" ex:nose1 ex:b \"2343\" . \n" +
|
||||
" ex:nose1 ex:hasHair ex:hair23. \n" +
|
||||
" ex:hair23 rdf:type " + depRes + " . \n" +
|
||||
" ex:hair23 ex:hasHairCount \"23\". " ;
|
||||
|
||||
String expected =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" ;
|
||||
|
||||
String retractions =
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
" ex:bob ex:hasNose ex:nose1 . ";
|
||||
|
||||
Model sourceModel = (ModelFactory.createDefaultModel()).read(new StringReader(source), "", "N3");
|
||||
Model additionsModel = (ModelFactory.createDefaultModel()); //no additions
|
||||
Model retractionsModel = (ModelFactory.createDefaultModel()).read(new StringReader(retractions), "", "N3");
|
||||
|
||||
Model deletes =
|
||||
DependentResourceDeleteJena.getDependentResourceDeleteForChange(additionsModel, retractionsModel, sourceModel);
|
||||
sourceModel.remove(retractionsModel);
|
||||
sourceModel.remove(deletes);
|
||||
|
||||
Model expectedModel = (ModelFactory.createDefaultModel()).read(new StringReader(expected), "", "N3");
|
||||
boolean same = expectedModel.isIsomorphicWith( sourceModel );
|
||||
if( ! same ) printModels( expectedModel, sourceModel);
|
||||
Assert.assertTrue( same );
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testDeleteForChangeWithReplace() {
|
||||
String source =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:bob ex:a \"Bob\". \n" +
|
||||
" ex:jim ex:a \"Jim\". \n" +
|
||||
" ex:bob ex:hasNose ex:nose1 . \n" +
|
||||
" ex:nose1 rdf:type " + depRes + " . \n" +
|
||||
" ex:nose1 ex:a \"this is a literal\". \n" +
|
||||
" ex:nose1 ex:b \"2343\" . \n" +
|
||||
" ex:nose1 ex:hasHair ex:hair23. \n" +
|
||||
" ex:hair23 rdf:type " + depRes + " . \n" +
|
||||
" ex:hair23 ex:hasHairCount \"23\". " ;
|
||||
|
||||
String expected =
|
||||
"@prefix vitro: <" + VitroVocabulary.vitroURI + "> . \n" +
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . \n"+
|
||||
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . \n"+
|
||||
"@prefix owl: <http://www.w3.org/2002/07/owl#> . \n"+
|
||||
" ex:jim ex:a \"Jim\". \n" +
|
||||
" ex:bob ex:a \"Bob\". \n" +
|
||||
" ex:jim ex:hasNose ex:nose1 . \n" +
|
||||
" ex:nose1 rdf:type " + depRes + " . \n" +
|
||||
" ex:nose1 ex:a \"this is a literal\". \n" +
|
||||
" ex:nose1 ex:b \"2343\" . \n" +
|
||||
" ex:nose1 ex:hasHair ex:hair23. \n" +
|
||||
" ex:hair23 rdf:type " + depRes + " . \n" +
|
||||
" ex:hair23 ex:hasHairCount \"23\". " ;
|
||||
|
||||
String additions =
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
" ex:jim ex:hasNose ex:nose1 . ";
|
||||
|
||||
String retractions =
|
||||
"@prefix ex: <http://example.com/> . \n" +
|
||||
" ex:bob ex:hasNose ex:nose1 . ";
|
||||
|
||||
Model sourceModel = (ModelFactory.createDefaultModel()).read(new StringReader(source), "", "N3");
|
||||
Model additionsModel = (ModelFactory.createDefaultModel()).read(new StringReader(additions), "", "N3");
|
||||
Model retractionsModel = (ModelFactory.createDefaultModel()).read(new StringReader(retractions), "", "N3");
|
||||
|
||||
Model depDeletes =
|
||||
DependentResourceDeleteJena.getDependentResourceDeleteForChange(additionsModel, retractionsModel, sourceModel);
|
||||
sourceModel.remove(depDeletes);
|
||||
sourceModel.remove(retractionsModel);
|
||||
sourceModel.add(additionsModel);
|
||||
|
||||
Model expectedModel = (ModelFactory.createDefaultModel()).read(new StringReader(expected), "", "N3");
|
||||
boolean same = expectedModel.isIsomorphicWith( sourceModel );
|
||||
if( ! same ) printModels( expectedModel, sourceModel);
|
||||
Assert.assertTrue( same );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler;
|
||||
|
||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.JenaNetidPolicyTest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.IndividualDaoJena;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
|
||||
public class EntityDaoJenaTest extends AbstractTestClass {
|
||||
|
||||
OntModel dorkHobbyModel;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Suppress error logging.
|
||||
setLoggerLevel(RDFDefaultErrorHandler.class, Level.OFF);
|
||||
|
||||
Model model = ModelFactory.createDefaultModel();
|
||||
InputStream in = JenaNetidPolicyTest.class.getResourceAsStream("resources/dorkyhobbies.owl");
|
||||
model.read(in,null);
|
||||
dorkHobbyModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM,model);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a class that had no tests, so Brian and I pulled one back. But it
|
||||
* doesn't compile, and it appears to be intended to test a method that has
|
||||
* not been implemented. So for now, we give it a pass.
|
||||
*/
|
||||
@Test
|
||||
public void testGetEntitiesByProperties() {
|
||||
// This is the class that had no tests, so we pulled one back.
|
||||
// IndividualDaoJena edj = new IndividualDaoJena();
|
||||
// edj.setOntModel(dorkHobbyModel);
|
||||
// String propURI="http://test.mannlib.cornell.edu#hasHobby",
|
||||
// ignoreEntURI="http://test.mannlib.cornell.edu#bob",
|
||||
// classURI=null;
|
||||
//
|
||||
// //bob hasHobby x
|
||||
// Collection ents =
|
||||
// edj.getIndividualsByObjectProperty(propURI, ignoreEntURI, classURI, true);
|
||||
// assertNotNull(ents);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,430 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||
import com.hp.hpl.jena.vocabulary.RDF;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
|
||||
|
||||
public class JenaBaseDaoTest {
|
||||
|
||||
@Test
|
||||
public void smartRemoveTestForIndivdiualDelete(){
|
||||
|
||||
OntModel model = ModelFactory.createOntologyModel();
|
||||
WebappDaoFactoryJena wdfj = new WebappDaoFactoryJena( model );
|
||||
|
||||
/* Need to have the DEPENDENT_RESOURCE class in the model */
|
||||
VClass cls = new VClass();
|
||||
cls.setURI(VitroVocabulary.DEPENDENT_RESOURCE);
|
||||
try {
|
||||
wdfj.getVClassDao().insertNewVClass(cls);
|
||||
} catch (InsertException e1) {
|
||||
Assert.fail("could not create class for dependentResourc");
|
||||
}
|
||||
|
||||
/* Need to have an Object Property */
|
||||
ObjectProperty op = new ObjectProperty();
|
||||
op.setURI("http://example.com/prop1");
|
||||
try {
|
||||
wdfj.getObjectPropertyDao().insertObjectProperty(op);
|
||||
} catch (InsertException e1) {
|
||||
Assert.fail("Could not create object property.");
|
||||
}
|
||||
|
||||
Individual ind = new IndividualImpl();
|
||||
ind.setURI("http://example.com/bob");
|
||||
ind.setName("Smith, Bob");
|
||||
try {
|
||||
wdfj.getIndividualDao().insertNewIndividual(ind);
|
||||
} catch (InsertException e) {
|
||||
Assert.fail("Could not create new Individual Smith, Bob");
|
||||
}
|
||||
|
||||
Individual indxyz = new IndividualImpl();
|
||||
indxyz.setURI("http://example.com/depResXYZ");
|
||||
indxyz.setName("depResXYZ");
|
||||
indxyz.setVClassURI(VitroVocabulary.DEPENDENT_RESOURCE);
|
||||
try {
|
||||
wdfj.getIndividualDao().insertNewIndividual(indxyz);
|
||||
} catch (InsertException e) {
|
||||
Assert.fail("Could not create new Individual depResXYZ");
|
||||
}
|
||||
StmtIterator it = model.listStatements(model.createResource("http://example.com/depResXYZ"),
|
||||
RDF.type, model.createResource(VitroVocabulary.DEPENDENT_RESOURCE));
|
||||
Assert.assertTrue("depResXYZ did not get rdf:type vitro:dependentResource" ,
|
||||
it != null && it.nextStatement() != null);
|
||||
|
||||
Individual indAbc = new IndividualImpl();
|
||||
indAbc.setURI("http://example.com/depResNested");
|
||||
indAbc.setName("depResNested");
|
||||
indAbc.setVClassURI(VitroVocabulary.DEPENDENT_RESOURCE);
|
||||
try {
|
||||
wdfj.getIndividualDao().insertNewIndividual(indAbc);
|
||||
} catch (InsertException e) {
|
||||
Assert.fail("Could not create new Individual depResNested");
|
||||
}
|
||||
it = model.listStatements(model.createResource("http://example.com/depResNested"),
|
||||
RDF.type, model.createResource(VitroVocabulary.DEPENDENT_RESOURCE));
|
||||
Assert.assertTrue("depResNested did not get rdf:type vitro:dependentResource" ,
|
||||
it != null && it.nextStatement() != null);
|
||||
|
||||
|
||||
ObjectPropertyStatement ops = new ObjectPropertyStatementImpl();
|
||||
ops.setSubjectURI("http://example.com/bob");
|
||||
ops.setPropertyURI("http://example.com/prop1");
|
||||
ops.setObjectURI("http://example.com/depResXYZ");
|
||||
wdfj.getObjectPropertyStatementDao().insertNewObjectPropertyStatement(ops);
|
||||
|
||||
ops = new ObjectPropertyStatementImpl();
|
||||
ops.setSubjectURI("http://example.com/depResXYZ");
|
||||
ops.setPropertyURI("http://example.com/prop1");
|
||||
ops.setObjectURI("http://example.com/depResNested");
|
||||
wdfj.getObjectPropertyStatementDao().insertNewObjectPropertyStatement(ops);
|
||||
|
||||
String expected = "<rdf:RDF\n"+
|
||||
" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"+
|
||||
" xmlns:j.0=\"http://vitro.mannlib.cornell.edu/ns/vitro/0.7#\"\n"+
|
||||
" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema#\"\n"+
|
||||
" xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\"\n"+
|
||||
" xmlns:owl=\"http://www.w3.org/2002/07/owl#\"\n"+
|
||||
" xmlns:j.1=\"http://example.com/\" > \n"+
|
||||
" <rdf:Description rdf:about=\"http://example.com/bob\">\n"+
|
||||
" <j.0:modTime rdf:datatype=\"http://www.w3.org/2001/XMLSchema#dateTime\">2010-01-25T15:27:54</j.0:modTime>\n"+
|
||||
" <rdfs:label xml:lang=\"en-US\">Smith, Bob</rdfs:label>\n"+
|
||||
" <rdf:type rdf:resource=\"http://www.w3.org/2002/07/owl#Thing\"/>\n"+
|
||||
" </rdf:Description>\n"+
|
||||
" <rdf:Description rdf:about=\"http://vitro.mannlib.cornell.edu/ns/vitro/0.7#DependentResource\">\n"+
|
||||
" <j.0:displayRankAnnot rdf:datatype=\"http://www.w3.org/2001/XMLSchema#int\">-1</j.0:displayRankAnnot>\n"+
|
||||
" <j.0:displayLimitAnnot rdf:datatype=\"http://www.w3.org/2001/XMLSchema#int\">-1</j.0:displayLimitAnnot>\n"+
|
||||
" <rdf:type rdf:resource=\"http://www.w3.org/2002/07/owl#Class\"/>\n"+
|
||||
" </rdf:Description>\n"+
|
||||
" <rdf:Description rdf:about=\"http://example.com/prop1\">\n"+
|
||||
" <j.0:selectFromExistingAnnot rdf:datatype=\"http://www.w3.org/2001/XMLSchema#boolean\">true</j.0:selectFromExistingAnnot>\n"+
|
||||
" <j.0:displayLimitAnnot rdf:datatype=\"http://www.w3.org/2001/XMLSchema#int\">5</j.0:displayLimitAnnot>\n"+
|
||||
" <rdf:type rdf:resource=\"http://www.w3.org/2002/07/owl#ObjectProperty\"/>\n"+
|
||||
" </rdf:Description>\n"+
|
||||
"</rdf:RDF>";
|
||||
|
||||
wdfj.getIndividualDao().deleteIndividual("http://example.com/depResXYZ");
|
||||
|
||||
|
||||
Model expectedModel = (ModelFactory.createOntologyModel()).read(new StringReader(expected), "", "RDF/XML");
|
||||
|
||||
//modtime times make it difficult to compare graphs
|
||||
wipeOutModTime(expectedModel);
|
||||
wipeOutModTime(model);
|
||||
|
||||
Assert.assertTrue( model.isIsomorphicWith(expectedModel));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void smartRemoveTestForObjPropStmtDelete(){
|
||||
|
||||
OntModel model = ModelFactory.createOntologyModel();
|
||||
WebappDaoFactoryJena wdfj = new WebappDaoFactoryJena( model );
|
||||
|
||||
/* Need to have the DEPENDENT_RESOURCE class in the model */
|
||||
VClass cls = new VClass();
|
||||
cls.setURI(VitroVocabulary.DEPENDENT_RESOURCE);
|
||||
try {
|
||||
wdfj.getVClassDao().insertNewVClass(cls);
|
||||
} catch (InsertException e1) {
|
||||
Assert.fail("could not create class for dependentResourc");
|
||||
}
|
||||
|
||||
/* Need to have an Object Property */
|
||||
ObjectProperty op = new ObjectProperty();
|
||||
op.setURI("http://example.com/prop1");
|
||||
try {
|
||||
wdfj.getObjectPropertyDao().insertObjectProperty(op);
|
||||
} catch (InsertException e1) {
|
||||
Assert.fail("Could not create object property.");
|
||||
}
|
||||
|
||||
Individual ind = new IndividualImpl();
|
||||
ind.setURI("http://example.com/bob");
|
||||
ind.setName("Smith, Bob");
|
||||
try {
|
||||
wdfj.getIndividualDao().insertNewIndividual(ind);
|
||||
} catch (InsertException e) {
|
||||
Assert.fail("Could not create new Individual Smith, Bob");
|
||||
}
|
||||
|
||||
Individual indxyz = new IndividualImpl();
|
||||
indxyz.setURI("http://example.com/depResXYZ");
|
||||
indxyz.setName("depResXYZ");
|
||||
indxyz.setVClassURI(VitroVocabulary.DEPENDENT_RESOURCE);
|
||||
try {
|
||||
wdfj.getIndividualDao().insertNewIndividual(indxyz);
|
||||
} catch (InsertException e) {
|
||||
Assert.fail("Could not create new Individual depResXYZ");
|
||||
}
|
||||
StmtIterator it = model.listStatements(model.createResource("http://example.com/depResXYZ"),
|
||||
RDF.type, model.createResource(VitroVocabulary.DEPENDENT_RESOURCE));
|
||||
Assert.assertTrue("depResXYZ did not get rdf:type vitro:dependentResource" ,
|
||||
it != null && it.nextStatement() != null);
|
||||
|
||||
Individual indAbc = new IndividualImpl();
|
||||
indAbc.setURI("http://example.com/depResNested");
|
||||
indAbc.setName("depResNested");
|
||||
indAbc.setVClassURI(VitroVocabulary.DEPENDENT_RESOURCE);
|
||||
try {
|
||||
wdfj.getIndividualDao().insertNewIndividual(indAbc);
|
||||
} catch (InsertException e) {
|
||||
Assert.fail("Could not create new Individual depResNested");
|
||||
}
|
||||
it = model.listStatements(model.createResource("http://example.com/depResNested"),
|
||||
RDF.type, model.createResource(VitroVocabulary.DEPENDENT_RESOURCE));
|
||||
Assert.assertTrue("depResNested did not get rdf:type vitro:dependentResource" ,
|
||||
it != null && it.nextStatement() != null);
|
||||
|
||||
|
||||
ObjectPropertyStatement ops = new ObjectPropertyStatementImpl();
|
||||
ops.setSubjectURI("http://example.com/bob");
|
||||
ops.setPropertyURI("http://example.com/prop1");
|
||||
ops.setObjectURI("http://example.com/depResXYZ");
|
||||
wdfj.getObjectPropertyStatementDao().insertNewObjectPropertyStatement(ops);
|
||||
|
||||
ops = new ObjectPropertyStatementImpl();
|
||||
ops.setSubjectURI("http://example.com/depResXYZ");
|
||||
ops.setPropertyURI("http://example.com/prop1");
|
||||
ops.setObjectURI("http://example.com/depResNested");
|
||||
wdfj.getObjectPropertyStatementDao().insertNewObjectPropertyStatement(ops);
|
||||
|
||||
String expected = "<rdf:RDF\n"+
|
||||
" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"+
|
||||
" xmlns:j.0=\"http://vitro.mannlib.cornell.edu/ns/vitro/0.7#\"\n"+
|
||||
" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema#\"\n"+
|
||||
" xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\"\n"+
|
||||
" xmlns:owl=\"http://www.w3.org/2002/07/owl#\"\n"+
|
||||
" xmlns:j.1=\"http://example.com/\" > \n"+
|
||||
" <rdf:Description rdf:about=\"http://example.com/bob\">\n"+
|
||||
" <j.0:modTime rdf:datatype=\"http://www.w3.org/2001/XMLSchema#dateTime\">2010-01-25T15:27:54</j.0:modTime>\n"+
|
||||
" <rdfs:label xml:lang=\"en-US\">Smith, Bob</rdfs:label>\n"+
|
||||
" <rdf:type rdf:resource=\"http://www.w3.org/2002/07/owl#Thing\"/>\n"+
|
||||
" </rdf:Description>\n"+
|
||||
" <rdf:Description rdf:about=\"http://vitro.mannlib.cornell.edu/ns/vitro/0.7#DependentResource\">\n"+
|
||||
" <j.0:displayRankAnnot rdf:datatype=\"http://www.w3.org/2001/XMLSchema#int\">-1</j.0:displayRankAnnot>\n"+
|
||||
" <j.0:displayLimitAnnot rdf:datatype=\"http://www.w3.org/2001/XMLSchema#int\">-1</j.0:displayLimitAnnot>\n"+
|
||||
" <rdf:type rdf:resource=\"http://www.w3.org/2002/07/owl#Class\"/>\n"+
|
||||
" </rdf:Description>\n"+
|
||||
" <rdf:Description rdf:about=\"http://example.com/prop1\">\n"+
|
||||
" <j.0:selectFromExistingAnnot rdf:datatype=\"http://www.w3.org/2001/XMLSchema#boolean\">true</j.0:selectFromExistingAnnot>\n"+
|
||||
" <j.0:displayLimitAnnot rdf:datatype=\"http://www.w3.org/2001/XMLSchema#int\">5</j.0:displayLimitAnnot>\n"+
|
||||
" <rdf:type rdf:resource=\"http://www.w3.org/2002/07/owl#ObjectProperty\"/>\n"+
|
||||
" </rdf:Description>\n"+
|
||||
"</rdf:RDF>";
|
||||
|
||||
|
||||
ops = new ObjectPropertyStatementImpl();
|
||||
ops.setSubjectURI("http://example.com/bob");
|
||||
ops.setPropertyURI("http://example.com/prop1");
|
||||
ops.setObjectURI("http://example.com/depResXYZ");
|
||||
wdfj.getObjectPropertyStatementDao().deleteObjectPropertyStatement(ops);
|
||||
|
||||
Model expectedModel = (ModelFactory.createOntologyModel()).read(new StringReader(expected), "", "RDF/XML");
|
||||
|
||||
//modtime times make it difficult to compare graphs
|
||||
wipeOutModTime(expectedModel);
|
||||
wipeOutModTime(model);
|
||||
|
||||
Assert.assertTrue( model.isIsomorphicWith(expectedModel));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void smartRemoveTestForObjPropDelete(){
|
||||
|
||||
OntModel model = ModelFactory.createOntologyModel();
|
||||
WebappDaoFactoryJena wdfj = new WebappDaoFactoryJena( model );
|
||||
|
||||
/* Need to have the DEPENDENT_RESOURCE class in the model */
|
||||
VClass cls = new VClass();
|
||||
cls.setURI(VitroVocabulary.DEPENDENT_RESOURCE);
|
||||
try {
|
||||
wdfj.getVClassDao().insertNewVClass(cls);
|
||||
} catch (InsertException e1) {
|
||||
Assert.fail("could not create class for dependentResourc");
|
||||
}
|
||||
|
||||
/* Need to have an Object Property */
|
||||
ObjectProperty op = new ObjectProperty();
|
||||
op.setURI("http://example.com/prop1");
|
||||
try {
|
||||
wdfj.getObjectPropertyDao().insertObjectProperty(op);
|
||||
} catch (InsertException e1) {
|
||||
Assert.fail("Could not create object property.");
|
||||
}
|
||||
|
||||
Individual ind = new IndividualImpl();
|
||||
ind.setURI("http://example.com/bob");
|
||||
ind.setName("Smith, Bob");
|
||||
try {
|
||||
wdfj.getIndividualDao().insertNewIndividual(ind);
|
||||
} catch (InsertException e) {
|
||||
Assert.fail("Could not create new Individual Smith, Bob");
|
||||
}
|
||||
|
||||
Individual indxyz = new IndividualImpl();
|
||||
indxyz.setURI("http://example.com/depResXYZ");
|
||||
indxyz.setName("depResXYZ");
|
||||
indxyz.setVClassURI(VitroVocabulary.DEPENDENT_RESOURCE);
|
||||
try {
|
||||
wdfj.getIndividualDao().insertNewIndividual(indxyz);
|
||||
} catch (InsertException e) {
|
||||
Assert.fail("Could not create new Individual depResXYZ");
|
||||
}
|
||||
StmtIterator it = model.listStatements(model.createResource("http://example.com/depResXYZ"),
|
||||
RDF.type, model.createResource(VitroVocabulary.DEPENDENT_RESOURCE));
|
||||
Assert.assertTrue("depResXYZ did not get rdf:type vitro:dependentResource" ,
|
||||
it != null && it.nextStatement() != null);
|
||||
|
||||
Individual indAbc = new IndividualImpl();
|
||||
indAbc.setURI("http://example.com/depResNested");
|
||||
indAbc.setName("depResNested");
|
||||
indAbc.setVClassURI(VitroVocabulary.DEPENDENT_RESOURCE);
|
||||
try {
|
||||
wdfj.getIndividualDao().insertNewIndividual(indAbc);
|
||||
} catch (InsertException e) {
|
||||
Assert.fail("Could not create new Individual depResNested");
|
||||
}
|
||||
it = model.listStatements(model.createResource("http://example.com/depResNested"),
|
||||
RDF.type, model.createResource(VitroVocabulary.DEPENDENT_RESOURCE));
|
||||
Assert.assertTrue("depResNested did not get rdf:type vitro:dependentResource" ,
|
||||
it != null && it.nextStatement() != null);
|
||||
|
||||
|
||||
ObjectPropertyStatement ops = new ObjectPropertyStatementImpl();
|
||||
ops.setSubjectURI("http://example.com/bob");
|
||||
ops.setPropertyURI("http://example.com/prop1");
|
||||
ops.setObjectURI("http://example.com/depResXYZ");
|
||||
wdfj.getObjectPropertyStatementDao().insertNewObjectPropertyStatement(ops);
|
||||
|
||||
ops = new ObjectPropertyStatementImpl();
|
||||
ops.setSubjectURI("http://example.com/depResXYZ");
|
||||
ops.setPropertyURI("http://example.com/prop1");
|
||||
ops.setObjectURI("http://example.com/depResNested");
|
||||
wdfj.getObjectPropertyStatementDao().insertNewObjectPropertyStatement(ops);
|
||||
|
||||
String expected = "<rdf:RDF\n"+
|
||||
" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n"+
|
||||
" xmlns:j.0=\"http://vitro.mannlib.cornell.edu/ns/vitro/0.7#\"\n"+
|
||||
" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema#\"\n"+
|
||||
" xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\"\n"+
|
||||
" xmlns:owl=\"http://www.w3.org/2002/07/owl#\"\n"+
|
||||
" xmlns:j.1=\"http://example.com/\" > \n"+
|
||||
" <rdf:Description rdf:about=\"http://example.com/bob\">\n"+
|
||||
" <rdfs:label xml:lang=\"en-US\">Smith, Bob</rdfs:label>\n"+
|
||||
" <rdf:type rdf:resource=\"http://www.w3.org/2002/07/owl#Thing\"/>\n"+
|
||||
" </rdf:Description>\n"+
|
||||
" <rdf:Description rdf:about=\"http://vitro.mannlib.cornell.edu/ns/vitro/0.7#DependentResource\">\n"+
|
||||
" <j.0:displayRankAnnot rdf:datatype=\"http://www.w3.org/2001/XMLSchema#int\">-1</j.0:displayRankAnnot>\n"+
|
||||
" <j.0:displayLimitAnnot rdf:datatype=\"http://www.w3.org/2001/XMLSchema#int\">-1</j.0:displayLimitAnnot>\n"+
|
||||
" <rdf:type rdf:resource=\"http://www.w3.org/2002/07/owl#Class\"/>\n"+
|
||||
" </rdf:Description>\n"+
|
||||
"</rdf:RDF>";
|
||||
|
||||
wdfj.getObjectPropertyDao().deleteObjectProperty(op);
|
||||
|
||||
Model expectedModel = (ModelFactory.createOntologyModel()).read(new StringReader(expected), "", "RDF/XML");
|
||||
|
||||
//modtime times make it difficult to compare graphs
|
||||
wipeOutModTime(expectedModel);
|
||||
wipeOutModTime(model);
|
||||
Assert.assertTrue( model.isIsomorphicWith(expectedModel));
|
||||
}
|
||||
void printModels(Model expected, Model result){
|
||||
System.out.println("Expected:");
|
||||
expected.write(System.out);
|
||||
System.out.println("Result:");
|
||||
result.write(System.out);
|
||||
}
|
||||
|
||||
void wipeOutModTime(Model model){
|
||||
model.removeAll(null, model.createProperty(VitroVocabulary.MODTIME), null);
|
||||
}
|
||||
|
||||
@Test
|
||||
/**
|
||||
* Tests that any statements with a property as predicate are removed
|
||||
* when the property itself is removed
|
||||
*/
|
||||
public void testABoxAssertionsRemovedWhenPropertyRemoved() throws InsertException {
|
||||
OntModel preModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
OntModel postModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
|
||||
|
||||
WebappDaoFactoryJena preWadf = new WebappDaoFactoryJena(preModel);
|
||||
|
||||
// make some other stuff that won't be deleted
|
||||
ObjectProperty objPropNotForDeletion = new ObjectProperty();
|
||||
objPropNotForDeletion.setURI("http://dont.delete.me/objProp");
|
||||
preWadf.getObjectPropertyDao().insertObjectProperty(objPropNotForDeletion);
|
||||
DataProperty dataPropNotForDeletion = new DataProperty();
|
||||
dataPropNotForDeletion.setURI("http://dont.delete.me/dataProp");
|
||||
preWadf.getDataPropertyDao().insertDataProperty(dataPropNotForDeletion);
|
||||
ObjectPropertyStatement objPropStmtNotForDeletion = new ObjectPropertyStatementImpl();
|
||||
objPropStmtNotForDeletion.setSubjectURI("http://individual.example.org/a/");
|
||||
objPropStmtNotForDeletion.setProperty(objPropNotForDeletion);
|
||||
objPropStmtNotForDeletion.setObjectURI("http://individual.example.org/b/");
|
||||
preWadf.getObjectPropertyStatementDao().insertNewObjectPropertyStatement(objPropStmtNotForDeletion);
|
||||
DataPropertyStatement dataPropStmtNotForDeletion = new DataPropertyStatementImpl();
|
||||
dataPropStmtNotForDeletion.setIndividualURI("http://individual.example.org/a/");
|
||||
dataPropStmtNotForDeletion.setDatapropURI(dataPropNotForDeletion.getURI());
|
||||
dataPropStmtNotForDeletion.setData("junk");
|
||||
|
||||
// copy the not-for-deletion data to the postModel
|
||||
postModel.add(preModel);
|
||||
|
||||
// Make some properties and assertions that should be deleted.
|
||||
// After deletion, the "preModel" should match the "postModel," which
|
||||
// only contains the not-for-deletion statements.
|
||||
ObjectProperty objProp = new ObjectProperty();
|
||||
objProp.setURI("http://example.org/objProp");
|
||||
preWadf.getObjectPropertyDao().insertObjectProperty(objProp);
|
||||
DataProperty dataProp = new DataProperty();
|
||||
dataProp.setURI("http://example.org/dataProp");
|
||||
preWadf.getDataPropertyDao().insertDataProperty(dataProp);
|
||||
ObjectPropertyStatement objPropStmtForDeletion = new ObjectPropertyStatementImpl();
|
||||
objPropStmtForDeletion.setSubjectURI("http://example.org/sdfadsf/");
|
||||
objPropStmtForDeletion.setProperty(objProp);
|
||||
objPropStmtForDeletion.setObjectURI("http://example.org/asdfasdfasfa/");
|
||||
preWadf.getObjectPropertyStatementDao().insertNewObjectPropertyStatement(objPropStmtForDeletion);
|
||||
DataPropertyStatement dataPropStmtForDeletion = new DataPropertyStatementImpl();
|
||||
dataPropStmtForDeletion.setIndividualURI("http://example.org/asdf123/");
|
||||
dataPropStmtForDeletion.setDatapropURI(dataProp.getURI());
|
||||
dataPropStmtForDeletion.setData("I will be deleted!");
|
||||
preWadf.getDataPropertyStatementDao().insertNewDataPropertyStatement(dataPropStmtForDeletion);
|
||||
|
||||
// delete the object property and the data property.
|
||||
// The abox assertions should go with them.
|
||||
preWadf.getObjectPropertyDao().deleteObjectProperty(objProp);
|
||||
preWadf.getDataPropertyDao().deleteDataProperty(dataProp);
|
||||
|
||||
// the preModel and the postModel should now have the same statements
|
||||
//Assert.assertTrue(preModel.isIsomorphicWith(postModel));
|
||||
Assert.assertTrue(preModel.size() == postModel.size());
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,294 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.dao.jena;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import junit.framework.Assert;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Link;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.PropertyGroup;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Tab;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.User;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.PortalDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.PropertyGroupDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.TabDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.UserDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassGroupDao;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
|
||||
/**
|
||||
* Test that the Jena DAOs write different types of data to the appropriate models.
|
||||
* @author bjl23
|
||||
*
|
||||
*/
|
||||
public class OntModelSegementationTest {
|
||||
|
||||
private WebappDaoFactoryJena wadf;
|
||||
|
||||
@org.junit.Before
|
||||
public void setUpWebappDaoFactoryJena() {
|
||||
wadf = new WebappDaoFactoryJena(new SimpleOntModelSelector());
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testUserAccountModel() {
|
||||
|
||||
UserDao udao = wadf.getUserDao();
|
||||
OntModelSelector oms = wadf.getOntModelSelector();
|
||||
|
||||
User user = new User();
|
||||
user.setFirstName("Chuck");
|
||||
user.setLastName("Roast");
|
||||
user.setUsername("chuckroast");
|
||||
|
||||
String userURI = udao.insertUser(user);
|
||||
user.setURI(userURI);
|
||||
Assert.assertTrue(oms.getUserAccountsModel().size() > 0);
|
||||
Assert.assertTrue(oms.getFullModel().size() == 0);
|
||||
Assert.assertTrue(oms.getABoxModel().size() == 0);
|
||||
Assert.assertTrue(oms.getTBoxModel().size() == 0);
|
||||
Assert.assertTrue(oms.getApplicationMetadataModel().size() == 0);
|
||||
|
||||
user.setUsername("todd");
|
||||
udao.updateUser(user);
|
||||
Assert.assertTrue(oms.getUserAccountsModel().size() > 0);
|
||||
Assert.assertTrue(oms.getFullModel().size() == 0);
|
||||
Assert.assertTrue(oms.getABoxModel().size() == 0);
|
||||
Assert.assertTrue(oms.getTBoxModel().size() == 0);
|
||||
Assert.assertTrue(oms.getApplicationMetadataModel().size() == 0);
|
||||
|
||||
udao.deleteUser(user);
|
||||
Assert.assertTrue(oms.getUserAccountsModel().size() == 0);
|
||||
Assert.assertTrue(oms.getFullModel().size() == 0);
|
||||
Assert.assertTrue(oms.getABoxModel().size() == 0);
|
||||
Assert.assertTrue(oms.getTBoxModel().size() == 0);
|
||||
Assert.assertTrue(oms.getApplicationMetadataModel().size() == 0);
|
||||
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testApplicationMetadataModel() throws InsertException {
|
||||
|
||||
PortalDao pdao = wadf.getPortalDao();
|
||||
TabDao tdao = wadf.getTabDao();
|
||||
VClassGroupDao vcgdao = wadf.getVClassGroupDao();
|
||||
PropertyGroupDao pgdao = wadf.getPropertyGroupDao();
|
||||
OntModelSelector oms = wadf.getOntModelSelector();
|
||||
|
||||
this.assertAllModelsEmpty(oms);
|
||||
|
||||
//insert a portal
|
||||
Portal portal = new Portal();
|
||||
portal.setPortalId(1);
|
||||
portal.setAppName("test portal");
|
||||
pdao.insertPortal(portal);
|
||||
this.assertMetadataModelNonemptyAndAllOtherModelsAreEmpty(oms);
|
||||
|
||||
//insert a tab
|
||||
Tab tab = new Tab();
|
||||
tab.setTitle("test tab");
|
||||
int tabId = tdao.insertTab(tab);
|
||||
tab.setTabId(tabId);
|
||||
this.assertMetadataModelNonemptyAndAllOtherModelsAreEmpty(oms);
|
||||
|
||||
//insert a classgroup
|
||||
VClassGroup group = new VClassGroup();
|
||||
group.setURI("http://example.org/classgroup");
|
||||
group.setPublicName("test group");
|
||||
vcgdao.insertNewVClassGroup(group);
|
||||
this.assertMetadataModelNonemptyAndAllOtherModelsAreEmpty(oms);
|
||||
|
||||
//insert a property group
|
||||
PropertyGroup pgroup = new PropertyGroup();
|
||||
pgroup.setURI("http://example.org/propertygroup");
|
||||
pgroup.setName("test property group");
|
||||
pgdao.insertNewPropertyGroup(pgroup);
|
||||
this.assertMetadataModelNonemptyAndAllOtherModelsAreEmpty(oms);
|
||||
|
||||
portal.setAppName("updated portal");
|
||||
tab.setTitle("updated tab");
|
||||
group.setPublicName("updated group");
|
||||
pgroup.setName("updated property group");
|
||||
|
||||
pdao.updatePortal(portal);
|
||||
this.assertMetadataModelNonemptyAndAllOtherModelsAreEmpty(oms);
|
||||
|
||||
tdao.updateTab(tab);
|
||||
this.assertMetadataModelNonemptyAndAllOtherModelsAreEmpty(oms);
|
||||
|
||||
vcgdao.updateVClassGroup(group);
|
||||
this.assertMetadataModelNonemptyAndAllOtherModelsAreEmpty(oms);
|
||||
|
||||
pgdao.updatePropertyGroup(pgroup);
|
||||
this.assertMetadataModelNonemptyAndAllOtherModelsAreEmpty(oms);
|
||||
|
||||
pdao.deletePortal(portal);
|
||||
tdao.deleteTab(tab);
|
||||
vcgdao.deleteVClassGroup(group);
|
||||
pgdao.deletePropertyGroup(pgroup);
|
||||
|
||||
this.assertAllModelsEmpty(oms);
|
||||
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testTBoxModel() throws InsertException {
|
||||
|
||||
OntModelSelector oms = wadf.getOntModelSelector();
|
||||
VClassDao vcDao = wadf.getVClassDao();
|
||||
ObjectPropertyDao opDao = wadf.getObjectPropertyDao();
|
||||
DataPropertyDao dpDao = wadf.getDataPropertyDao();
|
||||
OntologyDao oDao = wadf.getOntologyDao();
|
||||
|
||||
VClass vclass = new VClass();
|
||||
vclass.setURI("http://example.org/vclass");
|
||||
vcDao.insertNewVClass(vclass);
|
||||
this.assertTBoxModelNonemptyAndAllOtherModelsAreEmpty(oms);
|
||||
|
||||
ObjectProperty op = new ObjectProperty();
|
||||
op.setURI("http://example.org/objectProperty");
|
||||
opDao.insertObjectProperty(op);
|
||||
this.assertTBoxModelNonemptyAndAllOtherModelsAreEmpty(oms);
|
||||
|
||||
DataProperty dp = new DataProperty();
|
||||
dp.setURI("http://example.org/dataProperty");
|
||||
dpDao.insertDataProperty(dp);
|
||||
this.assertTBoxModelNonemptyAndAllOtherModelsAreEmpty(oms);
|
||||
|
||||
Ontology o = new Ontology();
|
||||
o.setURI("http://example.org/");
|
||||
oDao.insertNewOntology(o);
|
||||
this.assertTBoxModelNonemptyAndAllOtherModelsAreEmpty(oms);
|
||||
|
||||
vclass.setName("vclass");
|
||||
op.setDomainPublic("objectProperty");
|
||||
dp.setPublicName("dataProperty");
|
||||
o.setName("ontology");
|
||||
|
||||
vcDao.updateVClass(vclass);
|
||||
this.assertTBoxModelNonemptyAndAllOtherModelsAreEmpty(oms);
|
||||
|
||||
opDao.updateObjectProperty(op);
|
||||
this.assertTBoxModelNonemptyAndAllOtherModelsAreEmpty(oms);
|
||||
|
||||
dpDao.updateDataProperty(dp);
|
||||
this.assertTBoxModelNonemptyAndAllOtherModelsAreEmpty(oms);
|
||||
|
||||
oDao.updateOntology(o);
|
||||
this.assertTBoxModelNonemptyAndAllOtherModelsAreEmpty(oms);
|
||||
|
||||
vcDao.deleteVClass(vclass);
|
||||
opDao.deleteObjectProperty(op);
|
||||
dpDao.deleteDataProperty(dp);
|
||||
oDao.deleteOntology(o);
|
||||
|
||||
this.assertAllModelsEmpty(oms);
|
||||
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testAboxModel() throws InsertException {
|
||||
|
||||
OntModelSelector oms = wadf.getOntModelSelector();
|
||||
IndividualDao iDao = wadf.getIndividualDao();
|
||||
|
||||
Individual ind = new IndividualImpl("http://example.org/individual");
|
||||
iDao.insertNewIndividual(ind);
|
||||
this.assertABoxModelNonemptyAndAllOtherModelsAreEmpty(oms);
|
||||
|
||||
ind.setName("ind");
|
||||
iDao.updateIndividual(ind);
|
||||
this.assertABoxModelNonemptyAndAllOtherModelsAreEmpty(oms);
|
||||
|
||||
iDao.deleteIndividual(ind);
|
||||
this.assertAllModelsEmpty(oms);
|
||||
|
||||
}
|
||||
|
||||
private void assertAllModelsEmpty(OntModelSelector oms) {
|
||||
Assert.assertTrue(oms.getApplicationMetadataModel().size() == 0);
|
||||
Assert.assertTrue(oms.getFullModel().size() == 0);
|
||||
Assert.assertTrue(oms.getABoxModel().size() == 0);
|
||||
Assert.assertTrue(oms.getTBoxModel().size() == 0);
|
||||
Assert.assertTrue(oms.getUserAccountsModel().size() == 0);
|
||||
}
|
||||
|
||||
private void assertMetadataModelNonemptyAndAllOtherModelsAreEmpty(OntModelSelector oms) {
|
||||
Assert.assertTrue(oms.getApplicationMetadataModel().size() > 0);
|
||||
Assert.assertTrue(oms.getFullModel().size() == oms.getApplicationMetadataModel().size());
|
||||
Assert.assertTrue(oms.getABoxModel().size() == 0);
|
||||
Assert.assertTrue(oms.getTBoxModel().size() == 0);
|
||||
Assert.assertTrue(oms.getUserAccountsModel().size() == 0);
|
||||
}
|
||||
|
||||
private void assertTBoxModelNonemptyAndAllOtherModelsAreEmpty(OntModelSelector oms) {
|
||||
Assert.assertTrue(oms.getTBoxModel().size() > 0);
|
||||
Assert.assertTrue(oms.getFullModel().size() == oms.getTBoxModel().size());
|
||||
Assert.assertTrue(oms.getABoxModel().size() == 0);
|
||||
Assert.assertTrue(oms.getApplicationMetadataModel().size() == 0);
|
||||
Assert.assertTrue(oms.getUserAccountsModel().size() == 0);
|
||||
}
|
||||
|
||||
private void assertABoxModelNonemptyAndAllOtherModelsAreEmpty(OntModelSelector oms) {
|
||||
Assert.assertTrue(oms.getABoxModel().size() > 0);
|
||||
Assert.assertTrue(oms.getFullModel().size() == oms.getABoxModel().size());
|
||||
Assert.assertTrue(oms.getTBoxModel().size() == 0);
|
||||
Assert.assertTrue(oms.getApplicationMetadataModel().size() == 0);
|
||||
Assert.assertTrue(oms.getUserAccountsModel().size() == 0);
|
||||
}
|
||||
|
||||
@org.junit.Test
|
||||
public void testConcurrency() throws InsertException {
|
||||
// (new Thread(new ClassLister(wadf))).start();
|
||||
// (new Thread(new ClassLister(wadf))).start();
|
||||
// VClass v = null;
|
||||
// for (int i = 0; i < 50; i++) {
|
||||
// v = new VClass();
|
||||
// v.setURI("http://example.org/vclass" + i);
|
||||
// wadf.getVClassDao().insertNewVClass(v);
|
||||
// }
|
||||
// for (int i = 0; i < 500; i++) {
|
||||
// v.setName("blah " + i);
|
||||
// wadf.getVClassDao().updateVClass(v);
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
private class ClassLister implements Runnable {
|
||||
|
||||
private WebappDaoFactory wadf;
|
||||
|
||||
public ClassLister(WebappDaoFactory wadf) {
|
||||
this.wadf = wadf;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
||||
//int vclassTotal = wadf.getVClassDao().getAllVclasses().size();
|
||||
|
||||
for (int i = 0; i < 1500; i++) {
|
||||
|
||||
wadf.getVClassDao().getAllVclasses().size();
|
||||
|
||||
// if (vclassTotal != wadf.getVClassDao().getAllVclasses().size()) {
|
||||
// throw new RuntimeException("Inconsistent VClass list size");
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE owl [
|
||||
<!ENTITY test.mannlib "http://test.mannlib.cornell.edu#">
|
||||
<!ENTITY dc "http://purl.org/dc/elements/1.1/">
|
||||
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#">
|
||||
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||||
<!ENTITY owl "http://www.w3.org/2002/07/owl#">
|
||||
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#">
|
||||
]>
|
||||
<rdf:RDF
|
||||
xmlns:test.mannlib="http://test.mannlib.cornell.edu#"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:owl="http://www.w3.org/2002/07/owl#"
|
||||
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
|
||||
xml:base="http://test.mannlib.cornell.edu"
|
||||
>
|
||||
<owl:Ontology rdf:about="http://test.mannlib.cornell.edu">
|
||||
<owl:versionInfo>test-0.01</owl:versionInfo>
|
||||
<rdfs:label>testing ontology</rdfs:label>
|
||||
</owl:Ontology>
|
||||
<owl:Class rdf:about="http://test.mannlib.cornell.edu#dork">
|
||||
<rdfs:label>dork</rdfs:label>
|
||||
</owl:Class>
|
||||
<owl:Class rdf:about="http://test.mannlib.cornell.edu#dorkyhobby">
|
||||
<rdfs:label>dorky hobby</rdfs:label>
|
||||
</owl:Class>
|
||||
<owl:Class rdf:about="http://test.mannlib.cornell.edu#verydorkyhobby">
|
||||
<rdfs:subClassOf>
|
||||
<owl:Class rdf:about="http://test.mannlib.cornell.edu#dorkyhobby">
|
||||
</owl:Class>
|
||||
</rdfs:subClassOf>
|
||||
<rdfs:label>very dorky hobby</rdfs:label>
|
||||
</owl:Class>
|
||||
<owl:Class rdf:about="http://www.w3.org/2002/07/owl#Thing">
|
||||
</owl:Class>
|
||||
<owl:ObjectProperty rdf:about="http://test.mannlib.cornell.edu#hasHobby">
|
||||
<rdfs:domain>
|
||||
<owl:Class rdf:about="http://test.mannlib.cornell.edu#dork">
|
||||
</owl:Class>
|
||||
</rdfs:domain>
|
||||
<rdfs:range>
|
||||
<owl:Class rdf:about="http://test.mannlib.cornell.edu#dorkyhobby">
|
||||
</owl:Class>
|
||||
</rdfs:range>
|
||||
<rdfs:label>has hobby</rdfs:label>
|
||||
</owl:ObjectProperty>
|
||||
|
||||
|
||||
<rdf:Description rdf:about="http://test.mannlib.cornell.edu#baseballcardcollecting">
|
||||
<rdf:type>
|
||||
<owl:Class rdf:about="http://test.mannlib.cornell.edu#dorkyhobby">
|
||||
</owl:Class>
|
||||
</rdf:type>
|
||||
<rdfs:label>baseball card collecting</rdfs:label>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://test.mannlib.cornell.edu#bob">
|
||||
<rdf:type>
|
||||
<owl:Class rdf:about="http://test.mannlib.cornell.edu#dork">
|
||||
</owl:Class>
|
||||
</rdf:type>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://test.mannlib.cornell.edu#comicbookcollecting">
|
||||
<rdf:type>
|
||||
<owl:Class rdf:about="http://test.mannlib.cornell.edu#verydorkyhobby">
|
||||
</owl:Class>
|
||||
</rdf:type>
|
||||
<rdfs:label>comic book collecting</rdfs:label>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://test.mannlib.cornell.edu#cooking">
|
||||
<rdf:type>
|
||||
<owl:Class rdf:about="http://test.mannlib.cornell.edu#dorkyhobby">
|
||||
</owl:Class>
|
||||
</rdf:type>
|
||||
<rdfs:label>cooking</rdfs:label>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://test.mannlib.cornell.edu#jeff">
|
||||
<rdf:type>
|
||||
<owl:Class rdf:about="http://test.mannlib.cornell.edu#dork">
|
||||
</owl:Class>
|
||||
</rdf:type>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://test.mannlib.cornell.edu#sam">
|
||||
<rdf:type>
|
||||
<owl:Class rdf:about="http://test.mannlib.cornell.edu#dork">
|
||||
</owl:Class>
|
||||
</rdf:type>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://test.mannlib.cornell.edu#sewinghats">
|
||||
<rdf:type>
|
||||
<owl:Class rdf:about="http://test.mannlib.cornell.edu#verydorkyhobby">
|
||||
</owl:Class>
|
||||
</rdf:type>
|
||||
<rdfs:label>sewing hats</rdfs:label>
|
||||
</rdf:Description>
|
||||
|
||||
</rdf:RDF>
|
|
@ -0,0 +1,126 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.edit;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
|
||||
public class TestEditLiteral {
|
||||
|
||||
@Test
|
||||
public void testEqual(){
|
||||
Assert.assertTrue( EditLiteral.equalLiterals(
|
||||
new EditLiteral("dog", (String)null, (String)null ),
|
||||
new EditLiteral("dog", (String)null, (String)null )
|
||||
));
|
||||
Assert.assertTrue( EditLiteral.equalLiterals(
|
||||
new EditLiteral("dog", (String)"http://someUri", (String)null ),
|
||||
new EditLiteral("dog", (String)"http://someUri", (String)null )
|
||||
));
|
||||
Assert.assertTrue( EditLiteral.equalLiterals(
|
||||
new EditLiteral("dog", (String)null, (String)"SOMELANG" ),
|
||||
new EditLiteral("dog", (String)null, (String)"SOMELANG" )
|
||||
));
|
||||
|
||||
//datatype trumps lang
|
||||
Assert.assertTrue( EditLiteral.equalLiterals(
|
||||
new EditLiteral("dog", (String)"http://someUri", (String)"SOMELANG" ),
|
||||
new EditLiteral("dog", (String)"http://someUri", (String)null )
|
||||
));
|
||||
Assert.assertTrue( EditLiteral.equalLiterals(
|
||||
new EditLiteral("dog", (String)"http://someUri", (String)null ),
|
||||
new EditLiteral("dog", (String)"http://someUri", (String)"OTHERLANG" )
|
||||
));
|
||||
Assert.assertTrue( EditLiteral.equalLiterals(
|
||||
new EditLiteral("dog", (String)"http://someUri", (String)"SOMELANG" ),
|
||||
new EditLiteral("dog", (String)"http://someUri", (String)"SOMELANG" )
|
||||
));
|
||||
Assert.assertTrue( EditLiteral.equalLiterals(
|
||||
new EditLiteral("dog", (String)"http://someUri", (String)"SOMELANG" ),
|
||||
new EditLiteral("dog", (String)"http://someUri", (String)"OTHERLANG" )
|
||||
));
|
||||
|
||||
Assert.assertTrue( EditLiteral.equalLiterals(
|
||||
new EditLiteral("dog", (String)null, (String)"SOMELANG" ),
|
||||
new EditLiteral("dog", (String)null, (String)"SOMELANG" )
|
||||
));
|
||||
|
||||
|
||||
//NOT EQUAL CASES
|
||||
Assert.assertFalse( EditLiteral.equalLiterals(
|
||||
new EditLiteral("dog", (String)null, (String)null ),
|
||||
new EditLiteral("catFood", (String)null, (String)null )
|
||||
));
|
||||
Assert.assertFalse( EditLiteral.equalLiterals(
|
||||
new EditLiteral("dog", (String)"http://someUri", (String)null ),
|
||||
new EditLiteral("dog", (String)"http://otherUri.com", (String)null )
|
||||
));
|
||||
Assert.assertFalse( EditLiteral.equalLiterals(
|
||||
new EditLiteral("dog", (String)null, (String)"SOMELANG" ),
|
||||
new EditLiteral("dog", (String)null, (String)"OTHERLANG" )
|
||||
));
|
||||
Assert.assertFalse( EditLiteral.equalLiterals(
|
||||
new EditLiteral("dog", (String)"http://someUri", (String)"SOMELANG" ),
|
||||
new EditLiteral("dog", (String)"http://otherUri.com", (String)"SOMELANG" )
|
||||
));
|
||||
Assert.assertFalse( EditLiteral.equalLiterals(
|
||||
new EditLiteral("dog", (String)"http://someUri", (String)"SOMELANG" ),
|
||||
new EditLiteral("dog", (String)"http://otherUri.com", (String)null )
|
||||
));
|
||||
Assert.assertFalse( EditLiteral.equalLiterals(
|
||||
new EditLiteral("dog", (String)"http://someUri", (String)null ),
|
||||
new EditLiteral("dog", (String)"http://otherUri.com", (String)"SOMELANG" )
|
||||
));
|
||||
Assert.assertFalse( EditLiteral.equalLiterals(
|
||||
new EditLiteral("dog", (String)"http://someUri", (String)null ),
|
||||
new EditLiteral("dog", (String)null, (String)null )
|
||||
));
|
||||
Assert.assertFalse( EditLiteral.equalLiterals(
|
||||
new EditLiteral("dog", (String)null, (String)null ),
|
||||
new EditLiteral("dog", (String)"http://someUri", (String)null )
|
||||
));
|
||||
Assert.assertFalse( EditLiteral.equalLiterals(
|
||||
new EditLiteral("dog", (String)null, (String)"SOMELANG" ),
|
||||
new EditLiteral("dog", (String)null, (String)null )
|
||||
));
|
||||
Assert.assertFalse( EditLiteral.equalLiterals(
|
||||
new EditLiteral("dog", (String)null, (String)null ),
|
||||
new EditLiteral("dog", (String)null, (String)"SOMELANG" )
|
||||
));
|
||||
|
||||
Assert.assertFalse( EditLiteral.equalLiterals(
|
||||
new EditLiteral("dog", (String)null, (String)null ),
|
||||
new EditLiteral(null, (String)null, (String)null )
|
||||
));
|
||||
Assert.assertFalse( EditLiteral.equalLiterals(
|
||||
new EditLiteral(null, (String)null, (String)null ),
|
||||
new EditLiteral("dog", (String)null, (String)null )
|
||||
));
|
||||
|
||||
Assert.assertFalse( EditLiteral.equalLiterals(
|
||||
new EditLiteral("dog", (String)null, (String)"SOMELANG" ),
|
||||
new EditLiteral("catFood", (String)null, (String)"SOMELANG" )
|
||||
));
|
||||
Assert.assertFalse( EditLiteral.equalLiterals(
|
||||
new EditLiteral("dog", (String)"http://someUri", (String)null ),
|
||||
new EditLiteral("catFood", (String)"http://someUri", (String)null )
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBug2(){
|
||||
|
||||
Literal a2 = new EditLiteral("<ul><li>Stephen G. Yusem is the senior partner of High, Swartz, Roberts & Seidel in Norristown, Pennsylvania. <br /></li><li>He has been certified as a mediator for the United States District Court for the Eastern District of Pennsylvania since 1991. <br /></li><li>He is a Fellow of the College of Commercial Arbitrators, a member of the Chartered Institute of Arbitrators, a panelist on the CPR Roster of Distinguished Neutrals and a past director of the Commercial Section of the Association for Conflict Resolution. <br /></li><li>He co-chairs the Arbitration Committee of the Dispute Resolution Section of the American Bar Association and is a former member of the Arbitration Faculty of the American Arbitration Association. <br /></li><li>He is a past president of the Montgomery County (PA) Bar Association and was Founding President of the Montgomery County Bar Foundation. He co-teaches Dispute Resolution: Negotiation, Mediation and Arbitration in the fall semester.</li></ul>",
|
||||
"http://www.w3.org/2001/XMLSchema#string","");
|
||||
Literal b2 = new EditLiteral("<ul><li>Stephen G. Yusem is the senior partner of High, Swartz, Roberts & Seidel in Norristown, Pennsylvania. <br /></li><li>He has been certified as a mediator for the United States District Court for the Eastern District of Pennsylvania since 1991. <br /></li></ul>",
|
||||
"http://www.w3.org/2001/XMLSchema#string",null);
|
||||
Assert.assertFalse( EditLiteral.equalLiterals( a2, b2 ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.EditLiteral;
|
||||
|
||||
public class EditN3GeneratorTest {
|
||||
|
||||
EditN3Generator en3g ;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
en3g = new EditN3Generator((EditConfiguration) null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubInLiterals() {
|
||||
String var = "TestVar";
|
||||
String target = "Fake n3 ?TestVar .";
|
||||
Literal literal = null;
|
||||
|
||||
EditN3Generator en3g = new EditN3Generator((EditConfiguration) null);
|
||||
String result = en3g.subInLiterals(var, literal, target);
|
||||
Assert.assertNotNull( result );
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSubInLiteralsWithGroupReference() {
|
||||
String var = "TestVar";
|
||||
String target = "Fake n3 ?TestVar .";
|
||||
Literal literal = new EditLiteral("should not a regex group --> ?2 <-- blblkj (lskdfj) " ,null,null);
|
||||
|
||||
EditN3Generator en3g = new EditN3Generator((EditConfiguration) null);
|
||||
String result = en3g.subInLiterals(var, literal, target);
|
||||
Assert.assertNotNull( result );
|
||||
Assert.assertEquals("Fake n3 \"should not a regex group --> ?2 <-- blblkj (lskdfj) \" ." , result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConflictingVarNames(){
|
||||
Map<String,String> varToExisting= new HashMap<String,String>();
|
||||
varToExisting.put("bob", "http://uri.edu#BobTheElder");
|
||||
varToExisting.put("bobJr", "http://uri.edu#BobTheSon");
|
||||
|
||||
String target = "SELECT ?cat WHERE{ ?bobJr <http://uri.edu#hasCat> ?cat }" ;
|
||||
List<String> targets = new ArrayList<String>();
|
||||
targets.add(target);
|
||||
|
||||
List<String> out = en3g.subInUris(varToExisting, targets);
|
||||
Assert.assertNotNull(out);
|
||||
Assert.assertNotNull( out.get(0) );
|
||||
String expected = "SELECT ?cat WHERE{ <http://uri.edu#BobTheSon> <http://uri.edu#hasCat> ?cat }";
|
||||
Assert.assertEquals(expected, out.get(0) );
|
||||
|
||||
//force a non match on a initial-partial var name
|
||||
varToExisting= new HashMap<String,String>();
|
||||
varToExisting.put("bob", "http://uri.edu#BobTheElder");
|
||||
|
||||
target = "SELECT ?cat WHERE{ ?bobJr <http://uri.edu#hasCat> ?cat }" ;
|
||||
targets = new ArrayList<String>();
|
||||
targets.add(target);
|
||||
|
||||
out = en3g.subInUris(varToExisting, targets);
|
||||
Assert.assertNotNull(out);
|
||||
Assert.assertNotNull( out.get(0) );
|
||||
expected = target;
|
||||
Assert.assertEquals(expected, out.get(0) );
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import stubs.javax.servlet.http.HttpServletRequestStub;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
|
||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
|
||||
public class EditSubmissionTest extends AbstractTestClass {
|
||||
HttpServletRequestStub request;
|
||||
EditConfiguration editConfig;
|
||||
|
||||
@Before
|
||||
public void createEditConfig() throws IOException {
|
||||
InputStream is = this.getClass().getResourceAsStream(
|
||||
"testEditConfig.json");
|
||||
editConfig = new EditConfiguration(readAll(is));
|
||||
}
|
||||
|
||||
@Before
|
||||
public void createRequest() {
|
||||
request = new HttpServletRequestStub();
|
||||
|
||||
request.addParameter("yearfield222", "2001");
|
||||
request.addParameter("monthfield222", "10");
|
||||
request.addParameter("dayfield222", "13");
|
||||
request.addParameter("hourfield222", "11");
|
||||
request.addParameter("minutefield222", "00");
|
||||
|
||||
request.addParameter("talkName", "this is the name of a talk");
|
||||
|
||||
request.addParameter("room", "http://someBogusUri/#individual2323");
|
||||
request.addParameter("editKey", "fakeEditKey");
|
||||
}
|
||||
|
||||
public void testSetup() {
|
||||
Assert.assertNotNull("EditConfiguration is null", editConfig);
|
||||
Assert.assertNotNull("request must not be null", request);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDateTimeParameter() {
|
||||
EditSubmission editSub = new EditSubmission(request.getParameterMap(),
|
||||
editConfig);
|
||||
Literal field222 = editSub.getLiteralsFromForm().get("field222");
|
||||
Assert.assertNotNull(field222);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCanHandleMissingParameter() {
|
||||
/*
|
||||
* test if the EditSubmission can be passed a request which is missing a
|
||||
* parameter. This will be the case when a checkbox type input is not
|
||||
* selected.
|
||||
*/
|
||||
request.removeParameter("talkName");
|
||||
request.removeParameter("room");
|
||||
|
||||
// just trying to make this without an exception
|
||||
EditSubmission editSub = new EditSubmission(request.getParameterMap(),
|
||||
editConfig);
|
||||
Assert.assertNotNull(editSub);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,183 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
||||
|
||||
public class RdfLiteralHashTest {
|
||||
|
||||
final String TEST_VALUE ="this is a test literal string";
|
||||
final String TEST_DATA_PROP_URI ="http://this.is.a.test.uri.com/1999/02/blec-ns#test2332";
|
||||
final String TEST_INDIVIDUAL_URI ="http://this.is.a.testUri.com/1999/02/bleck-ns#INDIVIDUAL787878";
|
||||
final String TEST_DATA_TYPE_URI ="http://this.is.a.uri.com/TEST/DATA/TYPE#e8";
|
||||
final String TEST_LANG = "ENG";
|
||||
|
||||
@Test
|
||||
public void testEdBackground(){
|
||||
String value = "[CELE97] Waldemar Celes and Jonathan Corson-Rikert. "Act: An Easy-to-use and Dynamically Extensible 3D Graphics Library" in Proceedings, Brazilian Symposium on Computer Graphics and Image Processing, Campos do Jordao, SP -Brazil, October, 1997.";
|
||||
String propUri = "http://vivo.library.cornell.edu/ns/0.1#publications";
|
||||
String subject = "http://vivo.library.cornell.edu/ns/0.1#individual22972";
|
||||
String datatypeUri= null;
|
||||
String language = null;
|
||||
|
||||
DataPropertyStatement stmt = new DataPropertyStatementImpl();
|
||||
stmt.setIndividualURI(subject);
|
||||
stmt.setData(value);
|
||||
stmt.setDatapropURI(propUri);
|
||||
stmt.setDatatypeURI(datatypeUri);
|
||||
stmt.setLanguage(language);
|
||||
|
||||
int hash = RdfLiteralHash.makeRdfLiteralHash( stmt);
|
||||
Assert.assertTrue(hash != 0);
|
||||
Assert.assertEquals(1646037091 , hash);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMakeRdfLiteralHash() {
|
||||
DataPropertyStatement stmt = new DataPropertyStatementImpl();
|
||||
|
||||
stmt.setData(TEST_VALUE);
|
||||
stmt.setDatapropURI(TEST_DATA_PROP_URI);
|
||||
stmt.setIndividualURI(TEST_INDIVIDUAL_URI);
|
||||
int hash = RdfLiteralHash.makeRdfLiteralHash(stmt);
|
||||
Assert.assertTrue(hash != 0);
|
||||
|
||||
stmt = new DataPropertyStatementImpl();
|
||||
stmt.setData(TEST_VALUE);
|
||||
stmt.setDatapropURI(TEST_DATA_PROP_URI);
|
||||
stmt.setIndividualURI(TEST_INDIVIDUAL_URI);
|
||||
stmt.setDatatypeURI(TEST_DATA_TYPE_URI);
|
||||
hash = RdfLiteralHash.makeRdfLiteralHash(stmt);
|
||||
Assert.assertTrue(hash != 0);
|
||||
|
||||
stmt = new DataPropertyStatementImpl();
|
||||
stmt.setData(TEST_VALUE);
|
||||
stmt.setDatapropURI(TEST_DATA_PROP_URI);
|
||||
stmt.setIndividualURI(TEST_INDIVIDUAL_URI);
|
||||
stmt.setLanguage(TEST_LANG);
|
||||
hash = RdfLiteralHash.makeRdfLiteralHash(stmt);
|
||||
Assert.assertTrue(hash != 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoesStmtMatchHash() {
|
||||
DataPropertyStatement stmtA = new DataPropertyStatementImpl();
|
||||
DataPropertyStatement stmtB = new DataPropertyStatementImpl();
|
||||
int expectedHash = 0;
|
||||
|
||||
|
||||
stmtA.setData(TEST_VALUE);
|
||||
stmtA.setDatapropURI(TEST_DATA_PROP_URI);
|
||||
stmtA.setIndividualURI(TEST_INDIVIDUAL_URI);
|
||||
expectedHash = RdfLiteralHash.makeRdfLiteralHash(stmtA);
|
||||
stmtB.setData(TEST_VALUE);
|
||||
stmtB.setDatapropURI(TEST_DATA_PROP_URI);
|
||||
stmtB.setIndividualURI(TEST_INDIVIDUAL_URI);
|
||||
Assert.assertTrue(expectedHash == RdfLiteralHash.makeRdfLiteralHash(stmtB) );
|
||||
Assert.assertTrue( RdfLiteralHash.doesStmtMatchHash(stmtB, expectedHash));
|
||||
|
||||
|
||||
stmtA = new DataPropertyStatementImpl();
|
||||
stmtA.setData(TEST_VALUE);
|
||||
stmtA.setDatapropURI(TEST_DATA_PROP_URI);
|
||||
stmtA.setIndividualURI(TEST_INDIVIDUAL_URI);
|
||||
stmtA.setDatatypeURI(TEST_DATA_TYPE_URI);
|
||||
expectedHash = RdfLiteralHash.makeRdfLiteralHash(stmtA);
|
||||
stmtB = new DataPropertyStatementImpl();
|
||||
stmtB.setData(TEST_VALUE);
|
||||
stmtB.setDatapropURI(TEST_DATA_PROP_URI);
|
||||
stmtB.setIndividualURI(TEST_INDIVIDUAL_URI);
|
||||
stmtB.setDatatypeURI(TEST_DATA_TYPE_URI);
|
||||
Assert.assertTrue( expectedHash == RdfLiteralHash.makeRdfLiteralHash(stmtB) );
|
||||
Assert.assertTrue( RdfLiteralHash.doesStmtMatchHash(stmtB, expectedHash));
|
||||
|
||||
stmtA = new DataPropertyStatementImpl();
|
||||
stmtA.setData(TEST_VALUE);
|
||||
stmtA.setDatapropURI(TEST_DATA_PROP_URI);
|
||||
stmtA.setIndividualURI(TEST_INDIVIDUAL_URI);
|
||||
stmtA.setLanguage(TEST_LANG);
|
||||
expectedHash = RdfLiteralHash.makeRdfLiteralHash(stmtA);
|
||||
stmtB = new DataPropertyStatementImpl();
|
||||
stmtB.setData(TEST_VALUE);
|
||||
stmtB.setDatapropURI(TEST_DATA_PROP_URI);
|
||||
stmtB.setIndividualURI(TEST_INDIVIDUAL_URI);
|
||||
stmtB.setLanguage(TEST_LANG);
|
||||
Assert.assertTrue( expectedHash == RdfLiteralHash.makeRdfLiteralHash(stmtB) );
|
||||
Assert.assertTrue( RdfLiteralHash.doesStmtMatchHash(stmtB, expectedHash));
|
||||
|
||||
Assert.assertTrue( ! RdfLiteralHash.doesStmtMatchHash(null, expectedHash) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataPropertyStmtByHash() {
|
||||
DataPropertyStatement stmtA = new DataPropertyStatementImpl();
|
||||
IndividualImpl ind = new IndividualImpl();
|
||||
List<DataPropertyStatement> stmts = new ArrayList<DataPropertyStatement>();
|
||||
|
||||
int expectedHash = 0;
|
||||
|
||||
//test to see if the same subURI, predURI and Value can be distinguished by LANG/datatype
|
||||
stmtA.setData(TEST_VALUE);
|
||||
stmtA.setDatapropURI(TEST_DATA_PROP_URI);
|
||||
stmtA.setIndividualURI(TEST_INDIVIDUAL_URI);
|
||||
stmts.add(stmtA);
|
||||
int expectedHashForSimpleStmt = RdfLiteralHash.makeRdfLiteralHash(stmtA);
|
||||
|
||||
stmtA = new DataPropertyStatementImpl();
|
||||
stmtA.setData(TEST_VALUE );
|
||||
stmtA.setDatapropURI(TEST_DATA_PROP_URI);
|
||||
stmtA.setIndividualURI(TEST_INDIVIDUAL_URI);
|
||||
stmtA.setDatatypeURI(TEST_DATA_TYPE_URI);
|
||||
int expectedHashForDatatypeStmt = RdfLiteralHash.makeRdfLiteralHash(stmtA);
|
||||
stmts.add(stmtA);
|
||||
|
||||
stmtA = new DataPropertyStatementImpl();
|
||||
stmtA.setData(TEST_VALUE );
|
||||
stmtA.setDatapropURI(TEST_DATA_PROP_URI);
|
||||
stmtA.setIndividualURI(TEST_INDIVIDUAL_URI);
|
||||
stmtA.setLanguage(TEST_LANG);
|
||||
int expectedHashForLangStmt = RdfLiteralHash.makeRdfLiteralHash(stmtA);
|
||||
stmts.add(stmtA);
|
||||
|
||||
ind.setDataPropertyStatements(stmts);
|
||||
|
||||
DataPropertyStatement stmt = RdfLiteralHash.getDataPropertyStmtByHash(ind, expectedHashForLangStmt);
|
||||
Assert.assertNotNull(stmt);
|
||||
Assert.assertEquals(TEST_DATA_PROP_URI, stmt.getDatapropURI() );
|
||||
Assert.assertEquals(TEST_INDIVIDUAL_URI, stmt.getIndividualURI() );
|
||||
Assert.assertEquals(TEST_LANG, stmt.getLanguage() );
|
||||
Assert.assertEquals(TEST_VALUE, stmt.getData() );
|
||||
Assert.assertNull(stmt.getDatatypeURI());
|
||||
|
||||
stmt = RdfLiteralHash.getDataPropertyStmtByHash(ind, expectedHashForSimpleStmt);
|
||||
Assert.assertNotNull(stmt);
|
||||
Assert.assertEquals(TEST_DATA_PROP_URI, stmt.getDatapropURI() );
|
||||
Assert.assertEquals(TEST_INDIVIDUAL_URI, stmt.getIndividualURI() );
|
||||
Assert.assertEquals(TEST_VALUE, stmt.getData() );
|
||||
Assert.assertNull(stmt.getDatatypeURI());
|
||||
Assert.assertNull(stmt.getLanguage());
|
||||
|
||||
stmt = RdfLiteralHash.getDataPropertyStmtByHash(ind, expectedHashForDatatypeStmt);
|
||||
Assert.assertNotNull(stmt);
|
||||
Assert.assertEquals(TEST_DATA_PROP_URI, stmt.getDatapropURI() );
|
||||
Assert.assertEquals(TEST_INDIVIDUAL_URI, stmt.getIndividualURI() );
|
||||
Assert.assertEquals(TEST_VALUE, stmt.getData() );
|
||||
Assert.assertEquals(TEST_DATA_TYPE_URI, stmt.getDatatypeURI() );
|
||||
Assert.assertNull(stmt.getLanguage());
|
||||
|
||||
|
||||
stmt = RdfLiteralHash.getDataPropertyStmtByHash(ind, 111111);
|
||||
Assert.assertNull(stmt);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
|
||||
public class SparqlEvaluateTest {
|
||||
SparqlEvaluate sEval;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
EditConfiguration edConfig = new EditConfiguration();
|
||||
|
||||
Model model = ModelFactory.createDefaultModel(); //just used to parse sparql
|
||||
sEval = new SparqlEvaluate(model);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForNoSolution() {
|
||||
String uri = sEval.queryToUri("SELECT ?cat WHERE { ?cat <http://cornell.edu#hasOwner> <http://cornell.edu#bdc34>} ");
|
||||
Assert.assertNull( uri );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
{
|
||||
"formUrl" : "${formUrl}",
|
||||
"editKey" : "${editKey}",
|
||||
|
||||
"subject" : ["series", "${subjectUriJson}", ],
|
||||
"predicate" : ["predicate", "${predicateUriJson}" ],
|
||||
"object" : ["talk", "${objectUriJson}", "URI" ],
|
||||
|
||||
"urlPatternToReturnTo" : "/entity",
|
||||
"n3required" : [ ],
|
||||
"n3optional" : [ ],
|
||||
"newResources" : { "talk" : "http://vivo.library.cornell.edu/ns/0.1#individual" },
|
||||
"urisInScope" : { },
|
||||
"literalsInScope": { },
|
||||
"urisOnForm" : ["room"],
|
||||
"literalsOnForm" : [ "talkName", "field222" ],
|
||||
"sparqlForLiterals" : { },
|
||||
"sparqlForUris" : { },
|
||||
"sparqlForExistingLiterals" : { },
|
||||
"sparqlForExistingUris" : { },
|
||||
"filesOnForm" : [ ],
|
||||
"fields" : {
|
||||
"talkName" : {
|
||||
"newResource" : "false",
|
||||
"validators" : [ "nonempty" ],
|
||||
"optionsType" : "UNDEFINED",
|
||||
"literalOptions" : [],
|
||||
"subjectUri" : "${param.subjectUri}",
|
||||
"subjectClassUri" : "",
|
||||
"predicateUri" : "",
|
||||
"objectClassUri" : "",
|
||||
"rangeDatatypeUri" : "",
|
||||
"rangeLang" :"",
|
||||
"assertions" : [ ]
|
||||
},
|
||||
|
||||
"room" : {
|
||||
"newResource" : "false",
|
||||
"validators" : [ ],
|
||||
"optionsType" : "INDIVIDUALS_VIA_OBJECT_PROPERTY",
|
||||
"literalOptions" : [" (none)"],
|
||||
"subjectUri" : "${param.subjectUri}",
|
||||
"subjectClassUri" : "",
|
||||
"predicateUri" : "${heldInObjProp}",
|
||||
"objectClassUri" : "${buildingClass}",
|
||||
"rangeDatatypeUri" : "",
|
||||
"rangeLang" :"",
|
||||
"assertions" : [ ]
|
||||
} ,
|
||||
"field222" : {
|
||||
"newResource" : "false",
|
||||
"validators" : [ ],
|
||||
"optionsType" : "DATETIME",
|
||||
"literalOptions" : [],
|
||||
"subjectUri" : "${param.subjectUri}",
|
||||
"subjectClassUri" : "",
|
||||
"predicateUri" : "",
|
||||
"objectClassUri" : "",
|
||||
"rangeDatatypeUri" : "",
|
||||
"rangeLang" :"",
|
||||
"assertions" : [ ]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.test;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
|
||||
/**
|
||||
* this is a class to load owl files for testing.
|
||||
* @author bdc34
|
||||
*
|
||||
*/
|
||||
public class JenaOntologyLoader {
|
||||
public OntModel ontModel = null;
|
||||
|
||||
/**
|
||||
* This should load the system with classes, data properties and
|
||||
* object properties that the vitro systems needs.
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
OntModel loadSystemAndUsers() throws Exception{
|
||||
Model model = ModelFactory.createDefaultModel();
|
||||
for( String ont : systemOnts){
|
||||
InputStream in = this.getClass().getResourceAsStream(ont);
|
||||
model.read(in,null);
|
||||
in.close();
|
||||
}
|
||||
ontModel = ModelFactory.createOntologyModel(ONT_MODEL_SPEC,model);
|
||||
ontModel.prepare();
|
||||
return ontModel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads a owl file into the ontModel. Looks for files on classpath.
|
||||
* example: loadSpecialVivoModel("/testontologies/smallVivo-20070809.owl")
|
||||
*
|
||||
* @param junk
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
OntModel loadSpecialVivoModel(String junk) throws IOException{
|
||||
InputStream in = this.getClass().getResourceAsStream(junk);
|
||||
Model model = ModelFactory.createDefaultModel();
|
||||
model.read(in,null);
|
||||
in.close();
|
||||
|
||||
ontModel.add(model);
|
||||
ontModel.prepare();
|
||||
return ontModel;
|
||||
}
|
||||
|
||||
static String systemOnts[] ={
|
||||
"/testontologies/vitro1.owl",
|
||||
"/testontologies/vivo-users.owl" };
|
||||
|
||||
static String testOnt[] ={
|
||||
"/testontologies/smallVivo-20070809.owl" };
|
||||
|
||||
static OntModelSpec ONT_MODEL_SPEC = OntModelSpec.OWL_DL_MEM; // no additional entailment reasoning
|
||||
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.utils;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import net.sf.jga.fn.UnaryFunctor;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Tab;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.FiltersForTabs;
|
||||
|
||||
/**
|
||||
* User: bdc34
|
||||
* Date: Dec 13, 2007
|
||||
* Time: 2:47:03 PM
|
||||
*/
|
||||
public class FiltersForTabsTest {
|
||||
|
||||
@Before
|
||||
public void setup(){
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCollegeFiltering(){
|
||||
String flags [] = {"CALS","BOAK","FUNGORK","MACAWI"};
|
||||
UnaryFunctor<Individual,Boolean> testFn =
|
||||
FiltersForTabs.getCollegeFilter(flags);
|
||||
Assert.assertTrue ( testFn!=null);
|
||||
|
||||
IndividualImpl ind = new IndividualImpl();
|
||||
Assert.assertTrue(testFn.fn(ind) == false);
|
||||
|
||||
ind.setFlag2Set("BOAK");
|
||||
Assert.assertTrue( testFn.fn(ind) == true);
|
||||
|
||||
ind.setFlag2Set("");
|
||||
Assert.assertTrue(testFn.fn(ind) == false);
|
||||
|
||||
ind.setFlag2Set("CALS,BOAK,FUNGORK");
|
||||
Assert.assertTrue(testFn.fn(ind) == true);
|
||||
|
||||
ind.setFlag2Set("FINKLY,HAPTO,FOOTOP");
|
||||
Assert.assertTrue(testFn.fn(ind) == false);
|
||||
|
||||
ind.setFlag2Set("FINKLY,HAPTO,FOOTOP,CALS");
|
||||
Assert.assertTrue(testFn.fn(ind) == true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCollegeFilterCreation(){
|
||||
Tab tab = new Tab();
|
||||
tab.setFlag2Set("CALS,BOAK,FUNGORK");
|
||||
tab.setPortalId(7);
|
||||
|
||||
UnaryFunctor<Individual,Boolean> testFn =
|
||||
FiltersForTabs.getFilterForTab(tab, new Portal());
|
||||
Assert.assertTrue ( testFn!=null);
|
||||
|
||||
|
||||
IndividualImpl ind = new IndividualImpl();
|
||||
Assert.assertFalse( testFn.fn( ind) );
|
||||
|
||||
ind.setFlag2Set("CALS");
|
||||
ind.setFlag1Numeric((int)FlagMathUtils.portalId2Numeric( tab.getPortalId() ));
|
||||
|
||||
DateTime dt = new DateTime();
|
||||
ind.setSunrise(dt.minusDays(1000).toDate());
|
||||
ind.setSunset(dt.plusDays(1000).toDate());
|
||||
Assert.assertTrue( testFn.fn( ind));
|
||||
|
||||
tab.setFlag2Mode("OMIT");
|
||||
testFn = FiltersForTabs.getFilterForTab(tab, new Portal());
|
||||
|
||||
Assert.assertFalse( testFn.fn(ind));
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.utils;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils.bits2Numeric;
|
||||
import static edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils.numeric2Portalid;
|
||||
import static edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils.numeric2numerics;
|
||||
import static edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils.portalId2Numeric;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static junit.framework.Assert.fail;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
|
||||
/**
|
||||
* @author jeb228
|
||||
*/
|
||||
public class FlagMathUtilsTest extends AbstractTestClass {
|
||||
|
||||
@Test
|
||||
public void testBits2Num() {
|
||||
boolean[] bits = { false, false, false, false };
|
||||
assertEquals(0, bits2Numeric(bits));
|
||||
|
||||
boolean[] bits2 = { true, false, false, false };
|
||||
assertEquals(1, bits2Numeric(bits2));
|
||||
|
||||
boolean[] bits3 = { true, true, false, false };
|
||||
assertEquals(3, bits2Numeric(bits3));
|
||||
|
||||
boolean[] bits4 = { true, false, false, true };
|
||||
assertEquals(1 + 8, bits2Numeric(bits4));
|
||||
|
||||
boolean[] bits5 = { false, false, false, true };
|
||||
assertEquals(8, bits2Numeric(bits5));
|
||||
|
||||
boolean[] bits6 = { true, true, true, true };
|
||||
assertEquals(1 + 2 + 4 + 8, bits2Numeric(bits6));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNumeric2numerics() {
|
||||
Long[] num0 = { new Long(1), new Long(2), new Long(4), new Long(8) };
|
||||
assertTrue(Arrays.equals(num0, numeric2numerics(1 + 2 + 4 + 8)));
|
||||
|
||||
Long[] num1 = { new Long(1) };
|
||||
assertTrue(Arrays.equals(num1, numeric2numerics(1)));
|
||||
|
||||
Long[] num2 = {};
|
||||
assertTrue(Arrays.equals(num2, numeric2numerics(0)));
|
||||
|
||||
Long[] num3 = { new Long(1), new Long(8) };
|
||||
assertTrue(Arrays.equals(num3, numeric2numerics(1 + 8)));
|
||||
|
||||
Long[] num4 = { new Long(4), new Long(8) };
|
||||
assertTrue(Arrays.equals(num4, numeric2numerics(4 + 8)));
|
||||
|
||||
Long[] num5 = { new Long(8) };
|
||||
assertTrue(Arrays.equals(num5, numeric2numerics(8)));
|
||||
|
||||
Long[] num6 = { new Long(2), new Long(4) };
|
||||
assertTrue(Arrays.equals(num6, numeric2numerics(2 + 4)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNumeric2Portalid() {
|
||||
assertEquals(0, numeric2Portalid(1));
|
||||
assertEquals(1, numeric2Portalid(2));
|
||||
assertEquals(2, numeric2Portalid(4));
|
||||
assertEquals(3, numeric2Portalid(8));
|
||||
assertEquals(4, numeric2Portalid(16));
|
||||
assertEquals(5, numeric2Portalid(32));
|
||||
assertEquals(6, numeric2Portalid(64));
|
||||
assertEquals(7, numeric2Portalid(128));
|
||||
assertEquals(8, numeric2Portalid(256));
|
||||
|
||||
// make sure we throw errors on bad inputs
|
||||
try {
|
||||
numeric2Portalid(0);
|
||||
fail("should have thrown Error");
|
||||
} catch (Throwable e) {
|
||||
}
|
||||
try {
|
||||
numeric2Portalid(3);
|
||||
fail("should have thrown Error");
|
||||
} catch (Throwable e) {
|
||||
}
|
||||
try {
|
||||
numeric2Portalid(15);
|
||||
fail("should have thrown Error");
|
||||
} catch (Throwable e) {
|
||||
}
|
||||
try {
|
||||
numeric2Portalid(21);
|
||||
fail("should have thrown Error");
|
||||
} catch (Throwable e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPortalId2Num() {
|
||||
assertEquals(2, portalId2Numeric(1));
|
||||
assertEquals(4, portalId2Numeric(2));
|
||||
assertEquals(8, portalId2Numeric(3));
|
||||
assertEquals(16, portalId2Numeric(4));
|
||||
assertEquals(32, portalId2Numeric(5));
|
||||
assertEquals(64, portalId2Numeric(6));
|
||||
assertEquals(128, portalId2Numeric(7));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBackAndForth() {
|
||||
for (long i = 1; i < Long.SIZE - 1; i++) {
|
||||
long num = portalId2Numeric(i);
|
||||
int portal = numeric2Portalid(num);
|
||||
assertEquals(i, portal);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.utils;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
|
||||
/**
|
||||
* User: jc55
|
||||
* Date: August 22, 2008
|
||||
* Time: 4:37 PM
|
||||
*/
|
||||
public class MakeTidyTest extends AbstractTestClass {
|
||||
@Before
|
||||
public void suppressOutputMessage() {
|
||||
suppressSysout();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTidy(){
|
||||
String inputStr = "<p garbage here/><ul><li>list element one</li><li>list element two</li></ul></p";
|
||||
String expected = "<ul><li>list element one</li><li>list element two</li></ul>";
|
||||
|
||||
MakeTidy tidy = new MakeTidy();
|
||||
assertEquivalentXmlDocs(expected, tidy.process(inputStr));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.utils.jena;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Statement;
|
||||
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||
import com.hp.hpl.jena.vocabulary.OWL;
|
||||
import com.hp.hpl.jena.vocabulary.RDF;
|
||||
|
||||
public class JenaIngestUtilsTest extends AbstractTestClass {
|
||||
|
||||
@Test
|
||||
public void testRenameBNodes() {
|
||||
|
||||
JenaIngestUtils jiu = new JenaIngestUtils();
|
||||
|
||||
Model blankModel = ModelFactory.createDefaultModel();
|
||||
for (int i = 0; i < 20; i++) {
|
||||
blankModel.add(blankModel.createResource(), RDF.type, OWL.Thing);
|
||||
}
|
||||
Assert.assertTrue(blankModel.size() == 20);
|
||||
|
||||
Model named = jiu.renameBNodes(blankModel, "http://example.org/resource");
|
||||
Assert.assertTrue(named.size() == blankModel.size());
|
||||
Assert.assertTrue(named.size() == 20);
|
||||
|
||||
StmtIterator stmtIt = named.listStatements();
|
||||
while (stmtIt.hasNext()) {
|
||||
Statement stmt = stmtIt.nextStatement();
|
||||
Assert.assertEquals("http://example.org/", stmt.getSubject().getNameSpace());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
package edu.cornell.mannlib.vitro.webapp.web.jsptags;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.web.jsptags.PropertyEditLinks.EditLinkAccess;
|
||||
|
||||
public class PropertyEditLinksTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testDoDataProp() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testDoObjProp() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testDoDataPropStmt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testDoObjPropStmt() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMakeRelativeHrefStringStringArray() {
|
||||
Assert.assertEquals("base?bob=true", PropertyEditLinks.makeRelativeHref("base","bob","true"));
|
||||
Assert.assertEquals("base?bob=true+enough", PropertyEditLinks.makeRelativeHref("base","bob","true enough"));
|
||||
Assert.assertEquals("base?bob=where+did+you+go%3F",PropertyEditLinks.makeRelativeHref("base","bob","where did you go?"));
|
||||
|
||||
Assert.assertEquals("base?bob=true&hank=false",
|
||||
PropertyEditLinks.makeRelativeHref("base","bob","true","hank","false"));
|
||||
|
||||
Assert.assertEquals("base?bob=true&hank=he%27s+great+and+all&sue=%26%24%24%25%5E%40%40%40%09%40%24%5E%25+",PropertyEditLinks.makeRelativeHref("base","bob","true","hank","he's great and all", "sue","&$$%^@@@\t@$^% "));
|
||||
Assert.assertEquals("base/hats/gloves.jsp?bob=true",PropertyEditLinks.makeRelativeHref("base/hats/gloves.jsp","bob","true"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unescapedUrl(){
|
||||
Assert.assertEquals(
|
||||
"edit/editRequestDispatch.jsp?subjectUri=http%3A%2F%2Fvivo.library.cornell.edu%2Fns%2F0.1%23CarusoBrian&predicateUri=http%3A%2F%2Fvivo.library.cornell.edu%2Fns%2F0.1%23isActivityAdvisorFor&defaultForm=true",
|
||||
PropertyEditLinks.makeRelativeHref(
|
||||
"edit/editRequestDispatch.jsp",
|
||||
"subjectUri" ,
|
||||
"http://vivo.library.cornell.edu/ns/0.1#CarusoBrian",
|
||||
"predicateUri" ,
|
||||
"http://vivo.library.cornell.edu/ns/0.1#isActivityAdvisorFor",
|
||||
"defaultForm" ,
|
||||
"true"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContains() {
|
||||
EditLinkAccess[] access = {EditLinkAccess.ADDNEW , EditLinkAccess.MODIFY };
|
||||
Assert.assertTrue(PropertyEditLinks.contains(access, EditLinkAccess.ADDNEW));
|
||||
Assert.assertTrue(PropertyEditLinks.contains(access, EditLinkAccess.MODIFY));
|
||||
Assert.assertTrue( ! PropertyEditLinks.contains(access, EditLinkAccess.DELETE));
|
||||
Assert.assertTrue( ! PropertyEditLinks.contains(access, null));
|
||||
Assert.assertTrue( ! PropertyEditLinks.contains(null , EditLinkAccess.MODIFY));
|
||||
Assert.assertTrue( ! PropertyEditLinks.contains(null, null));
|
||||
}
|
||||
|
||||
}
|
343
webapp/test/stubs/javax/servlet/http/HttpServletRequestStub.java
Normal file
343
webapp/test/stubs/javax/servlet/http/HttpServletRequestStub.java
Normal file
|
@ -0,0 +1,343 @@
|
|||
package stubs.javax.servlet.http;
|
||||
|
||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.Principal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletInputStream;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jeb228
|
||||
*/
|
||||
public class HttpServletRequestStub implements HttpServletRequest {
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub infrastructure
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private final Map<String, List<String>> parameters;
|
||||
private final Map<String, Object> attributes;
|
||||
|
||||
public HttpServletRequestStub(Map<String, List<String>> parameters,
|
||||
Map<String, Object> attributes) {
|
||||
this();
|
||||
this.parameters.putAll(parameters);
|
||||
this.attributes.putAll(attributes);
|
||||
}
|
||||
|
||||
public HttpServletRequestStub() {
|
||||
parameters = new HashMap<String, List<String>>();
|
||||
attributes = new HashMap<String, Object>();
|
||||
}
|
||||
|
||||
public void addParameter(String name, String value) {
|
||||
if (!parameters.containsKey(name)) {
|
||||
parameters.put(name, new ArrayList<String>());
|
||||
}
|
||||
parameters.get(name).add(value);
|
||||
}
|
||||
|
||||
/** Clear all values for a given parameter name. */
|
||||
public void removeParameter(String name) {
|
||||
parameters.remove(name);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public String getParameter(String name) {
|
||||
if (!parameters.containsKey(name)) {
|
||||
return null;
|
||||
}
|
||||
return parameters.get(name).get(0);
|
||||
}
|
||||
|
||||
public Map getParameterMap() {
|
||||
Map<String,String[]> map = new HashMap<String,String[]>();
|
||||
for( String key : parameters.keySet() ){
|
||||
map.put(key, parameters.get(key).toArray(new String[0]));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public String getAuthType() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getAuthType() not implemented.");
|
||||
}
|
||||
|
||||
public String getContextPath() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getContextPath() not implemented.");
|
||||
}
|
||||
|
||||
public Cookie[] getCookies() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getCookies() not implemented.");
|
||||
}
|
||||
|
||||
public long getDateHeader(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getDateHeader() not implemented.");
|
||||
}
|
||||
|
||||
public String getHeader(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getHeader() not implemented.");
|
||||
}
|
||||
|
||||
public Enumeration getHeaderNames() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getHeaderNames() not implemented.");
|
||||
}
|
||||
|
||||
public Enumeration getHeaders(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getHeaders() not implemented.");
|
||||
}
|
||||
|
||||
public int getIntHeader(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getIntHeader() not implemented.");
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getMethod() not implemented.");
|
||||
}
|
||||
|
||||
public String getPathInfo() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getPathInfo() not implemented.");
|
||||
}
|
||||
|
||||
public String getPathTranslated() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getPathTranslated() not implemented.");
|
||||
}
|
||||
|
||||
public String getQueryString() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getQueryString() not implemented.");
|
||||
}
|
||||
|
||||
public String getRemoteUser() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getRemoteUser() not implemented.");
|
||||
}
|
||||
|
||||
public String getRequestURI() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getRequestURI() not implemented.");
|
||||
}
|
||||
|
||||
public StringBuffer getRequestURL() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getRequestURL() not implemented.");
|
||||
}
|
||||
|
||||
public String getRequestedSessionId() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getRequestedSessionId() not implemented.");
|
||||
}
|
||||
|
||||
public String getServletPath() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getServletPath() not implemented.");
|
||||
}
|
||||
|
||||
public HttpSession getSession() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getSession() not implemented.");
|
||||
}
|
||||
|
||||
public HttpSession getSession(boolean arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getSession() not implemented.");
|
||||
}
|
||||
|
||||
public Principal getUserPrincipal() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getUserPrincipal() not implemented.");
|
||||
}
|
||||
|
||||
public boolean isRequestedSessionIdFromCookie() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.isRequestedSessionIdFromCookie() not implemented.");
|
||||
}
|
||||
|
||||
public boolean isRequestedSessionIdFromURL() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.isRequestedSessionIdFromURL() not implemented.");
|
||||
}
|
||||
|
||||
public boolean isRequestedSessionIdFromUrl() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.isRequestedSessionIdFromUrl() not implemented.");
|
||||
}
|
||||
|
||||
public boolean isRequestedSessionIdValid() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.isRequestedSessionIdValid() not implemented.");
|
||||
}
|
||||
|
||||
public boolean isUserInRole(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.isUserInRole() not implemented.");
|
||||
}
|
||||
|
||||
public Object getAttribute(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getAttribute() not implemented.");
|
||||
}
|
||||
|
||||
public Enumeration getAttributeNames() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getAttributeNames() not implemented.");
|
||||
}
|
||||
|
||||
public String getCharacterEncoding() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getCharacterEncoding() not implemented.");
|
||||
}
|
||||
|
||||
public int getContentLength() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getContentLength() not implemented.");
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getContentType() not implemented.");
|
||||
}
|
||||
|
||||
public ServletInputStream getInputStream() throws IOException {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getInputStream() not implemented.");
|
||||
}
|
||||
|
||||
public String getLocalAddr() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getLocalAddr() not implemented.");
|
||||
}
|
||||
|
||||
public String getLocalName() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getLocalName() not implemented.");
|
||||
}
|
||||
|
||||
public int getLocalPort() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getLocalPort() not implemented.");
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getLocale() not implemented.");
|
||||
}
|
||||
|
||||
public Enumeration getLocales() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getLocales() not implemented.");
|
||||
}
|
||||
|
||||
public Enumeration getParameterNames() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getParameterNames() not implemented.");
|
||||
}
|
||||
|
||||
public String[] getParameterValues(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getParameterValues() not implemented.");
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getProtocol() not implemented.");
|
||||
}
|
||||
|
||||
public BufferedReader getReader() throws IOException {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getReader() not implemented.");
|
||||
}
|
||||
|
||||
public String getRealPath(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getRealPath() not implemented.");
|
||||
}
|
||||
|
||||
public String getRemoteAddr() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getRemoteAddr() not implemented.");
|
||||
}
|
||||
|
||||
public String getRemoteHost() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getRemoteHost() not implemented.");
|
||||
}
|
||||
|
||||
public int getRemotePort() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getRemotePort() not implemented.");
|
||||
}
|
||||
|
||||
public RequestDispatcher getRequestDispatcher(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getRequestDispatcher() not implemented.");
|
||||
}
|
||||
|
||||
public String getScheme() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getScheme() not implemented.");
|
||||
}
|
||||
|
||||
public String getServerName() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getServerName() not implemented.");
|
||||
}
|
||||
|
||||
public int getServerPort() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.getServerPort() not implemented.");
|
||||
}
|
||||
|
||||
public boolean isSecure() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.isSecure() not implemented.");
|
||||
}
|
||||
|
||||
public void removeAttribute(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.removeAttribute() not implemented.");
|
||||
}
|
||||
|
||||
public void setAttribute(String arg0, Object arg1) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.setAttribute() not implemented.");
|
||||
}
|
||||
|
||||
public void setCharacterEncoding(String arg0)
|
||||
throws UnsupportedEncodingException {
|
||||
throw new RuntimeException(
|
||||
"HttpServletRequestStub.setCharacterEncoding() not implemented.");
|
||||
}
|
||||
|
||||
}
|
5109
webapp/test/testontologies/smallVivo-20070809.owl
Normal file
5109
webapp/test/testontologies/smallVivo-20070809.owl
Normal file
File diff suppressed because one or more lines are too long
203
webapp/test/testontologies/vitro1.owl
Normal file
203
webapp/test/testontologies/vitro1.owl
Normal file
|
@ -0,0 +1,203 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rdf:RDF
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
|
||||
xmlns:owl="http://www.w3.org/2002/07/owl#"
|
||||
xmlns:vitro="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#"
|
||||
xmlns:akts="http://www.aktors.org/ontology/support#"
|
||||
xmlns:aktp="http://www.aktors.org/ontology/portal#"
|
||||
xmlns:hr="http://vivo.cornell.edu/ns/hr/0.9/hr.owl#"
|
||||
xmlns:mann="http://vivo.cornell.edu/ns/mannadditions/0.1#"
|
||||
xmlns:socsci="http://vivo.library.cornell.edu/ns/vivo/socsci/0.1/socsci.owl"
|
||||
xmlns:thomson="info:/fake/nsuri/for/Thomson/wos"
|
||||
xmlns:vivoa="http://vivo.library.cornell.edu/abox#"
|
||||
xmlns:vivo="http://vivo.library.cornell.edu/ns/0.1#"
|
||||
>
|
||||
|
||||
<owl:Ontology rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl">
|
||||
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Vitro internals</rdfs:label>
|
||||
</owl:Ontology>
|
||||
|
||||
<!-- externalIDs -->
|
||||
|
||||
<owl:DatatypeProperty rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#externalID"/>
|
||||
|
||||
|
||||
<!-- begin BJL afterthoughts -->
|
||||
|
||||
<owl:AnnotationProperty rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#descriptionAnnot"/>
|
||||
<owl:AnnotationProperty rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#shortDef"/>
|
||||
<owl:AnnotationProperty rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#example"/>
|
||||
<owl:AnnotationProperty rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#displayLimit"/>
|
||||
<owl:AnnotationProperty rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#hidden"/>
|
||||
|
||||
<!-- begin Pellet additions -->
|
||||
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#moreTag">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#PrimaryTabContent">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#linkedEntity">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#Collection">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#entitySortField">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#rootTab">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#flag3Set">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#MixedTab">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#SubcollectionCategory">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#rssUrl">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#bannerImage">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#inPortal">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#rootBreadCrumbAnchor">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#flag2Set">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#entitySortDirection">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#contactMail">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#flag2Mode">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#urlPrefix">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#dayLimit">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#galleryRows">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#aboutText">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#imageWidth">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#flag3SearchFiltering">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#PrimaryTab">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#Portal">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#flag2SearchFiltering">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#statusId">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#Subcollection">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#tabBody">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#logotypeWidth">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#galleryCols">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#subTabOf">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#modTime">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#rootBreadCrumbURL">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#AutoLinkableTab">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#copyrightURL">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#autoLinkedToTab">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#AnnotationProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#shortHand">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#copyrightAnchor">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#imageThumbWidth">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#Tab">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#flag3Numeric">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#sunset">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#logotypeImage">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#flag3Mode">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#acknowledgeText">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#themeDir">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#SecondaryTab">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#ManuallyLinkableTab">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#flag2Numeric">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#bannerHeight">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#flag1SearchFiltering">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#sunrise">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
<rdf:Description rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#bannerWidth">
|
||||
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
|
||||
</rdf:Description>
|
||||
|
||||
<!-- end Pellet additions -->
|
||||
|
||||
</rdf:RDF>
|
36
webapp/test/testontologies/vivo-users.owl
Normal file
36
webapp/test/testontologies/vivo-users.owl
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
|
||||
xmlns:owl="http://www.w3.org/2002/07/owl#"
|
||||
xmlns:vitro="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#"
|
||||
xmlns="http://vivo.library.cornell.edu/ns/0.1#">
|
||||
|
||||
<owl:DatatypeProperty rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#username"/>
|
||||
<owl:DatatypeProperty rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#md5password"/>
|
||||
<owl:DatatypeProperty rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#oldpassword"/>
|
||||
<owl:DatatypeProperty rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#modTime"/>
|
||||
<owl:DatatypeProperty rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#firstTime"/>
|
||||
<owl:DatatypeProperty rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#loginCount"/>
|
||||
<owl:DatatypeProperty rdf:about="http://lowe.mannlib.cornell.edu/ns/vitro/0.1/vitro.owl#roleURI"/>
|
||||
|
||||
<vitro:User rdf:about="#bjl23">
|
||||
<vitro:username rdf:datatype="http://www.w3.org/2001/XMLSchema#string">bjl23</vitro:username>
|
||||
<vitro:md5password rdf:datatype="http://www.w3.org/2001/XMLSchema#string">6ECCCD6725A0E17E0D9C91B4F63389CF</vitro:md5password>
|
||||
<vitro:oldpassword rdf:datatype="http://www.w3.org/2001/XMLSchema#string">8F6E2222AE1B0017EB1476BFE68C01EC</vitro:oldpassword>
|
||||
<vitro:modTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2007-07-17T14:54:14</vitro:modTime>
|
||||
<vitro:firstTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2004-11-16T16:05:07</vitro:firstTime>
|
||||
<vitro:loginCount rdf:datatype="http://www.w3.org/2001/XMLSchema#int">410</vitro:loginCount>
|
||||
<vitro:roleURI rdf:datatype="http://www.w3.org/2001/XMLSchema#string">role:/50</vitro:roleURI>
|
||||
</vitro:User>
|
||||
|
||||
<vitro:User rdf:about="#bdc34">
|
||||
<vitro:username rdf:datatype="http://www.w3.org/2001/XMLSchema#string">brian</vitro:username>
|
||||
<vitro:md5password rdf:datatype="http://www.w3.org/2001/XMLSchema#string">57EC9E19B943F4D3633B375111061C11</vitro:md5password>
|
||||
<vitro:oldpassword rdf:datatype="http://www.w3.org/2001/XMLSchema#string">8F6E2222AE1B0017EB1476BFE68C01EC</vitro:oldpassword>
|
||||
<vitro:modTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2007-03-27T14:54:14</vitro:modTime>
|
||||
<vitro:firstTime rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2004-11-30T16:05:07</vitro:firstTime>
|
||||
<vitro:loginCount rdf:datatype="http://www.w3.org/2001/XMLSchema#int">282</vitro:loginCount>
|
||||
<vitro:roleURI rdf:datatype="http://www.w3.org/2001/XMLSchema#string">role:/50</vitro:roleURI>
|
||||
</vitro:User>
|
||||
|
||||
</rdf:RDF>
|
Loading…
Add table
Add a link
Reference in a new issue