Search in sources :

Example 46 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class TestModelEvents method testTwoListeners.

public void testTwoListeners() {
    final Statement S = ModelHelper.statement(model, "S P O");
    final RecordingModelListener SL1 = new RecordingModelListener();
    final RecordingModelListener SL2 = new RecordingModelListener();
    model.register(SL1).register(SL2);
    model.add(S);
    SL2.assertHas(new Object[] { "add", S });
    SL1.assertHas(new Object[] { "add", S });
}
Also used : Statement(org.apache.jena.rdf.model.Statement) RecordingModelListener(org.apache.jena.rdf.model.test.helpers.RecordingModelListener)

Example 47 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class TestModelSetOperations method testIntersection.

public void testIntersection() {
    ModelHelper.modelAdd(model, "a P b; w R x");
    ModelHelper.modelAdd(model2, "w R x; y S z");
    final Model im = model.intersection(model2);
    Assert.assertFalse(model.containsAll(model2));
    Assert.assertFalse(model2.containsAll(model));
    Assert.assertTrue(model.containsAll(im));
    Assert.assertTrue(model2.containsAll(im));
    for (final StmtIterator it = im.listStatements(); it.hasNext(); ) {
        final Statement s = it.nextStatement();
        Assert.assertTrue(model.contains(s) && model2.contains(s));
    }
    for (final StmtIterator it = im.listStatements(); it.hasNext(); ) {
        Assert.assertTrue(model.contains(it.nextStatement()));
    }
    for (final StmtIterator it = im.listStatements(); it.hasNext(); ) {
        Assert.assertTrue(model2.contains(it.nextStatement()));
    }
    Assert.assertTrue(model.containsAll(im.listStatements()));
    Assert.assertTrue(model2.containsAll(im.listStatements()));
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model)

Example 48 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class TestModelSetOperations method testDifference.

public void testDifference() {
    ModelHelper.modelAdd(model, "a P b; w R x");
    ModelHelper.modelAdd(model2, "w R x; y S z");
    final Model dm = model.difference(model2);
    for (final StmtIterator it = dm.listStatements(); it.hasNext(); ) {
        final Statement s = it.nextStatement();
        Assert.assertTrue(model.contains(s) && !model2.contains(s));
    }
    for (final StmtIterator it = model.union(model2).listStatements(); it.hasNext(); ) {
        final Statement s = it.nextStatement();
        Assert.assertEquals(model.contains(s) && !model2.contains(s), dm.contains(s));
    }
    Assert.assertTrue(dm.containsAny(model));
    Assert.assertTrue(dm.containsAny(model.listStatements()));
    Assert.assertFalse(dm.containsAny(model2));
    Assert.assertFalse(dm.containsAny(model2.listStatements()));
    Assert.assertTrue(model.containsAll(dm));
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model)

Example 49 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class TestModelEvents method testObjectListener.

public void testObjectListener() {
    final OL ll = new OL();
    model.register(ll);
    final Statement s = ModelHelper.statement(model, "aa BB cc"), s2 = ModelHelper.statement(model, "dd EE ff");
    model.add(s);
    ll.recent("add", s);
    model.remove(s2);
    ll.recent("rem", s2);
    /* */
    final List<Statement> sList = Arrays.asList(ModelHelper.statements(model, "gg HH ii; jj KK ll"));
    model.add(sList);
    ll.recent("add", sList);
    final List<Statement> sList2 = Arrays.asList(ModelHelper.statements(model, "mm NN oo; pp QQ rr; ss TT uu"));
    model.remove(sList2);
    ll.recent("rem", sList2);
    /* */
    final Model m1 = ModelHelper.modelWithStatements(this, "vv WW xx; yy ZZ aa");
    model.add(m1);
    ll.recent("add", m1);
    final Model m2 = ModelHelper.modelWithStatements(this, "a B g; d E z");
    model.remove(m2);
    ll.recent("rem", m2);
    /* */
    final Statement[] sa1 = ModelHelper.statements(model, "th i k; l model n");
    model.add(sa1);
    ll.recent("add", sa1);
    final Statement[] sa2 = ModelHelper.statements(model, "x o p; r u ch");
    model.remove(sa2);
    ll.recent("rem", sa2);
    /* */
    final Statement[] si1 = ModelHelper.statements(model, "u ph ch; psi om eh");
    model.add(asIterator(si1));
    ll.recent("add", asIterator(si1));
    final Statement[] si2 = ModelHelper.statements(model, "at last the; end of these; tests ok guv");
    model.remove(asIterator(si2));
    ll.recent("rem", asIterator(si2));
}
Also used : Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model)

Example 50 with Statement

use of org.apache.jena.rdf.model.Statement in project jena by apache.

the class TestModelEvents method testRemoveSingleStatements.

public void testRemoveSingleStatements() {
    final Statement S = ModelHelper.statement(model, "D E F");
    model.register(SL);
    model.add(S);
    model.remove(S);
    SL.assertHas(new Object[] { "add", S, "remove", S });
}
Also used : Statement(org.apache.jena.rdf.model.Statement)

Aggregations

Statement (org.apache.jena.rdf.model.Statement)72 Model (org.apache.jena.rdf.model.Model)43 StmtIterator (org.apache.jena.rdf.model.StmtIterator)28 Test (org.junit.Test)25 Dataset (org.apache.jena.query.Dataset)24 Resource (org.apache.jena.rdf.model.Resource)19 WonMessageValidator (won.protocol.validation.WonMessageValidator)15 Property (org.apache.jena.rdf.model.Property)13 RDFNode (org.apache.jena.rdf.model.RDFNode)13 ArrayList (java.util.ArrayList)11 Ignore (org.junit.Ignore)11 Triple (org.apache.jena.graph.Triple)7 BaseTest (org.apache.jena.atlas.junit.BaseTest)6 Iterator (java.util.Iterator)4 RdfUtils (won.protocol.util.RdfUtils)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 OntModel (org.apache.jena.ontology.OntModel)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 GraphCollection (de.uni_koblenz.aggrimm.icp.crypto.sign.graph.GraphCollection)1