Search in sources :

Example 81 with ContractTest

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

the class GraphContractTest method testPartialUpdate.

// @ContractTest
// public void testTransactionCommit()
// {
// Graph g = producer.newInstance();
// if (g.getTransactionHandler().transactionsSupported())
// {
// Graph initial = graphWithTxn( "initial hasValue 42; also hasURI hello" );
// Graph extra = graphWithTxn( "extra hasValue 17; also hasURI world" );
// //File foo = FileUtils.tempFileName( "fileGraph", ".nt" );
//
// //Graph g = new FileGraph( foo, true, true );
//
// GraphUtil.addInto( g, initial );
// g.getTransactionHandler().begin();
// GraphUtil.addInto( g, extra );
// g.getTransactionHandler().commit();
// Graph union = graphWithTxn( "" );
// GraphUtil.addInto(union, initial );
// GraphUtil.addInto(union, extra );
// assertIsomorphic( union, g );
// //Model inFile = ModelFactory.createDefaultModel();
// //inFile.read( "file:///" + foo, "N-TRIPLES" );
// //assertIsomorphic( union, inFile.getGraph() );
// }
// }
//
// @ContractTest
// public void testTransactionAbort()
// {
// Graph g = producer.newInstance();
// if (g.getTransactionHandler().transactionsSupported())
// {
// Graph initial = graphWithTxn( "initial hasValue 42; also hasURI hello" );
// Graph extra = graphWithTxn( "extra hasValue 17; also hasURI world" );
// File foo = FileUtils.tempFileName( "fileGraph", ".n3" );
// //Graph g = new FileGraph( foo, true, true );
// GraphUtil.addInto( g, initial );
// g.getTransactionHandler().begin();
// GraphUtil.addInto( g, extra );
// g.getTransactionHandler().abort();
// assertIsomorphic( initial, g );
// }
// }
//
// @ContractTest
// public void testTransactionCommitThenAbort()
// {
// Graph g = producer.newInstance();
// if (g.getTransactionHandler().transactionsSupported())
// {
// Graph initial = graphWithTxn( "Foo pings B; B pings C" );
// Graph extra = graphWithTxn( "C pingedBy B; fileGraph rdf:type Graph" );
// //Graph g = producer.newInstance();
// //File foo = FileUtils.tempFileName( "fileGraph", ".nt" );
// //Graph g = new FileGraph( foo, true, true );
// 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() );
// }
// }
/**
	 * This test exposed that the update-existing-graph functionality was broken
	 * if the target graph already contained any statements with a subject S
	 * appearing as subject in the source graph - no further Spo statements were
	 * added.
	 */
@ContractTest
public void testPartialUpdate() {
    Graph source = graphWith(producer.newInstance(), "a R b; b S e");
    Graph dest = graphWith(producer.newInstance(), "b R d");
    GraphExtract e = new GraphExtract(TripleBoundary.stopNowhere);
    e.extractInto(dest, node("a"), source);
    assertIsomorphic(graphWith(producer.newInstance(), "a R b; b S e; b R d"), dest);
}
Also used : GraphHelper.memGraph(org.apache.jena.testing_framework.GraphHelper.memGraph) ContractTest(org.xenei.junit.contract.ContractTest)

Example 82 with ContractTest

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

the class DeltaTest method testDelta.

@ContractTest
public void testDelta() {
    Graph x = graphWith(getDeltaTestProducer().newInstance(), "x R y");
    assertContains("x", "x R y", x);
    x.delete(triple("x R y"));
    assertOmits("x", x, "x R y");
    /* */
    Graph base = graphWith("x R y; p S q; I like cheese; pins pop balloons");
    Delta delta = new Delta(base);
    assertContainsAll("Delta", delta, "x R y; p S q; I like cheese; pins pop balloons");
    assertContainsAll("Base", base, "x R y; p S q; I like cheese; pins pop balloons");
    /* */
    delta.add(triple("pigs fly winglessly"));
    delta.delete(triple("I like cheese"));
    /* */
    assertContainsAll("changed Delta", delta, "x R y; p S q; pins pop balloons; pigs fly winglessly");
    assertOmits("changed delta", delta, "I like cheese");
    assertContains("delta additions", "pigs fly winglessly", delta.getAdditions());
    assertOmits("delta additions", delta.getAdditions(), "I like cheese");
    assertContains("delta deletions", "I like cheese", delta.getDeletions());
    assertOmits("delta deletions", delta.getDeletions(), "pigs fly winglessly");
}
Also used : Graph(org.apache.jena.graph.Graph) ContractTest(org.xenei.junit.contract.ContractTest)

Example 83 with ContractTest

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

the class GraphContractTest method testContains_Node_Node_Node_RepeatedSubjectDoesNotConceal.

@ContractTest
public void testContains_Node_Node_Node_RepeatedSubjectDoesNotConceal() {
    Graph g = graphWith(producer.newInstance(), "s P o; s Q r");
    Node s = node("s");
    Node P = node("P");
    Node o = node("o");
    Node Q = node("Q");
    Node r = node("r");
    Node any = node("??");
    assertTrue(g.contains(s, P, o));
    assertTrue(g.contains(s, Q, r));
    assertTrue(g.contains(any, P, o));
    assertTrue(g.contains(any, Q, r));
    assertTrue(g.contains(any, P, any));
    assertTrue(g.contains(any, Q, any));
}
Also used : GraphHelper.memGraph(org.apache.jena.testing_framework.GraphHelper.memGraph) ContractTest(org.xenei.junit.contract.ContractTest)

Example 84 with ContractTest

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

the class GraphContractTest method testGetCapabilities.

@ContractTest
public void testGetCapabilities() {
    Graph g = producer.newInstance();
    Capabilities c = g.getCapabilities();
    assertNotNull("Capabilities are not returned", c);
    try {
        c.sizeAccurate();
    } catch (Exception e) {
        fail("sizeAccurate() threw Exception: " + e.toString());
    }
    try {
        c.addAllowed();
    } catch (Exception e) {
        fail("addAllowed() threw Exception: " + e.toString());
    }
    try {
        c.deleteAllowed();
    } catch (Exception e) {
        fail("deleteAllowed() threw Exception: " + e.toString());
    }
}
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 85 with ContractTest

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

the class GraphMakerContractTest method testCanCreateTwice.

@ContractTest
public void testCanCreateTwice() {
    String name = jName("bridge");
    Graph g1 = graphMaker.createGraph(name, true);
    Graph g2 = graphMaker.createGraph(name, false);
    assertTrue("graphs should be the same", sameGraph(g1, g2));
    Graph g3 = graphMaker.createGraph(name);
    assertTrue("graphs should be the same", sameGraph(g1, g3));
}
Also used : Graph(org.apache.jena.graph.Graph) 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