Search in sources :

Example 1 with ModelCom

use of org.apache.jena.rdf.model.impl.ModelCom in project jena by apache.

the class TestContains method testModelComContainsSPcallsContainsSPO.

public void testModelComContainsSPcallsContainsSPO() {
    final Graph g = Factory.createDefaultGraph();
    final boolean[] wasCalled = { false };
    // FIXME change to dynamic proxy
    final Model m = new ModelCom(g) {

        @Override
        public boolean contains(final Resource s, final Property p, final RDFNode o) {
            wasCalled[0] = true;
            return super.contains(s, p, o);
        }
    };
    Assert.assertFalse(m.contains(ModelHelper.resource("r"), ModelHelper.property("p")));
    Assert.assertTrue("contains(S,P) should call contains(S,P,O)", wasCalled[0]);
}
Also used : Graph(org.apache.jena.graph.Graph) ModelCom(org.apache.jena.rdf.model.impl.ModelCom)

Example 2 with ModelCom

use of org.apache.jena.rdf.model.impl.ModelCom in project jena by apache.

the class AbstractTestModel method testRemoveSPO.

/**
 	Test that remove(s, p, o) works, in the presence of inferencing graphs that
 	mean emptyness isn't available. This is why we go round the houses and
 	test that expected ~= initialContent + addedStuff - removed - initialContent.
 	*/
public void testRemoveSPO() {
    ModelCom mc = (ModelCom) ModelFactory.createDefaultModel();
    for (String[] aCase : cases) {
        for (int j = 0; j < 3; j += 1) {
            Model content = getModel();
            Model baseContent = copy(content);
            modelAdd(content, aCase[0]);
            Triple remove = triple(aCase[1]);
            Node s = remove.getSubject(), p = remove.getPredicate(), o = remove.getObject();
            Resource S = (Resource) (s.equals(Node.ANY) ? null : mc.getRDFNode(s));
            Property P = ((p.equals(Node.ANY) ? null : mc.getRDFNode(p).as(Property.class)));
            RDFNode O = o.equals(Node.ANY) ? null : mc.getRDFNode(o);
            Model expected = modelWithStatements(aCase[2]);
            content.removeAll(S, P, O);
            Model finalContent = copy(content).remove(baseContent);
            assertIsoModels(aCase[1], expected, finalContent);
        }
    }
}
Also used : Triple(org.apache.jena.graph.Triple) RDFNode(org.apache.jena.rdf.model.RDFNode) Node(org.apache.jena.graph.Node) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) ModelCom(org.apache.jena.rdf.model.impl.ModelCom) Property(org.apache.jena.rdf.model.Property) RDFNode(org.apache.jena.rdf.model.RDFNode)

Aggregations

ModelCom (org.apache.jena.rdf.model.impl.ModelCom)2 Graph (org.apache.jena.graph.Graph)1 Node (org.apache.jena.graph.Node)1 Triple (org.apache.jena.graph.Triple)1 Model (org.apache.jena.rdf.model.Model)1 Property (org.apache.jena.rdf.model.Property)1 RDFNode (org.apache.jena.rdf.model.RDFNode)1 Resource (org.apache.jena.rdf.model.Resource)1