Search in sources :

Example 91 with ContractTest

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

the class GraphContractTest method testIsClosed.

@ContractTest
public void testIsClosed() {
    Graph g = producer.newInstance();
    assertFalse("Graph created in closed state", g.isClosed());
    g.close();
    assertTrue("Graph does not report closed state after close called", g.isClosed());
}
Also used : GraphHelper.memGraph(org.apache.jena.testing_framework.GraphHelper.memGraph) ContractTest(org.xenei.junit.contract.ContractTest)

Example 92 with ContractTest

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

the class GraphContractTest method testTransactionHandler_CommitThenAbort.

@ContractTest
public void testTransactionHandler_CommitThenAbort() {
    Graph g = producer.newInstance();
    if (g.getTransactionHandler().transactionsSupported()) {
        Graph initial = graphWith(producer.newInstance(), "Foo pings B; B pings C");
        Graph extra = graphWith(producer.newInstance(), "C pingedBy B; fileGraph rdf:type Graph");
        g.getTransactionHandler().begin();
        GraphUtil.addInto(g, initial);
        g.getTransactionHandler().commit();
        g.getTransactionHandler().begin();
        GraphUtil.addInto(g, extra);
        g.getTransactionHandler().abort();
        assertIsomorphic(initial, g);
    // Model inFile = ModelFactory.createDefaultModel();
    // inFile.read( "file:///" + foo, "N-TRIPLES" );
    // assertIsomorphic( initial, inFile.getGraph() );
    }
}
Also used : GraphHelper.memGraph(org.apache.jena.testing_framework.GraphHelper.memGraph) ContractTest(org.xenei.junit.contract.ContractTest)

Example 93 with ContractTest

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

the class GraphContractTest method testDelete_Triple.

/**
	 * Inference graphs can not be empty
	 */
@ContractTest
public void testDelete_Triple() {
    Graph graph = graphWith(producer.newInstance(), "S P O; S2 P2 O2; S3 P3 O3");
    Graph base = producer.newInstance();
    graph.getEventManager().register(GL);
    txnBegin(graph);
    graph.delete(triple("S P O"));
    txnCommit(graph);
    GL.assertContains("delete", graph, triple("S P O"));
    assertFalse("Graph should not contain <S P O>", graph.contains(triple("S P O")));
    assertNotEmpty(graph, base);
    assertTrue("Graph should contain <S2 P2 O2>", graph.contains(triple("S2 P2 O2")));
    assertTrue("Graph should contain <S3 P3 O3>", graph.contains(triple("S3 P3 O3")));
    // should not modify anything on wildcard delete
    GL.clear();
    try {
        txnBegin(graph);
        graph.delete(new Triple(node("S2"), node("P2"), Node.ANY));
        txnCommit(graph);
    } catch (DeleteDeniedException expected) {
        txnRollback(graph);
    }
    assertTrue("Graph should contain <S2 P2 O2>", graph.contains(triple("S2 P2 O2")));
    assertTrue("Graph should contain <S3 P3 O3>", graph.contains(triple("S3 P3 O3")));
    GL.assertHas("delete", graph, new Triple(node("S2"), node("P2"), Node.ANY));
}
Also used : GraphHelper.memGraph(org.apache.jena.testing_framework.GraphHelper.memGraph) DeleteDeniedException(org.apache.jena.shared.DeleteDeniedException) ContractTest(org.xenei.junit.contract.ContractTest)

Example 94 with ContractTest

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

the class GraphContractTest method testFind_Node_Node_Node.

@ContractTest
public void testFind_Node_Node_Node() {
    Graph graph = graphWith(producer.newInstance(), "S P O; S2 P2 O2; S3 P3 O3");
    List<Triple> s = graph.find(Node.ANY, Node.ANY, Node.ANY).toList();
    assertEquals(3, s.size());
    List<Triple> expected = Arrays.asList(new Triple[] { triple("S P O"), triple("S2 P2 O2"), triple("S3 P3 O3") });
    assertTrue("Missing some values", expected.containsAll(s) && s.containsAll(expected));
    s = graph.find(node("S"), Node.ANY, Node.ANY).toList();
    assertEquals(1, s.size());
    assertTrue("Missing some values", s.contains(triple("S P O")));
    s = graph.find(Node.ANY, node("P"), Node.ANY).toList();
    assertEquals(1, s.size());
    assertTrue("Missing some values", s.contains(triple("S P O")));
    s = graph.find(Node.ANY, Node.ANY, node("O")).toList();
    assertEquals(1, s.size());
    assertTrue("Missing some values", s.contains(triple("S P O")));
    s = graph.find(node("S2"), node("P2"), node("O2")).toList();
    assertEquals(1, s.size());
    assertTrue("Missing some values", s.contains(triple("S2 P2 O2")));
    s = graph.find(node("S2"), node("P3"), node("O2")).toList();
    assertEquals(0, s.size());
    s = graph.find(Node.ANY, node("P3"), node("O2")).toList();
    assertEquals(0, s.size());
    s = graph.find(node("S3"), Node.ANY, node("O2")).toList();
    assertEquals(0, s.size());
    s = graph.find(node("S3"), node("P2"), Node.ANY).toList();
    assertEquals(0, s.size());
}
Also used : GraphHelper.memGraph(org.apache.jena.testing_framework.GraphHelper.memGraph) ContractTest(org.xenei.junit.contract.ContractTest)

Example 95 with ContractTest

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

the class GraphContractTest method testIsEmpty.

@ContractTest
public void testIsEmpty() {
    Graph g = producer.newInstance();
    if (!g.isEmpty()) {
        LOG.warn(String.format("Graph type %s can not be empty (Empty test skipped)", g.getClass()));
    } else {
        graphAddTxn(g, "S P O");
        assertFalse("Graph reports empty after add", g.isEmpty());
        txnBegin(g);
        g.add(NodeCreateUtils.createTriple("Foo B C"));
        g.delete(NodeCreateUtils.createTriple("S P O"));
        txnCommit(g);
        assertFalse("Should not report empty", g.isEmpty());
        txnBegin(g);
        g.delete(NodeCreateUtils.createTriple("Foo B C"));
        txnCommit(g);
        assertTrue("Should report empty after all entries deleted", g.isEmpty());
    }
}
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