Search in sources :

Example 11 with ContractTest

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) {
        }
    }
}
Also used : Command(org.apache.jena.shared.Command) TransactionHandler(org.apache.jena.graph.TransactionHandler) ContractTest(org.xenei.junit.contract.ContractTest)

Example 12 with ContractTest

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());
    }
}
Also used : GraphHelper.memGraph(org.apache.jena.testing_framework.GraphHelper.memGraph) 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)

Example 13 with ContractTest

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 ??")));
}
Also used : GraphHelper.memGraph(org.apache.jena.testing_framework.GraphHelper.memGraph) ContractTest(org.xenei.junit.contract.ContractTest)

Example 14 with ContractTest

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
    }
}
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)

Example 15 with ContractTest

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
    }
}
Also used : GraphHelper.memGraph(org.apache.jena.testing_framework.GraphHelper.memGraph) ContractTest(org.xenei.junit.contract.ContractTest)

Aggregations

ContractTest (org.xenei.junit.contract.ContractTest)102 GraphHelper.memGraph (org.apache.jena.testing_framework.GraphHelper.memGraph)51 Graph (org.apache.jena.graph.Graph)16 Var (org.apache.jena.sparql.core.Var)13 Query (org.apache.jena.query.Query)9 E_Random (org.apache.jena.sparql.expr.E_Random)9 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)6 DeleteDeniedException (org.apache.jena.shared.DeleteDeniedException)6 VarExprList (org.apache.jena.sparql.core.VarExprList)6 MalformedURLException (java.net.MalformedURLException)5 URISyntaxException (java.net.URISyntaxException)5 ClosedException (org.apache.jena.shared.ClosedException)5 Expr (org.apache.jena.sparql.expr.Expr)5 Triple (org.apache.jena.graph.Triple)4 PrefixMapping (org.apache.jena.shared.PrefixMapping)3 TriplePath (org.apache.jena.sparql.core.TriplePath)3 Node (org.apache.jena.graph.Node)2 TransactionHandler (org.apache.jena.graph.TransactionHandler)2 Intersection (org.apache.jena.graph.compose.Intersection)2 GraphWithPerform (org.apache.jena.graph.impl.GraphWithPerform)2