KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
3  * [See end of file]
4  */

5
6 package com.hp.hpl.jena.rdf.arp.test;
7
8 import java.io.FileInputStream JavaDoc;
9 import java.io.InputStream JavaDoc;
10 import java.util.Arrays JavaDoc;
11
12 import org.apache.xerces.parsers.SAXParser;
13 import org.xml.sax.InputSource JavaDoc;
14 import org.xml.sax.SAXParseException JavaDoc;
15 import org.xml.sax.XMLReader JavaDoc;
16
17 import com.hp.hpl.jena.rdf.arp.SAX2Model;
18 import com.hp.hpl.jena.rdf.arp.SAX2RDF;
19 import com.hp.hpl.jena.rdf.arp.test.SAX2RDFTest.RDFEHArray;
20 import com.hp.hpl.jena.rdf.model.Model;
21 import com.hp.hpl.jena.rdf.model.ModelFactory;
22 import com.hp.hpl.jena.rdf.model.RDFReader;
23
24 import junit.framework.TestCase;
25
26 /**
27  * @author Jeremy J. Carroll
28  *
29  */

30 public class SAX2RDFMoreTests extends TestCase {
31     public SAX2RDFMoreTests(String JavaDoc nm) {
32         super(nm);
33     }
34
35     public void testLang() throws Exception JavaDoc {
36         Model m = ModelFactory.createDefaultModel();
37         Model m2 = ModelFactory.createDefaultModel();
38         InputStream JavaDoc in = new FileInputStream JavaDoc(
39                 "testing/wg/rdfms-xmllang/test004.rdf");
40         RDFEHArray eh = new RDFEHArray();
41         RDFReader w = m.getReader();
42         w.setErrorHandler(eh);
43         w.read(m, in, "http://example.org/");
44         in.close();
45         in = new FileInputStream JavaDoc("testing/wg/rdfms-xmllang/test003.rdf");
46
47         RDFEHArray eh2 = new RDFEHArray();
48
49         XMLReader JavaDoc saxParser = new SAXParser();
50         SAX2Model handler = SAX2Model.newInstance("http://example.org/", m2,
51                 "fr");
52         SAX2RDF.installHandlers(saxParser, handler);
53         handler.setErrorHandler(eh2);
54
55         InputSource JavaDoc ins = new InputSource JavaDoc(in);
56         ins.setSystemId("http://example.org/");
57         try {
58             try {
59                 saxParser.parse(ins);
60             } finally {
61                 handler.close();
62             }
63         } catch (SAXParseException JavaDoc e) {
64             // already reported, leave it be.
65
}
66
67         in.close();
68         /*
69          * System.out.println("Normal:"); m.write(System.out,"N-TRIPLE");
70          *
71          * System.out.println("New:"); m2.write(System.out,"N-TRIPLE");
72          */

73         if (eh.v.size() == 0)
74             assertTrue("Not isomorphic", m.isIsomorphicWith(m2));
75         /*
76          * if ( eh.v.size()!=eh2.v.size()) { for (int i=0; i <a.length;i++)
77          * System.err.println(eh.v.get(i)); }
78          */

79         assertEquals("Different number of errors", eh.v.size(), eh2.v.size());
80
81         Object JavaDoc a[] = eh.v.toArray();
82         Object JavaDoc a2[] = eh2.v.toArray();
83         Arrays.sort(a);
84         Arrays.sort(a2);
85
86         for (int i = 0; i < eh.v.size(); i++) {
87             assertEquals("Error " + i + " different.", a[i], a2[i]);
88         }
89
90     }
91
92 }
93
94 /*
95  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP All rights
96  * reserved.
97  *
98  * Redistribution and use in source and binary forms, with or without
99  * modification, are permitted provided that the following conditions are met:
100  * 1. Redistributions of source code must retain the above copyright notice,
101  * this list of conditions and the following disclaimer. 2. Redistributions in
102  * binary form must reproduce the above copyright notice, this list of
103  * conditions and the following disclaimer in the documentation and/or other
104  * materials provided with the distribution. 3. The name of the author may not
105  * be used to endorse or promote products derived from this software without
106  * specific prior written permission.
107  *
108  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
109  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
110  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
111  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
112  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
113  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
114  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
115  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
116  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
117  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
118  */

119
120
Popular Tags