Search in sources :

Example 1 with ClosedException

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);
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) InfGraph(org.apache.jena.reasoner.InfGraph) ClosedException(org.apache.jena.shared.ClosedException)

Example 2 with ClosedException

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
    }
}
Also used : GraphHelper.memGraph(org.apache.jena.testing_framework.GraphHelper.memGraph) ClosedException(org.apache.jena.shared.ClosedException) ClosedException(org.apache.jena.shared.ClosedException) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) DeleteDeniedException(org.apache.jena.shared.DeleteDeniedException) ContractTest(org.xenei.junit.contract.ContractTest)

Aggregations

ClosedException (org.apache.jena.shared.ClosedException)2 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 InfGraph (org.apache.jena.reasoner.InfGraph)1 DeleteDeniedException (org.apache.jena.shared.DeleteDeniedException)1 GraphHelper.memGraph (org.apache.jena.testing_framework.GraphHelper.memGraph)1 ContractTest (org.xenei.junit.contract.ContractTest)1