Source Code Cross Referenced for TestDigReasoner.java in  » RSS-RDF » Jena-2.5.5 » com » hp » hpl » jena » reasoner » dig » test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » RSS RDF » Jena 2.5.5 » com.hp.hpl.jena.reasoner.dig.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*****************************************************************************
0002:         * Source code information
0003:         * -----------------------
0004:         * Original author    Ian Dickinson, HP Labs Bristol
0005:         * Author email       ian.dickinson@hp.com
0006:         * Package            Jena 2
0007:         * Web                http://sourceforge.net/projects/jena/
0008:         * Created            11-Sep-2003
0009:         * Filename           $RCSfile: TestDigReasoner.java,v $
0010:         * Revision           $Revision: 1.28 $
0011:         * Release status     $State: Exp $
0012:         *
0013:         * Last modified on   $Date: 2008/01/02 12:10:27 $
0014:         *               by   $Author: andy_seaborne $
0015:         *
0016:         * (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
0017:         * [See end of file]
0018:         *****************************************************************************/package com.hp.hpl.jena.reasoner.dig.test;
0019:
0020:        // Imports
0021:        ///////////////
0022:        import org.apache.commons.logging.*;
0023:        import org.w3c.dom.*;
0024:
0025:        import com.hp.hpl.jena.ontology.*;
0026:        import com.hp.hpl.jena.rdf.model.*;
0027:        import com.hp.hpl.jena.reasoner.ReasonerRegistry;
0028:        import com.hp.hpl.jena.reasoner.dig.*;
0029:        import com.hp.hpl.jena.reasoner.test.TestUtil;
0030:        import com.hp.hpl.jena.vocabulary.*;
0031:        import com.hp.hpl.jena.vocabulary.OWL;
0032:        import com.hp.hpl.jena.vocabulary.RDFS;
0033:
0034:        import junit.framework.*;
0035:
0036:        import java.io.*;
0037:        import java.util.*;
0038:
0039:        import javax.xml.parsers.*;
0040:        import javax.xml.parsers.DocumentBuilder;
0041:
0042:        /**
0043:         * <p>
0044:         * Unit tests for DIG reasoners
0045:         * </p>
0046:         *
0047:         * @author Ian Dickinson, HP Labs (<a href="mailto:Ian.Dickinson@hp.com">email</a>)
0048:         * @version Release @release@ ($Id: TestDigReasoner.java,v 1.28 2008/01/02 12:10:27 andy_seaborne Exp $)
0049:         */
0050:        public class TestDigReasoner extends TestCase {
0051:            // Constants
0052:            //////////////////////////////////
0053:
0054:            // Static variables
0055:            //////////////////////////////////
0056:
0057:            private static Log log = LogFactory.getLog(TestDigReasoner.class);
0058:
0059:            // Instance variables
0060:            //////////////////////////////////
0061:
0062:            protected Model m_base;
0063:
0064:            // Constructors
0065:            //////////////////////////////////
0066:
0067:            public TestDigReasoner(String name) {
0068:                super (name);
0069:            }
0070:
0071:            // External signature methods
0072:            //////////////////////////////////
0073:
0074:            public static TestSuite suite() {
0075:                TestSuite s = new TestSuite("TestDigReasoner");
0076:
0077:                buildConceptLangSuite("testing/ontology/dig/owl/cl",
0078:                        OntModelSpec.OWL_MEM, s);
0079:                buildBasicQuerySuite("testing/ontology/dig/owl/basicq",
0080:                        OntModelSpec.OWL_MEM, s);
0081:
0082:                // add the standard tests from this class
0083:                s.addTestSuite(TestDigReasoner.class);
0084:                return s;
0085:            }
0086:
0087:            public void setUp() {
0088:                // ensure the ont doc manager is in a consistent state
0089:                OntDocumentManager.getInstance().reset(true);
0090:            }
0091:
0092:            public void testAxioms() {
0093:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.getDIGReasoner();
0094:                DIGReasoner ro = (DIGReasoner) ReasonerRegistry.getDIGReasoner(
0095:                        OWL.NAMESPACE, null);
0096:                DIGReasoner rd = (DIGReasoner) ReasonerRegistry.getDIGReasoner(
0097:                        DAML_OIL.NAMESPACE_DAML, null);
0098:                DIGReasoner roA = (DIGReasoner) ReasonerRegistry
0099:                        .getDIGReasoner(OWL.NAMESPACE, true, null);
0100:                DIGReasoner rdA = (DIGReasoner) ReasonerRegistry
0101:                        .getDIGReasoner(DAML_OIL.NAMESPACE_DAML, true, null);
0102:
0103:                axiomTestAux(r, OntModelSpec.OWL_MEM, false, false);
0104:                //axiomTestAux( r, OntModelSpec.DAML_MEM, false, false );
0105:
0106:                axiomTestAux(ro, OntModelSpec.OWL_MEM, false, false);
0107:                axiomTestAux(rd, OntModelSpec.DAML_MEM, false, false);
0108:
0109:                axiomTestAux(roA, OntModelSpec.OWL_MEM, true, false);
0110:                axiomTestAux(rdA, OntModelSpec.DAML_MEM, false, true);
0111:            }
0112:
0113:            private void axiomTestAux(DIGReasoner dr, OntModelSpec baseSpec,
0114:                    boolean owlResult, boolean damlResult) {
0115:                OntModelSpec spec = new OntModelSpec(baseSpec);
0116:                spec.setReasoner(dr);
0117:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0118:
0119:                assertEquals("Result for owl:ObjectProperty", owlResult, m
0120:                        .contains(OWL.ObjectProperty, RDF.type, RDFS.Class));
0121:                assertEquals("Result for daml:ObjectProperty", damlResult,
0122:                        m.contains(DAML_OIL.ObjectProperty, RDF.type,
0123:                                RDFS.Class));
0124:            }
0125:
0126:            public void testQueryAllConcepts() {
0127:                String NS = "http://example.org/foo#";
0128:
0129:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0130:                        .create(DIGReasonerFactory.URI, null);
0131:
0132:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0133:                spec.setReasoner(r);
0134:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0135:                m.read("file:testing/ontology/dig/owl/test1.xml");
0136:
0137:                TestUtil.assertIteratorValues(this , m.listClasses(),
0138:                        new Resource[] { m.getResource(NS + "A"),
0139:                                m.getResource(NS + "B"),
0140:                                m.getResource(NS + "C"),
0141:                                m.getResource(NS + "D"),
0142:                                m.getResource(NS + "E"),
0143:                                m.getResource(NS + "BB"),
0144:                                m.getResource(NS + "F0"),
0145:                                m.getResource(NS + "F1"),
0146:                                m.getResource(NS + "F2"), }, 2);
0147:            }
0148:
0149:            public void testQuerySubsumes1() {
0150:                String NS = "http://example.org/foo#";
0151:
0152:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0153:                        .create(DIGReasonerFactory.URI, null);
0154:
0155:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0156:                spec.setReasoner(r);
0157:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0158:                m.read("file:testing/ontology/dig/owl/test1.xml");
0159:
0160:                OntClass A = m.getOntClass(NS + "A");
0161:                OntClass B = m.getOntClass(NS + "B");
0162:                assertTrue("A should be a sub-class of B", A.hasSuperClass(B));
0163:            }
0164:
0165:            public void testQuerySubsumes2() {
0166:                String NS = "http://example.org/foo#";
0167:
0168:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0169:                        .create(DIGReasonerFactory.URI, null);
0170:
0171:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0172:                spec.setReasoner(r);
0173:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0174:                m.read("file:testing/ontology/dig/owl/test1.xml");
0175:
0176:                OntClass C = m.getOntClass(NS + "C");
0177:                OntClass D = m.getOntClass(NS + "D");
0178:                assertTrue("D should be a sub-class of C", D.hasSuperClass(C));
0179:            }
0180:
0181:            public void testQuerySubsumes3() {
0182:                String NS = "http://example.org/foo#";
0183:
0184:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0185:                        .create(DIGReasonerFactory.URI, null);
0186:
0187:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0188:                spec.setReasoner(r);
0189:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0190:                m.read("file:testing/ontology/dig/owl/test1.xml");
0191:
0192:                OntClass A = m.getOntClass(NS + "A");
0193:                OntClass C = m.getOntClass(NS + "C");
0194:                assertFalse("A should not be a super-class of C", C
0195:                        .hasSuperClass(A));
0196:                assertFalse("C should not be a super-class of A", A
0197:                        .hasSuperClass(C));
0198:            }
0199:
0200:            public void testAncestors0() {
0201:                String NS = "http://example.org/foo#";
0202:
0203:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0204:                        .create(DIGReasonerFactory.URI, null);
0205:
0206:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0207:                spec.setReasoner(r);
0208:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0209:                m.read("file:testing/ontology/dig/owl/test1.xml");
0210:
0211:                OntClass A = m.getOntClass(NS + "A");
0212:                OntClass B = m.getOntClass(NS + "B");
0213:                OntClass BB = m.getOntClass(NS + "BB");
0214:
0215:                TestUtil.assertIteratorValues(this , A.listSuperClasses(),
0216:                        new Resource[] { B, BB, OWL.Thing });
0217:            }
0218:
0219:            public void testAncestors1() {
0220:                String NS = "http://example.org/foo#";
0221:
0222:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0223:                        .create(DIGReasonerFactory.URI, null);
0224:
0225:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0226:                spec.setReasoner(r);
0227:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0228:                m.read("file:testing/ontology/dig/owl/test1.xml");
0229:
0230:                OntClass A = m.getOntClass(NS + "A");
0231:                OntClass B = m.getOntClass(NS + "B");
0232:                OntClass BB = m.getOntClass(NS + "BB");
0233:
0234:                assertTrue(A.hasSuperClass(B));
0235:                assertTrue(A.hasSuperClass(BB));
0236:                assertTrue(B.hasSuperClass(BB));
0237:
0238:                assertTrue(BB.hasSubClass(B));
0239:                assertTrue(BB.hasSubClass(A));
0240:                assertTrue(B.hasSubClass(A));
0241:
0242:                assertFalse(B.hasSuperClass(A));
0243:                assertFalse(A.hasSubClass(BB));
0244:
0245:                assertTrue(A.hasSuperClass(OWL.Thing));
0246:                assertFalse(A.hasSubClass(OWL.Thing));
0247:            }
0248:
0249:            public void testDescendants() {
0250:                String NS = "http://example.org/foo#";
0251:
0252:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0253:                        .create(DIGReasonerFactory.URI, null);
0254:
0255:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0256:                spec.setReasoner(r);
0257:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0258:                m.read("file:testing/ontology/dig/owl/test1.xml");
0259:
0260:                OntClass A = m.getOntClass(NS + "A");
0261:                OntClass B = m.getOntClass(NS + "B");
0262:                OntClass BB = m.getOntClass(NS + "BB");
0263:
0264:                TestUtil.assertIteratorValues(this , BB.listSubClasses(),
0265:                        new Resource[] { B, A, OWL.Nothing });
0266:            }
0267:
0268:            public void testAllClassHierarchy() {
0269:                String NS = "http://example.org/foo#";
0270:
0271:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0272:                        .create(DIGReasonerFactory.URI, null);
0273:
0274:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0275:                spec.setReasoner(r);
0276:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0277:                m.read("file:testing/ontology/dig/owl/test1.xml");
0278:
0279:                OntClass A = m.getOntClass(NS + "A");
0280:                OntClass B = m.getOntClass(NS + "B");
0281:                OntClass BB = m.getOntClass(NS + "BB");
0282:                OntClass C = m.getOntClass(NS + "C");
0283:                OntClass D = m.getOntClass(NS + "D");
0284:                OntClass E = m.getOntClass(NS + "E");
0285:                OntClass F0 = m.getOntClass(NS + "F0");
0286:                OntClass F1 = m.getOntClass(NS + "F1");
0287:                OntClass F2 = m.getOntClass(NS + "F2");
0288:
0289:                TestUtil
0290:                        .assertIteratorValues(this , m.listStatements(null,
0291:                                RDFS.subClassOf, (RDFNode) null),
0292:                                new Statement[] {
0293:                                        m
0294:                                                .createStatement(A,
0295:                                                        RDFS.subClassOf, A),
0296:                                        m
0297:                                                .createStatement(A,
0298:                                                        RDFS.subClassOf, B),
0299:                                        m.createStatement(A, RDFS.subClassOf,
0300:                                                BB),
0301:                                        m
0302:                                                .createStatement(B,
0303:                                                        RDFS.subClassOf, B),
0304:                                        m.createStatement(B, RDFS.subClassOf,
0305:                                                BB),
0306:                                        m.createStatement(BB, RDFS.subClassOf,
0307:                                                BB),
0308:                                        m
0309:                                                .createStatement(C,
0310:                                                        RDFS.subClassOf, C),
0311:                                        m
0312:                                                .createStatement(D,
0313:                                                        RDFS.subClassOf, D),
0314:                                        m
0315:                                                .createStatement(D,
0316:                                                        RDFS.subClassOf, C),
0317:                                        m
0318:                                                .createStatement(E,
0319:                                                        RDFS.subClassOf, C),
0320:                                        m
0321:                                                .createStatement(E,
0322:                                                        RDFS.subClassOf, E),
0323:                                        m.createStatement(F0, RDFS.subClassOf,
0324:                                                F0),
0325:                                        m.createStatement(F1, RDFS.subClassOf,
0326:                                                F1),
0327:                                        m.createStatement(F2, RDFS.subClassOf,
0328:                                                F2),
0329:                                        m.createStatement(A, RDFS.subClassOf,
0330:                                                OWL.Thing),
0331:                                        m.createStatement(B, RDFS.subClassOf,
0332:                                                OWL.Thing),
0333:                                        m.createStatement(BB, RDFS.subClassOf,
0334:                                                OWL.Thing),
0335:                                        m.createStatement(C, RDFS.subClassOf,
0336:                                                OWL.Thing),
0337:                                        m.createStatement(D, RDFS.subClassOf,
0338:                                                OWL.Thing),
0339:                                        m.createStatement(E, RDFS.subClassOf,
0340:                                                OWL.Thing),
0341:                                        m.createStatement(F0, RDFS.subClassOf,
0342:                                                OWL.Thing),
0343:                                        m.createStatement(F1, RDFS.subClassOf,
0344:                                                OWL.Thing),
0345:                                        m.createStatement(F2, RDFS.subClassOf,
0346:                                                OWL.Thing), }, 4);
0347:            }
0348:
0349:            public void testQueryDisjoint1() {
0350:                String NS = "http://example.org/foo#";
0351:
0352:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0353:                        .create(DIGReasonerFactory.URI, null);
0354:
0355:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0356:                spec.setReasoner(r);
0357:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0358:                m.read("file:testing/ontology/dig/owl/test1.xml");
0359:
0360:                OntClass A = m.getOntClass(NS + "A");
0361:                OntClass C = m.getOntClass(NS + "C");
0362:
0363:                assertTrue("A should be disjoint with C", A.isDisjointWith(C));
0364:                assertTrue("C should be disjoint with A", C.isDisjointWith(A));
0365:            }
0366:
0367:            public void testQueryDisjoint2() {
0368:                String NS = "http://example.org/foo#";
0369:
0370:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0371:                        .create(DIGReasonerFactory.URI, null);
0372:
0373:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0374:                spec.setReasoner(r);
0375:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0376:                m.read("file:testing/ontology/dig/owl/test1.xml");
0377:
0378:                OntClass F0 = m.getOntClass(NS + "F0");
0379:                OntClass F1 = m.getOntClass(NS + "F1");
0380:
0381:                assertTrue("F0 should be disjoint with F1", F0
0382:                        .isDisjointWith(F1));
0383:                assertTrue("F1 should be disjoint with F0", F1
0384:                        .isDisjointWith(F0));
0385:            }
0386:
0387:            public void testParents0() {
0388:                String NS = "http://example.org/foo#";
0389:
0390:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0391:                        .create(DIGReasonerFactory.URI, null);
0392:
0393:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0394:                spec.setReasoner(r);
0395:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0396:                m.read("file:testing/ontology/dig/owl/test1.xml");
0397:
0398:                OntClass A = m.getOntClass(NS + "A");
0399:                OntClass B = m.getOntClass(NS + "B");
0400:
0401:                // note - direct super class
0402:                TestUtil.assertIteratorValues(this , A.listSuperClasses(true),
0403:                        new Resource[] { B });
0404:            }
0405:
0406:            public void testParents1() {
0407:                String NS = "http://example.org/foo#";
0408:
0409:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0410:                        .create(DIGReasonerFactory.URI, null);
0411:
0412:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0413:                spec.setReasoner(r);
0414:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0415:                m.read("file:testing/ontology/dig/owl/test1.xml");
0416:
0417:                OntClass A = m.getOntClass(NS + "A");
0418:                OntClass B = m.getOntClass(NS + "B");
0419:                OntClass BB = m.getOntClass(NS + "BB");
0420:
0421:                // note - direct super class
0422:                assertTrue(A.hasSuperClass(B, true));
0423:                assertTrue(B.hasSubClass(A, true));
0424:                assertFalse(A.hasSuperClass(BB, true));
0425:
0426:                assertTrue(BB.hasSuperClass(OWL.Thing, true));
0427:                assertFalse(B.hasSuperClass(OWL.Thing, true));
0428:            }
0429:
0430:            public void testChildren() {
0431:                String NS = "http://example.org/foo#";
0432:
0433:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0434:                        .create(DIGReasonerFactory.URI, null);
0435:
0436:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0437:                spec.setReasoner(r);
0438:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0439:                m.read("file:testing/ontology/dig/owl/test1.xml");
0440:
0441:                OntClass B = m.getOntClass(NS + "B");
0442:                OntClass BB = m.getOntClass(NS + "BB");
0443:
0444:                // note direct sub-class
0445:                TestUtil.assertIteratorValues(this , BB.listSubClasses(true),
0446:                        new Resource[] { B });
0447:            }
0448:
0449:            public void testEquivalents() {
0450:                String NS = "http://example.org/foo#";
0451:
0452:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0453:                        .create(DIGReasonerFactory.URI, null);
0454:
0455:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0456:                spec.setReasoner(r);
0457:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0458:                m.read("file:testing/ontology/dig/owl/test1.xml");
0459:
0460:                OntClass F0 = m.getOntClass(NS + "F0");
0461:                OntClass F2 = m.getOntClass(NS + "F2");
0462:                OntClass F1 = m.getOntClass(NS + "F1");
0463:
0464:                TestUtil.assertIteratorValues(this , F0.listEquivalentClasses(),
0465:                        new Resource[] { F2, F0 }, 1);
0466:                TestUtil.assertIteratorValues(this , F2.listEquivalentClasses(),
0467:                        new Resource[] { F0, F2 }, 1);
0468:                TestUtil.assertIteratorValues(this , F1.listEquivalentClasses(),
0469:                        new Resource[] { F1 }, 1);
0470:            }
0471:
0472:            public void testIsEquivalent() {
0473:                String NS = "http://example.org/foo#";
0474:
0475:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0476:                        .create(DIGReasonerFactory.URI, null);
0477:
0478:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0479:                spec.setReasoner(r);
0480:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0481:                m.read("file:testing/ontology/dig/owl/test1.xml");
0482:
0483:                OntClass F0 = m.getOntClass(NS + "F0");
0484:                OntClass F2 = m.getOntClass(NS + "F2");
0485:                OntClass F1 = m.getOntClass(NS + "F1");
0486:
0487:                assertTrue("F0 should be equivalent to F2", F0
0488:                        .hasEquivalentClass(F2));
0489:                assertFalse("F0 should not be equivalent to F1", F1
0490:                        .hasEquivalentClass(F0));
0491:            }
0492:
0493:            public void testRAncestors() {
0494:                String NS = "http://example.org/foo#";
0495:
0496:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0497:                        .create(DIGReasonerFactory.URI, null);
0498:
0499:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0500:                spec.setReasoner(r);
0501:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0502:                m.read("file:testing/ontology/dig/owl/test1.xml");
0503:
0504:                ObjectProperty p0 = m.getObjectProperty(NS + "p0");
0505:                ObjectProperty p1 = m.getObjectProperty(NS + "p1");
0506:                ObjectProperty p2 = m.getObjectProperty(NS + "p2");
0507:
0508:                TestUtil.assertIteratorValues(this , p0.listSuperProperties(),
0509:                        new Resource[] { p1, p2, p0 });
0510:            }
0511:
0512:            public void testRDescendants() {
0513:                String NS = "http://example.org/foo#";
0514:
0515:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0516:                        .create(DIGReasonerFactory.URI, null);
0517:
0518:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0519:                spec.setReasoner(r);
0520:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0521:                m.read("file:testing/ontology/dig/owl/test1.xml");
0522:
0523:                ObjectProperty p0 = m.getObjectProperty(NS + "p0");
0524:                ObjectProperty p1 = m.getObjectProperty(NS + "p1");
0525:                ObjectProperty p2 = m.getObjectProperty(NS + "p2");
0526:
0527:                TestUtil.assertIteratorValues(this , p2.listSubProperties(),
0528:                        new Resource[] { p1, p0, p2 });
0529:            }
0530:
0531:            public void testRParents() {
0532:                String NS = "http://example.org/foo#";
0533:
0534:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0535:                        .create(DIGReasonerFactory.URI, null);
0536:
0537:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0538:                spec.setReasoner(r);
0539:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0540:                m.read("file:testing/ontology/dig/owl/test1.xml");
0541:
0542:                ObjectProperty p0 = m.getObjectProperty(NS + "p0");
0543:                ObjectProperty p1 = m.getObjectProperty(NS + "p1");
0544:                //ObjectProperty p2 = m.getObjectProperty( NS + "p2" );
0545:
0546:                TestUtil.assertIteratorValues(this , p0
0547:                        .listSuperProperties(true), new Resource[] { p1 });
0548:            }
0549:
0550:            public void testRChildren() {
0551:                String NS = "http://example.org/foo#";
0552:
0553:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0554:                        .create(DIGReasonerFactory.URI, null);
0555:
0556:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0557:                spec.setReasoner(r);
0558:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0559:                m.read("file:testing/ontology/dig/owl/test1.xml");
0560:
0561:                //ObjectProperty p0 = m.getObjectProperty( NS + "p0" );
0562:                ObjectProperty p1 = m.getObjectProperty(NS + "p1");
0563:                ObjectProperty p2 = m.getObjectProperty(NS + "p2");
0564:
0565:                TestUtil.assertIteratorValues(this , p2.listSubProperties(true),
0566:                        new Resource[] { p1 });
0567:            }
0568:
0569:            public void testInstances() {
0570:                String NS = "http://example.org/foo#";
0571:
0572:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0573:                        .create(DIGReasonerFactory.URI, null);
0574:
0575:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0576:                spec.setReasoner(r);
0577:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0578:                m.read("file:testing/ontology/dig/owl/test1.xml");
0579:
0580:                OntClass F0 = m.getOntClass(NS + "F0");
0581:                Resource i0 = m.getResource(NS + "i0");
0582:                Resource i1 = m.getResource(NS + "i1");
0583:                Resource i2 = m.getResource(NS + "i2");
0584:                Resource q0 = m.getResource(NS + "q0");
0585:                Resource q1 = m.getResource(NS + "q1");
0586:                Resource q2 = m.getResource(NS + "q2");
0587:
0588:                TestUtil.assertIteratorValues(this , F0.listInstances(),
0589:                        new Resource[] { i0, i1, i2, q0, q2, q1 });
0590:            }
0591:
0592:            public void testTypes() {
0593:                String NS = "http://example.org/foo#";
0594:
0595:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0596:                        .create(DIGReasonerFactory.URI, null);
0597:
0598:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0599:                spec.setReasoner(r);
0600:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0601:                m.read("file:testing/ontology/dig/owl/test1.xml");
0602:
0603:                OntClass F0 = m.getOntClass(NS + "F0");
0604:                OntClass F2 = m.getOntClass(NS + "F2");
0605:                Individual i0 = m.getIndividual(NS + "i0");
0606:
0607:                TestUtil.assertIteratorValues(this , i0.listRDFTypes(false),
0608:                        new Resource[] { F0, F2, OWL.Thing }, 1);
0609:            }
0610:
0611:            public void testInstance() {
0612:                String NS = "http://example.org/foo#";
0613:
0614:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0615:                        .create(DIGReasonerFactory.URI, null);
0616:
0617:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0618:                spec.setReasoner(r);
0619:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0620:                m.read("file:testing/ontology/dig/owl/test1.xml");
0621:
0622:                OntClass F0 = m.getOntClass(NS + "F0");
0623:                OntClass F1 = m.getOntClass(NS + "F1");
0624:                Individual i0 = m.getIndividual(NS + "i0");
0625:
0626:                assertTrue("i0 should be an instance of F0", i0.hasRDFType(F0));
0627:                assertFalse("i0 should not be an instance of F1", i0
0628:                        .hasRDFType(F1));
0629:            }
0630:
0631:            public void testRoleFillers() {
0632:                String NS = "http://example.org/foo#";
0633:
0634:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0635:                        .create(DIGReasonerFactory.URI, null);
0636:
0637:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0638:                spec.setReasoner(r);
0639:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0640:                m.read("file:testing/ontology/dig/owl/test1.xml");
0641:
0642:                Individual q0 = m.getIndividual(NS + "q0");
0643:                Individual q1 = m.getIndividual(NS + "q1");
0644:                Individual q2 = m.getIndividual(NS + "q2");
0645:                Property q = m.getProperty(NS + "q");
0646:
0647:                TestUtil.assertIteratorValues(this , q0.listPropertyValues(q),
0648:                        new Resource[] { q1, q2 }, 0);
0649:            }
0650:
0651:            public void testIncrementalAdd() {
0652:                String NS = "http://example.org/foo#";
0653:
0654:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0655:                        .create(DIGReasonerFactory.URI, null);
0656:
0657:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0658:                spec.setReasoner(r);
0659:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0660:
0661:                OntClass F0 = m.createClass(NS + "F0");
0662:                OntClass F1 = m.createClass(NS + "F1");
0663:                OntClass F2 = m.createClass(NS + "F2");
0664:                Individual i0 = m.createIndividual(NS + "i0", F0);
0665:
0666:                assertFalse("i0 is not an F2", i0.hasRDFType(F2));
0667:                F0.addSuperClass(F1);
0668:                F1.addSuperClass(F2);
0669:                assertTrue("i0 should now be an F2", i0.hasRDFType(F2));
0670:            }
0671:
0672:            public void testIncrementalRemove() {
0673:                String NS = "http://example.org/foo#";
0674:
0675:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0676:                        .create(DIGReasonerFactory.URI, null);
0677:
0678:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0679:                spec.setReasoner(r);
0680:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0681:
0682:                OntClass F0 = m.createClass(NS + "F0");
0683:                OntClass F1 = m.createClass(NS + "F1");
0684:                OntClass F2 = m.createClass(NS + "F2");
0685:                Individual i0 = m.createIndividual(NS + "i0", F0);
0686:                F0.addSuperClass(F1);
0687:                F1.addSuperClass(F2);
0688:
0689:                assertTrue("i0 is an F2", i0.hasRDFType(F2));
0690:                F0.removeSuperClass(F1);
0691:                assertFalse("i0 should now not be an F2", i0.hasRDFType(F2));
0692:            }
0693:
0694:            public void testRemoveIndividual() {
0695:                String NS = "http://example.org/foo#";
0696:
0697:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0698:                        .create(DIGReasonerFactory.URI, null);
0699:
0700:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0701:                spec.setReasoner(r);
0702:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0703:                m.read("file:testing/ontology/dig/owl/test1.xml");
0704:
0705:                OntClass F0 = m.createClass(NS + "F0");
0706:                Individual i0 = m.getIndividual(NS + "i0");
0707:
0708:                boolean sawI0 = false;
0709:                for (Iterator i = F0.listInstances(); i.hasNext();) {
0710:                    Resource r0 = (Resource) i.next();
0711:                    log.debug("Pre remove, saw F0 instance " + r0);
0712:                    sawI0 = sawI0 || r0.getURI().equals(i0.getURI());
0713:                }
0714:                assertTrue(sawI0);
0715:
0716:                i0.remove();
0717:
0718:                sawI0 = false;
0719:                for (Iterator i = F0.listInstances(); i.hasNext();) {
0720:                    Resource r0 = (Resource) i.next();
0721:                    log.debug("Post remove, saw F0 instance " + r0);
0722:                    sawI0 = sawI0 || r0.getURI().equals(i0.getURI());
0723:                }
0724:                assertFalse(sawI0);
0725:            }
0726:
0727:            public void testRelatedIndividuals() {
0728:                String NS = "http://example.org/foo#";
0729:
0730:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0731:                        .create(DIGReasonerFactory.URI, null);
0732:
0733:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0734:                spec.setReasoner(r);
0735:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0736:
0737:                OntClass F0 = m.createClass(NS + "F0");
0738:                Individual i0 = F0.createIndividual(NS + "i0");
0739:                Individual i1 = F0.createIndividual(NS + "i1");
0740:                Individual i2 = F0.createIndividual(NS + "i2");
0741:                OntProperty p = m.createTransitiveProperty(NS + "p");
0742:
0743:                i0.addProperty(p, i1);
0744:                i1.addProperty(p, i2);
0745:
0746:                //TestUtil.assertIteratorValues( this, i0.listPropertyValues( p ), new Resource[] {i1, i2}, 0 );
0747:
0748:                int count = 0;
0749:                for (StmtIterator i = m.listStatements(null, p, (RDFNode) null); i
0750:                        .hasNext();) {
0751:                    Statement s = i.nextStatement();
0752:                    count++;
0753:                }
0754:                assertEquals("Should find 3 statements", 3, count);
0755:            }
0756:
0757:            // User bug reports
0758:
0759:            public void test_bug_codebaker_01() {
0760:                String NS = "http://www.owl-ontologies.com/pizza.owl#";
0761:
0762:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0763:                        .create(DIGReasonerFactory.URI, null);
0764:
0765:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0766:                spec.setReasoner(r);
0767:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0768:
0769:                m.read("file:testing/ontology/bugs/test_codebaker_01.owl");
0770:
0771:                OntClass mp = m.getOntClass(NS + "MargheritaPizza");
0772:                OntClass cp = m.getOntClass(NS + "CheesyPizza");
0773:
0774:                assertTrue("MargheritaPizza should be cheesy", mp
0775:                        .hasSuperClass(cp));
0776:            }
0777:
0778:            public void test_bug_koala_01() {
0779:                // set up a configuration resource to connect to the reasoner
0780:                // on port 2004 on the local system
0781:                Model cModel = ModelFactory.createDefaultModel();
0782:                Resource conf = cModel.createResource();
0783:                conf.addProperty(ReasonerVocabulary.EXT_REASONER_URL, cModel
0784:                        .createResource("http://localhost:8081"));
0785:
0786:                // create the reasoner factory and the reasoner
0787:                DIGReasonerFactory drf = (DIGReasonerFactory) ReasonerRegistry
0788:                        .theRegistry().getFactory(DIGReasonerFactory.URI);
0789:                DIGReasoner r = (DIGReasoner) drf.create(conf);
0790:
0791:                // now make a model
0792:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0793:                spec.setReasoner(r);
0794:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0795:
0796:                // load an input document
0797:                m
0798:                        .getDocumentManager()
0799:                        .addAltEntry(
0800:                                "http://protege.stanford.edu/plugins/owl/owl-library/koala.owl",
0801:                                "file:testing/ontology/bugs/koala.owl");
0802:                m
0803:                        .read("http://protege.stanford.edu/plugins/owl/owl-library/koala.owl");
0804:
0805:                // list the inconsistent classes
0806:                StmtIterator i = m.listStatements(null, OWL.equivalentClass,
0807:                        OWL.Nothing);
0808:                int unsatCount = 0;
0809:                while (i.hasNext()) {
0810:                    /*Resource s = */i.nextStatement().getSubject();
0811:                    //System.out.println( "Class " + s + " is unsatisfiable" );
0812:                    unsatCount++;
0813:                }
0814:                assertEquals("Should be 4 unsatisfiable classes", 5, unsatCount);
0815:            }
0816:
0817:            /* Bug report by Michele Orlando - duplicate results from rdql query */
0818:            public void test_bug_mo_1() {
0819:                String NS = "http://example.org/foo#";
0820:
0821:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0822:                        .create(DIGReasonerFactory.URI, null);
0823:
0824:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0825:                spec.setReasoner(r);
0826:                OntModel m = ModelFactory.createOntologyModel(spec, null);
0827:
0828:                OntClass a = m.createClass(NS + "A");
0829:                Individual i0 = m.createIndividual(NS + "i0", a);
0830:
0831:                int iCount = 0;
0832:                int nonICount = 0;
0833:
0834:                for (StmtIterator j = m.listStatements(null, RDF.type, m
0835:                        .getResource(NS + "A")); j.hasNext();) {
0836:                    if (j.nextStatement().getSubject().equals(i0)) {
0837:                        iCount++;
0838:                    } else {
0839:                        nonICount++;
0840:                    }
0841:                }
0842:                assertEquals("Should be no non i0's", 0, nonICount);
0843:                assertEquals("Should be only one i0", 1, iCount);
0844:            }
0845:
0846:            /* Bug report from Michele Orlando - failure on getLabel */
0847:            public void test_bug_mo_2() {
0848:                boolean ex0 = false;
0849:                boolean ex1 = false;
0850:                String NS = "http://example.org/foo#";
0851:
0852:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0853:                        .create(DIGReasonerFactory.URI, null);
0854:
0855:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0856:                spec.setReasoner(r);
0857:                OntModel model = ModelFactory.createOntologyModel(spec, null);
0858:
0859:                OntClass a = model.createClass(NS + "A");
0860:                Individual b = model.createIndividual(NS + "b", a);
0861:
0862:                Model base = model.getBaseModel();
0863:                Literal lbl = base.createLiteral("fubar", "en");
0864:                base.add(b, RDFS.label, lbl);
0865:
0866:                // ensure we have the model we want
0867:                //model.write( System.out, "N3" );
0868:
0869:                for (Iterator instances = model.listIndividuals(); instances
0870:                        .hasNext();) {
0871:                    Individual inst = (Individual) instances.next();
0872:
0873:                    try {
0874:                        //System.out.println( "Label try #1: " + "  "+inst.getLabel("en"));
0875:                        inst.getLabel("en");
0876:                    } catch (Exception e) {
0877:                        //System.out.println( "First attempt failed: " + e.getMessage() );
0878:                        ex0 = true;
0879:                    }
0880:
0881:                    try {
0882:                        Resource baseInst = (Resource) inst.inModel(base);
0883:                        /*String label =*/baseInst.getProperty(RDFS.label)
0884:                                .getString();
0885:                        //System.out.println("Label try #2: " +  label );
0886:                    } catch (Exception e) {
0887:                        System.out.println("Second attempt failed "
0888:                                + e.getMessage());
0889:                        ex1 = true;
0890:                    }
0891:                }
0892:
0893:                // Junit
0894:                assertTrue(!(ex0 || ex1));
0895:            }
0896:
0897:            public void test_bug_mo_3() {
0898:                DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry()
0899:                        .create(DIGReasonerFactory.URI, null);
0900:                OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_DL_MEM);
0901:                spec.setReasoner(r);
0902:                OntModel model = ModelFactory.createOntologyModel(spec);
0903:                OntClass c0 = model.createClass("ns:A");
0904:                c0.addLabel("this is just a test", "en");
0905:                Model base = model.getBaseModel();
0906:
0907:                OntClass cls = model.getOntClass("ns:A");
0908:                System.out.println(cls.getLocalName());
0909:                for (Iterator instances = cls.listInstances(); instances
0910:                        .hasNext();) {
0911:                    Resource inst = (Resource) instances.next();
0912:                    //        System.out.println(" "+inst.getLabel("it"));
0913:                    Property p = base.getProperty(
0914:                            "http://www.w3.org/2000/01/rdf-schema#", "label");
0915:                    Statement s = inst.getProperty(p);
0916:                    System.out.println(" " + s.getString());
0917:                }
0918:            }
0919:
0920:            // for debuging the basic query tests one at a time
0921:            public void xxtestBasicQueryN() throws Exception {
0922:                String root = "testing/ontology/dig/owl/basicq";
0923:                int testN = 24;
0924:
0925:                File testSource = new File(root + "/test_" + testN
0926:                        + ".source.xml");
0927:                File testQuery = new File(root + "/test_" + testN
0928:                        + ".query.xml");
0929:                File testTarget = new File(root + "/test_" + testN
0930:                        + ".result.xml");
0931:
0932:                new DigBasicQueryTest(testSource, testTarget, testQuery,
0933:                        OntModelSpec.OWL_MEM).runTest();
0934:            }
0935:
0936:            // Internal implementation methods
0937:            //////////////////////////////////
0938:
0939:            private static void buildConceptLangSuite(String root,
0940:                    OntModelSpec spec, TestSuite s) {
0941:                int i = 0;
0942:                while (true) {
0943:                    File testSource = new File(root + "/test_" + i
0944:                            + ".source.xml");
0945:                    File testTarget = new File(root + "/test_" + i + ".xml");
0946:
0947:                    if (!testSource.exists()) {
0948:                        break;
0949:                    } else {
0950:                        i++;
0951:                    }
0952:
0953:                    s.addTest(new DigTranslationTest(testSource, testTarget,
0954:                            spec));
0955:                }
0956:            }
0957:
0958:            private static void buildBasicQuerySuite(String root,
0959:                    OntModelSpec spec, TestSuite s) {
0960:                int i = 0;
0961:                while (true) {
0962:                    File testSource = new File(root + "/test_" + i
0963:                            + ".source.xml");
0964:                    File testQuery = new File(root + "/test_" + i
0965:                            + ".query.xml");
0966:                    File testTarget = new File(root + "/test_" + i
0967:                            + ".result.xml");
0968:
0969:                    if (!testSource.exists()) {
0970:                        break;
0971:                    } else {
0972:                        i++;
0973:                    }
0974:
0975:                    s.addTest(new DigBasicQueryTest(testSource, testTarget,
0976:                            testQuery, spec));
0977:                }
0978:            }
0979:
0980:            //==============================================================================
0981:            // Inner class definitions
0982:            //==============================================================================
0983:
0984:            private static class AbstractDigTest extends TestCase {
0985:                private boolean debug = true;
0986:
0987:                public AbstractDigTest(String name) {
0988:                    super (name);
0989:                }
0990:
0991:                /** This is a simple test that test xml structure isomorphism on elements and attributes */
0992:                protected void xmlEqualityTest(Document source, Document target) {
0993:                    // test both ways round to ensure compatability
0994:                    boolean test = xmlEqualityTest(source.getDocumentElement(),
0995:                            target.getDocumentElement());
0996:                    if (debug && !test) {
0997:                        PrintWriter out = new PrintWriter(System.err);
0998:                        out.println(getName() + " expected:");
0999:                        new DIGConnection().serialiseDocument(target, out);
1000:                        out.println();
1001:                        out.println("Saw:");
1002:                        new DIGConnection().serialiseDocument(source, out);
1003:                        out.println();
1004:                    }
1005:                    assertTrue("Failed to match source to target documents",
1006:                            test);
1007:
1008:                    test = xmlEqualityTest(target.getDocumentElement(), source
1009:                            .getDocumentElement());
1010:                    if (debug && !test) {
1011:                        PrintWriter out = new PrintWriter(System.err);
1012:                        out.println(getName() + " expected:");
1013:                        new DIGConnection().serialiseDocument(source, out);
1014:                        out.println();
1015:                        out.println("Saw:");
1016:                        new DIGConnection().serialiseDocument(target, out);
1017:                        out.println();
1018:                    }
1019:                    assertTrue("Failed to match target to source documents",
1020:                            test);
1021:                }
1022:
1023:                private boolean xmlEqualityTest(Element source, Element target) {
1024:                    boolean match = source.getNodeName().equals(
1025:                            target.getNodeName());
1026:                    NodeList children = source.getChildNodes();
1027:
1028:                    for (int i = 0; match && i < children.getLength(); i++) {
1029:                        Node child = children.item(i);
1030:                        // we're only looking at structural equivalence - elements and attributes
1031:                        if (child instanceof  Element) {
1032:                            match = findElementMatch((Element) child, target);
1033:                        }
1034:                    }
1035:
1036:                    NamedNodeMap attrs = source.getAttributes();
1037:
1038:                    for (int i = 0; match && i < attrs.getLength(); i++) {
1039:                        match = findAttributeMatch((Attr) attrs.item(i), target);
1040:                    }
1041:
1042:                    return match;
1043:                }
1044:
1045:                private boolean findElementMatch(Element sourceChild,
1046:                        Element target) {
1047:                    boolean found = false;
1048:
1049:                    NodeList targetChildren = target
1050:                            .getElementsByTagName(sourceChild.getNodeName());
1051:
1052:                    for (int i = 0; !found && i < targetChildren.getLength(); i++) {
1053:                        Node targetChild = targetChildren.item(i);
1054:
1055:                        if (targetChild instanceof  Element
1056:                                && sourceChild.getNodeName().equals(
1057:                                        targetChild.getNodeName())) {
1058:                            // we have found an element with the same name - see if it matches
1059:                            found = xmlEqualityTest(sourceChild,
1060:                                    (Element) targetChild);
1061:                        }
1062:                    }
1063:
1064:                    return found;
1065:                }
1066:
1067:                private boolean findAttributeMatch(Attr child, Element target) {
1068:                    String chValue = child.getValue();
1069:                    String targetValue = target.getAttribute(child.getName());
1070:
1071:                    return (chValue.startsWith(DIGAdapter.ANON_MARKER) && targetValue
1072:                            .startsWith(DIGAdapter.ANON_MARKER))
1073:                            || chValue.equals(targetValue);
1074:                }
1075:            }
1076:
1077:            private static class DigTranslationTest extends AbstractDigTest {
1078:                private File m_source;
1079:                private File m_target;
1080:                private OntModelSpec m_spec;
1081:
1082:                DigTranslationTest(File source, File target, OntModelSpec spec) {
1083:                    super ("DigTranslationTest " + source.getName());
1084:                    m_source = source;
1085:                    m_target = target;
1086:                    m_spec = spec;
1087:                }
1088:
1089:                public void runTest() throws Exception {
1090:                    DocumentBuilder builder = DocumentBuilderFactory
1091:                            .newInstance().newDocumentBuilder();
1092:
1093:                    Model m = ModelFactory.createDefaultModel();
1094:                    m.read(new FileInputStream(m_source), null);
1095:                    DIGAdapter da = new DIGAdapter(m_spec, m.getGraph());
1096:
1097:                    Document targetD = builder.parse(m_target);
1098:                    Document sourceD = da.translateKbToDig();
1099:
1100:                    // debug da.serialiseDocument( sourceD, new PrintWriter( System.out ));
1101:
1102:                    xmlEqualityTest(sourceD, targetD);
1103:                }
1104:            }
1105:
1106:            private static class DigBasicQueryTest extends AbstractDigTest {
1107:                private File m_source;
1108:                private File m_target;
1109:                private File m_query;
1110:                private OntModelSpec m_spec;
1111:
1112:                DigBasicQueryTest(File source, File target, File query,
1113:                        OntModelSpec spec) {
1114:                    super ("BasicQueryTest " + source.getName());
1115:                    m_source = source;
1116:                    m_target = target;
1117:                    m_query = query;
1118:                    m_spec = spec;
1119:                }
1120:
1121:                public void runTest() throws Exception {
1122:                    DocumentBuilder builder = DocumentBuilderFactory
1123:                            .newInstance().newDocumentBuilder();
1124:
1125:                    Model m = ModelFactory.createDefaultModel();
1126:                    m.read(new FileInputStream(m_source), null);
1127:                    DIGAdapter da = new DIGAdapter(m_spec, m.getGraph());
1128:
1129:                    // upload
1130:                    da.resetKB();
1131:                    boolean warn = !da.uploadKB();
1132:                    if (warn) {
1133:                        System.err.println("00 Warning!");
1134:                        for (Iterator i = da.getConnection().getWarnings(); i
1135:                                .hasNext();) {
1136:                            System.err.println(i.next());
1137:                        }
1138:                        assertFalse("Should not be upload warnings", warn);
1139:                    }
1140:
1141:                    Document queryD = builder.parse(m_query);
1142:                    Document targetD = builder.parse(m_target);
1143:
1144:                    log.debug("DIG test " + m_source.getPath());
1145:                    Document resultD = da.getConnection().sendDigVerb(queryD,
1146:                            da.getProfile());
1147:
1148:                    da.getConnection().errorCheck(resultD, da.getProfile());
1149:                    assertFalse("Should not be warnings", da.getConnection()
1150:                            .warningCheck(resultD));
1151:
1152:                    da.close();
1153:                    xmlEqualityTest(resultD, targetD);
1154:                }
1155:            }
1156:        }
1157:
1158:        /*
1159:         *  (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
1160:         *  All rights reserved.
1161:         *
1162:         * Redistribution and use in source and binary forms, with or without
1163:         * modification, are permitted provided that the following conditions
1164:         * are met:
1165:         * 1. Redistributions of source code must retain the above copyright
1166:         *    notice, this list of conditions and the following disclaimer.
1167:         * 2. Redistributions in binary form must reproduce the above copyright
1168:         *    notice, this list of conditions and the following disclaimer in the
1169:         *    documentation and/or other materials provided with the distribution.
1170:         * 3. The name of the author may not be used to endorse or promote products
1171:         *    derived from this software without specific prior written permission.
1172:         *
1173:         * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1174:         * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1175:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1176:         * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1177:         * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1178:         * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1179:         * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1180:         * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1181:         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
1182:         * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1183:         */
w___w__w__.ja__va___2_s__.__c___o__m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.