001: /*
002: * (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: * All rights reserved.
004: * [See end of file]
005: * $Id: ExceptionTests.java,v 1.10 2008/01/02 12:06:50 andy_seaborne Exp $
006: */
007:
008: package com.hp.hpl.jena.rdf.arp.test;
009:
010: import junit.framework.Test;
011: import junit.framework.TestCase;
012: import junit.framework.TestSuite;
013:
014: import com.hp.hpl.jena.rdf.arp.ARPErrorNumbers;
015: import com.hp.hpl.jena.rdf.model.Model;
016: import com.hp.hpl.jena.rdf.model.ModelFactory;
017: import com.hp.hpl.jena.rdf.model.RDFErrorHandler;
018: import com.hp.hpl.jena.rdf.model.RDFReader;
019: import com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler;
020: import com.hp.hpl.jena.shared.JenaException;
021:
022: /**
023: * @author jjc
024: *
025: */
026: public class ExceptionTests extends TestCase implements
027: RDFErrorHandler, ARPErrorNumbers {
028: static public Test suite() {
029: TestSuite suite = new TestSuite("ARP Exceptions");
030:
031: suite.addTest(new ExceptionTests("testDefaultFatal"));
032: suite.addTest(new ExceptionTests("testDefaultError"));
033: suite.addTest(new ExceptionTests("testDefaultWarning"));
034: suite.addTest(new ExceptionTests("testDefaultDemotedFatal"));
035: suite.addTest(new ExceptionTests("testDefaultPromotedError"));
036: suite.addTest(new ExceptionTests("testDefaultPromotedWarning"));
037: suite.addTest(new ExceptionTests("testNonExceptionFatal"));
038: suite.addTest(new ExceptionTests("testExceptionError"));
039: suite.addTest(new ExceptionTests("testExceptionWarning"));
040: return suite;
041: }
042:
043: ExceptionTests(String s) {
044: super (s);
045: }
046:
047: public void testDefaultFatal() {
048: //E301
049: RDFDefaultErrorHandler.silent = true;
050: try {
051: Model m = ModelFactory.createDefaultModel();
052: m.read("file:testing/arp/error-msgs/test06.rdf");
053: fail("Fatal error did not throw exception");
054: } catch (JenaException e) {
055:
056: } finally {
057: RDFDefaultErrorHandler.silent = false;
058: }
059:
060: }
061:
062: public void testDefaultError() {
063:
064: // E206
065: RDFDefaultErrorHandler.silent = true;
066: try {
067: Model m = ModelFactory.createDefaultModel();
068: m.read("file:testing/wg/rdfms-abouteach/error002.rdf");
069: } catch (JenaException e) {
070: fail("Error threw exception");
071: } finally {
072: RDFDefaultErrorHandler.silent = false;
073: }
074:
075: }
076:
077: public void testDefaultWarning() {
078: // W108
079: RDFDefaultErrorHandler.silent = true;
080: try {
081: Model m = ModelFactory.createDefaultModel();
082: m.read("file:testing/arp/qname-in-ID/bug74_0.rdf");
083: } catch (JenaException e) {
084: fail("Warning threw exception");
085: } finally {
086: RDFDefaultErrorHandler.silent = false;
087: }
088: }
089:
090: public void testDefaultDemotedFatal() {
091:
092: RDFDefaultErrorHandler.silent = true;
093: try {
094: Model m = ModelFactory.createDefaultModel();
095: RDFReader rdr = m.getReader();
096: rdr.setProperty("ERR_SAX_FATAL_ERROR", "EM_ERROR");
097: rdr.read(m, "file:testing/arp/error-msgs/test06.rdf");
098: } catch (JenaException e) {
099: System.err.println(e.getMessage());
100: e.printStackTrace();
101: fail("Demoted fatal error threw an exception");
102: } finally {
103: RDFDefaultErrorHandler.silent = false;
104: }
105:
106: }
107:
108: public void testDefaultPromotedError() {
109:
110: RDFDefaultErrorHandler.silent = true;
111: try {
112: Model m = ModelFactory.createDefaultModel();
113: RDFReader rdr = m.getReader();
114: rdr.setProperty("ERR_BAD_RDF_ATTRIBUTE", "EM_FATAL");
115: rdr.read(m, "file:testing/wg/rdfms-abouteach/error002.rdf");
116:
117: fail("Promoted error did not throw exception");
118: } catch (JenaException e) {
119: // System.err.println(e.getMessage());
120: } finally {
121: RDFDefaultErrorHandler.silent = false;
122: }
123:
124: }
125:
126: public void testDefaultPromotedWarning() {
127:
128: RDFDefaultErrorHandler.silent = true;
129: try {
130:
131: Model m = ModelFactory.createDefaultModel();
132: RDFReader rdr = m.getReader();
133: rdr.setProperty("WARN_BAD_NAME", "EM_FATAL");
134: rdr.read(m, "file:testing/arp/qname-in-ID/bug74_0.rdf");
135:
136: fail("Promoted warning did not throw exception");
137: } catch (JenaException e) {
138: } finally {
139: RDFDefaultErrorHandler.silent = false;
140: }
141:
142: }
143:
144: public void testNonExceptionFatal() {
145:
146: try {
147: Model m = ModelFactory.createDefaultModel();
148: RDFReader rdr = m.getReader();
149: rdr.setErrorHandler(this );
150: rdr.read(m, "file:testing/arp/error-msgs/test06.rdf");
151: } catch (JenaException e) {
152: fail("Fatal error threw an exception with non-exception handler");
153: }
154:
155: }
156:
157: public void testExceptionError() {
158: try {
159: Model m = ModelFactory.createDefaultModel();
160: RDFReader rdr = m.getReader();
161: rdr.setErrorHandler(this );
162: rdr.read(m, "file:testing/wg/rdfms-abouteach/error002.rdf");
163:
164: fail("Error did not throw exception with non-standard handler");
165: } catch (JenaException e) {
166: }
167:
168: }
169:
170: public void testExceptionWarning() {
171: try {
172:
173: Model m = ModelFactory.createDefaultModel();
174: RDFReader rdr = m.getReader();
175: rdr.setErrorHandler(this );
176: rdr.read(m, "file:testing/arp/qname-in-ID/bug74_0.rdf");
177:
178: fail("Warning did not throw exception with non-standard handler");
179: } catch (JenaException e) {
180: }
181:
182: }
183:
184: public void warning(Exception e) {
185: throw new JenaException(e);
186: }
187:
188: public void error(Exception e) {
189: throw new JenaException(e);
190: }
191:
192: public void fatalError(Exception e) {
193: }
194:
195: }
196:
197: /*
198: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
199: All rights reserved.
200:
201: Redistribution and use in source and binary forms, with or without
202: modification, are permitted provided that the following conditions
203: are met:
204:
205: 1. Redistributions of source code must retain the above copyright
206: notice, this list of conditions and the following disclaimer.
207:
208: 2. Redistributions in binary form must reproduce the above copyright
209: notice, this list of conditions and the following disclaimer in the
210: documentation and/or other materials provided with the distribution.
211:
212: 3. The name of the author may not be used to endorse or promote products
213: derived from this software without specific prior written permission.
214:
215: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
216: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
217: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
218: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
219: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
220: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
221: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
222: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
223: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
224: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
225: */
|