KickJava   Java API By Example, From Geeks To Geeks.

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


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 17-Jun-2003
9  * Filename $RCSfile: TestDAMLList.java,v $
10  * Revision $Revision: 1.4 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/02/21 12:05:47 $
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.daml.impl.test;
23
24
25 // Imports
26
///////////////
27
import com.hp.hpl.jena.ontology.daml.*;
28 import com.hp.hpl.jena.rdf.model.*;
29
30 import junit.framework.*;
31
32
33 /**
34  * <p>
35  * Unit tests for DAML List
36  * </p>
37  *
38  * @author Ian Dickinson, HP Labs
39  * (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
40  * @version CVS $Id: TestDAMLList.java,v 1.4 2005/02/21 12:05:47 andy_seaborne Exp $
41  */

42 public class TestDAMLList
43     extends DAMLTestBase
44 {
45     // Constants
46
//////////////////////////////////
47

48     // Static variables
49
//////////////////////////////////
50

51     // Instance variables
52
//////////////////////////////////
53

54     // Constructors
55
//////////////////////////////////
56

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

69     public OntTestCase[] getTests() {
70         return new OntTestCase[] {
71             new OntTestCase( "DAMLList.getAll" ) {
72                 public void doTest( DAMLModel m ) throws Exception JavaDoc {
73                     DAMLClass A = m.createDAMLClass( NS + "A" );
74                     DAMLClass B = m.createDAMLClass( NS + "B" );
75                     DAMLClass C = m.createDAMLClass( NS + "C" );
76                     
77                     DAMLList l = m.createDAMLList( new RDFNode[] {A,B,C} );
78                     
79                     iteratorTest( l.getAll(), new Object JavaDoc[] {A,B,C} );
80                 }
81             },
82             new OntTestCase( "DAMLList.getFirst" ) {
83                 public void doTest( DAMLModel m ) throws Exception JavaDoc {
84                     DAMLClass A = m.createDAMLClass( NS + "A" );
85                     DAMLClass B = m.createDAMLClass( NS + "B" );
86                     DAMLClass C = m.createDAMLClass( NS + "C" );
87                     
88                     DAMLList l = m.createDAMLList( new RDFNode[] {A,B,C} );
89                     
90                     assertEquals( "DAMLList.getFirst()", A, l.getFirst() );
91                 }
92             },
93             new OntTestCase( "DAMLList.cons" ) {
94                 public void doTest( DAMLModel m ) throws Exception JavaDoc {
95                     DAMLClass A = m.createDAMLClass( NS + "A" );
96                     DAMLClass B = m.createDAMLClass( NS + "B" );
97                     DAMLClass C = m.createDAMLClass( NS + "C" );
98                     
99                     DAMLList l = m.createDAMLList( new RDFNode[] {B,C} );
100                     DAMLList l2 = l.cons( A );
101                     
102                     iteratorTest( l2.getAll(), new Object JavaDoc[] {A,B,C} );
103                 }
104             },
105             new OntTestCase( "DAMLList.getRest" ) {
106                 public void doTest( DAMLModel m ) throws Exception JavaDoc {
107                     DAMLClass A = m.createDAMLClass( NS + "A" );
108                     DAMLClass B = m.createDAMLClass( NS + "B" );
109                     DAMLClass C = m.createDAMLClass( NS + "C" );
110                     
111                     DAMLList l = m.createDAMLList( new RDFNode[] {A,B,C} );
112                     
113                     iteratorTest( l.getRest().getAll(), new Object JavaDoc[] {B,C} );
114                 }
115             },
116             new OntTestCase( "DAMLList.getCount" ) {
117                 public void doTest( DAMLModel m ) throws Exception JavaDoc {
118                     DAMLClass A = m.createDAMLClass( NS + "A" );
119                     DAMLClass B = m.createDAMLClass( NS + "B" );
120                     DAMLClass C = m.createDAMLClass( NS + "C" );
121                     
122                     DAMLList l = m.createDAMLList( new RDFNode[] {A,B,C} );
123                     
124                     assertEquals( "count", 3, l.getCount() );
125                 }
126             },
127             new OntTestCase( "DAMLList.setFirst" ) {
128                 public void doTest( DAMLModel m ) throws Exception JavaDoc {
129                     DAMLClass A = m.createDAMLClass( NS + "A" );
130                     DAMLClass B = m.createDAMLClass( NS + "B" );
131                     DAMLClass C = m.createDAMLClass( NS + "C" );
132                     
133                     DAMLList l = m.createDAMLList( new RDFNode[] {B,B,C} );
134                     l.setFirst( A );
135                     
136                     iteratorTest( l.getAll(), new Object JavaDoc[] {A,B,C} );
137                 }
138             },
139             new OntTestCase( "DAMLList.setRest" ) {
140                 public void doTest( DAMLModel m ) throws Exception JavaDoc {
141                     DAMLClass A = m.createDAMLClass( NS + "A" );
142                     DAMLClass B = m.createDAMLClass( NS + "B" );
143                     DAMLClass C = m.createDAMLClass( NS + "C" );
144                     
145                     DAMLList l = m.createDAMLList( new RDFNode[] {A} );
146                     DAMLList l2 = m.createDAMLList( new RDFNode[] {B,C} );
147                     l.setRest( l2 );
148                     
149                     iteratorTest( l.getAll(), new Object JavaDoc[] {A,B,C} );
150                 }
151             },
152             new OntTestCase( "DAMLList.setRestNil" ) {
153                 public void doTest( DAMLModel m ) throws Exception JavaDoc {
154                     DAMLClass A = m.createDAMLClass( NS + "A" );
155                     DAMLClass B = m.createDAMLClass( NS + "B" );
156                     DAMLClass C = m.createDAMLClass( NS + "C" );
157                     
158                     DAMLList l = m.createDAMLList( new RDFNode[] {A,B,C} );
159                     l.getRest().setRestNil();
160                     
161                     iteratorTest( l.getAll(), new Object JavaDoc[] {A,B} );
162                 }
163             },
164             new OntTestCase( "DAMLList.nil" ) {
165                 public void doTest( DAMLModel m ) throws Exception JavaDoc {
166                     DAMLClass A = m.createDAMLClass( NS + "A" );
167                     DAMLList l = m.createDAMLList();
168                     
169                     assertTrue( "nil is nil", l.isNil( l.getNil() ) );
170                     assertFalse( "A is not nil", l.isNil( A ) );
171                 }
172             },
173             new OntTestCase( "DAMLList.findLast" ) {
174                 public void doTest( DAMLModel m ) throws Exception JavaDoc {
175                     DAMLClass A = m.createDAMLClass( NS + "A" );
176                     DAMLClass B = m.createDAMLClass( NS + "B" );
177                     DAMLClass C = m.createDAMLClass( NS + "C" );
178                     
179                     DAMLList l = m.createDAMLList( new RDFNode[] {A,B,C} );
180                     
181                     iteratorTest( l.findLast().getAll(), new Object JavaDoc[] {C} );
182                 }
183             },
184             new OntTestCase( "DAMLList.getItem" ) {
185                 public void doTest( DAMLModel m ) throws Exception JavaDoc {
186                     DAMLClass A = m.createDAMLClass( NS + "A" );
187                     DAMLClass B = m.createDAMLClass( NS + "B" );
188                     DAMLClass C = m.createDAMLClass( NS + "C" );
189                     
190                     DAMLList l = m.createDAMLList( new RDFNode[] {A,B,C} );
191                     
192                     assertEquals( "A", A, l.getItem( 0 ) );
193                     assertEquals( "B", B, l.getItem( 1 ) );
194                     assertEquals( "C", C, l.getItem( 2 ) );
195                 }
196             },
197         };
198     }
199     
200     
201     // Internal implementation methods
202
//////////////////////////////////
203

204     //==============================================================================
205
// Inner class definitions
206
//==============================================================================
207

208 }
209
210
211 /*
212     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
213     All rights reserved.
214
215     Redistribution and use in source and binary forms, with or without
216     modification, are permitted provided that the following conditions
217     are met:
218
219     1. Redistributions of source code must retain the above copyright
220        notice, this list of conditions and the following disclaimer.
221
222     2. Redistributions in binary form must reproduce the above copyright
223        notice, this list of conditions and the following disclaimer in the
224        documentation and/or other materials provided with the distribution.
225
226     3. The name of the author may not be used to endorse or promote products
227        derived from this software without specific prior written permission.
228
229     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
230     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
231     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
232     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
233     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
234     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
235     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
236     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
237     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
238     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
239 */

240
241
Popular Tags