Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/hp/hpl/jena/ontology/impl/test/TestBugReports.java


1   /*****************************************************************************
2    * Source code information
3    * -----------------------
4    * Original author    Ian Dickinson, HP Labs Bristol
5    * Author email       Ian.Dickinson@hp.com
6    * Package            Jena 2
7    * Web                http://sourceforge.net/projects/jena/
8    * Created            16-Jun-2003
9    * Filename           $RCSfile: TestBugReports.java,v $
10   * Revision           $Revision: 1.62 $
11   * Release status     $State: Exp $
12   *
13   * Last modified on   $Date: 2005/04/11 13:55:54 $
14   *               by   $Author: jeremy_carroll $
15   *
16   * (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
17   * (see footer for full conditions)
18   *****************************************************************************/
19  
20  // Package
21  ///////////////
22  package com.hp.hpl.jena.ontology.impl.test;
23  
24  // Imports
25  ///////////////
26  import java.io.*;
27  import java.lang.reflect.Field;
28  import java.lang.reflect.Modifier;
29  import java.util.*;
30  
31  import com.hp.hpl.jena.enhanced.EnhGraph;
32  import com.hp.hpl.jena.graph.*;
33  import com.hp.hpl.jena.graph.impl.*;
34  import com.hp.hpl.jena.mem.GraphMem;
35  import com.hp.hpl.jena.ontology.*;
36  import com.hp.hpl.jena.ontology.daml.*;
37  import com.hp.hpl.jena.ontology.daml.DAMLModel;
38  import com.hp.hpl.jena.ontology.impl.OntClassImpl;
39  import com.hp.hpl.jena.rdf.model.*;
40  import com.hp.hpl.jena.rdf.model.impl.ModelMakerImpl;
41  import com.hp.hpl.jena.reasoner.*;
42  import com.hp.hpl.jena.reasoner.ReasonerRegistry;
43  import com.hp.hpl.jena.reasoner.dig.*;
44  import com.hp.hpl.jena.reasoner.dig.DIGReasoner;
45  import com.hp.hpl.jena.reasoner.dig.DIGReasonerFactory;
46  import com.hp.hpl.jena.reasoner.test.TestUtil;
47  import com.hp.hpl.jena.util.FileUtils;
48  import com.hp.hpl.jena.util.iterator.ExtendedIterator;
49  import com.hp.hpl.jena.vocabulary.*;
50  import com.hp.hpl.jena.vocabulary.OWL;
51  
52  import junit.framework.*;
53  
54  /**
55   * <p>
56   * Unit tests that are derived from user bug reports
57   * </p>
58   *
59   * @author Ian Dickinson, HP Labs (<a  href="mailto:Ian.Dickinson@hp.com" >
60   *         email</a>)
61   * @version CVS $Id: TestBugReports.java,v 1.23 2003/11/20 17:53:10
62   *          ian_dickinson Exp $
63   */
64  public class TestBugReports
65      extends TestCase
66  {
67      // Constants
68      //////////////////////////////////
69  
70      public static String NS = "http://example.org/test#";
71  
72      // Static variables
73      //////////////////////////////////
74  
75      // Instance variables
76      //////////////////////////////////
77  
78      public TestBugReports(String name) {
79          super(name);
80      }
81  
82      // Constructors
83      //////////////////////////////////
84  
85      // External signature methods
86      //////////////////////////////////
87  
88      public void setUp() {
89          // ensure the ont doc manager is in a consistent state
90          OntDocumentManager.getInstance().reset( true );
91      }
92  
93  
94      /** Bug report by Danah Nada - listIndividuals returning too many results */
95      public void test_dn_0() {
96          OntModel schema = ModelFactory.createOntologyModel( OntModelSpec.OWL_LITE_MEM_RULES_INF, null );
97  
98          schema.read( "file:doc/inference/data/owlDemoSchema.xml", null );
99  
100         int count = 0;
101         for (Iterator i = schema.listIndividuals(); i.hasNext(); ) {
102             //Resource r = (Resource) i.next();
103             i.next();
104             count++;
105             /* Debugging * /
106             for (StmtIterator j = r.listProperties(RDF.type); j.hasNext(); ) {
107                 System.out.println( "ind - " + r + " rdf:type = " + j.nextStatement().getObject() );
108             }
109             System.out.println("----------"); /**/
110         }
111 
112         assertEquals( "Expecting 6 individuals", 6, count );
113     }
114 
115 
116     /* Bug report by Danah Nada - duplicate elements in property domain */
117     public void test_dn_01() {
118         // direct reading for the model method 1
119         OntModel m0 = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM_RULE_INF, null );
120         m0.read( "file:testing/ontology/bugs/test_hk_07B.owl" );
121 
122         OntProperty p0 = m0.getOntProperty( "file:testing/ontology/bugs/test_hk_07B.owl#PropB" );
123         int count = 0;
124         for (Iterator i = p0.listDomain(); i.hasNext();) {
125             count++;
126             i.next();
127         }
128         assertEquals( 3, count );
129 
130         // repeat test - thus using previously cached model for import
131 
132         OntModel m1 = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM_RULE_INF, null );
133         m1.read( "file:testing/ontology/bugs/test_hk_07B.owl" );
134 
135         OntProperty p1 = m1.getOntProperty( "file:testing/ontology/bugs/test_hk_07B.owl#PropB" );
136         count = 0;
137         for (Iterator i = p1.listDomain(); i.hasNext();) {
138             count++;
139             i.next();
140         }
141         assertEquals( 3, count );
142     }
143 
144     /** Bug report by Danah Nada - cannot remove import */
145     public void test_dn_02() {
146         OntModel mymod = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null );
147         mymod.read( "file:testing/ontology/testImport3/a.owl" );
148 
149         assertEquals( "Graph count..", 2, mymod.getSubGraphs().size() );
150 
151         for (Iterator it = mymod.listImportedModels(); it.hasNext();) {
152                 mymod.removeSubModel( (Model) it.next() );
153         }
154 
155         assertEquals( "Graph count..", 0, mymod.getSubGraphs().size() );
156     }
157 
158 
159     /**
160      * Bug report by Mariano Rico Almod�var [Mariano.Rico@uam.es] on June 16th.
161      * Said to raise exception.
162      */
163     public void test_mra_01() {
164         OntModel m = ModelFactory.createOntologyModel(OntModelSpec.DAML_MEM, null, null);
165         String myDicURI = "http://somewhere/myDictionaries/1.0#";
166         String damlURI = "http://www.daml.org/2001/03/daml+oil#";
167         m.setNsPrefix("DAML", damlURI);
168 
169         String c1_uri = myDicURI + "C1";
170         OntClass c1 = m.createClass(c1_uri);
171 
172         DatatypeProperty p1 = m.createDatatypeProperty(myDicURI + "P1");
173         p1.setDomain(c1);
174 
175         ByteArrayOutputStream strOut = new ByteArrayOutputStream();
176 
177         m.write(strOut, "RDF/XML-ABBREV", myDicURI);
178         //m.write(System.out,"RDF/XML-ABBREV", myDicURI);
179 
180     }
181 
182     /**
183      * Bug report from Holger Knublauch on July 25th 2003. Cannot convert
184      * owl:Class to an OntClass
185      */
186     public void test_hk_01() {
187         // synthesise a mini-document
188         String base = "http://jena.hpl.hp.com/test#";
189         String doc =
190             "<rdf:RDF"
191                 + "   xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\""
192                 + "   xmlns:owl=\"http://www.w3.org/2002/07/owl#\">"
193                 + "  <owl:Ontology rdf:about=\"\">"
194                 + "    <owl:imports rdf:resource=\"http://www.w3.org/2002/07/owl\" />"
195                 + "  </owl:Ontology>"
196                 + "</rdf:RDF>";
197 
198         // read in the base ontology, which includes the owl language
199         // definition
200         // note OWL_MEM => no reasoner is used
201         OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
202         m.getDocumentManager().setMetadataSearchPath( "file:etc/ont-policy-test.rdf", true );
203         m.read(new ByteArrayInputStream(doc.getBytes()), base);
204 
205         // we need a resource corresponding to OWL Class but in m
206         Resource owlClassRes = m.getResource(OWL.Class.getURI());
207 
208         // now can we see this as an OntClass?
209         OntClass c = (OntClass) owlClassRes.as(OntClass.class);
210         assertNotNull("OntClass c should not be null", c);
211 
212         //(OntClass) (ontModel.getProfile().CLASS()).as(OntClass.class);
213 
214     }
215 
216     /**
217      * Bug report from Hoger Knublauch on Aug 19th 2003. NPE when setting all
218      * distinct members
219      */
220     public void test_hk_02() {
221         OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM);
222         spec.setReasoner(null);
223         OntModel ontModel = ModelFactory.createOntologyModel(spec, null); // ProfileRegistry.OWL_LANG);
224         ontModel.createAllDifferent();
225         assertTrue(ontModel.listAllDifferent().hasNext());
226         AllDifferent allDifferent = (AllDifferent) ontModel.listAllDifferent().next();
227         //allDifferent.setDistinct(ontModel.createList());
228         assertFalse(allDifferent.listDistinctMembers().hasNext());
229     }
230 
231     /** Bug report from Holger Knublauch on Aug 19th, 2003. Initialisation error */
232     public void test_hk_03() {
233         OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM);
234         spec.setReasoner(null);
235         OntModel ontModel = ModelFactory.createOntologyModel(spec, null);
236         OntProperty property = ontModel.createObjectProperty("http://www.aldi.de#property");
237         /* MinCardinalityRestriction testClass = */
238         ontModel.createMinCardinalityRestriction(null, property, 42);
239 
240     }
241 
242     /**
243      * Bug report from Holger Knublauch on Aug 19th, 2003. Document manager alt
244      * mechanism breaks relative name translation
245      */
246     public void test_hk_04() {
247         OntModel m = ModelFactory.createOntologyModel();
248         m.getDocumentManager().addAltEntry(
249             "http://jena.hpl.hp.com/testing/ontology/relativenames",
250             "file:testing/ontology/relativenames.rdf");
251 
252         m.read("http://jena.hpl.hp.com/testing/ontology/relativenames");
253         assertTrue(
254             "#A should be a class",
255             m.getResource("http://jena.hpl.hp.com/testing/ontology/relativenames#A").canAs(OntClass.class));
256         assertFalse(
257             "file: #A should not be a class",
258             m.getResource("file:testing/ontology/relativenames.rdf#A").canAs(OntClass.class));
259     }
260 
261     /** Bug report from Holger Knublach: not all elements of a union are removed */
262     public void test_hk_05() {
263         OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM);
264         spec.setReasoner(null);
265         OntModel ontModel = ModelFactory.createOntologyModel(spec, null);
266         String ns = "http://foo.bar/fu#";
267         OntClass a = ontModel.createClass(ns + "A");
268         OntClass b = ontModel.createClass(ns + "B");
269 
270         int oldCount = getStatementCount(ontModel);
271 
272         RDFList members = ontModel.createList(new RDFNode[] { a, b });
273         IntersectionClass intersectionClass = ontModel.createIntersectionClass(null, members);
274         intersectionClass.remove();
275 
276         assertEquals("Before and after statement counts are different", oldCount, getStatementCount(ontModel));
277     }
278 
279     /**
280      * Bug report from Holger Knublach: moving between ontology models - comes
281      * down to a test for a resource being in the base model
282      */
283     public void test_hk_06() throws Exception {
284         OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
285         ontModel.read("file:testing/ontology/bugs/test_hk_06/a.owl");
286 
287         String NSa = "http://jena.hpl.hp.com/2003/03/testont/a#";
288         String NSb = "http://jena.hpl.hp.com/2003/03/testont/b#";
289 
290         OntClass A = ontModel.getOntClass(NSa + "A");
291         assertTrue("class A should be in the base model", ontModel.isInBaseModel(A));
292 
293         OntClass B = ontModel.getOntClass(NSb + "B");
294         assertFalse("class B should not be in the base model", ontModel.isInBaseModel(B));
295 
296         assertTrue(
297             "A rdf:type owl:Class should be in the base model",
298             ontModel.isInBaseModel(ontModel.createStatement(A, RDF.type, OWL.Class)));
299         assertFalse(
300             "B rdf:type owl:Class should not be in the base model",
301             ontModel.isInBaseModel(ontModel.createStatement(B, RDF.type, OWL.Class)));
302     }
303 
304     public void test_hk_importCache() {
305         final String BASE = "http://protege.stanford.edu/plugins/owl/testdata/";
306         OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM);
307         spec.setReasoner(null);
308         OntDocumentManager dm = OntDocumentManager.getInstance();
309         dm.reset();
310         dm.setCacheModels(false);
311         dm.addAltEntry( "http://protege.stanford.edu/plugins/owl/testdata/Import-normalizerBug.owl",
312                         "file:testing/ontology/bugs/test_hk_import/Import-normalizerBug.owl" );
313         dm.addAltEntry( "http://protege.stanford.edu/plugins/owl/testdata/normalizerBug.owl",
314                         "file:testing/ontology/bugs/test_hk_import/normalizerBug.owl" );
315         spec.setDocumentManager(dm);
316 
317         OntModel oldOntModel = ModelFactory.createOntologyModel(spec, null);
318         oldOntModel.read(BASE + "Import-normalizerBug.owl", FileUtils.langXMLAbbrev);
319         Graph oldSubGraph = (Graph) oldOntModel.getSubGraphs().iterator().next();
320         final int oldTripleCount = getTripleCount(oldSubGraph);
321         OntClass ontClass = oldOntModel.getOntClass(BASE + "normalizerBug.owl#SuperClass");
322         oldSubGraph.add(new Triple(ontClass.getNode(), RDF.type.getNode(), OWL.DeprecatedClass.getNode()));
323         assertEquals(oldTripleCount + 1, getTripleCount(oldSubGraph));
324 
325         // TODO this workaround to be removed
326         SimpleGraphMaker sgm = (SimpleGraphMaker) ((ModelMakerImpl) spec.getImportModelMaker()).getGraphMaker();
327         List toGo = new ArrayList();
328         for (Iterator i = sgm.listGraphs(); i.hasNext(); toGo.add( i.next() ));
329         for (Iterator i = toGo.iterator(); i.hasNext(); sgm.removeGraph( (String) i.next() ));
330         dm.clearCache();
331 
332         OntModel newOntModel = ModelFactory.createOntologyModel(spec, null);
333         newOntModel.read(BASE + "Import-normalizerBug.owl", FileUtils.langXMLAbbrev);
334         Graph newSubGraph = (Graph) newOntModel.getSubGraphs().iterator().next();
335         assertFalse(newOntModel == oldOntModel);  // OK!
336         assertFalse(newSubGraph == oldSubGraph);  // FAILS!
337         final int newTripleCount = getTripleCount(newSubGraph);
338         assertEquals(oldTripleCount, newTripleCount);
339     }
340 
341 
342     private int getTripleCount(Graph graph) {
343         int count = 0;
344         for (Iterator it = graph.find(null, null, null); it.hasNext();) {
345             it.next();
346             count++;
347         }
348         return count;
349     }
350 
351     /**
352      * Bug report by federico.carbone@bt.com, 30-July-2003. A literal can be
353      * turned into an individual.
354      */
355     public void test_fc_01() {
356         OntModel m = ModelFactory.createOntologyModel();
357 
358         ObjectProperty p = m.createObjectProperty(NS + "p");
359         Restriction r = m.createRestriction(p);
360         HasValueRestriction hv = r.convertToHasValueRestriction(m.createLiteral(1));
361 
362         RDFNode n = hv.getHasValue();
363         assertFalse("Should not be able to convert literal to individual", n.canAs(Individual.class));
364     }
365 
366     /**
367      * Bug report by Christoph Kunze (Christoph.Kunz@iao.fhg.de). 18/Aug/03 No
368      * transaction support in ontmodel.
369      */
370     public void test_ck_01() {
371         Graph g = new GraphMem() {
372             TransactionHandler m_t = new MockTransactionHandler();
373             public TransactionHandler getTransactionHandler() {
374                 return m_t;
375             }
376         };
377         Model m0 = ModelFactory.createModelForGraph(g);
378         OntModel m1 = ModelFactory.createOntologyModel(OntModelSpec.OWL_LITE_MEM, m0);
379 
380         assertFalse(
381             "Transaction not started yet",
382             ((MockTransactionHandler) m1.getGraph().getTransactionHandler()).m_inTransaction);
383         m1.begin();
384         assertTrue(
385             "Transaction started",
386             ((MockTransactionHandler) m1.getGraph().getTransactionHandler()).m_inTransaction);
387         m1.abort();
388         assertFalse(
389             "Transaction aborted",
390             ((MockTransactionHandler) m1.getGraph().getTransactionHandler()).m_inTransaction);
391         assertTrue("Transaction aborted", ((MockTransactionHandler) m1.getGraph().getTransactionHandler()).m_aborted);
392         m1.begin();
393         assertTrue(
394             "Transaction started",
395             ((MockTransactionHandler) m1.getGraph().getTransactionHandler()).m_inTransaction);
396         m1.commit();
397         assertFalse(
398             "Transaction committed",
399             ((MockTransactionHandler) m1.getGraph().getTransactionHandler()).m_inTransaction);
400         assertTrue(
401             "Transaction committed",
402             ((MockTransactionHandler) m1.getGraph().getTransactionHandler()).m_committed);
403     }
404 
405     /**
406      * Bug report by Christoph Kunz, 26/Aug/03. CCE when creating a statement
407      * from a vocabulary
408      *
409      */
410     public void test_ck_02() {
411         OntModel vocabModel = ModelFactory.createOntologyModel();
412         ObjectProperty p = vocabModel.createObjectProperty("p");
413         OntClass A = vocabModel.createClass("A");
414 
415         OntModel workModel = ModelFactory.createOntologyModel();
416         Individual sub = workModel.createIndividual("uri1", A);
417         Individual obj = workModel.createIndividual("uri2", A);
418         workModel.createStatement(sub, p, obj);
419     }
420 
421     /**
422      * Bug report from Christoph Kunz - reification problems and
423      * UnsupportedOperationException
424      */
425     public void test_ck_03() {
426         // part A - surprising reification
427         OntModel model1 = ModelFactory.createOntologyModel(OntModelSpec.DAML_MEM, null);
428         OntModel model2 = ModelFactory.createOntologyModel(OntModelSpec.DAML_MEM_RULE_INF, null);
429 
430         Individual sub = model1.createIndividual("http://mytest#i1", model1.getProfile().CLASS());
431         OntProperty pred = model1.createOntProperty("http://mytest#");
432         Individual obj = model1.createIndividual("http://mytest#i2", model1.getProfile().CLASS());
433         OntProperty probabilityP = model1.createOntProperty("http://mytest#prob");
434 
435         Statement st = model1.createStatement(sub, pred, obj);
436         model1.add(st);
437         st.createReifiedStatement().addProperty(probabilityP, 0.9);
438         assertTrue("st should be reified", st.isReified());
439 
440         Statement st2 = model2.createStatement(sub, pred, obj);
441         model2.add(st2);
442         st2.createReifiedStatement().addProperty(probabilityP, 0.3);
443         assertTrue("st2 should be reified", st2.isReified());
444 
445         sub.addProperty(probabilityP, 0.3);
446         sub.removeAll(probabilityP).addProperty(probabilityP, 0.3); //!!!
447                                                                     // exception
448 
449         // Part B - exception in remove All
450         Individual sub2 = model2.createIndividual("http://mytest#i1", model1.getProfile().CLASS());
451 
452         sub.addProperty(probabilityP, 0.3);
453         sub.removeAll(probabilityP); //!!! exception
454 
455         sub2.addProperty(probabilityP, 0.3);
456         sub2.removeAll(probabilityP); //!!! exception
457 
458     }
459 
460     /**
461      * Bug report by sjooseng [sjooseng@hotmail.com]. CCE in listOneOf in
462      * Enumerated Class with DAML profile.
463      */
464     public void test_sjooseng_01() {
465         String source =
466             "<rdf:RDF xmlns:daml='http://www.daml.org/2001/03/daml+oil#'"
467                 + "    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
468                 + "    xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#' >"
469                 + "    <daml:Class rdf:about='http://localhost:8080/kc2c#C1'>"
470                 + "        <daml:subClassOf>"
471                 + "            <daml:Restriction>"
472                 + "                <daml:onProperty rdf:resource='http://localhost:8080/kc2c#p1'/>"
473                 + "                <daml:hasClass>"
474                 + "                    <daml:Class>"
475                 + "                        <daml:oneOf rdf:parseType=\"daml:collection\">"
476                 + "                            <daml:Thing rdf:about='http://localhost:8080/kc2c#i1'/>"
477                 + "                            <daml:Thing rdf:about='http://localhost:8080/kc2c#i2'/>"
478                 + "                        </daml:oneOf>"
479                 + "                    </daml:Class>"
480                 + "                </daml:hasClass>"
481                 + "            </daml:Restriction>"
482                 + "        </daml:subClassOf>"
483                 + "    </daml:Class>"
484                 + "    <daml:ObjectProperty rdf:about='http://localhost:8080/kc2c#p1'>"
485                 + "        <rdfs:label>p1</rdfs:label>"
486                 + "    </daml:ObjectProperty>"
487                 + "</rdf:RDF>";
488 
489         OntModel m = ModelFactory.createOntologyModel(ProfileRegistry.DAML_LANG);
490         m.read(new ByteArrayInputStream(source.getBytes()), "http://localhost:8080/kc2c");
491 
492         OntClass kc1 = m.getOntClass("http://localhost:8080/kc2c#C1");
493 
494         boolean found = false;
495 
496         Iterator it = kc1.listSuperClasses(false);
497         while (it.hasNext()) {
498             OntClass oc = (OntClass) it.next();
499             if (oc.isRestriction()) {
500                 Restriction r = oc.asRestriction();
501                 if (r.isSomeValuesFromRestriction()) {
502                     SomeValuesFromRestriction sr = r.asSomeValuesFromRestriction();
503                     OntClass sc = (OntClass) sr.getSomeValuesFrom();
504                     if (sc.isEnumeratedClass()) {
505                         EnumeratedClass ec = sc.asEnumeratedClass();
506                         assertEquals("Enumeration size should be 2", 2, ec.getOneOf().size());
507                         found = true;
508                     }
509                 }
510             }
511         }
512 
513         assertTrue(found);
514     }
515 
516     /**
517      * Problem reported by Andy Seaborne - combine abox and tbox in RDFS with
518      * ontmodel
519      */
520     public void test_afs_01() {
521         String sourceT =
522             "<rdf:RDF "
523                 + "    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
524                 + "    xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'"
525                 + "   xmlns:owl=\"http://www.w3.org/2002/07/owl#\">"
526                 + "    <owl:Class rdf:about='http://example.org/foo#A'>"
527                 + "   </owl:Class>"
528                 + "</rdf:RDF>";
529 
530         String sourceA =
531             "<rdf:RDF "
532                 + "    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
533                 + "    xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#' "
534                 + "   xmlns:owl=\"http://www.w3.org/2002/07/owl#\">"
535                 + "    <rdf:Description rdf:about='http://example.org/foo#x'>"
536                 + "    <rdf:type rdf:resource='http://example.org/foo#A' />"
537                 + "   </rdf:Description>"
538                 + "</rdf:RDF>";
539 
540         Model tBox = ModelFactory.createDefaultModel();
541         tBox.read(new ByteArrayInputStream(sourceT.getBytes()), "http://example.org/foo");
542 
543         Model aBox = ModelFactory.createDefaultModel();
544         aBox.read(new ByteArrayInputStream(sourceA.getBytes()), "http://example.org/foo");
545 
546         Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
547         reasoner = reasoner.bindSchema(tBox);
548 
549         OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM_RULE_INF);
550         spec.setReasoner(reasoner);
551 
552         OntModel m = ModelFactory.createOntologyModel(spec, aBox);
553 
554         List inds = new ArrayList();
555         for (Iterator i = m.listIndividuals(); i.hasNext();) {
556             inds.add(i.next());
557         }
558 
559         assertTrue("x should be an individual", inds.contains(m.getResource("http://example.org/foo#x")));
560 
561     }
562 
563     /**
564      * Bug report by Thorsten Ottmann [Thorsten.Ottmann@rwth-aachen.de] -
565      * problem accessing elements of DAML list
566      */
567     public void test_to_01() {
568         String sourceT =
569             "<rdf:RDF "
570                 + "    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
571                 + "    xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'"
572                 + "    xmlns:daml='http://www.daml.org/2001/03/daml+oil#'>"
573                 + "  <daml:Class rdf:about='http://example.org/foo#A'>"
574                 + "    <daml:intersectionOf rdf:parseType=\"daml:collection\">"
575                 + "       <daml:Class rdf:ID=\"B\" />"
576                 + "       <daml:Class rdf:ID=\"C\" />"
577                 + "    </daml:intersectionOf>"
578                 + "  </daml:Class>"
579                 + "</rdf:RDF>";
580 
581         OntModel m = ModelFactory.createOntologyModel(OntModelSpec.DAML_MEM, null);
582         m.read(new ByteArrayInputStream(sourceT.getBytes()), "http://example.org/foo");
583 
584         OntClass A = m.getOntClass("http://example.org/foo#A");
585         assertNotNull(A);
586 
587         IntersectionClass iA = A.asIntersectionClass();
588         assertNotNull(iA);
589 
590         RDFList intersection = iA.getOperands();
591         assertNotNull(intersection);
592 
593         assertEquals(2, intersection.size());
594         assertTrue(intersection.contains(m.getOntClass("http://example.org/foo#B")));
595         assertTrue(intersection.contains(m.getOntClass("http://example.org/foo#C")));
596     }
597 
598     /**
599      * Bug report by Thorsten Liebig [liebig@informatik.uni-ulm.de] -
600      * SymmetricProperty etc not visible in list ont properties
601      */
602     public void test_tl_01() {
603         String sourceT =
604             "<rdf:RDF "
605                 + "    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
606                 + "    xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'"
607                 + "    xmlns:owl=\"http://www.w3.org/2002/07/owl#\">"
608                 + "   <owl:SymmetricProperty rdf:about='http://example.org/foo#p1'>"
609                 + "   </owl:SymmetricProperty>"
610                 + "   <owl:TransitiveProperty rdf:about='http://example.org/foo#p2'>"
611                 + "   </owl:TransitiveProperty>"
612                 + "   <owl:InverseFunctionalProperty rdf:about='http://example.org/foo#p3'>"
613                 + "   </owl:InverseFunctionalProperty>"
614                 + "</rdf:RDF>";
615 
616         OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF, null);
617         m.read(new ByteArrayInputStream(sourceT.getBytes()), "http://example.org/foo");
618 
619         boolean foundP1 = false;
620         boolean foundP2 = false;
621         boolean foundP3 = false;
622 
623         // iterator of properties should include p1-3
624         for (Iterator i = m.listOntProperties(); i.hasNext();) {
625             Resource r = (Resource) i.next();
626             foundP1 = foundP1 || r.getURI().equals("http://example.org/foo#p1");
627             foundP2 = foundP2 || r.getURI().equals("http://example.org/foo#p2");
628             foundP3 = foundP3 || r.getURI().equals("http://example.org/foo#p3");
629         }
630 
631         assertTrue("p1 not listed", foundP1);
632         assertTrue("p2 not listed", foundP2);
633         assertTrue("p3 not listed", foundP3);
634 
635         foundP1 = false;
636         foundP2 = false;
637         foundP3 = false;
638 
639         // iterator of object properties should include p1-3
640         for (Iterator i = m.listObjectProperties(); i.hasNext();) {
641             Resource r = (Resource) i.next();
642             foundP1 = foundP1 || r.getURI().equals("http://example.org/foo#p1");
643             foundP2 = foundP2 || r.getURI().equals("http://example.org/foo#p2");
644             foundP3 = foundP3 || r.getURI().equals("http://example.org/foo#p3");
645         }
646 
647         assertTrue("p1 not listed", foundP1);
648         assertTrue("p2 not listed", foundP2);
649         assertTrue("p3 not listed", foundP3);
650     }
651 
652     /** Bug report by Dave Reynolds - SF bug report 810492 */
653     public void test_der_01() {
654         OntModel m = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_TRANS_INF, null);
655         Resource a = m.createResource("http://example.org#A");
656         Resource b = m.createResource("http://example.org#B");
657         OntClass A = new OntClassImpl(a.getNode(), (EnhGraph) m) {
658             protected boolean hasSuperClassDirect(Resource cls) {
659                 throw new RuntimeException("did not find direct reasoner");
660             }
661         };
662 
663         // will throw an exception if the wrong code path is taken
664         A.hasSuperClass(b, true);
665     }
666 
667     /**
668      * Bug report by Ivan Ferrari (ivan_ferrari_75 [ivan_ferrari_75@yahoo.it]) -
669      * duplicate nodes in output
670      */
671     public void test_if_01() {
672         //create a new default model
673         OntModel m = ModelFactory.createOntologyModel();
674 
675         m.getDocumentManager().addAltEntry(
676             "http://www.w3.org/2001/sw/WebOnt/guide-src/wine",
677             "file:testing/ontology/bugs/oldwine.owl");
678         m.getDocumentManager().addAltEntry(
679             "http://www.w3.org/2001/sw/WebOnt/guide-src/food",
680             "file:testing/ontology/bugs/oldfood.owl");
681 
682         // note: due to bug in the Wine example, we have to manually read the
683         // imported food document
684         m.getDocumentManager().setProcessImports(false);
685         m.read("http://www.w3.org/2001/sw/WebOnt/guide-src/wine");
686         m.getDocumentManager().setProcessImports(true);
687         m.getDocumentManager().loadImport(m, "http://www.w3.org/2001/sw/WebOnt/guide-src/food");
688 
689         OntClass ontclass = m.getOntClass("http://www.w3.org/2001/sw/WebOnt/guide-src/wine#Wine");
690 
691         int nNamed = 0;
692         int nRestriction = 0;
693         int nAnon = 0;
694 
695         for (ExtendedIterator iter2 = ontclass.listSuperClasses(true); iter2.hasNext();) {
696             OntClass ontsuperclass = (OntClass) iter2.next();
697 
698             //this is to view different anonymous IDs
699             if (!ontsuperclass.isAnon()) {
700                 nNamed++;
701             }
702             else if (ontsuperclass.canAs(Restriction.class)) {
703                 ontsuperclass.asRestriction();
704                 nRestriction++;
705             }
706             else {
707                 //System.out.println("anon. super: " + ontsuperclass.getId());
708                 nAnon++;
709             }
710         }
711 
712         assertEquals("Should be two named super classes ", 2, nNamed);
713         assertEquals("Should be nine named super classes ", 9, nRestriction);
714         assertEquals("Should be no named super classes ", 0, nAnon);
715     }
716 
717     /** Bug report by Lawrence Tay - missing datatype property */
718     public void test_lt_01() {
719         OntModel m = ModelFactory.createOntologyModel();
720 
721         DatatypeProperty p = m.createDatatypeProperty(NS + "p");
722         OntClass c = m.createClass(NS + "A");
723 
724         Individual i = m.createIndividual(NS + "i", c);
725         i.addProperty(p, "testData");
726 
727         int count = 0;
728 
729         for (Iterator j = i.listPropertyValues(p); j.hasNext();) {
730             //System.err.println("Individual i has p value: " + j.next());
731             j.next();
732             count++;
733         }
734 
735         assertEquals("i should have one property", 1, count);
736     }
737 
738 
739     /** Bug report by David Kensche [david.kensche@post.rwth-aachen.de] - NPE in listDeclaredProperties */
740     public void test_dk_01() {
741         OntModel m = ModelFactory.createOntologyModel();
742         m.read( "file:testing/ontology/bugs/test_dk_01.xml" );
743 
744         String NS = "http://localhost:8080/Repository/QueryAgent/UserOntology/qgen-example-1#";
745         String[] classes = new String[] {NS+"C1", NS+"C3", NS+"C2"};
746 
747         for (int i = 0; i < classes.length; i++) {
748             OntClass c = m.getOntClass( classes[i] );
749             for (Iterator j = c.listDeclaredProperties(); j.hasNext(); j.next() );
750         }
751     }
752 
753     /** Bug report by Paulo Pinheiro da Silva [pp@ksl.stanford.edu] - exception while accessing PropertyAccessor.getDAMLValue */
754     public void test_ppds_01() {
755         DAMLModel m = ModelFactory.createDAMLModel();
756         DAMLClass c = m.createDAMLClass( NS + "C" );
757         DAMLInstance x = m.createDAMLInstance( c, NS + "x" );
758         DAMLProperty p = m.createDAMLProperty( NS + "p" );
759 
760         x.addProperty( p, "(s (s 0))" );
761 
762         PropertyAccessor a = x.accessProperty( p );
763         assertNull( "Property accessor value should be null", a.getDAMLValue() );
764     }
765 
766     /** Bug report by anon at SourceForge - Bug ID 887409 */
767     public void test_anon_0() {
768         String NS = "http://example.org/foo#";
769         String sourceT =
770             "<rdf:RDF "
771             + "    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
772             + "    xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'"
773             + "    xmlns:ex='http://example.org/foo#'"
774             + "    xmlns:owl='http://www.w3.org/2002/07/owl#'>"
775             + "   <owl:ObjectProperty rdf:about='http://example.org/foo#p' />"
776             + "   <owl:Class rdf:about='http://example.org/foo#A' />"
777             + "   <ex:A rdf:about='http://example.org/foo#x' />"
778             + "   <owl:Class rdf:about='http://example.org/foo#B'>"
779             + "     <owl:equivalentClass>"
780             + "      <owl:Restriction>"
781             + "        <owl:onProperty rdf:resource='http://example.org/foo#p' />"
782             + "        <owl:hasValue rdf:resource='http://example.org/foo#x' />"
783             + "      </owl:Restriction>"
784             + "     </owl:equivalentClass>"
785             + "   </owl:Class>"
786             + "</rdf:RDF>";
787 
788         OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
789         m.read(new ByteArrayInputStream(sourceT.getBytes()), "http://example.org/foo");
790 
791         OntClass B = m.getOntClass( NS + "B");
792         Restriction r = B.getEquivalentClass().asRestriction();
793         HasValueRestriction hvr = r.asHasValueRestriction();
794         RDFNode n = hvr.getHasValue();
795 
796         assertTrue( "Should be an individual", n instanceof Individual );
797     }
798 
799     /** Bug report by Zhao Jun [jeff@seu.edu.cn] - throws no such element exception */
800     public void test_zj_0() {
801         String NS = "file:/C:/orel/orel0_5.owl#";
802         String sourceT =
803             "<rdf:RDF " +
804             "    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'" +
805             "    xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'" +
806             "    xmlns:ex='http://example.org/foo#'" +
807             "    xmlns:owl='http://www.w3.org/2002/07/owl#'" +
808             "      xmlns:orel='file:/C:/orel/orel0_5.owl#'" +
809             "      xml:base='file:/C:/orel/orel0_5.owl#'" +
810             "      xmlns='file:/C:/orel/orel0_5.owl#'>" +
811             " <owl:ObjectProperty rdf:ID='hasAgent' />" +
812             " <owl:ObjectProperty rdf:ID='hasResource' />" +
813             " <owl:Class rdf:ID='MyPlay'>" +
814             "    <rdfs:subClassOf>" +
815             "      <owl:Restriction>" +
816             "        <owl:onProperty rdf:resource='file:/C:/orel/orel0_5.owl#hasResource'/>" +
817             "        <owl:hasValue>" +
818             "          <orel:Resource rdf:ID='myResource'>" +
819             "            <orel:resourceURI>http://mp3.com/newcd/sample.mp3</orel:resourceURI>" +
820             "          </orel:Resource>" +
821             "        </owl:hasValue>" +
822             "      </owl:Restriction>" +
823             "    </rdfs:subClassOf>" +
824             "    <rdfs:subClassOf rdf:resource='http://www.w3.org/2002/07/owl#Thing'/>" +
825             "    <rdfs:subClassOf>" +
826             "      <owl:Restriction>" +
827             "        <owl:onProperty rdf:resource='file:/C:/orel/orel0_5.owl#hasAgent'/>" +
828             "        <owl:hasValue>" +
829             "          <orel:Agent rdf:ID='myAgent'>" +
830             "            <orel:agentPK>123456789</orel:agentPK>" +
831             "          </orel:Agent>" +
832             "        </owl:hasValue>" +
833             "      </owl:Restriction>" +
834             "    </rdfs:subClassOf>" +
835             "    <rdfs:subClassOf rdf:resource='file:/C:/orel/orel0_5.owl#Play'/>" +
836             "  </owl:Class>" +
837             "</rdf:RDF>";
838 
839         OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF, null);
840         m.read(new ByteArrayInputStream(sourceT.getBytes()), "file:/C:/orel/orel0_5.owl");
841 
842         OntClass myPlay = m.getOntClass( NS + "MyPlay");
843         for (Iterator i = myPlay.listDeclaredProperties(); i.hasNext(); ) {
844             //System.err.println( "prop " + i.next() );
845             i.next();
846         }
847     }
848 
849     /* Bug reprort by E. Johnson ejohnson@carolina.rr.com - ill formed list in writer */
850     public void test_ej_01() {
851         String BASE  = "http://jena.hpl.hp.com/testing/ontology";
852         String NS = BASE + "#";
853 
854         DAMLModel m = ModelFactory.createDAMLModel();
855         DAMLClass A = m.createDAMLClass(NS + "A");
856         DAMLClass B = m.createDAMLClass(NS + "B");
857         DAMLClass C = m.createDAMLClass(NS + "C");
858         DAMLList l = m.createDAMLList(new RDFNode[] {A, B, C});
859 
860         assertTrue( l.isValid() );
861 
862         Model baseModel = m.getBaseModel();
863         RDFWriter writer = baseModel.getWriter("RDF/XML-ABBREV");
864 
865         // will generate warnings, so suppress until Jeremy has fixed
866         ByteArrayOutputStream out = new ByteArrayOutputStream();
867         //writer.write(baseModel, out, BASE );
868     }
869 
870     /** Bug report by Harry Chen - closed exception when reading many models */
871     public void test_hc_01()
872         throws Exception
873     {
874         for (int i = 0; i < 5; i++) {
875 
876             OntModel m = ModelFactory.createOntologyModel();
877 
878             FileInputStream ifs = new FileInputStream("testing/ontology/relativenames.rdf");
879 
880             //System.out.println("Start reading...");
881             m.read(ifs, "http://example.org/foo");
882             //System.out.println("Done reading...");
883 
884             ifs.close();
885             //System.out.println("Closed ifs");
886             m.close();
887             //System.out.println("Closed model");
888         }
889     }
890 
891     /** Bug report by sinclair bain (slbain) SF bugID 912202 - NPE in createOntResource() when 2nd param is null */
892     public void test_sb_01() {
893         OntModel model= ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RDFS_INF, null);
894 
895         Resource result= null;
896         Resource nullValueForResourceType= null;
897 
898         result= model.createOntResource( OntResource.class, nullValueForResourceType, "http://www.somewhere.com/models#SomeResourceName" );
899         assertNotNull( result );
900     }
901 
902     /* Bug report from Dave Reynolds: listDeclaredProperties not complete */
903     public void test_der_02() {
904         String SOURCE=
905         "<?xml version='1.0'?>" +
906         "<!DOCTYPE owl [" +
907         "      <!ENTITY rdf  'http://www.w3.org/1999/02/22-rdf-syntax-ns#' >" +
908         "      <!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#' >" +
909         "      <!ENTITY xsd  'http://www.w3.org/2001/XMLSchema#' >" +
910         "      <!ENTITY owl  'http://www.w3.org/2002/07/owl#' >" +
911         "      <!ENTITY dc   'http://purl.org/dc/elements/1.1/' >" +
912         "      <!ENTITY base  'http://jena.hpl.hp.com/test' >" +
913         "    ]>" +
914         "<rdf:RDF xmlns:owl ='&owl;' xmlns:rdf='&rdf;' xmlns:rdfs='&rdfs;' xmlns:dc='&dc;' xmlns='&base;#' xml:base='&base;'>" +
915         "  <owl:ObjectProperty rdf:ID='hasPublications'>" +
916         "    <rdfs:domain>" +
917         "      <owl:Class>" +
918         "        <owl:unionOf rdf:parseType='Collection'>" +
919         "          <owl:Class rdf:about='#Project'/>" +
920         "          <owl:Class rdf:about='#Task'/>" +
921         "        </owl:unionOf>" +
922         "      </owl:Class>" +
923         "    </rdfs:domain>" +
924         "    <rdfs:domain rdf:resource='#Dummy' />" +
925         "    <rdfs:range rdf:resource='#Publications'/>" +
926         "  </owl:ObjectProperty>" +
927         "  <owl:Class rdf:ID='Dummy'>" +
928         "  </owl:Class>" +
929         "</rdf:RDF>";
930         String NS = "http://jena.hpl.hp.com/test#";
931         OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
932         m.read(new ByteArrayInputStream( SOURCE.getBytes()), NS );
933 
934         OntClass dummy = m.getOntClass( NS + "Dummy" );
935         // assert commented out - bug not accepted -ijd
936         //TestUtil.assertIteratorValues( this, dummy.listDeclaredProperties(),
937         //                               new Object[] {m.getObjectProperty( NS+"hasPublications")} );
938     }
939 
940     /** Bug report from Dave - cycles checking code still not correct */
941     public void test_der_03() {
942         String NS = "http://jena.hpl.hp.com/test#";
943         OntModel om = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
944         OntClass A = om.createClass(NS+"A");
945         OntClass B = om.createClass(NS+"B");
946         OntClass C = om.createClass(NS+"C");
947         A.addSuperClass(B);
948         A.addSuperClass(C);
949         B.addSuperClass(C);
950         C.addSuperClass(B);
951 
952         TestUtil.assertIteratorValues( this, A.listSuperClasses( true ), new Object[] {B,C} );
953     }
954 
955 
956     /**
957      * Bug report by pierluigi.damadio@katamail.com: raises conversion exception
958      */
959     public void test_pd_01() {
960         String SOURCE =
961             "<?xml version='1.0'?>" +
962             "<rdf:RDF" +
963             "    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'" +
964             "    xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'" +
965             "    xmlns:owl='http://www.w3.org/2002/07/owl#'" +
966             "    xml:base='http://iasi.cnr.it/leks/localSchema1#'" +
967             "    xmlns:test='http://iasi.cnr.it/test/test1#'" +
968             "    xmlns='http://iasi.cnr.it/test/test1#'>" +
969             "    <owl:Ontology rdf:about=''/>" +
970             "    <owl:Class rdf:ID='Hotel'/>" +
971             "    <owl:Class rdf:ID='Hotel5Stars'>" +
972             "        <rdfs:subClassOf>" +
973             "            <owl:Restriction>" +
974             "                <owl:onProperty rdf:resource='#hasCategory'/>" +
975             "                <owl:hasValue rdf:resource='#Category5'/>" +
976             "            </owl:Restriction>" +
977             "        </rdfs:subClassOf>" +
978             "    </owl:Class>" +
979             "    <owl:DatatypeProperty rdf:ID='hasCategory'>" +
980             "        <rdfs:range rdf:resource='http://www.w3.org/2001/XMLSchema#string'/>" +
981             "        <rdfs:domain rdf:resource='#Hotel'/>" +
982             "        <rdf:type rdf:resource='http://www.w3.org/2002/07/owl#FunctionalProperty'/>" +
983             "    </owl:DatatypeProperty>" +
984             "    <owl:Thing rdf:ID='Category5'/>" +
985             "</rdf:RDF>";
986         String NS = "http://iasi.cnr.it/leks/localSchema1#";
987         OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, null);
988         m.read(new ByteArrayInputStream( SOURCE.getBytes()), NS );
989 
990         for (ExtendedIterator j = m.listRestrictions(); j.hasNext(); ) {
991               Restriction r = (Restriction) j.next();
992               if (r.isHasValueRestriction()) {
993                   HasValueRestriction hv = r.asHasValueRestriction();
994                   String s = hv.getHasValue().toString();
995                   //System.out.println( s );
996               }
997         }
998     }
999 
1000    /** Bug report from Ole Hjalmar - direct subClassOf not reporting correct result with rule reasoner */
1001    public void xxtest_oh_01() {
1002        String NS = "http://www.idi.ntnu.no/~herje/ja/";
1003        Resource[] expected = new Resource[] {
1004            ResourceFactory.createResource( NS+"reiseliv.owl#Reiseliv" ),
1005            ResourceFactory.createResource( NS+"hotell.owl#Hotell" ),
1006            ResourceFactory.createResource( NS+"restaurant.owl#Restaurant" ),
1007            ResourceFactory.createResource( NS+"restaurant.owl#UteRestaurant" ),
1008            ResourceFactory.createResource( NS+"restaurant.owl#UteBadRestaurant" ),
1009            ResourceFactory.createResource( NS+"restaurant.owl#UteDoRestaurant" ),
1010            ResourceFactory.createResource( NS+"restaurant.owl#SkogRestaurant" ),
1011        };
1012
1013        test_oh_01scan( OntModelSpec.OWL_MEM, "No inf", expected );
1014        test_oh_01scan( OntModelSpec.OWL_MEM_MINI_RULE_INF, "Mini rule inf", expected );
1015        test_oh_01scan( OntModelSpec.OWL_MEM_RULE_INF, "Full rule inf", expected );
1016        test_oh_01scan( OntModelSpec.OWL_MEM_MICRO_RULE_INF, "Micro rule inf", expected );
1017    }
1018
1019    private void test_oh_01scan( OntModelSpec s, String prompt, Resource[] expected ) {
1020        String NS = "http://www.idi.ntnu.no/~herje/ja/reiseliv.owl#";
1021        OntModel m = ModelFactory.createOntologyModel(s, null);
1022        m.read( "file:testing/ontology/bugs/test_oh_01.owl");
1023
1024        System.out.println( prompt );
1025        OntClass r = m.getOntClass( NS + "Reiseliv" );
1026        List q = new ArrayList();
1027        Set seen = new HashSet();
1028        q.add( r );
1029
1030        while (!q.isEmpty()) {
1031            OntClass c = (OntClass) q.remove( 0 );
1032            seen.add( c );
1033
1034            for (Iterator i = c.listSubClasses( true ); i.hasNext(); ) {
1035                OntClass sub = (OntClass) i.next();
1036                if (!seen.contains( sub )) {
1037                    q.add( sub );
1038                }
1039            }
1040
1041            System.out.println( "  Seen class " + c );
1042        }
1043
1044        // check we got all classes
1045        int mask = (1 << expected.length) - 1;
1046
1047        for (int j = 0;  j < expected.length; j++) {
1048            if (seen.contains( expected[j] )) {
1049                mask &= ~(1 << j);
1050            }
1051            else {
1052                System.out.println( "Expected but did not see " + expected[j] );
1053            }
1054        }
1055
1056        for (Iterator k = seen.iterator();  k.hasNext(); ) {
1057            Resource res = (Resource) k.next();
1058            boolean isExpected = false;
1059            for (int j = 0;  !isExpected && j < expected.length; j++) {
1060                isExpected = expected[j].equals( res );
1061            }
1062            if (!isExpected) {
1063                System.out.println( "Got unexpected result " + res );
1064            }
1065        }
1066
1067        assertEquals( "Some expected results were not seen", 0, mask );
1068    }
1069
1070    /** Test case for SF bug 927641 - list direct subclasses */
1071    public void test_sf_927641() {
1072        String NS = "http://example.org/test#";
1073        OntModel m0 = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
1074        OntClass c0 = m0.createClass( NS + "C0" );
1075        OntClass c1 = m0.createClass( NS + "C1" );
1076        OntClass c2 = m0.createClass( NS + "C2" );
1077        OntClass c3 = m0.createClass( NS + "C3" );
1078
1079        c0.addSubClass( c1 );
1080        c1.addSubClass( c2 );
1081        c2.addEquivalentClass( c3 );
1082
1083        // now c1 is the direct super-class of c2, even allowing for the equiv with c3
1084        assertFalse( "pass 1: c0 should not be a direct super of c2", c2.hasSuperClass( c0, true ) );
1085        assertFalse( "pass 1: c3 should not be a direct super of c2", c2.hasSuperClass( c3, true ) );
1086        assertFalse( "pass 1: c2 should not be a direct super of c2", c2.hasSuperClass( c2, true ) );
1087        assertTrue( "pass 1: c1 should be a direct super of c2", c2.hasSuperClass( c1, true ) );
1088
1089        // second pass - with inference
1090        m0 = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_RULE_INF );
1091        c0 = m0.createClass( NS + "C0" );
1092        c1 = m0.createClass( NS + "C1" );
1093        c2 = m0.createClass( NS + "C2" );