KickJava   Java API By Example, From Geeks To Geeks.

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


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 23-May-2003
9  * Filename $RCSfile: DAMLTestBase.java,v $
10  * Revision $Revision: 1.7 $
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 2001, 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 java.util.*;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31
32 import com.hp.hpl.jena.ontology.*;
33 import com.hp.hpl.jena.ontology.daml.DAMLModel;
34 import com.hp.hpl.jena.rdf.model.*;
35
36 import junit.framework.*;
37
38
39 /**
40  * <p>
41  * Generic test case for DAML ontology unit testing
42  * </p>
43  *
44  * @author Ian Dickinson, HP Labs
45  * (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
46  * @version CVS $Id: DAMLTestBase.java,v 1.7 2005/02/21 12:05:47 andy_seaborne Exp $
47  */

48 public abstract class DAMLTestBase
49     extends TestSuite
50 {
51     // Constants
52
//////////////////////////////////
53

54     public static final String JavaDoc BASE = "http://jena.hpl.hp.com/testing/ontology";
55     public static final String JavaDoc NS = BASE + "#";
56     
57     
58     // Static variables
59
//////////////////////////////////
60

61     // Instance variables
62
//////////////////////////////////
63

64     
65     // Constructors
66
//////////////////////////////////
67

68     public DAMLTestBase( String JavaDoc name ) {
69         super( name );
70         TestCase[] tc = getTests();
71         
72         for (int i = 0; i < tc.length; i++) {
73             addTest( tc[i] );
74         }
75     }
76     
77     // External signature methods
78
//////////////////////////////////
79

80
81     // Internal implementation methods
82
//////////////////////////////////
83

84     /** Return the array of tests for the suite */
85     protected OntTestCase[] getTests() {
86         return null;
87     }
88     
89     
90     //==============================================================================
91
// Inner class definitions
92
//==============================================================================
93

94     protected abstract class OntTestCase
95         extends TestCase
96     {
97         protected String JavaDoc m_langElement;
98
99         public OntTestCase( String JavaDoc langElement ) {
100             super( "DAML API test " + langElement );
101             m_langElement = langElement;
102         }
103
104         public void setUp() {
105             // ensure the ont doc manager is in a consistent state
106
OntDocumentManager.getInstance().reset( true );
107         }
108         
109         
110         public void runTest()
111             throws Exception JavaDoc
112         {
113             boolean profileEx = false;
114             DAMLModel m = ModelFactory.createDAMLModel();
115         
116             try {
117                 doTest( m );
118             }
119             catch (ProfileException e) {
120                 profileEx = true;
121             }
122         
123             assertTrue( "language element " + m_langElement + " was expected in DAML model ", !profileEx );
124         }
125     
126         /** Does the work in the test sub-class */
127         protected abstract void doTest( DAMLModel m ) throws Exception JavaDoc;
128     
129         /** Test that an iterator delivers the expected values */
130         protected void iteratorTest( Iterator i, Object JavaDoc[] expected ) {
131             Log logger = LogFactory.getLog( getClass() );
132             List expList = new ArrayList();
133             for (int j = 0; j < expected.length; j++) {
134                 expList.add( expected[j] );
135             }
136         
137             while (i.hasNext()) {
138                 Object JavaDoc next = i.next();
139                 
140                 // debugging
141
if (!expList.contains( next )) {
142                     logger.debug( getName() + " - Unexpected iterator result: " + next );
143                 }
144                 
145                 assertTrue( "Value " + next + " was not expected as a result from this iterator ", expList.contains( next ) );
146                 assertTrue( "Value " + next + " was not removed from the list ", expList.remove( next ) );
147             }
148         
149             if (!(expList.size() == 0)) {
150                 logger.debug( getName() + "Expected iterator results not found" );
151                 for (Iterator j = expList.iterator(); j.hasNext(); ) {
152                     logger.debug( getName() + " - missing: " + j.next() );
153                 }
154             }
155             assertEquals( "There were expected elements from the iterator that were not found", 0, expList.size() );
156         }
157     }
158 }
159
160
161 /*
162     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
163     All rights reserved.
164
165     Redistribution and use in source and binary forms, with or without
166     modification, are permitted provided that the following conditions
167     are met:
168
169     1. Redistributions of source code must retain the above copyright
170        notice, this list of conditions and the following disclaimer.
171
172     2. Redistributions in binary form must reproduce the above copyright
173        notice, this list of conditions and the following disclaimer in the
174        documentation and/or other materials provided with the distribution.
175
176     3. The name of the author may not be used to endorse or promote products
177        derived from this software without specific prior written permission.
178
179     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
180     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
181     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
182     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
183     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
184     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
185     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
186     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
187     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
188     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
189 */

190
191
Popular Tags