Search in sources :

Example 76 with ContractTest

use of org.xenei.junit.contract.ContractTest in project jena by apache.

the class GraphMakerContractTest method testCanFindCreatedGraph.

/**
	 * Test that we can find a graph once its been created. We need to know if
	 * two graphs are "the same" here: we have a temporary work-around but it is
	 * not sound.
	 * 
	 */
@ContractTest
public void testCanFindCreatedGraph() {
    String alpha = jName("alpha"), beta = jName("beta");
    Graph g1 = graphMaker.createGraph(alpha, true);
    Graph h1 = graphMaker.createGraph(beta, true);
    Graph g2 = graphMaker.openGraph(alpha, true);
    Graph h2 = graphMaker.openGraph(beta, true);
    assertTrue("should find alpha", sameGraph(g1, g2));
    assertTrue("should find beta", sameGraph(h1, h2));
}
Also used : Graph(org.apache.jena.graph.Graph) ContractTest(org.xenei.junit.contract.ContractTest)

Example 77 with ContractTest

use of org.xenei.junit.contract.ContractTest in project jena by apache.

the class GraphContractTest method testDoubletonStatisticsWithTriples.

@ContractTest
public void testDoubletonStatisticsWithTriples() {
    Graph g = graphWith(producer.newInstance(), "a P b; a P c; a Q b; x S y");
    GraphStatisticsHandler h = g.getStatisticsHandler();
    if (h != null) {
        assertEquals(-1L, h.getStatistic(node("a"), node("P"), Node.ANY));
        assertEquals(-1L, h.getStatistic(Node.ANY, node("P"), node("b")));
        assertEquals(-1L, h.getStatistic(node("a"), Node.ANY, node("b")));
        //
        assertEquals(0L, h.getStatistic(node("no"), node("P"), Node.ANY));
    }
}
Also used : GraphHelper.memGraph(org.apache.jena.testing_framework.GraphHelper.memGraph) ContractTest(org.xenei.junit.contract.ContractTest)

Example 78 with ContractTest

use of org.xenei.junit.contract.ContractTest in project jena by apache.

the class GraphContractTest method testContains_Triple_Fluid.

@ContractTest
public void testContains_Triple_Fluid() {
    Graph g = graphWith(producer.newInstance(), "x R y; a P b");
    assertTrue(g.contains(triple("?? R y")));
    assertTrue(g.contains(triple("x ?? y")));
    assertTrue(g.contains(triple("x R ??")));
    assertTrue(g.contains(triple("?? P b")));
    assertTrue(g.contains(triple("a ?? b")));
    assertTrue(g.contains(triple("a P ??")));
    assertTrue(g.contains(triple("?? R y")));
    /* */
    assertFalse(g.contains(triple("?? R b")));
    assertFalse(g.contains(triple("a ?? y")));
    assertFalse(g.contains(triple("x P ??")));
    assertFalse(g.contains(triple("?? R x")));
    assertFalse(g.contains(triple("x ?? R")));
    assertFalse(g.contains(triple("a S ??")));
}
Also used : GraphHelper.memGraph(org.apache.jena.testing_framework.GraphHelper.memGraph) ContractTest(org.xenei.junit.contract.ContractTest)

Example 79 with ContractTest

use of org.xenei.junit.contract.ContractTest in project jena by apache.

the class GraphContractTest method testAddWithReificationPreamble.

@ContractTest
public void testAddWithReificationPreamble() {
    Graph g = producer.newInstance();
    txnBegin(g);
    xSPO(g);
    txnCommit(g);
    assertFalse(g.isEmpty());
}
Also used : GraphHelper.memGraph(org.apache.jena.testing_framework.GraphHelper.memGraph) ContractTest(org.xenei.junit.contract.ContractTest)

Example 80 with ContractTest

use of org.xenei.junit.contract.ContractTest in project jena by apache.

the class TransactionHandlerContractTest method testExecuteInTransactionCatchesThrowable.

@SuppressWarnings("deprecation")
@ContractTest
public void testExecuteInTransactionCatchesThrowable() {
    TransactionHandler th = getTransactionHandlerProducer().newInstance();
    if (th.transactionsSupported()) {
        Command cmd = new Command() {

            @Override
            public Object execute() throws Error {
                throw new Error();
            }
        };
        try {
            th.executeInTransaction(cmd);
            fail("Should have thrown JenaException");
        } catch (JenaException x) {
        }
        try {
            th.execute(() -> {
                throw new Error();
            });
            fail("Should have thrown JenaException");
        } catch (JenaException x) {
        }
        try {
            th.calculate(() -> {
                throw new Error();
            });
            fail("Should have thrown JenaException");
        } catch (JenaException x) {
        }
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) Command(org.apache.jena.shared.Command) TransactionHandler(org.apache.jena.graph.TransactionHandler) 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