1 7 8 package com.hp.hpl.jena.xmloutput.test; 11 12 15 import com.hp.hpl.jena.rdf.model.*; 16 import com.hp.hpl.jena.rdf.model.test.*; 17 import com.hp.hpl.jena.ontology.*; 18 21 import org.apache.oro.text.awk.AwkCompiler; 22 import org.apache.oro.text.awk.AwkMatcher; 23 import org.apache.oro.text.regex.MalformedPatternException; 24 25 import java.io.*; 26 27 33 34 public class PrettyWriterTest extends ModelTestBase { 35 36 41 public PrettyWriterTest(String name) { 42 super(name); 43 } 44 45 static AwkCompiler awk = new AwkCompiler(); 48 static AwkMatcher matcher = new AwkMatcher(); 49 50 55 private void check(String filename, String regex) 56 throws IOException, MalformedPatternException { 57 String contents = null; 58 try { 59 Model m = createMemModel(); 60 m.read(filename); 61 StringWriter sw = new StringWriter(); 62 m.write(sw, "RDF/XML-ABBREV", filename); 63 sw.close(); 64 contents = sw.toString(); 65 Model m2 = createMemModel(); 66 m2.read(new StringReader(contents), filename); 67 assertTrue(m.isIsomorphicWith(m2)); 68 assertTrue( 69 "Looking for /" + regex + "/", 70 matcher.contains(contents, awk.compile(regex))); 71 contents = null; 72 } finally { 73 if (contents != null) { 74 System.err.println("Incorrect contents:"); 75 System.err.println(contents); 76 } 77 } 78 } 79 80 public void testAnonDamlClass() 81 throws IOException, MalformedPatternException { 82 check( 83 "file:testing/abbreviated/daml.rdf", 84 "rdf:parseType=[\"']daml:collection[\"']"); 85 } 86 87 public void testRDFCollection() 88 throws IOException, MalformedPatternException { 89 check( 90 "file:testing/abbreviated/collection.rdf", 91 "rdf:parseType=[\"']Collection[\"']"); 92 } 93 94 public void testOWLPrefix() throws IOException, MalformedPatternException { 95 } 99 100 public void testLi() throws IOException, MalformedPatternException { 101 check( 102 "file:testing/abbreviated/container.rdf", 103 "<rdf:li.*<rdf:li.*<rdf:li.*<rdf:li"); 104 } 105 public void test803804() { 106 String sourceT = 107 "<rdf:RDF " 108 + " xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'" 109 + " xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'" 110 + " xmlns:owl=\"http://www.w3.org/2002/07/owl#\">" 111 + " <owl:ObjectProperty rdf:about=" 112 + "'http://example.org/foo#p'>" 113 + " </owl:ObjectProperty>" 114 + "</rdf:RDF>"; 115 116 OntModel m = 117 ModelFactory.createOntologyModel( 118 OntModelSpec.OWL_MEM_RULE_INF, 119 null); 120 m.read( 121 new ByteArrayInputStream(sourceT.getBytes()), 122 "http://example.org/foo"); 123 124 Model m0 = ModelFactory.createModelForGraph(m.getGraph()); 125 144 TestXMLFeatures.blockLogger(); 145 try { 146 m0.write(new OutputStream() { 147 public void write(int b) throws IOException { 148 } 149 }, "RDF/XML-ABBREV"); 150 151 } finally { 152 154 assertTrue(TestXMLFeatures.unblockLogger()); 155 } 156 } 157 } 158 159 197 | Popular Tags |