use of org.apache.jena.shared.ClosedException in project jena by apache.
the class TestFBRules method testClose.
/**
* Test the close operation.
*/
public void testClose() {
String rules = "[rule1: (?x p ?y) -> (?x q ?y)]";
Graph data = Factory.createGraphMem();
data.add(new Triple(n1, p, n2));
InfGraph infgraph = createInfGraph(rules, data);
TestUtil.assertIteratorValues(this, infgraph.find(n1, null, null), new Triple[] { new Triple(n1, p, n2), new Triple(n1, q, n2) });
infgraph.close();
boolean foundException = false;
try {
infgraph.find(n1, null, null);
} catch (ClosedException e) {
foundException = true;
}
assertTrue("Close detected", foundException);
}
use of org.apache.jena.shared.ClosedException in project jena by apache.
the class GraphContractTest method testClose.
@ContractTest
public void testClose() {
Graph graph = graphWith(producer.newInstance(), "S P O; S P2 O2; S3 P P3");
graph.getEventManager().register(GL);
assertFalse("Graph was constructed closed", graph.isClosed());
graph.close();
assertTrue("Graph should be closed", graph.isClosed());
// exception may be thrown on begin or on execution.
try {
txnBegin(graph);
try {
graph.add(triple("S P O"));
fail("added when closed");
} catch (Exception expected) {
GL.assertEmpty();
// expected
} finally {
txnRollback(graph);
}
} catch (Exception expected) {
GL.assertEmpty();
// expected
}
try {
txnBegin(graph);
try {
graph.delete(triple("x R y"));
fail("delete when closed");
} catch (ClosedException c) {
// Expected
} finally {
txnRollback(graph);
GL.assertEmpty();
}
} catch (Exception expected) {
GL.assertEmpty();
// expected
}
try {
txnBegin(graph);
try {
graph.add(triple("x R y"));
fail("add when closed");
} catch (ClosedException c) {
/* as required */
} finally {
txnRollback(graph);
GL.assertEmpty();
}
} catch (Exception expected) {
GL.assertEmpty();
// expected
}
try {
txnBegin(graph);
try {
graph.contains(triple("x R y"));
fail("contains[triple] when closed");
} catch (ClosedException c) {
/* as required */
} finally {
txnRollback(graph);
GL.assertEmpty();
}
} catch (Exception expected) {
GL.assertEmpty();
// expected
}
try {
txnBegin(graph);
try {
graph.contains(Node.ANY, Node.ANY, Node.ANY);
fail("contains[SPO] when closed");
} catch (ClosedException c) {
/* as required */
} finally {
txnRollback(graph);
GL.assertEmpty();
}
} catch (Exception expected) {
GL.assertEmpty();
// expected
}
try {
txnBegin(graph);
try {
graph.find(triple("x R y"));
fail("find [triple] when closed");
} catch (ClosedException c) {
/* as required */
} finally {
txnRollback(graph);
GL.assertEmpty();
}
} catch (Exception expected) {
GL.assertEmpty();
// expected
}
try {
txnBegin(graph);
try {
graph.find(Node.ANY, Node.ANY, Node.ANY);
fail("find[SPO] when closed");
} catch (ClosedException c) {
/* as required */
} finally {
txnRollback(graph);
GL.assertEmpty();
}
} catch (Exception expected) {
GL.assertEmpty();
// expected
}
try {
txnBegin(graph);
try {
graph.size();
fail("size when closed (" + this.getClass() + ")");
} catch (ClosedException c) {
/* as required */
} finally {
txnRollback(graph);
GL.assertEmpty();
}
} catch (Exception expected) {
GL.assertEmpty();
// expected
}
}
Aggregations