001: /*****************************************************************************
002: * Source code information
003: * -----------------------
004: * Original author Ian Dickinson, HP Labs Bristol
005: * Author email Ian.Dickinson@hp.com
006: * Package Jena 2
007: * Web http://sourceforge.net/projects/jena/
008: * Created 27-May-2003
009: * Filename $RCSfile: TestAllDifferent.java,v $
010: * Revision $Revision: 1.11 $
011: * Release status $State: Exp $
012: *
013: * Last modified on $Date: 2008/01/02 12:08:40 $
014: * by $Author: andy_seaborne $
015: *
016: * (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
017: * (see footer for full conditions)
018: *****************************************************************************/package com.hp.hpl.jena.ontology.impl.test;
019:
020: // Imports
021: ///////////////
022: import com.hp.hpl.jena.ontology.*;
023: import com.hp.hpl.jena.rdf.model.RDFNode;
024:
025: import junit.framework.*;
026:
027: /**
028: * <p>
029: * Unit tests for the AllDifferent declaration.
030: * </p>
031: *
032: * @author Ian Dickinson, HP Labs
033: * (<a href="mailto:Ian.Dickinson@hp.com" >email</a>)
034: * @version CVS $Id: TestAllDifferent.java,v 1.11 2008/01/02 12:08:40 andy_seaborne Exp $
035: */
036: public class TestAllDifferent extends OntTestBase {
037: // Constants
038: //////////////////////////////////
039:
040: // Static variables
041: //////////////////////////////////
042:
043: // Instance variables
044: //////////////////////////////////
045:
046: // Constructors
047: //////////////////////////////////
048:
049: static public TestSuite suite() {
050: return new TestAllDifferent("TestAllDifferent");
051: }
052:
053: public TestAllDifferent(String name) {
054: super (name);
055: }
056:
057: // External signature methods
058: //////////////////////////////////
059:
060: public OntTestCase[] getTests() {
061: return new OntTestCase[] { new OntTestCase(
062: "AllDifferent.distinctMembers", true, true, false,
063: false) {
064: public void ontTest(OntModel m) throws Exception {
065: Profile prof = m.getProfile();
066: AllDifferent a = m.createAllDifferent();
067: OntResource b = (OntResource) m.getResource(NS + "b")
068: .as(OntResource.class);
069: OntResource c = (OntResource) m.getResource(NS + "c")
070: .as(OntResource.class);
071:
072: a.addDistinctMember(b);
073: assertEquals("Cardinality should be 1", 1, a
074: .getCardinality(prof.DISTINCT_MEMBERS()));
075: assertEquals("List size should be 1", 1, a
076: .getDistinctMembers().size());
077: assertTrue("a should have b as distinct", a
078: .hasDistinctMember(b));
079:
080: a.addDistinctMember(c);
081: assertEquals("Cardinality should be 1", 1, a
082: .getCardinality(prof.DISTINCT_MEMBERS()));
083: assertEquals("List size should be 2", 2, a
084: .getDistinctMembers().size());
085: iteratorTest(a.listDistinctMembers(), new Object[] { b,
086: c });
087:
088: assertTrue("a should have b as distinct", a
089: .hasDistinctMember(b));
090: assertTrue("a should have c as distinct", a
091: .hasDistinctMember(c));
092:
093: a.setDistinctMembers(m.createList(new RDFNode[] { b }));
094: assertEquals("Cardinality should be 1", 1, a
095: .getCardinality(prof.DISTINCT_MEMBERS()));
096: assertEquals("List size should be 1", 1, a
097: .getDistinctMembers().size());
098: assertTrue("a should have b as distinct", a
099: .hasDistinctMember(b));
100: assertTrue("a should not have c as distinct", !a
101: .hasDistinctMember(c));
102:
103: a.removeDistinctMember(b);
104: assertTrue("a should have not b as distinct", !a
105: .hasDistinctMember(b));
106: }
107: }, };
108: }
109:
110: // Internal implementation methods
111: //////////////////////////////////
112:
113: //==============================================================================
114: // Inner class definitions
115: //==============================================================================
116:
117: }
118:
119: /*
120: (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
121: All rights reserved.
122:
123: Redistribution and use in source and binary forms, with or without
124: modification, are permitted provided that the following conditions
125: are met:
126:
127: 1. Redistributions of source code must retain the above copyright
128: notice, this list of conditions and the following disclaimer.
129:
130: 2. Redistributions in binary form must reproduce the above copyright
131: notice, this list of conditions and the following disclaimer in the
132: documentation and/or other materials provided with the distribution.
133:
134: 3. The name of the author may not be used to endorse or promote products
135: derived from this software without specific prior written permission.
136:
137: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
138: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
139: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
140: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
141: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
142: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
143: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
144: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
145: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
146: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
147: */
|