KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > ontology > impl > test > TestAllDifferent


1 /*****************************************************************************
2  * Source code information
3  * -----------------------
4  * Original author Ian Dickinson, HP Labs Bristol
5  * Author email Ian.Dickinson@hp.com
6  * Package Jena 2
7  * Web http://sourceforge.net/projects/jena/
8  * Created 27-May-2003
9  * Filename $RCSfile: TestAllDifferent.java,v $
10  * Revision $Revision: 1.8 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/02/21 12:07:13 $
14  * by $Author: andy_seaborne $
15  *
16  * (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
17  * (see footer for full conditions)
18  *****************************************************************************/

19
20 // Package
21
///////////////
22
package com.hp.hpl.jena.ontology.impl.test;
23
24
25
26 // Imports
27
///////////////
28
import com.hp.hpl.jena.ontology.*;
29 import com.hp.hpl.jena.rdf.model.RDFNode;
30
31 import junit.framework.*;
32
33
34 /**
35  * <p>
36  * Unit tests for the AllDifferent declaration.
37  * </p>
38  *
39  * @author Ian Dickinson, HP Labs
40  * (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
41  * @version CVS $Id: TestAllDifferent.java,v 1.8 2005/02/21 12:07:13 andy_seaborne Exp $
42  */

43 public class TestAllDifferent
44     extends OntTestBase
45 {
46     // Constants
47
//////////////////////////////////
48

49     // Static variables
50
//////////////////////////////////
51

52     // Instance variables
53
//////////////////////////////////
54

55     // Constructors
56
//////////////////////////////////
57

58     static public TestSuite suite() {
59         return new TestAllDifferent( "TestAllDifferent" );
60     }
61     
62     public TestAllDifferent( String JavaDoc name ) {
63         super( name );
64     }
65     
66
67     // External signature methods
68
//////////////////////////////////
69

70     public OntTestCase[] getTests() {
71         return new OntTestCase[] {
72             new OntTestCase( "AllDifferent.distinctMembers", true, true, false, false ) {
73                 public void ontTest( OntModel m ) throws Exception JavaDoc {
74                     Profile prof = m.getProfile();
75                     AllDifferent a = m.createAllDifferent();
76                     OntResource b = (OntResource) m.getResource( NS + "b" ).as( OntResource.class );
77                     OntResource c = (OntResource) m.getResource( NS + "c" ).as( OntResource.class );
78                     
79                     a.addDistinctMember( b );
80                     assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.DISTINCT_MEMBERS() ) );
81                     assertEquals( "List size should be 1", 1, a.getDistinctMembers().size() );
82                     assertTrue( "a should have b as distinct", a.hasDistinctMember( b ) );
83                     
84                     a.addDistinctMember( c );
85                     assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.DISTINCT_MEMBERS() ) );
86                     assertEquals( "List size should be 2", 2, a.getDistinctMembers().size() );
87                     iteratorTest( a.listDistinctMembers(), new Object JavaDoc[] {b, c} );
88                     
89                     assertTrue( "a should have b as distinct", a.hasDistinctMember( b ) );
90                     assertTrue( "a should have c as distinct", a.hasDistinctMember( c ) );
91                     
92                     a.setDistinctMembers( m.createList( new RDFNode[] {b} ) );
93                     assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.DISTINCT_MEMBERS() ) );
94                     assertEquals( "List size should be 1", 1, a.getDistinctMembers().size() );
95                     assertTrue( "a should have b as distinct", a.hasDistinctMember( b ) );
96                     assertTrue( "a should not have c as distinct", !a.hasDistinctMember( c ) );
97                     
98                     a.removeDistinctMember( b );
99                     assertTrue( "a should have not b as distinct", !a.hasDistinctMember( b ) );
100                 }
101             },
102         };
103     }
104     
105     // Internal implementation methods
106
//////////////////////////////////
107

108     //==============================================================================
109
// Inner class definitions
110
//==============================================================================
111

112 }
113
114
115 /*
116     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
117     All rights reserved.
118
119     Redistribution and use in source and binary forms, with or without
120     modification, are permitted provided that the following conditions
121     are met:
122
123     1. Redistributions of source code must retain the above copyright
124        notice, this list of conditions and the following disclaimer.
125
126     2. Redistributions in binary form must reproduce the above copyright
127        notice, this list of conditions and the following disclaimer in the
128        documentation and/or other materials provided with the distribution.
129
130     3. The name of the author may not be used to endorse or promote products
131        derived from this software without specific prior written permission.
132
133     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
134     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
135     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
136     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
137     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
138     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
139     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
140     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
141     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
142     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
143 */

144
Popular Tags