1 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 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 s) { 40 super(s); 41 } 42 43 public void testDefaultFatal() { 44 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 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 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 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 } 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 e) { 193 throw new JenaException(e); 194 } 195 196 public void error(Exception e) { 197 throw new JenaException(e); 198 } 199 200 public void fatalError(Exception e) { 201 } 202 203 } 204 205 | Popular Tags |