use of org.xenei.junit.contract.ContractTest in project jena by apache.
the class GraphContractTest method failingTestDoubleRemoveAll.
@ContractTest
public void failingTestDoubleRemoveAll() {
final Graph g = producer.newInstance();
try {
graphAddTxn(g, "c S d; e:ff GGG hhhh; _i J 27; Ell Em 'en'");
Iterator<Triple> it = new TrackingTripleIterator(g.find(Triple.ANY)) {
@Override
public void remove() {
// removes current
super.remove();
// no-op.
g.delete(current);
}
};
while (it.hasNext()) {
it.next();
it.remove();
}
assertTrue(g.isEmpty());
} catch (UnsupportedOperationException e) {
// No Iterator.remove
}
}
use of org.xenei.junit.contract.ContractTest in project jena by apache.
the class UnionTest method testUnion.
@ContractTest
public void testUnion() {
Graph g1 = graphWith("x R y; p R q");
Graph g2 = graphWith("r Foo s; x R y");
Union u = new Union(g1, g2);
assertContains("Union", "x R y", u);
assertContains("Union", "p R q", u);
assertContains("Union", "r Foo s", u);
if (u.size() != 3)
fail("oops: size of union is not 3");
u.add(triple("cats eat cheese"));
assertContains("Union", "cats eat cheese", u);
if (contains(g1, "cats eat cheese") == false && contains(g2, "cats eat cheese") == false)
fail("oops: neither g1 nor g2 contains `cats eat cheese`");
}
use of org.xenei.junit.contract.ContractTest in project jena by apache.
the class GraphContractTest method testFind_Triple_ProgrammaticValues.
@ContractTest
public void testFind_Triple_ProgrammaticValues() {
Graph g = producer.newInstance();
if (g.getCapabilities().handlesLiteralTyping()) {
Node ab = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(new Byte((byte) 42)));
Node as = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(new Short((short) 42)));
Node ai = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(new Integer(42)));
Node al = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(new Long(42)));
Node SB = NodeCreateUtils.create("SB");
Node SS = NodeCreateUtils.create("SS");
Node SI = NodeCreateUtils.create("SI");
Node SL = NodeCreateUtils.create("SL");
Node P = NodeCreateUtils.create("P");
txnBegin(g);
try {
g.add(Triple.create(SB, P, ab));
g.add(Triple.create(SS, P, as));
g.add(Triple.create(SI, P, ai));
g.add(Triple.create(SL, P, al));
} catch (Exception e) {
txnRollback(g);
fail(e.getMessage());
}
txnCommit(g);
assertEquals(String.format("Should have found 4 elements, does %s really implement literal typing", g.getClass()), 4, iteratorToSet(g.find(new Triple(Node.ANY, P, NodeCreateUtils.create("42")))).size());
}
}
use of org.xenei.junit.contract.ContractTest in project jena by apache.
the class GraphContractTest method testClear.
/**
* Test that clear works, in the presence of inferencing graphs that mean
* emptyness isn't available. This is why we go round the houses and test
* that expected ~= initialContent + addedStuff - removed - initialContent.
*/
@ContractTest
public void testClear() {
Graph graph = producer.newInstance();
Graph base = copy(graph);
graph.getEventManager().register(GL);
txnBegin(graph);
graph.clear();
txnCommit(graph);
assertEmpty(graph, base);
GL.assertHasStart("someEvent", graph, GraphEvents.removeAll);
GL.clear();
// test after adding
graph = graphWith(producer.newInstance(), "S P O; S e:ff 27; _1 P P3; S4 P4 'en'");
graph.getEventManager().register(GL);
txnBegin(graph);
graph.clear();
txnCommit(graph);
assertEmpty(graph, base);
if (GL.contains("delete")) {
// deletes are listed -- ensure all deletes are listed
GL.assertContains("delete", graph, triple("S P O"));
GL.assertContains("delete", graph, triple("S e:ff 27"));
GL.assertContains("delete", graph, triple("_1 P P3"));
GL.assertContains("delete", graph, triple("S4 P4 'en'"));
}
GL.assertHasEnd("someEvent", graph, GraphEvents.removeAll);
GL.clear();
}
use of org.xenei.junit.contract.ContractTest in project jena by apache.
the class GraphContractTest method testTransactionHandler_Commit.
@ContractTest
public void testTransactionHandler_Commit() {
Graph g = producer.newInstance();
if (g.getTransactionHandler().transactionsSupported()) {
Graph initial = graphWith(producer.newInstance(), "initial hasValue 42; also hasURI hello");
Graph extra = graphWith(producer.newInstance(), "extra hasValue 17; also hasURI world");
GraphUtil.addInto(g, initial);
g.getTransactionHandler().begin();
GraphUtil.addInto(g, extra);
g.getTransactionHandler().commit();
Graph union = memGraph();
GraphUtil.addInto(union, initial);
GraphUtil.addInto(union, extra);
assertIsomorphic(union, g);
// Model inFiIProducer<TransactionHandler>le =
// ModelFactory.createDefaultModel();
// inFile.read( "file:///" + foo, "N-TRIPLES" );
// assertIsomorphic( union, inFile.getGraph() );
}
}
Aggregations