1 6 7 package com.hp.hpl.jena.rdf.arp.test; 8 9 import com.hp.hpl.jena.rdf.arp.*; 10 11 import junit.framework.*; 12 import org.xml.sax.*; 13 import org.apache.oro.text.awk.AwkCompiler; 14 import org.apache.oro.text.awk.AwkMatcher; 15 import org.apache.oro.text.regex.MalformedPatternException; 16 17 import java.io.*; 18 19 public class TestErrorMsg extends TestCase { 20 static AwkCompiler awk = new AwkCompiler(); 21 static AwkMatcher matcher = new AwkMatcher(); 22 23 public TestErrorMsg(String name) { 24 super(name); 25 } 26 public String toString() { 27 return getName(); 28 } 29 30 public static Test suite() { 31 TestSuite s= new TestSuite(TestErrorMsg.class); 32 s.setName("ARP Error Messages"); 33 return s; 34 } 35 36 47 private void check( 48 String filename, 49 String regexPresent, 50 String regexAbsent) 51 throws IOException, MalformedPatternException { 52 final StringBuffer buf = new StringBuffer (); 53 ARP arp = new ARP(); 54 arp.getHandlers().setErrorHandler(new ErrorHandler() { 55 56 public void warning(SAXParseException exception) { 57 buf.append(exception.getMessage()); 58 buf.append("\n"); 59 } 60 61 public void error(SAXParseException e) { 62 warning(e); 63 } 64 65 public void fatalError(SAXParseException e) { 66 warning(e); 67 } 68 69 }); 70 InputStream in = new FileInputStream("testing/arp/error-msgs/"+filename+".rdf"); 71 try { 72 arp.load(in, "file:///" + filename); 73 } 74 catch (SAXException e){ 75 76 } 77 78 in.close(); 79 String contents = buf.toString(); 80 81 if (regexPresent != null) 82 assertTrue( 83 "Should find /" + regexPresent + "/", 84 matcher.contains(contents, awk.compile(regexPresent))); 85 if (regexAbsent != null) 86 assertTrue( 87 "Should not find /" + regexAbsent + "/", 88 !matcher.contains(contents, awk.compile(regexAbsent))); 89 contents = null; 90 } 91 92 public void testErrMsg01() throws Exception { 93 check("test01",null,"Unusual"); 94 } 95 96 public void testErrMsg02() throws Exception { 97 check("test02","parseType","Unusual"); 98 } 99 public void testErrMsg03() throws Exception { 100 check("test03","parseType","Unusual"); 101 } 102 public void testErrMsg04a() throws Exception { 103 check("test04",null,"Unusual"); 104 } 105 public void testErrMsg04b() throws Exception { 106 check("test04",null,"parseType"); 107 } 108 public void testErrMsg05() throws Exception { 109 check("test05",null,"Unusual"); 110 } 111 public void testUTF8() throws Exception { 112 check("testutf8","UTF","Unusual"); 113 } 114 } 115 142 | Popular Tags |