KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP All
3  * rights reserved. [See end of file] $Id: TestXMLFeatures.java,v 1.35
4  * 2003/11/29 15:07:53 jeremy_carroll Exp $
5  */

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 JavaDoc name) {
24         super(name);
25     }
26     public String JavaDoc 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     /**
37      * @param filename
38      * Read this file
39      * @param regex
40      * Error msg must match this.
41      *
42     private void check(String filename, String regex)
43         throws IOException, MalformedPatternException, SAXException {
44         check(filename, regex, null);
45     }
46     */

47     private void check(
48         String JavaDoc filename,
49         String JavaDoc regexPresent,
50         String JavaDoc regexAbsent)
51         throws IOException, MalformedPatternException {
52         final StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
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 JavaDoc 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 JavaDoc {
93         check("test01",null,"Unusual");
94     }
95
96     public void testErrMsg02() throws Exception JavaDoc {
97         check("test02","parseType","Unusual");
98     }
99     public void testErrMsg03() throws Exception JavaDoc {
100         check("test03","parseType","Unusual");
101     }
102     public void testErrMsg04a() throws Exception JavaDoc {
103         check("test04",null,"Unusual");
104     }
105     public void testErrMsg04b() throws Exception JavaDoc {
106         check("test04",null,"parseType");
107     }
108     public void testErrMsg05() throws Exception JavaDoc {
109         check("test05",null,"Unusual");
110     }
111     public void testUTF8() throws Exception JavaDoc {
112         check("testutf8","UTF","Unusual");
113     }
114 }
115 /*
116  * (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP All
117  * rights reserved.
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions are met: 1.
121  * Redistributions of source code must retain the above copyright notice, this
122  * list of conditions and the following disclaimer. 2. Redistributions in
123  * binary form must reproduce the above copyright notice, this list of
124  * conditions and the following disclaimer in the documentation and/or other
125  * materials provided with the distribution. 3. The name of the author may not
126  * be used to endorse or promote products derived from this software without
127  * specific prior written permission.
128  *
129  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
130  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
131  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
132  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
133  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
134  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
135  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
136  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
137  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
138  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
139  *
140  * $Id: TestErrorMsg.java,v 1.5 2005/02/21 12:11:08 andy_seaborne Exp $
141  */

142
Popular Tags