1 5 6 package com.hp.hpl.jena.rdf.arp.test; 7 8 import java.io.FileInputStream ; 9 import java.io.InputStream ; 10 import java.util.Arrays ; 11 12 import org.apache.xerces.parsers.SAXParser; 13 import org.xml.sax.InputSource ; 14 import org.xml.sax.SAXParseException ; 15 import org.xml.sax.XMLReader ; 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 30 public class SAX2RDFMoreTests extends TestCase { 31 public SAX2RDFMoreTests(String nm) { 32 super(nm); 33 } 34 35 public void testLang() throws Exception { 36 Model m = ModelFactory.createDefaultModel(); 37 Model m2 = ModelFactory.createDefaultModel(); 38 InputStream in = new FileInputStream ( 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 ("testing/wg/rdfms-xmllang/test003.rdf"); 46 47 RDFEHArray eh2 = new RDFEHArray(); 48 49 XMLReader 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 ins = new InputSource (in); 56 ins.setSystemId("http://example.org/"); 57 try { 58 try { 59 saxParser.parse(ins); 60 } finally { 61 handler.close(); 62 } 63 } catch (SAXParseException e) { 64 } 66 67 in.close(); 68 73 if (eh.v.size() == 0) 74 assertTrue("Not isomorphic", m.isIsomorphicWith(m2)); 75 79 assertEquals("Different number of errors", eh.v.size(), eh2.v.size()); 80 81 Object a[] = eh.v.toArray(); 82 Object 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 119 120 | Popular Tags |