Search in sources :

Example 86 with ContractTest

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

the class GraphContractTest method testContains_Node_Node_Node.

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

Example 87 with ContractTest

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

the class GraphContractTest method testFind_Node_Node_Node_ProgrammaticValues.

@ContractTest
public void testFind_Node_Node_Node_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(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 88 with ContractTest

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

the class GraphMakerContractTest method testCarefulClose.

@ContractTest
public void testCarefulClose() {
    Graph x = graphMaker.createGraph("x");
    Graph y = graphMaker.openGraph("x");
    x.add(GraphHelper.triple("a BB c"));
    x.close();
    y.add(GraphHelper.triple("p RR q"));
    y.close();
}
Also used : Graph(org.apache.jena.graph.Graph) ContractTest(org.xenei.junit.contract.ContractTest)

Example 89 with ContractTest

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

the class GraphContractTest method testFind_Triple_ByFluidTriple.

@ContractTest
public void testFind_Triple_ByFluidTriple() {
    Graph g = graphWith(producer.newInstance(), "x y z ");
    Set<Triple> expect = tripleSet("x y z");
    assertEquals(expect, g.find(triple("?? y z")).toSet());
    assertEquals(expect, g.find(triple("x ?? z")).toSet());
    assertEquals(expect, g.find(triple("x y ??")).toSet());
}
Also used : GraphHelper.memGraph(org.apache.jena.testing_framework.GraphHelper.memGraph) ContractTest(org.xenei.junit.contract.ContractTest)

Example 90 with ContractTest

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

the class GraphContractTest method testContains_Node_Node_Node_Fluid.

@ContractTest
public void testContains_Node_Node_Node_Fluid() {
    Node x = node("x");
    Node R = node("R");
    Node P = node("P");
    Node y = node("y");
    Node a = node("a");
    Node b = node("b");
    Graph g = graphWith(producer.newInstance(), "x R y; a P b");
    assertTrue(g.contains(Node.ANY, R, y));
    assertTrue(g.contains(x, Node.ANY, y));
    assertTrue(g.contains(x, R, Node.ANY));
    assertTrue(g.contains(Node.ANY, P, b));
    assertTrue(g.contains(a, Node.ANY, b));
    assertTrue(g.contains(a, P, Node.ANY));
    assertTrue(g.contains(Node.ANY, R, y));
    /* */
    assertFalse(g.contains(Node.ANY, R, b));
    assertFalse(g.contains(a, Node.ANY, y));
    assertFalse(g.contains(x, P, Node.ANY));
    assertFalse(g.contains(Node.ANY, R, x));
    assertFalse(g.contains(x, Node.ANY, R));
    assertFalse(g.contains(a, node("S"), Node.ANY));
}
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