use of org.xenei.junit.contract.ContractTest in project jena by apache.
the class TransactionHandlerContractTest method testTransactionsExistAsPerTransactionSupported.
/**
* Test that Graphs have transaction support methods, and that if they fail
* on some g they fail because they do not support the operation.
*/
@SuppressWarnings("deprecation")
@ContractTest
public void testTransactionsExistAsPerTransactionSupported() {
// Write out explicitly
Command cmd = new Command() {
@Override
public Object execute() {
return null;
}
};
TransactionHandler th = getTransactionHandlerProducer().newInstance();
if (th.transactionsSupported()) {
th.begin();
th.abort();
th.begin();
th.commit();
th.execute(() -> {
});
th.calculate(() -> null);
th.executeInTransaction(cmd);
th.executeInTransaction(() -> null);
} else {
try {
th.begin();
fail("Should have thrown UnsupportedOperationException");
} catch (UnsupportedOperationException x) {
}
try {
th.abort();
fail("Should have thrown UnsupportedOperationException");
} catch (UnsupportedOperationException x) {
}
try {
th.commit();
fail("Should have thrown UnsupportedOperationException");
} catch (UnsupportedOperationException x) {
}
/* */
try {
th.execute(() -> {
});
fail("Should have thrown UnsupportedOperationException");
} catch (UnsupportedOperationException x) {
}
try {
th.calculate(() -> null);
fail("Should have thrown UnsupportedOperationException");
} catch (UnsupportedOperationException x) {
}
try {
th.executeInTransaction(cmd);
fail("Should have thrown UnsupportedOperationException");
} catch (UnsupportedOperationException x) {
}
try {
th.executeInTransaction(() -> null);
fail("Should have thrown UnsupportedOperationException");
} catch (UnsupportedOperationException x) {
}
}
}
use of org.xenei.junit.contract.ContractTest in project jena by apache.
the class GraphContractTest method testFindAndContains.
/**
* This test case was generated by Ian and was caused by GraphMem not
* keeping up with changes to the find interface.
*/
@ContractTest
public void testFindAndContains() {
Graph g = producer.newInstance();
Node r = NodeCreateUtils.create("r"), s = NodeCreateUtils.create("s"), p = NodeCreateUtils.create("P");
txnBegin(g);
try {
g.add(Triple.create(r, p, s));
txnCommit(g);
assertTrue(g.contains(r, p, Node.ANY));
assertEquals(1, g.find(r, p, Node.ANY).toList().size());
} catch (Exception e) {
txnRollback(g);
fail(e.getMessage());
}
}
use of org.xenei.junit.contract.ContractTest in project jena by apache.
the class GraphContractTest method testContains_Triple_RepeatedSubjectDoesNotConceal.
@ContractTest
public void testContains_Triple_RepeatedSubjectDoesNotConceal() {
Graph g = graphWith(producer.newInstance(), "s P o; s Q r");
assertTrue(g.contains(triple("s P o")));
assertTrue(g.contains(triple("s Q r")));
assertTrue(g.contains(triple("?? P o")));
assertTrue(g.contains(triple("?? Q r")));
assertTrue(g.contains(triple("?? P ??")));
assertTrue(g.contains(triple("?? Q ??")));
}
use of org.xenei.junit.contract.ContractTest 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
}
}
use of org.xenei.junit.contract.ContractTest in project jena by apache.
the class GraphContractTest method testSizeAfterRemove.
@ContractTest
public void testSizeAfterRemove() {
Graph g = graphWith(producer.newInstance(), "x p y");
try {
ExtendedIterator<Triple> it = g.find(triple("x ?? ??"));
it.removeNext();
assertEquals(0, g.size());
} catch (UnsupportedOperationException e) {
// No Iterator.remove
}
}
Aggregations