# # Copyright (c) 2003 by Benja Fallenstein # # This file is part of Fenfire. # # Fenfire is free software; you can redistribute it and/or modify it under # the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # Fenfire is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General # Public License for more details. # # You should have received a copy of the GNU Lesser General # Public License along with Fenfire; if not, write to the Free # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, # MA 02111-1307 USA # import java import com.hp.hpl.mesa.rdf.jena import org.fenfire.loom def setUp(): global model, sel, p, q, r, s, t model = com.hp.hpl.mesa.rdf.jena.mem.ModelMem() sel = org.fenfire.loom.PropertySetSelector() p = model.createProperty("http://fenfire.org/2003/02/test#", "test-property") q = model.createProperty("http://fenfire.org/2003/02/test#", "test-prop-2") r,s,t = [model.createResource("urn:x-foo:%s" % i) for i in range(3)] r.addProperty(p, r) r.addProperty(p, s) r.addProperty(q, t) def set(list): s = java.util.HashSet() for el in list: s.add(el) return s def objects(collection, list): if collection.size() != len(list): raise AssertionError("objects from %s != %s" % (collection, list)) iter = collection.iterator() while iter.hasNext(): if not iter.next().getObject() in list: raise AssertionError("object from %s != %s" % (collection, list)) def test(): c = sel.getConnections(r, 1) objects(c, [r,s,t]) sel.setProperties(set([p]), 1) c = sel.getConnections(r, 1) objects(c, [r,s]) sel.setProperties(set([]), 1) c = sel.getConnections(r, 1) assert c.isEmpty() sel.setProperties(set([q]), 1) c = sel.getConnections(r, 1) objects(c, [t]) sel.setProperties(None, 1) c = sel.getConnections(r, 1) objects(c, [r,s,t]) sel.setProperties(set([p, q]), 1) c = sel.getConnections(r, 1) objects(c, [r,s,t])