use of org.xenei.junit.contract.ContractTest in project jena by apache.
the class GraphContractTest method testIterator_Remove.
/**
* Ensure that triples removed by calling .remove() on the iterator returned
* by a find() will generate deletion notifications.
*/
@ContractTest
public void testIterator_Remove() {
Graph graph = graphWith(producer.newInstance(), "a R b; b S e");
try {
graph.getEventManager().register(GL);
txnBegin(graph);
Triple toRemove = triple("a R b");
ExtendedIterator<Triple> rtr = graph.find(toRemove);
assertTrue("ensure a(t least) one triple", rtr.hasNext());
rtr.next();
rtr.remove();
rtr.close();
GL.assertHas("delete", graph, toRemove);
} catch (UnsupportedOperationException e) {
// No Iterator.remove
}
}
use of org.xenei.junit.contract.ContractTest in project jena by apache.
the class GraphContractTest method testSingletonStatisticsWithSeveralTriples.
@ContractTest
public void testSingletonStatisticsWithSeveralTriples() {
Graph g = graphWith(producer.newInstance(), "a P b; a P c; a Q b; x S y");
GraphStatisticsHandler h = g.getStatisticsHandler();
if (h != null) {
assertEquals(3L, h.getStatistic(node("a"), Node.ANY, Node.ANY));
assertEquals(1L, h.getStatistic(node("x"), Node.ANY, Node.ANY));
assertEquals(0L, h.getStatistic(node("y"), Node.ANY, Node.ANY));
//
assertEquals(2L, h.getStatistic(Node.ANY, node("P"), Node.ANY));
assertEquals(1L, h.getStatistic(Node.ANY, node("Q"), Node.ANY));
assertEquals(0L, h.getStatistic(Node.ANY, node("R"), Node.ANY));
//
assertEquals(2L, h.getStatistic(Node.ANY, Node.ANY, node("b")));
assertEquals(1L, h.getStatistic(Node.ANY, Node.ANY, node("c")));
assertEquals(0L, h.getStatistic(Node.ANY, Node.ANY, node("d")));
}
}
use of org.xenei.junit.contract.ContractTest in project jena by apache.
the class GraphEventManagerContractTest method testAddGraph.
/**
* Test that adding a graph is reported as adding a graph.
*/
@ContractTest
public void testAddGraph() {
gem.register(L);
Graph other = Mockito.mock(Graph.class);
gem.notifyAddGraph(mockGraph, other);
L.assertHas(new Object[] { "addGraph", mockGraph, other });
}
use of org.xenei.junit.contract.ContractTest in project jena by apache.
the class GraphContractTest method testContains_Triple.
@ContractTest
public void testContains_Triple() {
Graph graph = graphWith(producer.newInstance(), "S P O; S2 P2 O2; S3 P3 O3");
assertTrue(graph.contains(triple("S P O")));
assertFalse(graph.contains(triple("S P O2")));
assertFalse(graph.contains(triple("S P2 O")));
assertFalse(graph.contains(triple("S2 P O")));
assertTrue(graph.contains(Triple.ANY));
assertTrue(graph.contains(new Triple(Node.ANY, Node.ANY, node("O"))));
assertTrue(graph.contains(new Triple(Node.ANY, node("P"), Node.ANY)));
assertTrue(graph.contains(new Triple(node("S"), Node.ANY, Node.ANY)));
}
use of org.xenei.junit.contract.ContractTest in project jena by apache.
the class GraphContractTest method testAGraph.
/**
* Check that contains respects by-value semantics.
*/
@ContractTest
public void testAGraph() {
String title = this.getClass().getName();
Graph g = producer.newInstance();
int baseSize = g.size();
graphAddTxn(g, "x R y; p S q; a T b");
/* */
assertContainsAll(title + ": simple graph", g, "x R y; p S q; a T b");
assertEquals(title + ": size", baseSize + 3, g.size());
graphAddTxn(g, "spindizzies lift cities; Diracs communicate instantaneously");
assertEquals(title + ": size after adding", baseSize + 5, g.size());
txnBegin(g);
g.delete(triple("x R y"));
g.delete(triple("a T b"));
txnCommit(g);
assertEquals(title + ": size after deleting", baseSize + 3, g.size());
assertContainsAll(title + ": modified simple graph", g, "p S q; spindizzies lift cities; Diracs communicate instantaneously");
assertOmitsAll(title + ": modified simple graph", g, "x R y; a T b");
/* */
ClosableIterator<Triple> it = g.find(Node.ANY, node("lift"), Node.ANY);
assertTrue(title + ": finds some triple(s)", it.hasNext());
assertEquals(title + ": finds a 'lift' triple", triple("spindizzies lift cities"), it.next());
assertFalse(title + ": finds exactly one triple", it.hasNext());
it.close();
}
Aggregations