Search in sources :

Example 41 with Graph

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

the class TestCustomAggregates method customAgg_20.

@Test
public void customAgg_20() {
    Graph g = SSE.parseGraph("(graph (:s :p :o) (:s :p 1))");
    Model m = ModelFactory.createModelForGraph(g);
    String qs = "SELECT (<" + aggIRI + ">(?o) AS ?x) {?s ?p ?o } GROUP BY ?s";
    Query q = QueryFactory.create(qs, Syntax.syntaxARQ);
    try (QueryExecution qExec = QueryExecutionFactory.create(q, m)) {
        ResultSet rs = qExec.execSelect();
        QuerySolution soln = rs.nextSolution();
        assertFalse(rs.hasNext());
        int v = soln.getLiteral("x").getInt();
        assertEquals(1, v);
    }
}
Also used : Graph(org.apache.jena.graph.Graph) Model(org.apache.jena.rdf.model.Model) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 42 with Graph

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

the class TestCustomAggregates method customAgg_21.

@Test
public void customAgg_21() {
    Graph g = SSE.parseGraph("(graph (:s :p :o) (:s :p 1))");
    Model m = ModelFactory.createModelForGraph(g);
    String qs = "SELECT (<" + aggIRI + ">(?o) AS ?x) {?s ?p ?o FILTER (false) } GROUP BY ?s";
    Query q = QueryFactory.create(qs, Syntax.syntaxARQ);
    try (QueryExecution qExec = QueryExecutionFactory.create(q, m)) {
        ResultSet rs = qExec.execSelect();
        QuerySolution soln = rs.nextSolution();
        assertFalse(rs.hasNext());
        int v = soln.getLiteral("x").getInt();
        assertEquals(-1, v);
    }
}
Also used : Graph(org.apache.jena.graph.Graph) Model(org.apache.jena.rdf.model.Model) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 43 with Graph

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

the class AbstractTestDatasetGraphAccessor method put_02.

@Test
public void put_02() {
    DatasetGraphAccessor updater = getDatasetUpdater();
    updater.httpPut(n1, graph1);
    Graph graph = updater.httpGet();
    assertNullOrEmpty(graph);
    graph = updater.httpGet(n1);
    assertNotNull("Graph is null", graph);
    assertTrue(graph.isIsomorphicWith(graph1));
}
Also used : Graph(org.apache.jena.graph.Graph) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 44 with Graph

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

the class AbstractTestDatasetGraphAccessor method put_01.

@Test
public void put_01() {
    DatasetGraphAccessor updater = getDatasetUpdater();
    updater.httpPut(graph1);
    Graph graph = updater.httpGet();
    assertNotNull("Graph is null", graph);
    assertTrue(graph.isIsomorphicWith(graph1));
}
Also used : Graph(org.apache.jena.graph.Graph) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 45 with Graph

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

the class GraphMakerContractTest method testListAfterDelete.

/**
	 * Test that a maker with some things put in and then some removed gets the
	 * right things listed.
	 */
@ContractTest
public void testListAfterDelete() {
    String x = "x_y", y = "y//zub", z = "a:b/c";
    Graph X = graphMaker.createGraph(x);
    Graph Y = graphMaker.createGraph(y);
    Graph Z = graphMaker.createGraph(z);
    graphMaker.removeGraph(x);
    Set<String> s = GraphHelper.iteratorToSet(graphMaker.listGraphs());
    assertEquals(TestUtils.setOfStrings(y + " " + z), s);
    X.close();
    Y.close();
    Z.close();
}
Also used : Graph(org.apache.jena.graph.Graph) ContractTest(org.xenei.junit.contract.ContractTest)

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