use of org.xenei.junit.contract.ContractTest in project jena by apache.
the class GraphContractTest method testIsClosed.
@ContractTest
public void testIsClosed() {
Graph g = producer.newInstance();
assertFalse("Graph created in closed state", g.isClosed());
g.close();
assertTrue("Graph does not report closed state after close called", g.isClosed());
}
use of org.xenei.junit.contract.ContractTest in project jena by apache.
the class GraphContractTest method testTransactionHandler_CommitThenAbort.
@ContractTest
public void testTransactionHandler_CommitThenAbort() {
Graph g = producer.newInstance();
if (g.getTransactionHandler().transactionsSupported()) {
Graph initial = graphWith(producer.newInstance(), "Foo pings B; B pings C");
Graph extra = graphWith(producer.newInstance(), "C pingedBy B; fileGraph rdf:type Graph");
g.getTransactionHandler().begin();
GraphUtil.addInto(g, initial);
g.getTransactionHandler().commit();
g.getTransactionHandler().begin();
GraphUtil.addInto(g, extra);
g.getTransactionHandler().abort();
assertIsomorphic(initial, g);
// Model inFile = ModelFactory.createDefaultModel();
// inFile.read( "file:///" + foo, "N-TRIPLES" );
// assertIsomorphic( initial, inFile.getGraph() );
}
}
use of org.xenei.junit.contract.ContractTest in project jena by apache.
the class GraphContractTest method testDelete_Triple.
/**
* Inference graphs can not be empty
*/
@ContractTest
public void testDelete_Triple() {
Graph graph = graphWith(producer.newInstance(), "S P O; S2 P2 O2; S3 P3 O3");
Graph base = producer.newInstance();
graph.getEventManager().register(GL);
txnBegin(graph);
graph.delete(triple("S P O"));
txnCommit(graph);
GL.assertContains("delete", graph, triple("S P O"));
assertFalse("Graph should not contain <S P O>", graph.contains(triple("S P O")));
assertNotEmpty(graph, base);
assertTrue("Graph should contain <S2 P2 O2>", graph.contains(triple("S2 P2 O2")));
assertTrue("Graph should contain <S3 P3 O3>", graph.contains(triple("S3 P3 O3")));
// should not modify anything on wildcard delete
GL.clear();
try {
txnBegin(graph);
graph.delete(new Triple(node("S2"), node("P2"), Node.ANY));
txnCommit(graph);
} catch (DeleteDeniedException expected) {
txnRollback(graph);
}
assertTrue("Graph should contain <S2 P2 O2>", graph.contains(triple("S2 P2 O2")));
assertTrue("Graph should contain <S3 P3 O3>", graph.contains(triple("S3 P3 O3")));
GL.assertHas("delete", graph, new Triple(node("S2"), node("P2"), Node.ANY));
}
use of org.xenei.junit.contract.ContractTest in project jena by apache.
the class GraphContractTest method testFind_Node_Node_Node.
@ContractTest
public void testFind_Node_Node_Node() {
Graph graph = graphWith(producer.newInstance(), "S P O; S2 P2 O2; S3 P3 O3");
List<Triple> s = graph.find(Node.ANY, Node.ANY, Node.ANY).toList();
assertEquals(3, s.size());
List<Triple> expected = Arrays.asList(new Triple[] { triple("S P O"), triple("S2 P2 O2"), triple("S3 P3 O3") });
assertTrue("Missing some values", expected.containsAll(s) && s.containsAll(expected));
s = graph.find(node("S"), Node.ANY, Node.ANY).toList();
assertEquals(1, s.size());
assertTrue("Missing some values", s.contains(triple("S P O")));
s = graph.find(Node.ANY, node("P"), Node.ANY).toList();
assertEquals(1, s.size());
assertTrue("Missing some values", s.contains(triple("S P O")));
s = graph.find(Node.ANY, Node.ANY, node("O")).toList();
assertEquals(1, s.size());
assertTrue("Missing some values", s.contains(triple("S P O")));
s = graph.find(node("S2"), node("P2"), node("O2")).toList();
assertEquals(1, s.size());
assertTrue("Missing some values", s.contains(triple("S2 P2 O2")));
s = graph.find(node("S2"), node("P3"), node("O2")).toList();
assertEquals(0, s.size());
s = graph.find(Node.ANY, node("P3"), node("O2")).toList();
assertEquals(0, s.size());
s = graph.find(node("S3"), Node.ANY, node("O2")).toList();
assertEquals(0, s.size());
s = graph.find(node("S3"), node("P2"), Node.ANY).toList();
assertEquals(0, s.size());
}
use of org.xenei.junit.contract.ContractTest in project jena by apache.
the class GraphContractTest method testIsEmpty.
@ContractTest
public void testIsEmpty() {
Graph g = producer.newInstance();
if (!g.isEmpty()) {
LOG.warn(String.format("Graph type %s can not be empty (Empty test skipped)", g.getClass()));
} else {
graphAddTxn(g, "S P O");
assertFalse("Graph reports empty after add", g.isEmpty());
txnBegin(g);
g.add(NodeCreateUtils.createTriple("Foo B C"));
g.delete(NodeCreateUtils.createTriple("S P O"));
txnCommit(g);
assertFalse("Should not report empty", g.isEmpty());
txnBegin(g);
g.delete(NodeCreateUtils.createTriple("Foo B C"));
txnCommit(g);
assertTrue("Should report empty after all entries deleted", g.isEmpty());
}
}
Aggregations