Search in sources :

Example 21 with ContractTest

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

the class GraphContractTest method failingTestDoubleRemoveAll.

@ContractTest
public void failingTestDoubleRemoveAll() {
    final Graph g = producer.newInstance();
    try {
        graphAddTxn(g, "c S d; e:ff GGG hhhh; _i J 27; Ell Em 'en'");
        Iterator<Triple> it = new TrackingTripleIterator(g.find(Triple.ANY)) {

            @Override
            public void remove() {
                // removes current
                super.remove();
                // no-op.
                g.delete(current);
            }
        };
        while (it.hasNext()) {
            it.next();
            it.remove();
        }
        assertTrue(g.isEmpty());
    } catch (UnsupportedOperationException e) {
    // No Iterator.remove
    }
}
Also used : GraphHelper.memGraph(org.apache.jena.testing_framework.GraphHelper.memGraph) TrackingTripleIterator(org.apache.jena.mem.TrackingTripleIterator) ContractTest(org.xenei.junit.contract.ContractTest)

Example 22 with ContractTest

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

the class UnionTest method testUnion.

@ContractTest
public void testUnion() {
    Graph g1 = graphWith("x R y; p R q");
    Graph g2 = graphWith("r Foo s; x R y");
    Union u = new Union(g1, g2);
    assertContains("Union", "x R y", u);
    assertContains("Union", "p R q", u);
    assertContains("Union", "r Foo s", u);
    if (u.size() != 3)
        fail("oops: size of union is not 3");
    u.add(triple("cats eat cheese"));
    assertContains("Union", "cats eat cheese", u);
    if (contains(g1, "cats eat cheese") == false && contains(g2, "cats eat cheese") == false)
        fail("oops: neither g1 nor g2 contains `cats eat cheese`");
}
Also used : Graph(org.apache.jena.graph.Graph) Union(org.apache.jena.graph.compose.Union) ContractTest(org.xenei.junit.contract.ContractTest)

Example 23 with ContractTest

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

the class GraphContractTest method testFind_Triple_ProgrammaticValues.

@ContractTest
public void testFind_Triple_ProgrammaticValues() {
    Graph g = producer.newInstance();
    if (g.getCapabilities().handlesLiteralTyping()) {
        Node ab = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(new Byte((byte) 42)));
        Node as = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(new Short((short) 42)));
        Node ai = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(new Integer(42)));
        Node al = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(new Long(42)));
        Node SB = NodeCreateUtils.create("SB");
        Node SS = NodeCreateUtils.create("SS");
        Node SI = NodeCreateUtils.create("SI");
        Node SL = NodeCreateUtils.create("SL");
        Node P = NodeCreateUtils.create("P");
        txnBegin(g);
        try {
            g.add(Triple.create(SB, P, ab));
            g.add(Triple.create(SS, P, as));
            g.add(Triple.create(SI, P, ai));
            g.add(Triple.create(SL, P, al));
        } catch (Exception e) {
            txnRollback(g);
            fail(e.getMessage());
        }
        txnCommit(g);
        assertEquals(String.format("Should have found 4 elements, does %s really implement literal typing", g.getClass()), 4, iteratorToSet(g.find(new Triple(Node.ANY, P, NodeCreateUtils.create("42")))).size());
    }
}
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 24 with ContractTest

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

the class GraphContractTest method testClear.

/**
	 * Test that clear works, in the presence of inferencing graphs that mean
	 * emptyness isn't available. This is why we go round the houses and test
	 * that expected ~= initialContent + addedStuff - removed - initialContent.
	 */
@ContractTest
public void testClear() {
    Graph graph = producer.newInstance();
    Graph base = copy(graph);
    graph.getEventManager().register(GL);
    txnBegin(graph);
    graph.clear();
    txnCommit(graph);
    assertEmpty(graph, base);
    GL.assertHasStart("someEvent", graph, GraphEvents.removeAll);
    GL.clear();
    // test after adding
    graph = graphWith(producer.newInstance(), "S P O; S e:ff 27; _1 P P3; S4 P4 'en'");
    graph.getEventManager().register(GL);
    txnBegin(graph);
    graph.clear();
    txnCommit(graph);
    assertEmpty(graph, base);
    if (GL.contains("delete")) {
        // deletes are listed -- ensure all deletes are listed
        GL.assertContains("delete", graph, triple("S P O"));
        GL.assertContains("delete", graph, triple("S e:ff 27"));
        GL.assertContains("delete", graph, triple("_1 P P3"));
        GL.assertContains("delete", graph, triple("S4 P4 'en'"));
    }
    GL.assertHasEnd("someEvent", graph, GraphEvents.removeAll);
    GL.clear();
}
Also used : GraphHelper.memGraph(org.apache.jena.testing_framework.GraphHelper.memGraph) ContractTest(org.xenei.junit.contract.ContractTest)

Example 25 with ContractTest

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

the class GraphContractTest method testTransactionHandler_Commit.

@ContractTest
public void testTransactionHandler_Commit() {
    Graph g = producer.newInstance();
    if (g.getTransactionHandler().transactionsSupported()) {
        Graph initial = graphWith(producer.newInstance(), "initial hasValue 42; also hasURI hello");
        Graph extra = graphWith(producer.newInstance(), "extra hasValue 17; also hasURI world");
        GraphUtil.addInto(g, initial);
        g.getTransactionHandler().begin();
        GraphUtil.addInto(g, extra);
        g.getTransactionHandler().commit();
        Graph union = memGraph();
        GraphUtil.addInto(union, initial);
        GraphUtil.addInto(union, extra);
        assertIsomorphic(union, g);
    // Model inFiIProducer<TransactionHandler>le =
    // ModelFactory.createDefaultModel();
    // inFile.read( "file:///" + foo, "N-TRIPLES" );
    // assertIsomorphic( union, inFile.getGraph() );
    }
}
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