001: /*
002: * (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP All
003: * rights reserved. [See end of file] $Id: TestXMLFeatures.java,v 1.35
004: * 2003/11/29 15:07:53 jeremy_carroll Exp $
005: */
006:
007: package com.hp.hpl.jena.rdf.arp.test;
008:
009: import java.io.FileInputStream;
010: import java.io.IOException;
011: import java.io.InputStream;
012: import java.util.regex.Pattern;
013:
014: import junit.framework.Test;
015: import junit.framework.TestCase;
016: import junit.framework.TestSuite;
017:
018: import org.xml.sax.ErrorHandler;
019: import org.xml.sax.SAXException;
020: import org.xml.sax.SAXParseException;
021:
022: import com.hp.hpl.jena.rdf.arp.ARP;
023:
024: public class TestErrorMsg extends TestCase {
025:
026: public TestErrorMsg(String name) {
027: super (name);
028: }
029:
030: public String toString() {
031: return getName();
032: }
033:
034: public static Test suite() {
035: TestSuite s = new TestSuite(TestErrorMsg.class);
036: s.setName("ARP Error Messages");
037: return s;
038: }
039:
040: /**
041: * @param filename
042: * Read this file
043: * @param regex
044: * Error msg must match this.
045: *
046: private void check(String filename, String regex)
047: throws IOException, MalformedPatternException, SAXException {
048: check(filename, regex, null);
049: }
050: */
051: private void check(String filename, String regexPresent,
052: String regexAbsent) throws IOException {
053: final StringBuffer buf = new StringBuffer();
054: ARP arp = new ARP();
055: arp.getHandlers().setErrorHandler(new ErrorHandler() {
056:
057: public void warning(SAXParseException exception) {
058: buf.append(exception.getMessage());
059: buf.append("\n");
060: }
061:
062: public void error(SAXParseException e) {
063: warning(e);
064: }
065:
066: public void fatalError(SAXParseException e) {
067: warning(e);
068: }
069:
070: });
071: InputStream in = new FileInputStream("testing/arp/error-msgs/"
072: + filename + ".rdf");
073: try {
074: arp.load(in, "file:///" + filename);
075: } catch (SAXException e) {
076:
077: }
078:
079: in.close();
080: String contents = buf.toString();
081:
082: if (regexPresent != null)
083: assertTrue("Should find /" + regexPresent + "/", Pattern
084: .compile(regexPresent, Pattern.DOTALL).matcher(
085: contents).find());
086: if (regexAbsent != null)
087: assertTrue("Should not find /" + regexAbsent + "/",
088: !Pattern.compile(regexAbsent, Pattern.DOTALL)
089: .matcher(contents).find());
090: contents = null;
091: }
092:
093: public void testErrMsg01() throws Exception {
094: check("test01", null, "Unusual");
095: }
096:
097: public void testErrMsg02() throws Exception {
098: check("test02", "parseType", "Unusual");
099: }
100:
101: public void testErrMsg03() throws Exception {
102: check("test03", "parseType", "Unusual");
103: }
104:
105: public void testErrMsg04a() throws Exception {
106: check("test04", null, "Unusual");
107: }
108:
109: public void testErrMsg04b() throws Exception {
110: check("test04", null, "parseType");
111: }
112:
113: public void testErrMsg05() throws Exception {
114: check("test05", null, "Unusual");
115: }
116:
117: public void testUTF8() throws Exception {
118: check("testutf8", "UTF", "Unusual");
119: }
120: }
121: /*
122: * (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP All
123: * rights reserved.
124: *
125: * Redistribution and use in source and binary forms, with or without
126: * modification, are permitted provided that the following conditions are met: 1.
127: * Redistributions of source code must retain the above copyright notice, this
128: * list of conditions and the following disclaimer. 2. Redistributions in
129: * binary form must reproduce the above copyright notice, this list of
130: * conditions and the following disclaimer in the documentation and/or other
131: * materials provided with the distribution. 3. The name of the author may not
132: * be used to endorse or promote products derived from this software without
133: * specific prior written permission.
134: *
135: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
136: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
137: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
138: * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
140: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
141: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
142: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
143: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
144: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145: *
146: * $Id: TestErrorMsg.java,v 1.13 2008/01/02 12:06:50 andy_seaborne Exp $
147: */
|