*/
public class DefinitionsTest extends RippleTestCase {
public void testDefinitions() throws Exception {
Sail sail = getTestSail();
SailConnection sc = sail.getConnection();
QueryEngine qe = getTestQueryEngine();
ListAST foobar = new ListAST(
new PlainLiteralAST("foo"), new ListAST(new PlainLiteralAST("bar"), new ListAST()));
ListAST foobar2 = new ListAST(
new PlainLiteralAST("foo2"), new ListAST(new PlainLiteralAST("bar2"), new ListAST()));
URI foobarUri = sail.getValueFactory().createURI(qe.getLexicon().getDefaultNamespace() + "foobar");
Literal foo = sail.getValueFactory().createLiteral("foo");
Literal foo2 = sail.getValueFactory().createLiteral("foo2");
Command defCmd = new DefineListCmd("foobar", foobar);
Command undefCmd = new UndefineListCmd("foobar");
Command redefCmd = new RedefineListCmd("foobar", foobar2);
int count;
Value obj;
count = countStatements(sc.getStatements(foobarUri, null, null, false));
assertEquals(0, count);
// Undefine a term which has not been defined.
qe.executeCommand(undefCmd);
count = countStatements(sc.getStatements(foobarUri, null, null, false));
assertEquals(0, count);
// Define a term which is not yet defined.
qe.executeCommand(defCmd);
count = countStatements(sc.getStatements(foobarUri, null, null, false));
assertEquals(3, count);
obj = getSingleStatement(sc.getStatements(foobarUri, RDF.FIRST, null, false)).getObject();
//System.out.println("obj = " + obj + " (datatype = " + ((Literal) obj).getDatatype());
assertTrue(obj.equals(foo));
assertFalse(obj.equals(foo2));
// Undefine a term which has been defined.
qe.executeCommand(undefCmd);
count = countStatements(sc.getStatements(foobarUri, null, null, false));
assertEquals(0, count);
// Redefine a term which has already been defined.
qe.executeCommand(defCmd);
count = countStatements(sc.getStatements(foobarUri, null, null, false));
assertEquals(3, count);
obj = getSingleStatement(sc.getStatements(foobarUri, RDF.FIRST, null, false)).getObject();
assertTrue(obj.equals(foo));
assertFalse(obj.equals(foo2));
qe.executeCommand(redefCmd);
count = countStatements(sc.getStatements(foobarUri, null, null, false));
assertEquals(3, count);
obj = getSingleStatement(sc.getStatements(foobarUri, RDF.FIRST, null, false)).getObject();
assertTrue(obj.equals(foo2));
assertFalse(obj.equals(foo));
// Undefine a term which has been redefined.
qe.executeCommand(undefCmd);
count = countStatements(sc.getStatements(foobarUri, null, null, false));
assertEquals(0, count);
// Redefine a term which has not yet been defined.
qe.executeCommand(redefCmd);
count = countStatements(sc.getStatements(foobarUri, null, null, false));
assertEquals(3, count);
obj = getSingleStatement(sc.getStatements(foobarUri, RDF.FIRST, null, false)).getObject();
assertTrue(obj.equals(foo2));
assertFalse(obj.equals(foo));