KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > arp > test > ExceptionTests


1 /*
2  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
3  * All rights reserved.
4  * [See end of file]
5  * $Id: ExceptionTests.java,v 1.5 2005/02/21 12:11:05 andy_seaborne Exp $
6  */

7
8 package com.hp.hpl.jena.rdf.arp.test;
9 import junit.framework.*;
10
11
12
13 import com.hp.hpl.jena.rdf.arp.*;
14 import com.hp.hpl.jena.rdf.model.*;
15 import com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler;
16 import com.hp.hpl.jena.shared.JenaException;
17 /**
18  * @author jjc
19  *
20  */

21 public class ExceptionTests
22     extends TestCase
23     implements RDFErrorHandler, ARPErrorNumbers {
24     static public Test suite() {
25         TestSuite suite = new TestSuite("ARP Exceptions");
26         
27         suite.addTest(new ExceptionTests("testDefaultFatal"));
28         suite.addTest(new ExceptionTests("testDefaultError"));
29         suite.addTest(new ExceptionTests("testDefaultWarning"));
30         suite.addTest(new ExceptionTests("testDefaultDemotedFatal"));
31         suite.addTest(new ExceptionTests("testDefaultPromotedError"));
32         suite.addTest(new ExceptionTests("testDefaultPromotedWarning"));
33         suite.addTest(new ExceptionTests("testNonExceptionFatal"));
34         suite.addTest(new ExceptionTests("testExceptionError"));
35         suite.addTest(new ExceptionTests("testExceptionWarning"));
36         return suite;
37     }
38
39     ExceptionTests(String JavaDoc s) {
40         super(s);
41     }
42     
43     public void testDefaultFatal() {
44         //E301
45
RDFDefaultErrorHandler.silent = true;
46         try {
47           Model m = ModelFactory.createDefaultModel();
48           m.read("file:testing/arp/error-msgs/test06.rdf");
49           fail("Fatal error did not throw exception");
50         }
51         catch (JenaException e){
52             
53         }
54         finally {
55             RDFDefaultErrorHandler.silent = false;
56         }
57         
58     }
59     public void testDefaultError() {
60
61         // E206
62
RDFDefaultErrorHandler.silent = true;
63         try {
64           Model m = ModelFactory.createDefaultModel();
65           m.read("file:testing/wg/rdfms-abouteach/error002.rdf");
66         }
67         catch (JenaException e){
68               fail("Error threw exception");
69         }
70         finally {
71             RDFDefaultErrorHandler.silent = false;
72         }
73         
74     }
75     public void testDefaultWarning() {
76         // W108
77
RDFDefaultErrorHandler.silent = true;
78         try {
79           Model m = ModelFactory.createDefaultModel();
80           m.read("file:testing/arp/qname-in-ID/bug74_0.rdf");
81         }
82         catch (JenaException e){
83               fail("Warning threw exception");
84         }
85         finally {
86             RDFDefaultErrorHandler.silent = false;
87         }
88     }
89
90     public void testDefaultDemotedFatal() {
91
92         RDFDefaultErrorHandler.silent = true;
93         try {
94           Model m = ModelFactory.createDefaultModel();
95           RDFReader rdr = m.getReader();
96           rdr.setProperty("ERR_SAX_FATAL_ERROR","EM_ERROR");
97           rdr.read(m,"file:testing/arp/error-msgs/test06.rdf");
98         }
99         catch (JenaException e){
100         // System.err.println(e.getMessage());
101
// e.printStackTrace();
102
fail("Demoted fatal error threw an exception");
103         }
104         finally {
105             RDFDefaultErrorHandler.silent = false;
106         }
107     
108     }
109     public void testDefaultPromotedError() {
110
111         RDFDefaultErrorHandler.silent = true;
112         try {
113           Model m = ModelFactory.createDefaultModel();
114           RDFReader rdr = m.getReader();
115           rdr.setProperty("ERR_BAD_RDF_ATTRIBUTE","EM_FATAL");
116           rdr.read(m,"file:testing/wg/rdfms-abouteach/error002.rdf");
117
118           fail("Promoted error did not throw exception");
119         }
120         catch (JenaException e){
121     // System.err.println(e.getMessage());
122
}
123         finally {
124             RDFDefaultErrorHandler.silent = false;
125         }
126         
127         
128     }
129     public void testDefaultPromotedWarning() {
130
131         RDFDefaultErrorHandler.silent = true;
132         try {
133
134           Model m = ModelFactory.createDefaultModel();
135           RDFReader rdr = m.getReader();
136           rdr.setProperty("WARN_BAD_NAME","EM_FATAL");
137           rdr.read(m,"file:testing/arp/qname-in-ID/bug74_0.rdf");
138
139           fail("Promoted warning did not throw exception");
140         }
141         catch (JenaException e){
142         }
143         finally {
144             RDFDefaultErrorHandler.silent = false;
145         }
146         
147     }
148     public void testNonExceptionFatal() {
149
150         try {
151           Model m = ModelFactory.createDefaultModel();
152           RDFReader rdr = m.getReader();
153           rdr.setErrorHandler(this);
154           rdr.read(m,"file:testing/arp/error-msgs/test06.rdf");
155         }
156         catch (JenaException e){
157               fail("Fatal error threw an exception with non-exception handler");
158         }
159         
160         
161     }
162     public void testExceptionError() {
163         try {
164           Model m = ModelFactory.createDefaultModel();
165           RDFReader rdr = m.getReader();
166           rdr.setErrorHandler(this);
167           rdr.read(m,"file:testing/wg/rdfms-abouteach/error002.rdf");
168
169           fail("Error did not throw exception with non-standard handler");
170         }
171         catch (JenaException e){
172         }
173                 
174     }
175     public void testExceptionWarning() {
176         try {
177
178           Model m = ModelFactory.createDefaultModel();
179           RDFReader rdr = m.getReader();
180           rdr.setErrorHandler(this);
181           rdr.read(m,"file:testing/arp/qname-in-ID/bug74_0.rdf");
182
183           fail("Warning did not throw exception with non-standard handler");
184         }
185         catch (JenaException e){
186         }
187         
188     }
189     
190
191
192     public void warning(Exception JavaDoc e) {
193         throw new JenaException(e);
194     }
195
196     public void error(Exception JavaDoc e) {
197         throw new JenaException(e);
198     }
199
200     public void fatalError(Exception JavaDoc e) {
201     }
202
203 }
204
205 /*
206     (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
207     All rights reserved.
208
209     Redistribution and use in source and binary forms, with or without
210     modification, are permitted provided that the following conditions
211     are met:
212
213     1. Redistributions of source code must retain the above copyright
214        notice, this list of conditions and the following disclaimer.
215
216     2. Redistributions in binary form must reproduce the above copyright
217        notice, this list of conditions and the following disclaimer in the
218        documentation and/or other materials provided with the distribution.
219
220     3. The name of the author may not be used to endorse or promote products
221        derived from this software without specific prior written permission.
222
223     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
224     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
225     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
226     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
227     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
228     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
229     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
230     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
231     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
232     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
233 */
Popular Tags