Search in sources :

Example 71 with ContractTest

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

the class GraphContractTest method testIterator_Remove.

/**
	 * Ensure that triples removed by calling .remove() on the iterator returned
	 * by a find() will generate deletion notifications.
	 */
@ContractTest
public void testIterator_Remove() {
    Graph graph = graphWith(producer.newInstance(), "a R b; b S e");
    try {
        graph.getEventManager().register(GL);
        txnBegin(graph);
        Triple toRemove = triple("a R b");
        ExtendedIterator<Triple> rtr = graph.find(toRemove);
        assertTrue("ensure a(t least) one triple", rtr.hasNext());
        rtr.next();
        rtr.remove();
        rtr.close();
        GL.assertHas("delete", graph, toRemove);
    } catch (UnsupportedOperationException e) {
    // No Iterator.remove
    }
}
Also used : GraphHelper.memGraph(org.apache.jena.testing_framework.GraphHelper.memGraph) ContractTest(org.xenei.junit.contract.ContractTest)

Example 72 with ContractTest

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

the class GraphContractTest method testSingletonStatisticsWithSeveralTriples.

@ContractTest
public void testSingletonStatisticsWithSeveralTriples() {
    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(3L, h.getStatistic(node("a"), Node.ANY, Node.ANY));
        assertEquals(1L, h.getStatistic(node("x"), Node.ANY, Node.ANY));
        assertEquals(0L, h.getStatistic(node("y"), Node.ANY, Node.ANY));
        //
        assertEquals(2L, h.getStatistic(Node.ANY, node("P"), Node.ANY));
        assertEquals(1L, h.getStatistic(Node.ANY, node("Q"), Node.ANY));
        assertEquals(0L, h.getStatistic(Node.ANY, node("R"), Node.ANY));
        //
        assertEquals(2L, h.getStatistic(Node.ANY, Node.ANY, node("b")));
        assertEquals(1L, h.getStatistic(Node.ANY, Node.ANY, node("c")));
        assertEquals(0L, h.getStatistic(Node.ANY, Node.ANY, node("d")));
    }
}
Also used : GraphHelper.memGraph(org.apache.jena.testing_framework.GraphHelper.memGraph) ContractTest(org.xenei.junit.contract.ContractTest)

Example 73 with ContractTest

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

the class GraphEventManagerContractTest method testAddGraph.

/**
	 * Test that adding a graph is reported as adding a graph.
	 */
@ContractTest
public void testAddGraph() {
    gem.register(L);
    Graph other = Mockito.mock(Graph.class);
    gem.notifyAddGraph(mockGraph, other);
    L.assertHas(new Object[] { "addGraph", mockGraph, other });
}
Also used : Graph(org.apache.jena.graph.Graph) ContractTest(org.xenei.junit.contract.ContractTest)

Example 74 with ContractTest

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

the class GraphContractTest method testContains_Triple.

@ContractTest
public void testContains_Triple() {
    Graph graph = graphWith(producer.newInstance(), "S P O; S2 P2 O2; S3 P3 O3");
    assertTrue(graph.contains(triple("S P O")));
    assertFalse(graph.contains(triple("S P O2")));
    assertFalse(graph.contains(triple("S P2 O")));
    assertFalse(graph.contains(triple("S2 P O")));
    assertTrue(graph.contains(Triple.ANY));
    assertTrue(graph.contains(new Triple(Node.ANY, Node.ANY, node("O"))));
    assertTrue(graph.contains(new Triple(Node.ANY, node("P"), Node.ANY)));
    assertTrue(graph.contains(new Triple(node("S"), Node.ANY, Node.ANY)));
}
Also used : GraphHelper.memGraph(org.apache.jena.testing_framework.GraphHelper.memGraph) ContractTest(org.xenei.junit.contract.ContractTest)

Example 75 with ContractTest

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

the class GraphContractTest method testAGraph.

/**
	 * Check that contains respects by-value semantics.
	 */
@ContractTest
public void testAGraph() {
    String title = this.getClass().getName();
    Graph g = producer.newInstance();
    int baseSize = g.size();
    graphAddTxn(g, "x R y; p S q; a T b");
    /* */
    assertContainsAll(title + ": simple graph", g, "x R y; p S q; a T b");
    assertEquals(title + ": size", baseSize + 3, g.size());
    graphAddTxn(g, "spindizzies lift cities; Diracs communicate instantaneously");
    assertEquals(title + ": size after adding", baseSize + 5, g.size());
    txnBegin(g);
    g.delete(triple("x R y"));
    g.delete(triple("a T b"));
    txnCommit(g);
    assertEquals(title + ": size after deleting", baseSize + 3, g.size());
    assertContainsAll(title + ": modified simple graph", g, "p S q; spindizzies lift cities; Diracs communicate instantaneously");
    assertOmitsAll(title + ": modified simple graph", g, "x R y; a T b");
    /* */
    ClosableIterator<Triple> it = g.find(Node.ANY, node("lift"), Node.ANY);
    assertTrue(title + ": finds some triple(s)", it.hasNext());
    assertEquals(title + ": finds a 'lift' triple", triple("spindizzies lift cities"), it.next());
    assertFalse(title + ": finds exactly one triple", it.hasNext());
    it.close();
}
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