Search in sources :

Example 66 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class AbstractTestGraph2 method remove_01.

@Test
public void remove_01() {
    Graph g = emptyGraph();
    Triple t1 = triple(s1, p1, o1);
    g.add(t1);
    g.remove(any, any, any);
    assertEquals(0, g.size());
    returnGraph(g);
}
Also used : Triple(org.apache.jena.graph.Triple) Graph(org.apache.jena.graph.Graph) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 67 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class AbstractTestGraph2 method graph_add_delete_03.

@Test
public void graph_add_delete_03() {
    Graph g = emptyGraph();
    Triple t = triple(s1, p1, o1);
    // Add twice, delete once => empty
    g.add(t);
    g.add(t);
    g.delete(t);
    assertEquals(0, g.size());
    assertFalse("g contains t", g.contains(t));
    returnGraph(g);
}
Also used : Triple(org.apache.jena.graph.Triple) Graph(org.apache.jena.graph.Graph) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 68 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class AbstractTestGraph2 method graph_add_03.

@Test
public void graph_add_03() {
    Graph g = emptyGraph();
    // SPO twice -- as different nodes.
    Node ns1 = NodeFactoryExtra.parseNode("<ex:s>");
    Node np1 = NodeFactoryExtra.parseNode("<ex:p>");
    Node no1 = NodeFactoryExtra.parseNode("<ex:o>");
    Node ns2 = NodeFactoryExtra.parseNode("<ex:s>");
    Node np2 = NodeFactoryExtra.parseNode("<ex:p>");
    Node no2 = NodeFactoryExtra.parseNode("<ex:o>");
    Triple t1 = triple(ns1, np1, no1);
    Triple t2 = triple(ns2, np2, no2);
    g.add(t1);
    g.add(t2);
    assertEquals(1, g.size());
    assertTrue(g.contains(t1));
    assertTrue(g.contains(t2));
    assertTrue(g.contains(ns1, np1, no1));
    returnGraph(g);
}
Also used : Triple(org.apache.jena.graph.Triple) Graph(org.apache.jena.graph.Graph) Node(org.apache.jena.graph.Node) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 69 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class TestFindLiterals method aTest.

public static TestFindLiterals aTest(final String graph, final int size, final String search, final String results) {
    return new TestFindLiterals("TestFindLiterals: graph {" + graph + "} size " + size + " search " + search + " expecting {" + results + "}") {

        @Override
        public void runBare() {
            Graph g = graphWith(graph);
            Node literal = NodeCreateUtils.create(search);
            //
            assertEquals("graph has wrong size", size, g.size());
            Set<Node> got = g.find(Node.ANY, Node.ANY, literal).mapWith(t -> t.getObject()).toSet();
            assertEquals(nodeSet(results), got);
        }
    };
}
Also used : TestSuite(junit.framework.TestSuite) LiteralLabelFactory(org.apache.jena.graph.impl.LiteralLabelFactory) JenaRuntime(org.apache.jena.JenaRuntime) Node(org.apache.jena.graph.Node) NodeFactory(org.apache.jena.graph.NodeFactory) Set(java.util.Set) Triple(org.apache.jena.graph.Triple) Graph(org.apache.jena.graph.Graph) Graph(org.apache.jena.graph.Graph) Node(org.apache.jena.graph.Node)

Example 70 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class TestIntersection method testDelete.

public void testDelete() {
    Graph l = graphWith("r A s; x R y");
    Graph r = graphWith("x R y; p S q");
    Intersection isec = new Intersection(l, r);
    assertIsomorphic(graphWith("x R y"), isec);
    // removing non-contained triples is a no-op
    isec.delete(triple("r A s"));
    assertIsomorphic(graphWith("r A s; x R y"), l);
    isec.delete(triple("p S q"));
    assertIsomorphic(graphWith("x R y; p S q"), r);
    // removing a contained triple removes it from the left operand
    isec.delete(triple("x R y"));
    assertIsomorphic(graphWith(""), isec);
    assertIsomorphic(graphWith("r A s"), l);
    assertIsomorphic(graphWith("x R y; p S q"), r);
}
Also used : Intersection(org.apache.jena.graph.compose.Intersection) Graph(org.apache.jena.graph.Graph)

Aggregations

Graph (org.apache.jena.graph.Graph)247 Test (org.junit.Test)90 BaseTest (org.apache.jena.atlas.junit.BaseTest)56 Triple (org.apache.jena.graph.Triple)56 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)54 Node (org.apache.jena.graph.Node)46 AbstractTestGraph (org.apache.jena.graph.test.AbstractTestGraph)16 InfGraph (org.apache.jena.reasoner.InfGraph)16 ContractTest (org.xenei.junit.contract.ContractTest)16 Model (org.apache.jena.rdf.model.Model)14 MultiUnion (org.apache.jena.graph.compose.MultiUnion)9 Delta (org.apache.jena.graph.compose.Delta)8 BuilderGraph (org.apache.jena.sparql.sse.builders.BuilderGraph)8 StreamRDF (org.apache.jena.riot.system.StreamRDF)7 PrefixMapping (org.apache.jena.shared.PrefixMapping)7 GraphUnionRead (org.apache.jena.sparql.graph.GraphUnionRead)7 IOException (java.io.IOException)6 Dataset (org.apache.jena.query.Dataset)6 Rule (org.apache.jena.reasoner.rulesys.Rule)6 ConfigTest (org.apache.jena.tdb.ConfigTest)6