}
}
@Test
public void testGetStatementsP_SOG() throws Exception {
SailConnection sc = sail.getConnection();
try {
sc.begin();
URI uriA = sail.getValueFactory().createURI("http://example.org/test/P_SOG#a");
URI uriB = sail.getValueFactory().createURI("http://example.org/test/P_SOG#b");
URI uriC = sail.getValueFactory().createURI("http://example.org/test/P_SOG#c");
URI foo = sail.getValueFactory().createURI("http://example.org/ns#foo");
URI firstName = sail.getValueFactory().createURI("http://example.org/ns#firstName");
Literal plainLitA = sail.getValueFactory().createLiteral("arbitrary plain literal 238445");
Literal fooLabel = sail.getValueFactory().createLiteral("foo", XMLSchema.STRING);
int before, after;
// Add statement to the implicit null context.
sc.removeStatements(null, uriA, null);
sc.commit();
sc.begin();
before = countStatements(sc, null, uriA, null, false);
sc.addStatement(uriB, uriA, uriC);
sc.commit();
sc.begin();
after = countStatements(sc, null, uriA, null, false);
assertEquals(0, before);
assertEquals(1, after);
// Add plain literal statement to the default context.
sc.removeStatements(null, uriA, null);
sc.commit();
sc.begin();
before = countStatements(sc, null, uriA, null, false);
sc.addStatement(uriA, uriA, plainLitA);
sc.addStatement(uriA, uriB, plainLitA);
sc.addStatement(uriB, uriB, plainLitA);
sc.commit();
sc.begin();
after = countStatements(sc, null, uriA, null, false);
assertEquals(0, before);
assertEquals(1, after);
// Add string-typed literal statement to the default context.
sc.removeStatements(null, firstName, null);
sc.commit();
sc.begin();
before = countStatements(sc, null, firstName, null, false);
sc.addStatement(foo, firstName, fooLabel);
sc.commit();
sc.begin();
after = countStatements(sc, null, firstName, null, false);
assertEquals(0, before);
assertEquals(1, after);
assertEquals(foo, toSet(sc.getStatements(null, firstName, null, false)).iterator().next().getSubject());
// Add statement to a non-null context.
sc.removeStatements(null, uriA, null);
sc.commit();
sc.begin();
before = countStatements(sc, null, uriA, null, false);
sc.addStatement(uriB, uriA, uriC, uriA);
sc.commit();
sc.begin();
after = countStatements(sc, null, uriA, null, false);
assertEquals(0, before);
assertEquals(1, after);
sc.removeStatements(null, uriA, null);
sc.commit();
sc.begin();
before = countStatements(sc, null, uriA, null, false);
sc.addStatement(uriB, uriA, uriC, uriC);
sc.addStatement(uriC, uriA, uriA, uriA);
sc.commit();
sc.begin();
sc.addStatement(uriA, uriA, uriB, uriB);
sc.commit();
sc.begin();
after = countStatements(sc, null, uriA, null, false);
assertEquals(0, before);
assertEquals(3, after);
} finally {
sc.rollback();
sc.close();
}
}