testCon.add(alice, mbox, mboxAlice, context2);
testCon.add(context2, publisher, nameAlice);
testCon.commit();
// get statements with either no context or context2
ModelResult iter = testCon.match(null, null, null, false, null, context2);
try {
int count = 0;
while (iter.hasNext()) {
count++;
Statement st = iter.next();
assertTrue(st.getContext() == null || context2.equals(st.getContext()));
}
assertEquals("there should be three statements", 3, count);
}
finally {
iter.close();
}
// get all statements with context1 or context2. Note that context1 and
// context2 are both known
// in the store because they have been created through the store's own
// value vf.
iter = testCon.match(null, null, null, false, context1, context2);
try {
int count = 0;
while (iter.hasNext()) {
count++;
Statement st = iter.next();
// we should have _only_ statements from context2
assertEquals(context2, st.getContext());
}
assertEquals("there should be two statements", 2, count);
}
finally {
iter.close();
}
// get all statements with unknownContext or context2.
iter = testCon.match(null, null, null, false, unknownContext, context2);
try {
int count = 0;
while (iter.hasNext()) {
count++;
Statement st = iter.next();
// we should have _only_ statements from context2
assertEquals(context2, st.getContext());
}
assertEquals("there should be two statements", 2, count);
}
finally {
iter.close();
}
// add statements to context1
testCon.begin();
testCon.add(bob, name, nameBob, context1);
testCon.add(bob, mbox, mboxBob, context1);
testCon.add(context1, publisher, nameBob);
testCon.commit();
iter = testCon.match(null, null, null, false, context1);
try {
assertNotNull(iter);
assertTrue(iter.hasNext());
}
finally {
iter.close();
}
// get statements with either no context or context2
iter = testCon.match(null, null, null, false, null, context2);
try {
int count = 0;
while (iter.hasNext()) {
count++;
Statement st = iter.next();
// we should have _only_ statements from context2, or without
// context
assertTrue(st.getContext() == null || context2.equals(st.getContext()));
}
assertEquals("there should be four statements", 4, count);
}
finally {
iter.close();
}
// get all statements with context1 or context2
iter = testCon.match(null, null, null, false, context1, context2);
try {
int count = 0;
while (iter.hasNext()) {
count++;
Statement st = iter.next();
assertTrue(context1.equals(st.getContext()) || context2.equals(st.getContext()));
}
assertEquals("there should be four statements", 4, count);
}
finally {
iter.close();
}
}