Search in sources :

Example 1 with ContractTest

use of org.xenei.junit.contract.ContractTest 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)

Example 2 with ContractTest

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

the class GraphMakerContractTest method testGetGraph.

/**
	 * Foo trivial test that getGraph delivers a proper graph, not cheating with
	 * null, and that getGraph() "always" delivers the same Graph.
	 */
@ContractTest
public void testGetGraph() {
    Graph g1 = graphMaker.getGraph();
    assertFalse("should deliver a Graph", g1 == null);
    assertSame(g1, graphMaker.getGraph());
    g1.close();
}
Also used : Graph(org.apache.jena.graph.Graph) ContractTest(org.xenei.junit.contract.ContractTest)

Example 3 with ContractTest

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

the class GraphMakerContractTest method testListThreeGraphs.

/**
	 * Test that a maker with three graphs inserted lists those three grapsh; we
	 * don't mind what order they appear in. We also use funny names to ensure
	 * that the spelling that goes in is the one that comes out [should really
	 * be in a separate test].
	 */
@ContractTest
public void testListThreeGraphs() {
    String x = "x", y = "y/sub", z = "z:boo";
    Graph X = graphMaker.createGraph(x);
    Graph Y = graphMaker.createGraph(y);
    Graph Z = graphMaker.createGraph(z);
    Set<String> wanted = TestUtils.setOfStrings(x + " " + y + " " + z);
    assertEquals(wanted, GraphHelper.iteratorToSet(graphMaker.listGraphs()));
    X.close();
    Y.close();
    Z.close();
}
Also used : Graph(org.apache.jena.graph.Graph) ContractTest(org.xenei.junit.contract.ContractTest)

Example 4 with ContractTest

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

the class TransactionHandlerContractTest method testTransactionsExistAsPerTransactionSupported.

/**
	 * Test that Graphs have transaction support methods, and that if they fail
	 * on some g they fail because they do not support the operation.
	 */
@SuppressWarnings("deprecation")
@ContractTest
public void testTransactionsExistAsPerTransactionSupported() {
    // Write out explicitly
    Command cmd = new Command() {

        @Override
        public Object execute() {
            return null;
        }
    };
    TransactionHandler th = getTransactionHandlerProducer().newInstance();
    if (th.transactionsSupported()) {
        th.begin();
        th.abort();
        th.begin();
        th.commit();
        th.execute(() -> {
        });
        th.calculate(() -> null);
        th.executeInTransaction(cmd);
        th.executeInTransaction(() -> null);
    } else {
        try {
            th.begin();
            fail("Should have thrown UnsupportedOperationException");
        } catch (UnsupportedOperationException x) {
        }
        try {
            th.abort();
            fail("Should have thrown UnsupportedOperationException");
        } catch (UnsupportedOperationException x) {
        }
        try {
            th.commit();
            fail("Should have thrown UnsupportedOperationException");
        } catch (UnsupportedOperationException x) {
        }
        /* */
        try {
            th.execute(() -> {
            });
            fail("Should have thrown UnsupportedOperationException");
        } catch (UnsupportedOperationException x) {
        }
        try {
            th.calculate(() -> null);
            fail("Should have thrown UnsupportedOperationException");
        } catch (UnsupportedOperationException x) {
        }
        try {
            th.executeInTransaction(cmd);
            fail("Should have thrown UnsupportedOperationException");
        } catch (UnsupportedOperationException x) {
        }
        try {
            th.executeInTransaction(() -> null);
            fail("Should have thrown UnsupportedOperationException");
        } catch (UnsupportedOperationException x) {
        }
    }
}
Also used : Command(org.apache.jena.shared.Command) TransactionHandler(org.apache.jena.graph.TransactionHandler) ContractTest(org.xenei.junit.contract.ContractTest)

Example 5 with ContractTest

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

the class GraphContractTest method testGetStatisticsHandler.

@ContractTest
public void testGetStatisticsHandler() {
    Graph g = producer.newInstance();
    GraphStatisticsHandler sh = g.getStatisticsHandler();
    if (sh != null) {
        assertSame("getStatisticsHandler must always return the same object", sh, g.getStatisticsHandler());
    }
}
Also used : GraphHelper.memGraph(org.apache.jena.testing_framework.GraphHelper.memGraph) ContractTest(org.xenei.junit.contract.ContractTest)

Aggregations

ContractTest (org.xenei.junit.contract.ContractTest)169 Query (org.apache.jena.query.Query)65 GraphHelper.memGraph (org.apache.jena.testing_framework.GraphHelper.memGraph)57 WhereValidator (org.apache.jena.arq.querybuilder.WhereValidator)42 Var (org.apache.jena.sparql.core.Var)42 ExprVar (org.apache.jena.sparql.expr.ExprVar)39 ElementSubQuery (org.apache.jena.sparql.syntax.ElementSubQuery)26 ElementPathBlock (org.apache.jena.sparql.syntax.ElementPathBlock)25 Node (org.apache.jena.graph.Node)23 Triple (org.apache.jena.graph.Triple)22 FrontsTriple (org.apache.jena.graph.FrontsTriple)21 TriplePath (org.apache.jena.sparql.core.TriplePath)18 Binding (org.apache.jena.sparql.engine.binding.Binding)16 Graph (org.apache.jena.graph.Graph)15 VarExprList (org.apache.jena.sparql.core.VarExprList)12 E_Random (org.apache.jena.sparql.expr.E_Random)12 Expr (org.apache.jena.sparql.expr.Expr)11 ElementData (org.apache.jena.sparql.syntax.ElementData)11 ElementOptional (org.apache.jena.sparql.syntax.ElementOptional)10 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)9