Source Code Cross Referenced for TestClassExpression.java in  » RSS-RDF » Jena-2.5.5 » com » hp » hpl » jena » ontology » impl » 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.ontology.impl.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            27-May-2003
0009:         * Filename           $RCSfile: TestClassExpression.java,v $
0010:         * Revision           $Revision: 1.36 $
0011:         * Release status     $State: Exp $
0012:         *
0013:         * Last modified on   $Date: 2008/01/02 12:08:39 $
0014:         *               by   $Author: andy_seaborne $
0015:         *
0016:         * (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
0017:         * (see footer for full conditions)
0018:         *****************************************************************************/package com.hp.hpl.jena.ontology.impl.test;
0019:
0020:        // Imports
0021:        ///////////////
0022:        import com.hp.hpl.jena.ontology.*;
0023:        import com.hp.hpl.jena.rdf.model.*;
0024:        import com.hp.hpl.jena.util.iterator.ClosableIterator;
0025:        import com.hp.hpl.jena.util.iterator.NullIterator;
0026:        import com.hp.hpl.jena.vocabulary.*;
0027:
0028:        import junit.framework.*;
0029:
0030:        /**
0031:         * <p>
0032:         * Unit tests for OntClass and other class expressions.
0033:         * </p>
0034:         *
0035:         * @author Ian Dickinson, HP Labs
0036:         *         (<a  href="mailto:Ian.Dickinson@hp.com" >email</a>)
0037:         * @version CVS $Id: TestClassExpression.java,v 1.36 2008/01/02 12:08:39 andy_seaborne Exp $
0038:         */
0039:        public class TestClassExpression extends OntTestBase {
0040:            // Constants
0041:            //////////////////////////////////
0042:
0043:            // Static variables
0044:            //////////////////////////////////
0045:
0046:            // Instance variables
0047:            //////////////////////////////////
0048:
0049:            // Constructors
0050:            //////////////////////////////////
0051:
0052:            static public TestSuite suite() {
0053:                return new TestClassExpression("TestClassExpression");
0054:            }
0055:
0056:            public TestClassExpression(String name) {
0057:                super (name);
0058:            }
0059:
0060:            // External signature methods
0061:            //////////////////////////////////
0062:
0063:            public OntTestCase[] getTests() {
0064:                return new OntTestCase[] {
0065:                        new OntTestCase("OntClass.super-class", true, true,
0066:                                true, true) {
0067:                            public void ontTest(OntModel m) throws Exception {
0068:                                Profile prof = m.getProfile();
0069:                                OntClass A = m.createClass(NS + "A");
0070:                                OntClass B = m.createClass(NS + "B");
0071:                                OntClass C = m.createClass(NS + "C");
0072:
0073:                                A.addSuperClass(B);
0074:                                assertEquals("Cardinality should be 1", 1, A
0075:                                        .getCardinality(prof.SUB_CLASS_OF()));
0076:                                assertEquals("A should have super-class B", B,
0077:                                        A.getSuperClass());
0078:
0079:                                A.addSuperClass(C);
0080:                                assertEquals("Cardinality should be 2", 2, A
0081:                                        .getCardinality(prof.SUB_CLASS_OF()));
0082:                                iteratorTest(A.listSuperClasses(),
0083:                                        new Object[] { C, B });
0084:
0085:                                A.setSuperClass(C);
0086:                                assertEquals("Cardinality should be 1", 1, A
0087:                                        .getCardinality(prof.SUB_CLASS_OF()));
0088:                                assertEquals("A shuold have super-class C", C,
0089:                                        A.getSuperClass());
0090:                                assertTrue("A shuold not have super-class B",
0091:                                        !A.hasSuperClass(B, false));
0092:
0093:                                A.removeSuperClass(B);
0094:                                assertEquals("Cardinality should be 1", 1, A
0095:                                        .getCardinality(prof.SUB_CLASS_OF()));
0096:                                A.removeSuperClass(C);
0097:                                assertEquals("Cardinality should be 0", 0, A
0098:                                        .getCardinality(prof.SUB_CLASS_OF()));
0099:                            }
0100:                        },
0101:                        new OntTestCase("OntClass.sub-class", true, true, true,
0102:                                true) {
0103:                            public void ontTest(OntModel m) throws Exception {
0104:                                Profile prof = m.getProfile();
0105:                                OntClass A = m.createClass(NS + "A");
0106:                                OntClass B = m.createClass(NS + "B");
0107:                                OntClass C = m.createClass(NS + "C");
0108:
0109:                                A.addSubClass(B);
0110:                                assertEquals("Cardinality should be 1", 1, B
0111:                                        .getCardinality(prof.SUB_CLASS_OF()));
0112:                                assertEquals("A should have sub-class B", B, A
0113:                                        .getSubClass());
0114:
0115:                                A.addSubClass(C);
0116:                                assertEquals("Cardinality should be 2", 2, B
0117:                                        .getCardinality(prof.SUB_CLASS_OF())
0118:                                        + C.getCardinality(prof.SUB_CLASS_OF()));
0119:                                iteratorTest(A.listSubClasses(), new Object[] {
0120:                                        C, B });
0121:
0122:                                A.setSubClass(C);
0123:                                assertEquals("Cardinality should be 1", 1, B
0124:                                        .getCardinality(prof.SUB_CLASS_OF())
0125:                                        + C.getCardinality(prof.SUB_CLASS_OF()));
0126:                                assertEquals("A shuold have sub-class C", C, A
0127:                                        .getSubClass());
0128:                                assertTrue("A shuold not have sub-class B", !A
0129:                                        .hasSubClass(B, false));
0130:
0131:                                A.removeSubClass(B);
0132:                                assertTrue("A should have sub-class C", A
0133:                                        .hasSubClass(C, false));
0134:                                A.removeSubClass(C);
0135:                                assertTrue("A should not have sub-class C", !A
0136:                                        .hasSubClass(C, false));
0137:                            }
0138:                        },
0139:                        new OntTestCase("OntClass.equivalentClass", true, true,
0140:                                true, false) {
0141:                            public void ontTest(OntModel m) throws Exception {
0142:                                Profile prof = m.getProfile();
0143:                                OntClass A = m.createClass(NS + "A");
0144:                                OntClass B = m.createClass(NS + "B");
0145:                                OntClass C = m.createClass(NS + "C");
0146:
0147:                                A.addEquivalentClass(B);
0148:                                assertEquals("Cardinality should be 1", 1,
0149:                                        A.getCardinality(prof
0150:                                                .EQUIVALENT_CLASS()));
0151:                                assertEquals("A have equivalentClass B", B, A
0152:                                        .getEquivalentClass());
0153:
0154:                                A.addEquivalentClass(C);
0155:                                assertEquals("Cardinality should be 2", 2,
0156:                                        A.getCardinality(prof
0157:                                                .EQUIVALENT_CLASS()));
0158:                                iteratorTest(A.listEquivalentClasses(),
0159:                                        new Object[] { C, B });
0160:
0161:                                A.setEquivalentClass(C);
0162:                                assertEquals("Cardinality should be 1", 1,
0163:                                        A.getCardinality(prof
0164:                                                .EQUIVALENT_CLASS()));
0165:                                assertEquals("A should have equivalentClass C",
0166:                                        C, A.getEquivalentClass());
0167:                                assertTrue(
0168:                                        "A should not have equivalentClass B",
0169:                                        !A.hasEquivalentClass(B));
0170:
0171:                                A.removeEquivalentClass(B);
0172:                                assertEquals("Cardinality should be 1", 1,
0173:                                        A.getCardinality(prof
0174:                                                .EQUIVALENT_CLASS()));
0175:                                A.removeEquivalentClass(C);
0176:                                assertEquals("Cardinality should be 0", 0,
0177:                                        A.getCardinality(prof
0178:                                                .EQUIVALENT_CLASS()));
0179:                            }
0180:                        },
0181:                        new OntTestCase("OntClass.disjointWith", true, false,
0182:                                true, false) {
0183:                            public void ontTest(OntModel m) throws Exception {
0184:                                Profile prof = m.getProfile();
0185:                                OntClass A = m.createClass(NS + "A");
0186:                                OntClass B = m.createClass(NS + "B");
0187:                                OntClass C = m.createClass(NS + "C");
0188:
0189:                                A.addDisjointWith(B);
0190:                                assertEquals("Cardinality should be 1", 1, A
0191:                                        .getCardinality(prof.DISJOINT_WITH()));
0192:                                assertEquals("A have be disjoint with B", B, A
0193:                                        .getDisjointWith());
0194:
0195:                                A.addDisjointWith(C);
0196:                                assertEquals("Cardinality should be 2", 2, A
0197:                                        .getCardinality(prof.DISJOINT_WITH()));
0198:                                iteratorTest(A.listDisjointWith(),
0199:                                        new Object[] { C, B });
0200:
0201:                                A.setDisjointWith(C);
0202:                                assertEquals("Cardinality should be 1", 1, A
0203:                                        .getCardinality(prof.DISJOINT_WITH()));
0204:                                assertEquals("A should be disjoint with C", C,
0205:                                        A.getDisjointWith());
0206:                                assertTrue("A should not be disjoint with B",
0207:                                        !A.isDisjointWith(B));
0208:
0209:                                A.removeDisjointWith(B);
0210:                                assertEquals("Cardinality should be 1", 1, A
0211:                                        .getCardinality(prof.DISJOINT_WITH()));
0212:                                A.removeDisjointWith(C);
0213:                                assertEquals("Cardinality should be 0", 0, A
0214:                                        .getCardinality(prof.DISJOINT_WITH()));
0215:                            }
0216:                        },
0217:                        new OntTestCase("EnumeratedClass.oneOf", true, false,
0218:                                true, false) {
0219:                            public void ontTest(OntModel m) throws Exception {
0220:                                Profile prof = m.getProfile();
0221:                                EnumeratedClass A = m.createEnumeratedClass(NS
0222:                                        + "A", null);
0223:                                OntResource a = (OntResource) m.getResource(
0224:                                        NS + "a").as(OntResource.class);
0225:                                OntResource b = (OntResource) m.getResource(
0226:                                        NS + "b").as(OntResource.class);
0227:
0228:                                A.addOneOf(a);
0229:                                assertEquals("Cardinality should be 1", 1, A
0230:                                        .getCardinality(prof.ONE_OF()));
0231:                                assertEquals("Size should be 1", 1, A
0232:                                        .getOneOf().size());
0233:                                assertTrue(
0234:                                        "A should have a as enumerated member",
0235:                                        A.getOneOf().contains(a));
0236:
0237:                                A.addOneOf(b);
0238:                                assertEquals("Cardinality should be 1", 1, A
0239:                                        .getCardinality(prof.ONE_OF()));
0240:                                assertEquals("Size should be 2", 2, A
0241:                                        .getOneOf().size());
0242:                                iteratorTest(A.listOneOf(),
0243:                                        new Object[] { a, b });
0244:
0245:                                A.setOneOf(m.createList(new RDFNode[] { b }));
0246:                                assertEquals("Cardinality should be 1", 1, A
0247:                                        .getCardinality(prof.ONE_OF()));
0248:                                assertEquals("Size should be 1", 1, A
0249:                                        .getOneOf().size());
0250:                                assertTrue("A should have b in the enum", A
0251:                                        .hasOneOf(b));
0252:                                assertTrue("A should not have a in the enum",
0253:                                        !A.hasOneOf(a));
0254:
0255:                                A.removeOneOf(a);
0256:                                assertTrue("Should have b as an enum value", A
0257:                                        .hasOneOf(b));
0258:                                A.removeOneOf(b);
0259:                                assertTrue(
0260:                                        "Should not have b as an enum value",
0261:                                        !A.hasOneOf(b));
0262:                            }
0263:                        },
0264:                        new OntTestCase("IntersectionClass.intersectionOf",
0265:                                true, true, true, false) {
0266:                            public void ontTest(OntModel m) throws Exception {
0267:                                Profile prof = m.getProfile();
0268:                                IntersectionClass A = m
0269:                                        .createIntersectionClass(NS + "A", null);
0270:                                OntClass B = m.createClass(NS + "B");
0271:                                OntClass C = m.createClass(NS + "C");
0272:
0273:                                A.addOperand(B);
0274:                                assertEquals("Cardinality should be 1", 1, A
0275:                                        .getCardinality(prof.INTERSECTION_OF()));
0276:                                assertEquals("Size should be 1", 1, A
0277:                                        .getOperands().size());
0278:                                assertTrue(
0279:                                        "A should have a as intersection member",
0280:                                        A.getOperands().contains(B));
0281:
0282:                                A.addOperand(C);
0283:                                assertEquals("Cardinality should be 1", 1, A
0284:                                        .getCardinality(prof.INTERSECTION_OF()));
0285:                                assertEquals("Size should be 2", 2, A
0286:                                        .getOperands().size());
0287:                                iteratorTest(A.listOperands(), new Object[] {
0288:                                        B, C });
0289:
0290:                                ClosableIterator i = A.listOperands();
0291:                                assertTrue("Argument should be an OntClass", i
0292:                                        .next() instanceof  OntClass);
0293:                                i.close();
0294:
0295:                                A
0296:                                        .setOperands(m
0297:                                                .createList(new RDFNode[] { C }));
0298:                                assertEquals("Cardinality should be 1", 1, A
0299:                                        .getCardinality(prof.INTERSECTION_OF()));
0300:                                assertEquals("Size should be 1", 1, A
0301:                                        .getOperands().size());
0302:                                assertTrue(
0303:                                        "A should have C in the intersection",
0304:                                        A.hasOperand(C));
0305:                                assertTrue(
0306:                                        "A should not have B in the intersection",
0307:                                        !A.hasOperand(B));
0308:
0309:                                A.removeOperand(B);
0310:                                assertTrue("Should have C as an operand", A
0311:                                        .hasOperand(C));
0312:                                A.removeOperand(C);
0313:                                assertTrue("Should not have C as an operand",
0314:                                        !A.hasOperand(C));
0315:                            }
0316:                        },
0317:                        new OntTestCase("UnionClass.unionOf", true, false,
0318:                                true, false) {
0319:                            public void ontTest(OntModel m) throws Exception {
0320:                                Profile prof = m.getProfile();
0321:                                UnionClass A = m.createUnionClass(NS + "A",
0322:                                        null);
0323:                                OntClass B = m.createClass(NS + "B");
0324:                                OntClass C = m.createClass(NS + "C");
0325:
0326:                                A.addOperand(B);
0327:                                assertEquals("Cardinality should be 1", 1, A
0328:                                        .getCardinality(prof.UNION_OF()));
0329:                                assertEquals("Size should be 1", 1, A
0330:                                        .getOperands().size());
0331:                                assertTrue("A should have a as union member", A
0332:                                        .getOperands().contains(B));
0333:
0334:                                A.addOperand(C);
0335:                                assertEquals("Cardinality should be 1", 1, A
0336:                                        .getCardinality(prof.UNION_OF()));
0337:                                assertEquals("Size should be 2", 2, A
0338:                                        .getOperands().size());
0339:                                iteratorTest(A.listOperands(), new Object[] {
0340:                                        B, C });
0341:
0342:                                ClosableIterator i = A.listOperands();
0343:                                assertTrue("Argument should be an OntClass", i
0344:                                        .next() instanceof  OntClass);
0345:                                i.close();
0346:
0347:                                A
0348:                                        .setOperands(m
0349:                                                .createList(new RDFNode[] { C }));
0350:                                assertEquals("Cardinality should be 1", 1, A
0351:                                        .getCardinality(prof.UNION_OF()));
0352:                                assertEquals("Size should be 1", 1, A
0353:                                        .getOperands().size());
0354:                                assertTrue("A should have C in the union", A
0355:                                        .hasOperand(C));
0356:                                assertTrue("A should not have B in the union",
0357:                                        !A.hasOperand(B));
0358:
0359:                                A.removeOperand(B);
0360:                                assertTrue("Should have C as an operand", A
0361:                                        .hasOperand(C));
0362:                                A.removeOperand(C);
0363:                                assertTrue("Should not have C as an operand",
0364:                                        !A.hasOperand(C));
0365:                            }
0366:                        },
0367:                        new OntTestCase("ComplementClass.complementOf", true,
0368:                                false, true, false) {
0369:                            public void ontTest(OntModel m) throws Exception {
0370:                                Profile prof = m.getProfile();
0371:                                ComplementClass A = m.createComplementClass(NS
0372:                                        + "A", null);
0373:                                OntClass B = m.createClass(NS + "B");
0374:                                OntClass C = m.createClass(NS + "C");
0375:                                boolean ex = false;
0376:
0377:                                try {
0378:                                    A.addOperand(B);
0379:                                } catch (UnsupportedOperationException e) {
0380:                                    ex = true;
0381:                                }
0382:                                assertTrue(
0383:                                        "Should fail to add to a complement",
0384:                                        ex);
0385:
0386:                                ex = false;
0387:                                try {
0388:                                    A.addOperands(NullIterator.instance);
0389:                                } catch (UnsupportedOperationException e) {
0390:                                    ex = true;
0391:                                }
0392:                                assertTrue(
0393:                                        "Should fail to add to a complement",
0394:                                        ex);
0395:
0396:                                ex = false;
0397:                                try {
0398:                                    A.setOperands(m
0399:                                            .createList(new RDFNode[] { C }));
0400:                                } catch (UnsupportedOperationException e) {
0401:                                    ex = true;
0402:                                }
0403:                                assertTrue(
0404:                                        "Should fail to set a list to a complement",
0405:                                        ex);
0406:
0407:                                A.setOperand(B);
0408:                                assertEquals("Cardinality should be 1", 1, A
0409:                                        .getCardinality(prof.COMPLEMENT_OF()));
0410:                                assertEquals("Complement should be B", B, A
0411:                                        .getOperand());
0412:                                iteratorTest(A.listOperands(),
0413:                                        new Object[] { B });
0414:
0415:                                A.setOperand(C);
0416:                                assertEquals("Cardinality should be 1", 1, A
0417:                                        .getCardinality(prof.COMPLEMENT_OF()));
0418:                                assertTrue("A should have C in the complement",
0419:                                        A.hasOperand(C));
0420:                                assertTrue(
0421:                                        "A should not have B in the complement",
0422:                                        !A.hasOperand(B));
0423:
0424:                                A.removeOperand(B);
0425:                                assertTrue("Should have C as an operand", A
0426:                                        .hasOperand(C));
0427:                                A.removeOperand(C);
0428:                                assertTrue("Should not have C as an operand",
0429:                                        !A.hasOperand(C));
0430:                            }
0431:                        },
0432:                        new OntTestCase("Restriction.onProperty", true, true,
0433:                                true, false) {
0434:                            public void ontTest(OntModel m) throws Exception {
0435:                                Profile prof = m.getProfile();
0436:                                OntProperty p = m
0437:                                        .createObjectProperty(NS + "p");
0438:                                OntProperty q = m
0439:                                        .createObjectProperty(NS + "q");
0440:                                OntClass B = m.createClass(NS + "B");
0441:
0442:                                Restriction A = m
0443:                                        .createAllValuesFromRestriction(NS
0444:                                                + "A", p, B);
0445:
0446:                                assertEquals(
0447:                                        "Restriction should be on property p",
0448:                                        p, A.getOnProperty());
0449:                                assertTrue(
0450:                                        "Restriction should be on property p",
0451:                                        A.onProperty(p));
0452:                                assertTrue(
0453:                                        "Restriction should not be on property q",
0454:                                        !A.onProperty(q));
0455:                                assertEquals("cardinality should be 1 ", 1, A
0456:                                        .getCardinality(prof.ON_PROPERTY()));
0457:
0458:                                A.setOnProperty(q);
0459:
0460:                                assertEquals(
0461:                                        "Restriction should be on property q",
0462:                                        q, A.getOnProperty());
0463:                                assertTrue(
0464:                                        "Restriction should not be on property p",
0465:                                        !A.onProperty(p));
0466:                                assertTrue(
0467:                                        "Restriction should not on property q",
0468:                                        A.onProperty(q));
0469:                                assertEquals("cardinality should be 1 ", 1, A
0470:                                        .getCardinality(prof.ON_PROPERTY()));
0471:
0472:                                A.removeOnProperty(p);
0473:                                assertTrue("Should have q as on property", A
0474:                                        .onProperty(q));
0475:                                A.removeOnProperty(q);
0476:                                assertTrue("Should not have q as on property",
0477:                                        !A.onProperty(q));
0478:                            }
0479:                        },
0480:                        new OntTestCase(
0481:                                "AllValuesFromRestriction.allValuesFrom", true,
0482:                                true, true, false) {
0483:                            public void ontTest(OntModel m) throws Exception {
0484:                                Profile prof = m.getProfile();
0485:                                OntProperty p = m
0486:                                        .createObjectProperty(NS + "p");
0487:                                OntClass B = m.createClass(NS + "B");
0488:                                OntClass C = m.createClass(NS + "C");
0489:
0490:                                AllValuesFromRestriction A = m
0491:                                        .createAllValuesFromRestriction(NS
0492:                                                + "A", p, B);
0493:
0494:                                assertEquals(
0495:                                        "Restriction should be all values from B",
0496:                                        B, A.getAllValuesFrom());
0497:                                assertTrue(
0498:                                        "Restriction should be all values from B",
0499:                                        A.hasAllValuesFrom(B));
0500:                                assertTrue(
0501:                                        "Restriction should not be all values from C",
0502:                                        !A.hasAllValuesFrom(C));
0503:                                assertEquals("cardinality should be 1 ", 1, A
0504:                                        .getCardinality(prof.ALL_VALUES_FROM()));
0505:
0506:                                A.setAllValuesFrom(C);
0507:
0508:                                assertEquals(
0509:                                        "Restriction should be all values from C",
0510:                                        C, A.getAllValuesFrom());
0511:                                assertTrue(
0512:                                        "Restriction should not be all values from B",
0513:                                        !A.hasAllValuesFrom(B));
0514:                                assertTrue(
0515:                                        "Restriction should be all values from C",
0516:                                        A.hasAllValuesFrom(C));
0517:                                assertEquals("cardinality should be 1 ", 1, A
0518:                                        .getCardinality(prof.ALL_VALUES_FROM()));
0519:
0520:                                A.removeAllValuesFrom(C);
0521:
0522:                                assertTrue(
0523:                                        "Restriction should not be some values from C",
0524:                                        !A.hasAllValuesFrom(C));
0525:                                assertEquals("cardinality should be 0 ", 0, A
0526:                                        .getCardinality(prof.ALL_VALUES_FROM()));
0527:                            }
0528:                        },
0529:                        new OntTestCase(
0530:                                "AllValuesFromRestriction.allValuesFrom.datatype",
0531:                                true, true, true, false) {
0532:                            public void ontTest(OntModel m) throws Exception {
0533:                                Profile prof = m.getProfile();
0534:                                OntProperty p = m
0535:                                        .createObjectProperty(NS + "p");
0536:
0537:                                AllValuesFromRestriction A = m
0538:                                        .createAllValuesFromRestriction(NS
0539:                                                + "A", p, XSD.gDay);
0540:
0541:                                assertEquals(
0542:                                        "Restriction should be all values from gDay",
0543:                                        XSD.gDay, A.getAllValuesFrom());
0544:                                assertTrue(
0545:                                        "Restriction should be all values from gDay",
0546:                                        A.hasAllValuesFrom(XSD.gDay));
0547:                                assertTrue(
0548:                                        "Restriction should not be all values from decimal",
0549:                                        !A.hasAllValuesFrom(XSD.decimal));
0550:                                assertEquals("cardinality should be 1 ", 1, A
0551:                                        .getCardinality(prof.ALL_VALUES_FROM()));
0552:
0553:                                A.setAllValuesFrom(XSD.gMonth);
0554:
0555:                                assertEquals(
0556:                                        "Restriction should be all values from gMonth",
0557:                                        XSD.gMonth, A.getAllValuesFrom());
0558:                                assertTrue(
0559:                                        "Restriction should not be all values from gDay",
0560:                                        !A.hasAllValuesFrom(XSD.gDay));
0561:                                assertTrue(
0562:                                        "Restriction should be all values from gMonth",
0563:                                        A.hasAllValuesFrom(XSD.gMonth));
0564:                                assertEquals("cardinality should be 1 ", 1, A
0565:                                        .getCardinality(prof.ALL_VALUES_FROM()));
0566:
0567:                                A.removeAllValuesFrom(XSD.gMonth);
0568:
0569:                                assertTrue(
0570:                                        "Restriction should not be some values from gMonth",
0571:                                        !A.hasAllValuesFrom(XSD.gMonth));
0572:                                assertEquals("cardinality should be 0 ", 0, A
0573:                                        .getCardinality(prof.ALL_VALUES_FROM()));
0574:                            }
0575:                        },
0576:                        new OntTestCase(
0577:                                "AllValuesFromRestriction.allValuesFrom.literal",
0578:                                true, true, true, false) {
0579:                            public void ontTest(OntModel m) throws Exception {
0580:                                Profile prof = m.getProfile();
0581:                                OntProperty p = m
0582:                                        .createObjectProperty(NS + "p");
0583:
0584:                                AllValuesFromRestriction A = m
0585:                                        .createAllValuesFromRestriction(NS
0586:                                                + "A", p, RDFS.Literal);
0587:
0588:                                assertEquals(
0589:                                        "Restriction should be all values from literal",
0590:                                        RDFS.Literal, A.getAllValuesFrom());
0591:                                assertTrue(
0592:                                        "Restriction should be all values from literal",
0593:                                        A.hasAllValuesFrom(RDFS.Literal));
0594:                                assertTrue(
0595:                                        "Restriction should not be all values from decimal",
0596:                                        !A.hasAllValuesFrom(XSD.decimal));
0597:                                assertEquals("cardinality should be 1 ", 1, A
0598:                                        .getCardinality(prof.ALL_VALUES_FROM()));
0599:                            }
0600:                        },
0601:                        new OntTestCase(
0602:                                "AllValuesFromRestriction.allValuesFrom.datarange",
0603:                                true, false, false, false) {
0604:                            public void ontTest(OntModel m) throws Exception {
0605:                                Profile prof = m.getProfile();
0606:                                Literal x = m.createTypedLiteral(1);
0607:                                Literal y = m.createTypedLiteral(2);
0608:                                DataRange dr = m.createDataRange(m
0609:                                        .createList(new RDFNode[] { x, y }));
0610:                                OntProperty p = m
0611:                                        .createObjectProperty(NS + "p");
0612:
0613:                                AllValuesFromRestriction A = m
0614:                                        .createAllValuesFromRestriction(NS
0615:                                                + "A", p, dr);
0616:
0617:                                assertEquals(
0618:                                        "Restriction should be all values from dr",
0619:                                        dr, A.getAllValuesFrom());
0620:                                assertTrue(
0621:                                        "value should be a datarange",
0622:                                        A.getAllValuesFrom() instanceof  DataRange);
0623:                                assertTrue(
0624:                                        "Restriction should be all values from dr",
0625:                                        A.hasAllValuesFrom(dr));
0626:                                assertTrue(
0627:                                        "Restriction should not be all values from decimal",
0628:                                        !A.hasAllValuesFrom(XSD.decimal));
0629:                                assertEquals("cardinality should be 1 ", 1, A
0630:                                        .getCardinality(prof.ALL_VALUES_FROM()));
0631:
0632:                                A.removeAllValuesFrom(dr);
0633:
0634:                                assertTrue(
0635:                                        "Restriction should not be some values from gMonth",
0636:                                        !A.hasAllValuesFrom(dr));
0637:                                assertEquals("cardinality should be 0 ", 0, A
0638:                                        .getCardinality(prof.ALL_VALUES_FROM()));
0639:                            }
0640:                        },
0641:                        new OntTestCase("HasValueRestriction.hasValue", true,
0642:                                false, true, false) {
0643:                            public void ontTest(OntModel m) throws Exception {
0644:                                Profile prof = m.getProfile();
0645:                                OntProperty p = m
0646:                                        .createObjectProperty(NS + "p");
0647:                                OntClass B = m.createClass(NS + "B");
0648:                                Individual b = m.createIndividual(B);
0649:                                OntClass C = m.createClass(NS + "C");
0650:                                Individual c = m.createIndividual(C);
0651:
0652:                                HasValueRestriction A = m
0653:                                        .createHasValueRestriction(NS + "A", p,
0654:                                                b);
0655:
0656:                                assertEquals(
0657:                                        "Restriction should be has value b", b,
0658:                                        A.getHasValue());
0659:                                assertTrue(
0660:                                        "Restriction should be to have value b",
0661:                                        A.hasValue(b));
0662:                                assertTrue(
0663:                                        "Restriction should not be have value c",
0664:                                        !A.hasValue(c));
0665:                                assertEquals("cardinality should be 1 ", 1, A
0666:                                        .getCardinality(prof.HAS_VALUE()));
0667:
0668:                                A.setHasValue(c);
0669:
0670:                                assertEquals(
0671:                                        "Restriction should be has value c", c,
0672:                                        A.getHasValue());
0673:                                assertTrue(
0674:                                        "Restriction should not be to have value b",
0675:                                        !A.hasValue(b));
0676:                                assertTrue(
0677:                                        "Restriction should not be have value c",
0678:                                        A.hasValue(c));
0679:                                assertEquals("cardinality should be 1 ", 1, A
0680:                                        .getCardinality(prof.HAS_VALUE()));
0681:
0682:                                A.removeHasValue(c);
0683:
0684:                                assertTrue(
0685:                                        "Restriction should not be to have value b",
0686:                                        !A.hasValue(b));
0687:                                assertTrue(
0688:                                        "Restriction should not be have value c",
0689:                                        !A.hasValue(c));
0690:                                assertEquals("cardinality should be 0 ", 0, A
0691:                                        .getCardinality(prof.HAS_VALUE()));
0692:                            }
0693:                        },
0694:                        new OntTestCase(
0695:                                "SomeValuesFromRestriction.someValuesFrom",
0696:                                true, true, true, false) {
0697:                            public void ontTest(OntModel m) throws Exception {
0698:                                Profile prof = m.getProfile();
0699:                                OntProperty p = m
0700:                                        .createObjectProperty(NS + "p");
0701:                                OntClass B = m.createClass(NS + "B");
0702:                                OntClass C = m.createClass(NS + "C");
0703:
0704:                                SomeValuesFromRestriction A = m
0705:                                        .createSomeValuesFromRestriction(NS
0706:                                                + "A", p, B);
0707:
0708:                                assertEquals(
0709:                                        "Restriction should be some values from B",
0710:                                        B, A.getSomeValuesFrom());
0711:                                assertTrue(
0712:                                        "Restriction should be some values from B",
0713:                                        A.hasSomeValuesFrom(B));
0714:                                assertTrue(
0715:                                        "Restriction should not be some values from C",
0716:                                        !A.hasSomeValuesFrom(C));
0717:                                assertEquals("cardinality should be 1 ", 1,
0718:                                        A.getCardinality(prof
0719:                                                .SOME_VALUES_FROM()));
0720:
0721:                                A.setSomeValuesFrom(C);
0722:
0723:                                assertEquals(
0724:                                        "Restriction should be some values from C",
0725:                                        C, A.getSomeValuesFrom());
0726:                                assertTrue(
0727:                                        "Restriction should not be some values from B",
0728:                                        !A.hasSomeValuesFrom(B));
0729:                                assertTrue(
0730:                                        "Restriction should be some values from C",
0731:                                        A.hasSomeValuesFrom(C));
0732:                                assertEquals("cardinality should be 1 ", 1,
0733:                                        A.getCardinality(prof
0734:                                                .SOME_VALUES_FROM()));
0735:
0736:                                A.removeSomeValuesFrom(C);
0737:
0738:                                assertTrue(
0739:                                        "Restriction should not be some values from C",
0740:                                        !A.hasSomeValuesFrom(C));
0741:                                assertEquals("cardinality should be 0 ", 0,
0742:                                        A.getCardinality(prof
0743:                                                .SOME_VALUES_FROM()));
0744:                            }
0745:                        },
0746:                        new OntTestCase(
0747:                                "SomeValuesFromRestriction.SomeValuesFrom.datatype",
0748:                                true, true, true, false) {
0749:                            public void ontTest(OntModel m) throws Exception {
0750:                                Profile prof = m.getProfile();
0751:                                OntProperty p = m
0752:                                        .createObjectProperty(NS + "p");
0753:
0754:                                SomeValuesFromRestriction A = m
0755:                                        .createSomeValuesFromRestriction(NS
0756:                                                + "A", p, XSD.gDay);
0757:
0758:                                assertEquals(
0759:                                        "Restriction should be some values from gDay",
0760:                                        XSD.gDay, A.getSomeValuesFrom());
0761:                                assertTrue(
0762:                                        "Restriction should be some values from gDay",
0763:                                        A.hasSomeValuesFrom(XSD.gDay));
0764:                                assertTrue(
0765:                                        "Restriction should not be some values from decimal",
0766:                                        !A.hasSomeValuesFrom(XSD.decimal));
0767:                                assertEquals("cardinality should be 1 ", 1,
0768:                                        A.getCardinality(prof
0769:                                                .SOME_VALUES_FROM()));
0770:
0771:                                A.setSomeValuesFrom(XSD.gMonth);
0772:
0773:                                assertEquals(
0774:                                        "Restriction should be some values from gMonth",
0775:                                        XSD.gMonth, A.getSomeValuesFrom());
0776:                                assertTrue(
0777:                                        "Restriction should not be some values from gDay",
0778:                                        !A.hasSomeValuesFrom(XSD.gDay));
0779:                                assertTrue(
0780:                                        "Restriction should be some values from gMonth",
0781:                                        A.hasSomeValuesFrom(XSD.gMonth));
0782:                                assertEquals("cardinality should be 1 ", 1,
0783:                                        A.getCardinality(prof
0784:                                                .SOME_VALUES_FROM()));
0785:
0786:                                A.removeSomeValuesFrom(XSD.gMonth);
0787:
0788:                                assertTrue(
0789:                                        "Restriction should not be some values from gMonth",
0790:                                        !A.hasSomeValuesFrom(XSD.gMonth));
0791:                                assertEquals("cardinality should be 0 ", 0,
0792:                                        A.getCardinality(prof
0793:                                                .SOME_VALUES_FROM()));
0794:                            }
0795:                        },
0796:                        new OntTestCase(
0797:                                "SomeValuesFromRestriction.SomeValuesFrom.literal",
0798:                                true, true, true, false) {
0799:                            public void ontTest(OntModel m) throws Exception {
0800:                                Profile prof = m.getProfile();
0801:                                OntProperty p = m
0802:                                        .createObjectProperty(NS + "p");
0803:
0804:                                SomeValuesFromRestriction A = m
0805:                                        .createSomeValuesFromRestriction(NS
0806:                                                + "A", p, RDFS.Literal);
0807:
0808:                                assertEquals(
0809:                                        "Restriction should be some values from literal",
0810:                                        RDFS.Literal, A.getSomeValuesFrom());
0811:                                assertTrue(
0812:                                        "Restriction should be some values from literal",
0813:                                        A.hasSomeValuesFrom(RDFS.Literal));
0814:                                assertTrue(
0815:                                        "Restriction should not be some values from decimal",
0816:                                        !A.hasSomeValuesFrom(XSD.decimal));
0817:                                assertEquals("cardinality should be 1 ", 1,
0818:                                        A.getCardinality(prof
0819:                                                .SOME_VALUES_FROM()));
0820:                            }
0821:                        },
0822:                        new OntTestCase(
0823:                                "SomeValuesFromRestriction.SomeValuesFrom.datarange",
0824:                                true, false, false, false) {
0825:                            public void ontTest(OntModel m) throws Exception {
0826:                                Profile prof = m.getProfile();
0827:                                Literal x = m.createTypedLiteral(1);
0828:                                Literal y = m.createTypedLiteral(2);
0829:                                DataRange dr = m.createDataRange(m
0830:                                        .createList(new RDFNode[] { x, y }));
0831:                                OntProperty p = m
0832:                                        .createObjectProperty(NS + "p");
0833:
0834:                                SomeValuesFromRestriction A = m
0835:                                        .createSomeValuesFromRestriction(NS
0836:                                                + "A", p, dr);
0837:
0838:                                assertEquals(
0839:                                        "Restriction should be some values from dr",
0840:                                        dr, A.getSomeValuesFrom());
0841:                                assertTrue(
0842:                                        "value should be a datarange",
0843:                                        A.getSomeValuesFrom() instanceof  DataRange);
0844:                                assertTrue(
0845:                                        "Restriction should be some values from dr",
0846:                                        A.hasSomeValuesFrom(dr));
0847:                                assertTrue(
0848:                                        "Restriction should not be some values from decimal",
0849:                                        !A.hasSomeValuesFrom(XSD.decimal));
0850:                                assertEquals("cardinality should be 1 ", 1,
0851:                                        A.getCardinality(prof
0852:                                                .SOME_VALUES_FROM()));
0853:
0854:                                A.removeSomeValuesFrom(dr);
0855:
0856:                                assertTrue(
0857:                                        "Restriction should not be some values from gMonth",
0858:                                        !A.hasSomeValuesFrom(dr));
0859:                                assertEquals("cardinality should be 0 ", 0,
0860:                                        A.getCardinality(prof
0861:                                                .SOME_VALUES_FROM()));
0862:                            }
0863:                        },
0864:                        new OntTestCase("CardinalityRestriction.cardinality",
0865:                                true, true, true, false) {
0866:                            public void ontTest(OntModel m) throws Exception {
0867:                                Profile prof = m.getProfile();
0868:                                OntProperty p = m
0869:                                        .createObjectProperty(NS + "p");
0870:
0871:                                CardinalityRestriction A = m
0872:                                        .createCardinalityRestriction(NS + "A",
0873:                                                p, 3);
0874:
0875:                                assertEquals(
0876:                                        "Restriction should be cardinality 3",
0877:                                        3, A.getCardinality());
0878:                                assertTrue(
0879:                                        "Restriction should be cardinality 3",
0880:                                        A.hasCardinality(3));
0881:                                assertTrue(
0882:                                        "Restriction should not be cardinality 2",
0883:                                        !A.hasCardinality(2));
0884:                                assertEquals("cardinality should be 1 ", 1, A
0885:                                        .getCardinality(prof.CARDINALITY()));
0886:
0887:                                A.setCardinality(2);
0888:
0889:                                assertEquals(
0890:                                        "Restriction should be cardinality 2",
0891:                                        2, A.getCardinality());
0892:                                assertTrue(
0893:                                        "Restriction should not be cardinality 3",
0894:                                        !A.hasCardinality(3));
0895:                                assertTrue(
0896:                                        "Restriction should be cardinality 2",
0897:                                        A.hasCardinality(2));
0898:                                assertEquals("cardinality should be 1 ", 1, A
0899:                                        .getCardinality(prof.CARDINALITY()));
0900:
0901:                                A.removeCardinality(2);
0902:
0903:                                assertTrue(
0904:                                        "Restriction should not be cardinality 3",
0905:                                        !A.hasCardinality(3));
0906:                                assertTrue(
0907:                                        "Restriction should not be cardinality 2",
0908:                                        !A.hasCardinality(2));
0909:                                assertEquals("cardinality should be 0 ", 0, A
0910:                                        .getCardinality(prof.CARDINALITY()));
0911:                            }
0912:                        },
0913:                        new OntTestCase(
0914:                                "MinCardinalityRestriction.minCardinality",
0915:                                true, true, true, false) {
0916:                            public void ontTest(OntModel m) throws Exception {
0917:                                Profile prof = m.getProfile();
0918:                                OntProperty p = m
0919:                                        .createObjectProperty(NS + "p");
0920:
0921:                                MinCardinalityRestriction A = m
0922:                                        .createMinCardinalityRestriction(NS
0923:                                                + "A", p, 3);
0924:
0925:                                assertEquals(
0926:                                        "Restriction should be min cardinality 3",
0927:                                        3, A.getMinCardinality());
0928:                                assertTrue(
0929:                                        "Restriction should be min cardinality 3",
0930:                                        A.hasMinCardinality(3));
0931:                                assertTrue(
0932:                                        "Restriction should not be min cardinality 2",
0933:                                        !A.hasMinCardinality(2));
0934:                                assertEquals("cardinality should be 1 ", 1, A
0935:                                        .getCardinality(prof.MIN_CARDINALITY()));
0936:
0937:                                A.setMinCardinality(2);
0938:
0939:                                assertEquals(
0940:                                        "Restriction should be min cardinality 2",
0941:                                        2, A.getMinCardinality());
0942:                                assertTrue(
0943:                                        "Restriction should not be min cardinality 3",
0944:                                        !A.hasMinCardinality(3));
0945:                                assertTrue(
0946:                                        "Restriction should be min cardinality 2",
0947:                                        A.hasMinCardinality(2));
0948:                                assertEquals("cardinality should be 1 ", 1, A
0949:                                        .getCardinality(prof.MIN_CARDINALITY()));
0950:
0951:                                A.removeMinCardinality(2);
0952:
0953:                                assertTrue(
0954:                                        "Restriction should not be cardinality 3",
0955:                                        !A.hasMinCardinality(3));
0956:                                assertTrue(
0957:                                        "Restriction should not be cardinality 2",
0958:                                        !A.hasMinCardinality(2));
0959:                                assertEquals("cardinality should be 0 ", 0, A
0960:                                        .getCardinality(prof.MIN_CARDINALITY()));
0961:                            }
0962:                        },
0963:                        new OntTestCase(
0964:                                "MaxCardinalityRestriction.maxCardinality",
0965:                                true, true, true, false) {
0966:                            public void ontTest(OntModel m) throws Exception {
0967:                                Profile prof = m.getProfile();
0968:                                OntProperty p = m
0969:                                        .createObjectProperty(NS + "p");
0970:
0971:                                MaxCardinalityRestriction A = m
0972:                                        .createMaxCardinalityRestriction(NS
0973:                                                + "A", p, 3);
0974:
0975:                                assertEquals(
0976:                                        "Restriction should be max cardinality 3",
0977:                                        3, A.getMaxCardinality());
0978:                                assertTrue(
0979:                                        "Restriction should be max cardinality 3",
0980:                                        A.hasMaxCardinality(3));
0981:                                assertTrue(
0982:                                        "Restriction should not be max cardinality 2",
0983:                                        !A.hasMaxCardinality(2));
0984:                                assertEquals("cardinality should be 1 ", 1, A
0985:                                        .getCardinality(prof.MAX_CARDINALITY()));
0986:
0987:                                A.setMaxCardinality(2);
0988:
0989:                                assertEquals(
0990:                                        "Restriction should be max cardinality 2",
0991:                                        2, A.getMaxCardinality());
0992:                                assertTrue(
0993:                                        "Restriction should not be max cardinality 3",
0994:                                        !A.hasMaxCardinality(3));
0995:                                assertTrue(
0996:                                        "Restriction should be max cardinality 2",
0997:                                        A.hasMaxCardinality(2));
0998:                                assertEquals("cardinality should be 1 ", 1, A
0999:                                        .getCardinality(prof.MAX_CARDINALITY()));
1000:
1001:                                A.removeMaxCardinality(2);
1002:
1003:                                assertTrue(
1004:                                        "Restriction should not be cardinality 3",
1005:                                        !A.hasMaxCardinality(3));
1006:                                assertTrue(
1007:                                        "Restriction should not be cardinality 2",
1008:                                        !A.hasMaxCardinality(2));
1009:                                assertEquals("cardinality should be 0 ", 0, A
1010:                                        .getCardinality(prof.MAX_CARDINALITY()));
1011:                            }
1012:                        },
1013:                        new OntTestCase("QualifiedRestriction.hasClassQ",
1014:                                false, false, true, false) {
1015:                            public void ontTest(OntModel m) throws Exception {
1016:                                OntProperty p = m
1017:                                        .createObjectProperty(NS + "p");
1018:                                OntClass c = m.createClass(NS + "C");
1019:                                OntClass d = m.createClass(NS + "D");
1020:
1021:                                String nameA = "ABCBA";
1022:                                QualifiedRestriction A = m
1023:                                        .createMaxCardinalityQRestriction(NS
1024:                                                + nameA, p, 3, c);
1025:
1026:                                assertEquals("Restriction should hasClassQ c",
1027:                                        c, A.getHasClassQ());
1028:                                assertTrue("Restriction should be hasClassQ c",
1029:                                        A.hasHasClassQ(c));
1030:                                assertFalse(
1031:                                        "Restriction should not be hasClassQ d",
1032:                                        A.hasHasClassQ(d));
1033:
1034:                                A.setHasClassQ(d);
1035:
1036:                                assertEquals("Restriction should hasClassQ d",
1037:                                        d, A.getHasClassQ());
1038:                                assertTrue("Restriction should be hasClassQ d",
1039:                                        A.hasHasClassQ(d));
1040:                                assertFalse(
1041:                                        "Restriction should not be hasClassQ c",
1042:                                        A.hasHasClassQ(c));
1043:
1044:                                assertTrue("Should be a qualified restriction",
1045:                                        m.getResource(NS + nameA).canAs(
1046:                                                QualifiedRestriction.class));
1047:                                A.removeHasClassQ(d);
1048:                                assertFalse(
1049:                                        "Should not be a qualified restriction",
1050:                                        m.getResource(NS + nameA).canAs(
1051:                                                QualifiedRestriction.class));
1052:                            }
1053:                        },
1054:                        new OntTestCase("CardinalityQRestriction.cardinality",
1055:                                false, false, true, false) {
1056:                            public void ontTest(OntModel m) throws Exception {
1057:                                OntProperty p = m
1058:                                        .createObjectProperty(NS + "p");
1059:                                OntClass c = m.createClass(NS + "C");
1060:
1061:                                CardinalityQRestriction A = m
1062:                                        .createCardinalityQRestriction(
1063:                                                NS + "A", p, 3, c);
1064:
1065:                                assertEquals(
1066:                                        "Restriction should cardinality 3", 3,
1067:                                        A.getCardinalityQ());
1068:                                assertTrue(
1069:                                        "Restriction should be cardinality 3",
1070:                                        A.hasCardinalityQ(3));
1071:                                assertFalse(
1072:                                        "Restriction should not be cardinality 1",
1073:                                        A.hasCardinalityQ(1));
1074:
1075:                                A.setCardinalityQ(1);
1076:
1077:                                assertEquals(
1078:                                        "Restriction should cardinality 1", 1,
1079:                                        A.getCardinalityQ());
1080:                                assertFalse(
1081:                                        "Restriction should not be cardinality 3",
1082:                                        A.hasCardinalityQ(3));
1083:                                assertTrue(
1084:                                        "Restriction should be cardinality 1",
1085:                                        A.hasCardinalityQ(1));
1086:
1087:                                assertTrue(
1088:                                        "Should be a qualified cardinality restriction",
1089:                                        m.getResource(NS + "A").canAs(
1090:                                                CardinalityQRestriction.class));
1091:                                A.removeCardinalityQ(1);
1092:                                assertFalse(
1093:                                        "Should not be a qualified cardinality restriction",
1094:                                        m.getResource(NS + "A").canAs(
1095:                                                CardinalityQRestriction.class));
1096:                            }
1097:                        },
1098:                        new OntTestCase(
1099:                                "MinCardinalityQRestriction.minCardinality",
1100:                                false, false, true, false) {
1101:                            public void ontTest(OntModel m) throws Exception {
1102:                                OntProperty p = m
1103:                                        .createObjectProperty(NS + "p");
1104:                                OntClass c = m.createClass(NS + "C");
1105:
1106:                                MinCardinalityQRestriction A = m
1107:                                        .createMinCardinalityQRestriction(NS
1108:                                                + "A", p, 3, c);
1109:
1110:                                assertEquals(
1111:                                        "Restriction should min cardinality 3",
1112:                                        3, A.getMinCardinalityQ());
1113:                                assertTrue(
1114:                                        "Restriction should be min cardinality 3",
1115:                                        A.hasMinCardinalityQ(3));
1116:                                assertFalse(
1117:                                        "Restriction should not be min cardinality 1",
1118:                                        A.hasMinCardinalityQ(1));
1119:
1120:                                A.setMinCardinalityQ(1);
1121:
1122:                                assertEquals(
1123:                                        "Restriction should min cardinality 1",
1124:                                        1, A.getMinCardinalityQ());
1125:                                assertFalse(
1126:                                        "Restriction should not be min cardinality 3",
1127:                                        A.hasMinCardinalityQ(3));
1128:                                assertTrue(
1129:                                        "Restriction should be min cardinality 1",
1130:                                        A.hasMinCardinalityQ(1));
1131:
1132:                                assertTrue(
1133:                                        "Should be a qualified min cardinality restriction",
1134:                                        m
1135:                                                .getResource(NS + "A")
1136:                                                .canAs(
1137:                                                        MinCardinalityQRestriction.class));
1138:                                A.removeMinCardinalityQ(1);
1139:                                assertFalse(
1140:                                        "Should not be a qualified min cardinality restriction",
1141:                                        m
1142:                                                .getResource(NS + "A")
1143:                                                .canAs(
1144:                                                        MinCardinalityQRestriction.class));
1145:                            }
1146:                        },
1147:                        new OntTestCase(
1148:                                "MaxCardinalityQRestriction.maxCardinality",
1149:                                false, false, true, false) {
1150:                            public void ontTest(OntModel m) throws Exception {
1151:                                OntProperty p = m
1152:                                        .createObjectProperty(NS + "p");
1153:                                OntClass c = m.createClass(NS + "C");
1154:
1155:                                MaxCardinalityQRestriction A = m
1156:                                        .createMaxCardinalityQRestriction(NS
1157:                                                + "A", p, 3, c);
1158:
1159:                                assertEquals(
1160:                                        "Restriction should max cardinality 3",
1161:                                        3, A.getMaxCardinalityQ());
1162:                                assertTrue(
1163:                                        "Restriction should be max cardinality 3",
1164:                                        A.hasMaxCardinalityQ(3));
1165:                                assertFalse(
1166:                                        "Restriction should not be max cardinality 1",
1167:                                        A.hasMaxCardinalityQ(1));
1168:
1169:                                A.setMaxCardinalityQ(1);
1170:
1171:                                assertEquals(
1172:                                        "Restriction should max cardinality 1",
1173:                                        1, A.getMaxCardinalityQ());
1174:                                assertFalse(
1175:                                        "Restriction should not be max cardinality 3",
1176:                                        A.hasMaxCardinalityQ(3));
1177:                                assertTrue(
1178:                                        "Restriction should be max cardinality 1",
1179:                                        A.hasMaxCardinalityQ(1));
1180:
1181:                                assertTrue(
1182:                                        "Should be a qualified max cardinality restriction",
1183:                                        m
1184:                                                .getResource(NS + "A")
1185:                                                .canAs(
1186:                                                        MaxCardinalityQRestriction.class));
1187:                                A.removeMaxCardinalityQ(1);
1188:                                assertFalse(
1189:                                        "Should not be a qualified max cardinality restriction",
1190:                                        m
1191:                                                .getResource(NS + "A")
1192:                                                .canAs(
1193:                                                        MaxCardinalityQRestriction.class));
1194:                            }
1195:                        },
1196:
1197:                        // from file
1198:                        new OntTestCase("OntClass.subclass.fromFile", true,
1199:                                true, true, true) {
1200:                            public void ontTest(OntModel m) throws Exception {
1201:                                String lang = m_owlLang ? "owl"
1202:                                        : (m_damlLang ? "daml" : "rdfs");
1203:                                String fileName = "file:testing/ontology/"
1204:                                        + lang + "/ClassExpression/test.rdf";
1205:                                m.read(fileName);
1206:
1207:                                OntClass A = m.createClass(NS + "ClassA");
1208:                                OntClass B = m.createClass(NS + "ClassB");
1209:
1210:                                iteratorTest(A.listSuperClasses(),
1211:                                        new Object[] { B });
1212:                                iteratorTest(B.listSubClasses(),
1213:                                        new Object[] { A });
1214:                            }
1215:                        },
1216:                        new OntTestCase("OntClass.equivalentClass.fromFile",
1217:                                true, true, true, false) {
1218:                            public void ontTest(OntModel m) throws Exception {
1219:                                String lang = m_owlLang ? "owl"
1220:                                        : (m_damlLang ? "daml" : "rdfs");
1221:                                String fileName = "file:testing/ontology/"
1222:                                        + lang + "/ClassExpression/test.rdf";
1223:                                m.read(fileName);
1224:
1225:                                OntClass A = m.createClass(NS + "ClassA");
1226:                                OntClass C = m.createClass(NS + "ClassC");
1227:
1228:                                assertTrue("A should be equiv to C", A
1229:                                        .hasEquivalentClass(C));
1230:                            }
1231:                        },
1232:                        new OntTestCase("OntClass.disjoint.fromFile", true,
1233:                                false, true, false) {
1234:                            public void ontTest(OntModel m) throws Exception {
1235:                                String lang = m_owlLang ? "owl"
1236:                                        : (m_damlLang ? "daml" : "rdfs");
1237:                                String fileName = "file:testing/ontology/"
1238:                                        + lang + "/ClassExpression/test.rdf";
1239:                                m.read(fileName);
1240:
1241:                                OntClass A = m.createClass(NS + "ClassA");
1242:                                OntClass D = m.createClass(NS + "ClassD");
1243:
1244:                                assertTrue("A should be disjoint with D", A
1245:                                        .isDisjointWith(D));
1246:                            }
1247:                        },
1248:
1249:                        // type testing
1250:                        new OntTestCase("OntClass.isEnumeratedClass", true,
1251:                                false, true, false) {
1252:                            public void ontTest(OntModel m) throws Exception {
1253:                                OntClass b = m.createClass(NS + "B");
1254:                                Individual x = m.createIndividual(NS + "x", b);
1255:                                Individual y = m.createIndividual(NS + "y", b);
1256:                                OntClass a = m.createEnumeratedClass(NS + "A",
1257:                                        m.createList(new RDFNode[] { x, y }));
1258:
1259:                                assertTrue("enumerated class test not correct",
1260:                                        a.isEnumeratedClass());
1261:                                assertTrue(
1262:                                        "intersection class test not correct",
1263:                                        !a.isIntersectionClass());
1264:                                assertTrue("union class test not correct", !a
1265:                                        .isUnionClass());
1266:                                assertTrue("complement class test not correct",
1267:                                        !a.isComplementClass());
1268:                                assertTrue("restriction test not correct", !a
1269:                                        .isRestriction());
1270:                            }
1271:                        },
1272:                        new OntTestCase("OntClass.isIntersectionClass", true,
1273:                                true, true, false) {
1274:                            public void ontTest(OntModel m) throws Exception {
1275:                                OntClass b = m.createClass(NS + "B");
1276:                                OntClass c = m.createClass(NS + "C");
1277:                                OntClass a = m.createIntersectionClass(
1278:                                        NS + "A", m.createList(new RDFNode[] {
1279:                                                b, c }));
1280:
1281:                                assertTrue("enumerated class test not correct",
1282:                                        m_owlLiteLang || !a.isEnumeratedClass());
1283:                                assertTrue(
1284:                                        "intersection class test not correct",
1285:                                        a.isIntersectionClass());
1286:                                assertTrue("union class test not correct",
1287:                                        m_owlLiteLang || !a.isUnionClass());
1288:                                assertTrue("complement class test not correct",
1289:                                        m_owlLiteLang || !a.isComplementClass());
1290:                                assertTrue("restriction test not correct", !a
1291:                                        .isRestriction());
1292:                            }
1293:                        },
1294:                        new OntTestCase("OntClass.isUnionClass", true, false,
1295:                                true, false) {
1296:                            public void ontTest(OntModel m) throws Exception {
1297:                                OntClass b = m.createClass(NS + "B");
1298:                                OntClass c = m.createClass(NS + "C");
1299:                                OntClass a = m.createUnionClass(NS + "A", m
1300:                                        .createList(new RDFNode[] { b, c }));
1301:
1302:                                assertTrue("enumerated class test not correct",
1303:                                        !a.isEnumeratedClass());
1304:                                assertTrue(
1305:                                        "intersection class test not correct",
1306:                                        !a.isIntersectionClass());
1307:                                assertTrue("union class test not correct", a
1308:                                        .isUnionClass());
1309:                                assertTrue("complement class test not correct",
1310:                                        !a.isComplementClass());
1311:                                assertTrue("restriction test not correct", !a
1312:                                        .isRestriction());
1313:                            }
1314:                        },
1315:                        new OntTestCase("OntClass.isComplementClass", true,
1316:                                false, true, false) {
1317:                            public void ontTest(OntModel m) throws Exception {
1318:                                OntClass b = m.createClass(NS + "B");
1319:                                OntClass a = m.createComplementClass(NS + "A",
1320:                                        b);
1321:
1322:                                assertTrue("enumerated class test not correct",
1323:                                        !a.isEnumeratedClass());
1324:                                assertTrue(
1325:                                        "intersection class test not correct",
1326:                                        !a.isIntersectionClass());
1327:                                assertTrue("union class test not correct", !a
1328:                                        .isUnionClass());
1329:                                assertTrue("complement class test not correct",
1330:                                        a.isComplementClass());
1331:                                assertTrue("restriction test not correct", !a
1332:                                        .isRestriction());
1333:                            }
1334:                        },
1335:                        new OntTestCase("OntClass.isRestriction", true, true,
1336:                                true, false) {
1337:                            public void ontTest(OntModel m) throws Exception {
1338:                                OntClass a = m.createRestriction(null);
1339:
1340:                                assertTrue("enumerated class test not correct",
1341:                                        m_owlLiteLang || !a.isEnumeratedClass());
1342:                                assertTrue(
1343:                                        "intersection class test not correct",
1344:                                        !a.isIntersectionClass());
1345:                                assertTrue("union class test not correct",
1346:                                        m_owlLiteLang || !a.isUnionClass());
1347:                                assertTrue("complement class test not correct",
1348:                                        m_owlLiteLang || !a.isComplementClass());
1349:                                assertTrue("restriction test not correct", a
1350:                                        .isRestriction());
1351:                            }
1352:                        },
1353:
1354:                        // conversion
1355:                        new OntTestCase("OntClass.toEnumeratedClass", true,
1356:                                false, true, false) {
1357:                            public void ontTest(OntModel m) throws Exception {
1358:                                OntClass a = m.createClass(NS + "A");
1359:
1360:                                assertTrue("enumerated class test not correct",
1361:                                        !a.isEnumeratedClass());
1362:                                assertTrue(
1363:                                        "intersection class test not correct",
1364:                                        !a.isIntersectionClass());
1365:                                assertTrue("union class test not correct", !a
1366:                                        .isUnionClass());
1367:                                assertTrue("complement class test not correct",
1368:                                        !a.isComplementClass());
1369:                                assertTrue("restriction test not correct", !a
1370:                                        .isRestriction());
1371:
1372:                                OntClass b = m.createClass(NS + "B");
1373:                                Individual x = m.createIndividual(NS + "x", b);
1374:                                Individual y = m.createIndividual(NS + "y", b);
1375:                                a = a.convertToEnumeratedClass(m
1376:                                        .createList(new RDFNode[] { x, y }));
1377:
1378:                                assertTrue("enumerated class test not correct",
1379:                                        a.isEnumeratedClass());
1380:                                assertTrue(
1381:                                        "intersection class test not correct",
1382:                                        !a.isIntersectionClass());
1383:                                assertTrue("union class test not correct", !a
1384:                                        .isUnionClass());
1385:                                assertTrue("complement class test not correct",
1386:                                        !a.isComplementClass());
1387:                                assertTrue("restriction test not correct", !a
1388:                                        .isRestriction());
1389:                            }
1390:                        },
1391:                        new OntTestCase("OntClass.toIntersectionClass", true,
1392:                                true, true, false) {
1393:                            public void ontTest(OntModel m) throws Exception {
1394:                                OntClass a = m.createClass(NS + "A");
1395:
1396:                                assertTrue("enumerated class test not correct",
1397:                                        m_owlLiteLang || !a.isEnumeratedClass());
1398:                                assertTrue(
1399:                                        "intersection class test not correct",
1400:                                        !a.isIntersectionClass());
1401:                                assertTrue("union class test not correct",
1402:                                        m_owlLiteLang || !a.isUnionClass());
1403:                                assertTrue("complement class test not correct",
1404:                                        m_owlLiteLang || !a.isComplementClass());
1405:                                assertTrue("restriction test not correct", !a
1406:                                        .isRestriction());
1407:
1408:                                OntClass b = m.createClass(NS + "B");
1409:                                OntClass c = m.createClass(NS + "C");
1410:                                a = a.convertToIntersectionClass(m
1411:                                        .createList(new RDFNode[] { b, c }));
1412:
1413:                                assertTrue("enumerated class test not correct",
1414:                                        m_owlLiteLang || !a.isEnumeratedClass());
1415:                                assertTrue(
1416:                                        "intersection class test not correct",
1417:                                        a.isIntersectionClass());
1418:                                assertTrue("union class test not correct",
1419:                                        m_owlLiteLang || !a.isUnionClass());
1420:                                assertTrue("complement class test not correct",
1421:                                        m_owlLiteLang || !a.isComplementClass());
1422:                                assertTrue("restriction test not correct", !a
1423:                                        .isRestriction());
1424:                            }
1425:                        },
1426:                        new OntTestCase("OntClass.toUnionClass", true, false,
1427:                                true, false) {
1428:                            public void ontTest(OntModel m) throws Exception {
1429:                                OntClass a = m.createClass(NS + "A");
1430:
1431:                                assertTrue("enumerated class test not correct",
1432:                                        !a.isEnumeratedClass());
1433:                                assertTrue(
1434:                                        "intersection class test not correct",
1435:                                        !a.isIntersectionClass());
1436:                                assertTrue("union class test not correct", !a
1437:                                        .isUnionClass());
1438:                                assertTrue("complement class test not correct",
1439:                                        !a.isComplementClass());
1440:                                assertTrue("restriction test not correct", !a
1441:                                        .isRestriction());
1442:
1443:                                OntClass b = m.createClass(NS + "B");
1444:                                OntClass c = m.createClass(NS + "C");
1445:                                a = a.convertToUnionClass(m
1446:                                        .createList(new RDFNode[] { b, c }));
1447:
1448:                                assertTrue("enumerated class test not correct",
1449:                                        m_owlLiteLang || !a.isEnumeratedClass());
1450:                                assertTrue(
1451:                                        "intersection class test not correct",
1452:                                        !a.isIntersectionClass());
1453:                                assertTrue("union class test not correct",
1454:                                        m_owlLiteLang || a.isUnionClass());
1455:                                assertTrue("complement class test not correct",
1456:                                        m_owlLiteLang || !a.isComplementClass());
1457:                                assertTrue("restriction test not correct", !a
1458:                                        .isRestriction());
1459:                            }
1460:                        },
1461:                        new OntTestCase("OntClass.toComplementClass", true,
1462:                                false, true, false) {
1463:                            public void ontTest(OntModel m) throws Exception {
1464:                                OntClass a = m.createClass(NS + "A");
1465:
1466:                                assertTrue("enumerated class test not correct",
1467:                                        !a.isEnumeratedClass());
1468:                                assertTrue(
1469:                                        "intersection class test not correct",
1470:                                        !a.isIntersectionClass());
1471:                                assertTrue("union class test not correct", !a
1472:                                        .isUnionClass());
1473:                                assertTrue("complement class test not correct",
1474:                                        !a.isComplementClass());
1475:                                assertTrue("restriction test not correct", !a
1476:                                        .isRestriction());
1477:
1478:                                OntClass b = m.createClass(NS + "B");
1479:                                a = a.convertToComplementClass(b);
1480:
1481:                                assertTrue("enumerated class test not correct",
1482:                                        m_owlLiteLang || !a.isEnumeratedClass());
1483:                                assertTrue(
1484:                                        "intersection class test not correct",
1485:                                        !a.isIntersectionClass());
1486:                                assertTrue("union class test not correct",
1487:                                        m_owlLiteLang || !a.isUnionClass());
1488:                                assertTrue("complement class test not correct",
1489:                                        m_owlLiteLang || a.isComplementClass());
1490:                                assertTrue("restriction test not correct", !a
1491:                                        .isRestriction());
1492:                            }
1493:                        },
1494:                        new OntTestCase("OntClass.toRestriction", true, true,
1495:                                true, false) {
1496:                            public void ontTest(OntModel m) throws Exception {
1497:                                OntClass a = m.createClass(NS + "A");
1498:
1499:                                assertTrue("enumerated class test not correct",
1500:                                        m_owlLiteLang || !a.isEnumeratedClass());
1501:                                assertTrue(
1502:                                        "intersection class test not correct",
1503:                                        !a.isIntersectionClass());
1504:                                assertTrue("union class test not correct",
1505:                                        m_owlLiteLang || !a.isUnionClass());
1506:                                assertTrue("complement class test not correct",
1507:                                        m_owlLiteLang || !a.isComplementClass());
1508:                                assertTrue("restriction test not correct", !a
1509:                                        .isRestriction());
1510:
1511:                                ObjectProperty p = m.createObjectProperty(NS
1512:                                        + "p");
1513:                                a = a.convertToRestriction(p);
1514:
1515:                                assertTrue("enumerated class test not correct",
1516:                                        m_owlLiteLang || !a.isEnumeratedClass());
1517:                                assertTrue(
1518:                                        "intersection class test not correct",
1519:                                        !a.isIntersectionClass());
1520:                                assertTrue("union class test not correct",
1521:                                        m_owlLiteLang || !a.isUnionClass());
1522:                                assertTrue("complement class test not correct",
1523:                                        m_owlLiteLang || !a.isComplementClass());
1524:                                assertTrue("restriction test not correct", a
1525:                                        .isRestriction());
1526:                            }
1527:                        },
1528:
1529:                        // restriction type testing
1530:                        new OntTestCase("Restriction.isAllValuesFrom", true,
1531:                                true, true, false) {
1532:                            public void ontTest(OntModel m) throws Exception {
1533:                                OntClass b = m.createClass(NS + "B");
1534:                                ObjectProperty p = m.createObjectProperty(NS
1535:                                        + "p");
1536:                                Restriction a = m
1537:                                        .createAllValuesFromRestriction(null,
1538:                                                p, b);
1539:
1540:                                assertTrue("all values from test not correct",
1541:                                        a.isAllValuesFromRestriction());
1542:                                assertTrue("some values from test not correct",
1543:                                        !a.isSomeValuesFromRestriction());
1544:                                assertTrue("has value test not correct",
1545:                                        m_owlLiteLang
1546:                                                || !a.isHasValueRestriction());
1547:                                assertTrue("cardinality test not correct", !a
1548:                                        .isCardinalityRestriction());
1549:                                assertTrue("min cardinality test not correct",
1550:                                        !a.isMinCardinalityRestriction());
1551:                                assertTrue("max cardinality test not correct",
1552:                                        !a.isMaxCardinalityRestriction());
1553:                            }
1554:                        },
1555:                        new OntTestCase("Restriction.isSomeValuesFrom", true,
1556:                                true, true, false) {
1557:                            public void ontTest(OntModel m) throws Exception {
1558:                                OntClass b = m.createClass(NS + "B");
1559:                                ObjectProperty p = m.createObjectProperty(NS
1560:                                        + "p");
1561:                                Restriction a = m
1562:                                        .createSomeValuesFromRestriction(null,
1563:                                                p, b);
1564:
1565:                                assertTrue("all values from test not correct",
1566:                                        !a.isAllValuesFromRestriction());
1567:                                assertTrue("some values from test not correct",
1568:                                        a.isSomeValuesFromRestriction());
1569:                                assertTrue("has value test not correct",
1570:                                        m_owlLiteLang
1571:                                                || !a.isHasValueRestriction());
1572:                                assertTrue("cardinality test not correct", !a
1573:                                        .isCardinalityRestriction());
1574:                                assertTrue("min cardinality test not correct",
1575:                                        !a.isMinCardinalityRestriction());
1576:                                assertTrue("max cardinality test not correct",
1577:                                        !a.isMaxCardinalityRestriction());
1578:                            }
1579:                        },
1580:                        new OntTestCase("Restriction.isHasValue", true, false,
1581:                                true, false) {
1582:                            public void ontTest(OntModel m) throws Exception {
1583:                                OntClass b = m.createClass(NS + "B");
1584:                                Individual x = m.createIndividual(b);
1585:                                ObjectProperty p = m.createObjectProperty(NS
1586:                                        + "p");
1587:                                Restriction a = m.createHasValueRestriction(
1588:                                        null, p, x);
1589:
1590:                                assertTrue("all values from test not correct",
1591:                                        !a.isAllValuesFromRestriction());
1592:                                assertTrue("some values from test not correct",
1593:                                        !a.isSomeValuesFromRestriction());
1594:                                assertTrue("has value test not correct",
1595:                                        m_owlLiteLang
1596:                                                || a.isHasValueRestriction());
1597:                                assertTrue("cardinality test not correct", !a
1598:                                        .isCardinalityRestriction());
1599:                                assertTrue("min cardinality test not correct",
1600:                                        !a.isMinCardinalityRestriction());
1601:                                assertTrue("max cardinality test not correct",
1602:                                        !a.isMaxCardinalityRestriction());
1603:                            }
1604:                        },
1605:                        new OntTestCase("Restriction.isCardinality", true,
1606:                                true, true, false) {
1607:                            public void ontTest(OntModel m) throws Exception {
1608:                                ObjectProperty p = m.createObjectProperty(NS
1609:                                        + "p");
1610:                                Restriction a = m.createCardinalityRestriction(
1611:                                        null, p, 3);
1612:
1613:                                assertTrue("all values from test not correct",
1614:                                        !a.isAllValuesFromRestriction());
1615:                                assertTrue("some values from test not correct",
1616:                                        !a.isSomeValuesFromRestriction());
1617:                                assertTrue("has value test not correct",
1618:                                        m_owlLiteLang
1619:                                                || !a.isHasValueRestriction());
1620:                                assertTrue("cardinality test not correct", a
1621:                                        .isCardinalityRestriction());
1622:                                assertTrue("min cardinality test not correct",
1623:                                        !a.isMinCardinalityRestriction());
1624:                                assertTrue("max cardinality test not correct",
1625:                                        !a.isMaxCardinalityRestriction());
1626:                            }
1627:                        },
1628:                        new OntTestCase("Restriction.isMinCardinality", true,
1629:                                true, true, false) {
1630:                            public void ontTest(OntModel m) throws Exception {
1631:                                ObjectProperty p = m.createObjectProperty(NS
1632:                                        + "p");
1633:                                Restriction a = m
1634:                                        .createMinCardinalityRestriction(null,
1635:                                                p, 1);
1636:
1637:                                assertTrue("all values from test not correct",
1638:                                        !a.isAllValuesFromRestriction());
1639:                                assertTrue("some values from test not correct",
1640:                                        !a.isSomeValuesFromRestriction());
1641:                                assertTrue("has value test not correct",
1642:                                        m_owlLiteLang
1643:                                                || !a.isHasValueRestriction());
1644:                                assertTrue("cardinality test not correct", !a
1645:                                        .isCardinalityRestriction());
1646:                                assertTrue("min cardinality test not correct",
1647:                                        a.isMinCardinalityRestriction());
1648:                                assertTrue("max cardinality test not correct",
1649:                                        !a.isMaxCardinalityRestriction());
1650:                            }
1651:                        },
1652:                        new OntTestCase("Restriction.isMaxCardinality", true,
1653:                                true, true, false) {
1654:                            public void ontTest(OntModel m) throws Exception {
1655:                                ObjectProperty p = m.createObjectProperty(NS
1656:                                        + "p");
1657:                                Restriction a = m
1658:                                        .createMaxCardinalityRestriction(null,
1659:                                                p, 5);
1660:
1661:                                assertTrue("all values from test not correct",
1662:                                        !a.isAllValuesFromRestriction());
1663:                                assertTrue("some values from test not correct",
1664:                                        !a.isSomeValuesFromRestriction());
1665:                                assertTrue("has value test not correct",
1666:                                        m_owlLiteLang
1667:                                                || !a.isHasValueRestriction());
1668:                                assertTrue("cardinality test not correct", !a
1669:                                        .isCardinalityRestriction());
1670:                                assertTrue("min cardinality test not correct",
1671:                                        !a.isMinCardinalityRestriction());
1672:                                assertTrue("max cardinality test not correct",
1673:                                        a.isMaxCardinalityRestriction());
1674:                            }
1675:                        },
1676:
1677:                        // restriction conversions
1678:                        new OntTestCase("Restriction.convertToAllValuesFrom",
1679:                                true, true, true, false) {
1680:                            public void ontTest(OntModel m) throws Exception {
1681:                                ObjectProperty p = m.createObjectProperty(NS
1682:                                        + "p");
1683:                                Restriction a = m.createRestriction(p);
1684:
1685:                                assertTrue("all values from test not correct",
1686:                                        !a.isAllValuesFromRestriction());
1687:                                assertTrue("some values from test not correct",
1688:                                        !a.isSomeValuesFromRestriction());
1689:                                assertTrue("has value test not correct",
1690:                                        m_owlLiteLang
1691:                                                || !a.isHasValueRestriction());
1692:                                assertTrue("cardinality test not correct", !a
1693:                                        .isCardinalityRestriction());
1694:                                assertTrue("min cardinality test not correct",
1695:                                        !a.isMinCardinalityRestriction());
1696:                                assertTrue("max cardinality test not correct",
1697:                                        !a.isMaxCardinalityRestriction());
1698:
1699:                                OntClass b = m.createClass(NS + "B");
1700:                                a = a.convertToAllValuesFromRestriction(b);
1701:
1702:                                assertTrue("all values from test not correct",
1703:                                        a.isAllValuesFromRestriction());
1704:                                assertTrue("some values from test not correct",
1705:                                        !a.isSomeValuesFromRestriction());
1706:                                assertTrue("has value test not correct",
1707:                                        m_owlLiteLang
1708:                                                || !a.isHasValueRestriction());
1709:                                assertTrue("cardinality test not correct", !a
1710:                                        .isCardinalityRestriction());
1711:                                assertTrue("min cardinality test not correct",
1712:                                        !a.isMinCardinalityRestriction());
1713:                                assertTrue("max cardinality test not correct",
1714:                                        !a.isMaxCardinalityRestriction());
1715:                            }
1716:                        },
1717:                        new OntTestCase("Restriction.convertToSomeValuesFrom",
1718:                                true, true, true, false) {
1719:                            public void ontTest(OntModel m) throws Exception {
1720:                                ObjectProperty p = m.createObjectProperty(NS
1721:                                        + "p");
1722:                                Restriction a = m.createRestriction(p);
1723:
1724:                                assertTrue("all values from test not correct",
1725:                                        !a.isAllValuesFromRestriction());
1726:                                assertTrue("some values from test not correct",
1727:                                        !a.isSomeValuesFromRestriction());
1728:                                assertTrue("has value test not correct",
1729:                                        m_owlLiteLang
1730:                                                || !a.isHasValueRestriction());
1731:                                assertTrue("cardinality test not correct", !a
1732:                                        .isCardinalityRestriction());
1733:                                assertTrue("min cardinality test not correct",
1734:                                        !a.isMinCardinalityRestriction());
1735:                                assertTrue("max cardinality test not correct",
1736:                                        !a.isMaxCardinalityRestriction());
1737:
1738:                                OntClass b = m.createClass(NS + "B");
1739:                                a = a.convertToSomeValuesFromRestriction(b);
1740:
1741:                                assertTrue("all values from test not correct",
1742:                                        !a.isAllValuesFromRestriction());
1743:                                assertTrue("some values from test not correct",
1744:                                        a.isSomeValuesFromRestriction());
1745:                                assertTrue("has value test not correct",
1746:                                        m_owlLiteLang
1747:                                                || !a.isHasValueRestriction());
1748:                                assertTrue("cardinality test not correct", !a
1749:                                        .isCardinalityRestriction());
1750:                                assertTrue("min cardinality test not correct",
1751:                                        !a.isMinCardinalityRestriction());
1752:                                assertTrue("max cardinality test not correct",
1753:                                        !a.isMaxCardinalityRestriction());
1754:                            }
1755:                        },
1756:                        new OntTestCase("Restriction.convertToHasValue", true,
1757:                                false, true, false) {
1758:                            public void ontTest(OntModel m) throws Exception {
1759:                                ObjectProperty p = m.createObjectProperty(NS
1760:                                        + "p");
1761:                                Restriction a = m.createRestriction(p);
1762:
1763:                                assertTrue("all values from test not correct",
1764:                                        !a.isAllValuesFromRestriction());
1765:                                assertTrue("some values from test not correct",
1766:                                        !a.isSomeValuesFromRestriction());
1767:                                assertTrue("has value test not correct",
1768:                                        m_owlLiteLang
1769:                                                || !a.isHasValueRestriction());
1770:                                assertTrue("cardinality test not correct", !a
1771:                                        .isCardinalityRestriction());
1772:                                assertTrue("min cardinality test not correct",
1773:                                        !a.isMinCardinalityRestriction());
1774:                                assertTrue("max cardinality test not correct",
1775:                                        !a.isMaxCardinalityRestriction());
1776:
1777:                                OntClass b = m.createClass(NS + "B");
1778:                                Individual x = m.createIndividual(b);
1779:                                a = a.convertToHasValueRestriction(x);
1780:
1781:                                assertTrue("all values from test not correct",
1782:                                        !a.isAllValuesFromRestriction());
1783:                                assertTrue("some values from test not correct",
1784:                                        !a.isSomeValuesFromRestriction());
1785:                                assertTrue("has value test not correct",
1786:                                        m_owlLiteLang
1787:                                                || a.isHasValueRestriction());
1788:                                assertTrue("cardinality test not correct", !a
1789:                                        .isCardinalityRestriction());
1790:                                assertTrue("min cardinality test not correct",
1791:                                        !a.isMinCardinalityRestriction());
1792:                                assertTrue("max cardinality test not correct",
1793:                                        !a.isMaxCardinalityRestriction());
1794:                            }
1795:                        },
1796:                        new OntTestCase("Restriction.convertCardinality", true,
1797:                                true, true, false) {
1798:                            public void ontTest(OntModel m) throws Exception {
1799:                                ObjectProperty p = m.createObjectProperty(NS
1800:                                        + "p");
1801:                                Restriction a = m.createRestriction(p);
1802:
1803:                                assertTrue("all values from test not correct",
1804:                                        !a.isAllValuesFromRestriction());
1805:                                assertTrue("some values from test not correct",
1806:                                        !a.isSomeValuesFromRestriction());
1807:                                assertTrue("has value test not correct",
1808:                                        m_owlLiteLang
1809:                                                || !a.isHasValueRestriction());
1810:                                assertTrue("cardinality test not correct", !a
1811:                                        .isCardinalityRestriction());
1812:                                assertTrue("min cardinality test not correct",
1813:                                        !a.isMinCardinalityRestriction());
1814:                                assertTrue("max cardinality test not correct",
1815:                                        !a.isMaxCardinalityRestriction());
1816:
1817:                                a = a.convertToCardinalityRestriction(3);
1818:
1819:                                assertTrue("all values from test not correct",
1820:                                        !a.isAllValuesFromRestriction());
1821:                                assertTrue("some values from test not correct",
1822:                                        !a.isSomeValuesFromRestriction());
1823:                                assertTrue("has value test not correct",
1824:                                        m_owlLiteLang
1825:                                                || !a.isHasValueRestriction());
1826:                                assertTrue("cardinality test not correct", a
1827:                                        .isCardinalityRestriction());
1828:                                assertTrue("min cardinality test not correct",
1829:                                        !a.isMinCardinalityRestriction());
1830:                                assertTrue("max cardinality test not correct",
1831:                                        !a.isMaxCardinalityRestriction());
1832:                            }
1833:                        },
1834:                        new OntTestCase("Restriction.convertMinCardinality",
1835:                                true, true, true, false) {
1836:                            public void ontTest(OntModel m) throws Exception {
1837:                                ObjectProperty p = m.createObjectProperty(NS
1838:                                        + "p");
1839:                                Restriction a = m.createRestriction(p);
1840:
1841:                                assertTrue("all values from test not correct",
1842:                                        !a.isAllValuesFromRestriction());
1843:                                assertTrue("some values from test not correct",
1844:                                        !a.isSomeValuesFromRestriction());
1845:                                assertTrue("has value test not correct",
1846:                                        m_owlLiteLang
1847:                                                || !a.isHasValueRestriction());
1848:                                assertTrue("cardinality test not correct", !a
1849:                                        .isCardinalityRestriction());
1850:                                assertTrue("min cardinality test not correct",
1851:                                        !a.isMinCardinalityRestriction());
1852:                                assertTrue("max cardinality test not correct",
1853:                                        !a.isMaxCardinalityRestriction());
1854:
1855:                                a = a.convertToMinCardinalityRestriction(3);
1856:
1857:                                assertTrue("all values from test not correct",
1858:                                        !a.isAllValuesFromRestriction());
1859:                                assertTrue("some values from test not correct",
1860:                                        !a.isSomeValuesFromRestriction());
1861:                                assertTrue("has value test not correct",
1862:                                        m_owlLiteLang
1863:                                                || !a.isHasValueRestriction());
1864:                                assertTrue("cardinality test not correct", !a
1865:                                        .isCardinalityRestriction());
1866:                                assertTrue("min cardinality test not correct",
1867:                                        a.isMinCardinalityRestriction());
1868:                                assertTrue("max cardinality test not correct",
1869:                                        !a.isMaxCardinalityRestriction());
1870:                            }
1871:                        },
1872:                        new OntTestCase("Restriction.convertMaxCardinality",
1873:                                true, true, true, false) {
1874:                            public void ontTest(OntModel m) throws Exception {
1875:                                ObjectProperty p = m.createObjectProperty(NS
1876:                                        + "p");
1877:                                Restriction a = m.createRestriction(p);
1878:
1879:                                assertTrue("all values from test not correct",
1880:                                        !a.isAllValuesFromRestriction());
1881:                                assertTrue("some values from test not correct",
1882:                                        !a.isSomeValuesFromRestriction());
1883:                                assertTrue("has value test not correct",
1884:                                        m_owlLiteLang
1885:                                                || !a.isHasValueRestriction());
1886:                                assertTrue("cardinality test not correct", !a
1887:                                        .isCardinalityRestriction());
1888:                                assertTrue("min cardinality test not correct",
1889:                                        !a.isMinCardinalityRestriction());
1890:                                assertTrue("max cardinality test not correct",
1891:                                        !a.isMaxCardinalityRestriction());
1892:
1893:                                a = a.convertToMaxCardinalityRestriction(3);
1894:
1895:                                assertTrue("all values from test not correct",
1896:                                        !a.isAllValuesFromRestriction());
1897:                                assertTrue("some values from test not correct",
1898:                                        !a.isSomeValuesFromRestriction());
1899:                                assertTrue("has value test not correct",
1900:                                        m_owlLiteLang
1901:                                                || !a.isHasValueRestriction());
1902:                                assertTrue("cardinality test not correct", !a
1903:                                        .isCardinalityRestriction());
1904:                                assertTrue("min cardinality test not correct",
1905:                                        !a.isMinCardinalityRestriction());
1906:                                assertTrue("max cardinality test not correct",
1907:                                        a.isMaxCardinalityRestriction());
1908:                            }
1909:                        },
1910:                        new OntTestCase("OntClass.listInstances", true, true,
1911:                                true, true) {
1912:                            public void ontTest(OntModel m) throws Exception {
1913:                                OntClass A = m.createClass(NS + "A");
1914:                                OntClass B = m.createClass(NS + "B");
1915:
1916:                                Individual a0 = m.createIndividual(A);
1917:                                Individual a1 = m
1918:                                        .createIndividual(NS + "a1", A);
1919:                                Individual b0 = m.createIndividual(B);
1920:                                /*Individual b1 =*/m.createIndividual(NS
1921:                                        + "b1", B);
1922:                                b0.addRDFType(A);
1923:
1924:                                iteratorTest(A.listInstances(), new Object[] {
1925:                                        a0, a1, b0 });
1926:                            }
1927:                        },
1928:                        new OntTestCase("OntClass.listDefinedProperties", true,
1929:                                true, true, true) {
1930:                            public void ontTest(OntModel m) throws Exception {
1931:                                OntClass A = m.createClass(NS + "A");
1932:                                //OntClass B = m.createClass( NS + "B" );
1933:                                OntClass C = m.createClass(NS + "C");
1934:
1935:                                OntProperty p = m.createOntProperty(NS + "p");
1936:                                OntProperty q = m.createOntProperty(NS + "q");
1937:                                OntProperty r = m.createOntProperty(NS + "r");
1938:                                OntProperty s = m.createOntProperty(NS + "s");
1939:
1940:                                p.setDomain(A);
1941:                                q.setDomain(A);
1942:                                s.setDomain(C);
1943:
1944:                                if (m_rdfsLang) {
1945:                                    iteratorTest(A.listDeclaredProperties(),
1946:                                            new Object[] { p, q, r });
1947:                                } else {
1948:                                    Restriction r0 = m.createRestriction(r);
1949:                                    C.addSuperClass(r0);
1950:
1951:                                    iteratorTest(A.listDeclaredProperties(),
1952:                                            new Object[] { p, q, r });
1953:
1954:                                    iteratorTest(C.listDeclaredProperties(),
1955:                                            new Object[] { s, r });
1956:
1957:                                    iteratorTest(r0.listDeclaredProperties(),
1958:                                            new Object[] { r });
1959:                                }
1960:                            }
1961:                        },
1962:                        new OntTestCase(
1963:                                "OntClass.listDefinedProperties.notAll", true,
1964:                                true, true, true) {
1965:                            public void ontTest(OntModel m) throws Exception {
1966:                                OntClass A = m.createClass(NS + "A");
1967:                                OntClass C = m.createClass(NS + "C");
1968:                                C.addSuperClass(A);
1969:
1970:                                OntProperty p = m.createOntProperty(NS + "p");
1971:                                OntProperty q = m.createOntProperty(NS + "q");
1972:                                OntProperty s = m.createOntProperty(NS + "s");
1973:
1974:                                p.setDomain(A);
1975:                                q.setDomain(A);
1976:                                s.setDomain(C);
1977:
1978:                                iteratorTest(C.listDeclaredProperties(false),
1979:                                        new Object[] { p, q, s });
1980:                                iteratorTest(C.listDeclaredProperties(true),
1981:                                        new Object[] { s });
1982:
1983:                                assertTrue(
1984:                                        "declared property should be an ont prop",
1985:                                        C.listDeclaredProperties(true).next() instanceof  OntProperty);
1986:                                assertTrue(
1987:                                        "declared property should be an ont prop",
1988:                                        C.listDeclaredProperties(false).next() instanceof  OntProperty);
1989:                            }
1990:                        },
1991:                        new OntTestCase("DataRange.oneOf", true, false, false,
1992:                                false) {
1993:                            public void ontTest(OntModel m) throws Exception {
1994:                                Literal x = m.createTypedLiteral(42);
1995:                                Literal y = m.createTypedLiteral(true);
1996:                                Literal z = m.createTypedLiteral("life");
1997:                                RDFList lits = m.createList(new RDFNode[] { x,
1998:                                        y });
1999:
2000:                                DataRange d0 = m.createDataRange(lits);
2001:
2002:                                assertTrue("datarange should contain x", d0
2003:                                        .hasOneOf(x));
2004:                                assertTrue("datarange should contain y", d0
2005:                                        .hasOneOf(y));
2006:                                assertFalse("datarange should not contain z",
2007:                                        d0.hasOneOf(z));
2008:
2009:                                d0.removeOneOf(z);
2010:                                assertTrue("datarange should contain x", d0
2011:                                        .hasOneOf(x));
2012:                                assertTrue("datarange should contain y", d0
2013:                                        .hasOneOf(y));
2014:                                assertFalse("datarange should not contain z",
2015:                                        d0.hasOneOf(z));
2016:
2017:                                d0.removeOneOf(x);
2018:                                assertFalse("datarange should not contain x",
2019:                                        d0.hasOneOf(x));
2020:                                assertTrue("datarange should contain y", d0
2021:                                        .hasOneOf(y));
2022:                                assertFalse("datarange should not contain z",
2023:                                        d0.hasOneOf(z));
2024:
2025:                                d0.addOneOf(z);
2026:                                assertEquals("datarange should be size 2", 2,
2027:                                        d0.getOneOf().size());
2028:                                iteratorTest(d0.listOneOf(), new Object[] { y,
2029:                                        z });
2030:
2031:                                d0.setOneOf(m.createList(new RDFNode[] { x }));
2032:                                iteratorTest(d0.listOneOf(), new Object[] { x });
2033:                            }
2034:                        },
2035:
2036:                };
2037:            }
2038:
2039:            // Internal implementation methods
2040:            //////////////////////////////////
2041:
2042:            //==============================================================================
2043:            // Inner class definitions
2044:            //==============================================================================
2045:
2046:        }
2047:
2048:        /*
2049:         (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
2050:         All rights reserved.
2051:
2052:         Redistribution and use in source and binary forms, with or without
2053:         modification, are permitted provided that the following conditions
2054:         are met:
2055:
2056:         1. Redistributions of source code must retain the above copyright
2057:         notice, this list of conditions and the following disclaimer.
2058:
2059:         2. Redistributions in binary form must reproduce the above copyright
2060:         notice, this list of conditions and the following disclaimer in the
2061:         documentation and/or other materials provided with the distribution.
2062:
2063:         3. The name of the author may not be used to endorse or promote products
2064:         derived from this software without specific prior written permission.
2065:
2066:         THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2067:         IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2068:         OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2069:         IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2070:         INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2071:         NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2072:         DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2073:         THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2074:         (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2075:         THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2076:         */
w_w_w___.j___a_v__a__2_s.c_om__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.