001: /*
002: * (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: * [See end of file]
004: */
005:
006: package com.hp.hpl.jena.rdf.arp.test;
007:
008: import java.io.FileInputStream;
009: import java.io.InputStream;
010: import java.util.Arrays;
011:
012: import junit.framework.TestCase;
013:
014: import org.apache.xerces.parsers.SAXParser;
015: import org.xml.sax.InputSource;
016: import org.xml.sax.SAXParseException;
017: import org.xml.sax.XMLReader;
018:
019: import com.hp.hpl.jena.rdf.arp.SAX2Model;
020: import com.hp.hpl.jena.rdf.arp.SAX2RDF;
021: import com.hp.hpl.jena.rdf.arp.test.SAX2RDFTest.RDFEHArray;
022: import com.hp.hpl.jena.rdf.model.Model;
023: import com.hp.hpl.jena.rdf.model.ModelFactory;
024: import com.hp.hpl.jena.rdf.model.RDFReader;
025:
026: /**
027: * @author Jeremy J. Carroll
028: *
029: */
030: public class SAX2RDFMoreTests extends TestCase {
031: public SAX2RDFMoreTests(String nm) {
032: super (nm);
033: }
034:
035: public void testLang() throws Exception {
036: Model m = ModelFactory.createDefaultModel();
037: Model m2 = ModelFactory.createDefaultModel();
038: InputStream in = new FileInputStream(
039: "testing/wg/rdfms-xmllang/test004.rdf");
040: RDFEHArray eh = new RDFEHArray();
041: RDFReader w = m.getReader();
042: w.setErrorHandler(eh);
043: w.read(m, in, "http://example.org/");
044: in.close();
045: in = new FileInputStream("testing/wg/rdfms-xmllang/test003.rdf");
046:
047: RDFEHArray eh2 = new RDFEHArray();
048:
049: XMLReader saxParser = new SAXParser();
050: SAX2Model handler = SAX2Model.create("http://example.org/", m2,
051: "fr");
052: SAX2RDF.installHandlers(saxParser, handler);
053: handler.setErrorHandler(eh2);
054:
055: InputSource ins = new InputSource(in);
056: ins.setSystemId("http://example.org/");
057: try {
058: try {
059: saxParser.parse(ins);
060: } finally {
061: handler.close();
062: }
063: } catch (SAXParseException e) {
064: // already reported, leave it be.
065: }
066:
067: in.close();
068: /*
069: * System.out.println("Normal:"); m.write(System.out,"N-TRIPLE");
070: *
071: * System.out.println("New:"); m2.write(System.out,"N-TRIPLE");
072: */
073: if (eh.v.size() == 0)
074: assertTrue("Not isomorphic", m.isIsomorphicWith(m2));
075: /*
076: * if ( eh.v.size()!=eh2.v.size()) { for (int i=0; i <a.length;i++)
077: * System.err.println(eh.v.get(i)); }
078: */
079: assertEquals("Different number of errors", eh.v.size(), eh2.v
080: .size());
081:
082: Object a[] = eh.v.toArray();
083: Object a2[] = eh2.v.toArray();
084: Arrays.sort(a);
085: Arrays.sort(a2);
086:
087: for (int i = 0; i < eh.v.size(); i++) {
088: assertEquals("Error " + i + " different.", a[i], a2[i]);
089: }
090:
091: }
092:
093: }
094:
095: /*
096: * (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP All rights
097: * reserved.
098: *
099: * Redistribution and use in source and binary forms, with or without
100: * modification, are permitted provided that the following conditions are met:
101: * 1. Redistributions of source code must retain the above copyright notice,
102: * this list of conditions and the following disclaimer. 2. Redistributions in
103: * binary form must reproduce the above copyright notice, this list of
104: * conditions and the following disclaimer in the documentation and/or other
105: * materials provided with the distribution. 3. The name of the author may not
106: * be used to endorse or promote products derived from this software without
107: * specific prior written permission.
108: *
109: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
110: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
111: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
112: * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
113: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
114: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
115: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
116: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
117: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
118: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
119: */
|