1 7 8 package com.hp.hpl.jena.xmloutput.test; 9 10 import com.hp.hpl.jena.*; 11 import com.hp.hpl.jena.rdf.model.*; 12 import com.hp.hpl.jena.rdf.model.test.*; 13 import com.hp.hpl.jena.xmloutput.impl.*; 14 import com.hp.hpl.jena.rdf.model.impl.*; 15 import com.hp.hpl.jena.shared.*; 16 17 import java.io.*; 18 19 24 public class testWriterInterface extends ModelTestBase { 25 private String lang; 26 31 public testWriterInterface(String name, String lang) { 32 super(name); 33 this.lang = lang; 34 } 38 39 45 public void testLineSeparator() { 46 String newline = System.getProperty( "line.separator" ); 47 String newline_XMLNS = newline + " xmlns"; 48 Model m = modelWithStatements( "http://eh/spoo thingies something" ); 49 m.setNsPrefix( "eh", "http://eh/" ); 50 StringWriter sos = new StringWriter(); 51 m.write( sos ); 52 assertTrue( sos.toString().indexOf( newline_XMLNS ) > -1 ); 53 } 54 55 public void testInterface() { 56 Model m1 = createMemModel(); 57 assertTrue( "Default writer should be Basic.", m1.getWriter() instanceof Basic ); 58 assertTrue( "RDF/XML writer should be Basic.", m1.getWriter() instanceof Basic ); 59 assertTrue( 60 "RDF/XML-ABBREV writer should be Abbreviated.", 61 m1.getWriter("RDF/XML-ABBREV") instanceof Abbreviated); 62 assertTrue( 63 "N-TRIPLE writer should be NTripleWriter.", 64 m1.getWriter("N-TRIPLE") instanceof NTripleWriter); 65 } 66 67 public void testNoWriter() { 68 Model m1 = createMemModel(); 69 try { 70 m1.setWriterClassName("foobar", ""); 71 m1.getWriter("foobar"); 72 fail("Missing Writer undetected."); 73 } catch (NoWriterForLangException jx) { 74 } 76 } 77 78 public void testAnotherWriter() { 79 Model m1 = createMemModel(); 80 m1.setWriterClassName("foobar", Jena.PATH + ".xmloutput.impl.Basic"); 81 assertTrue( 82 "Failed to access set writer", 83 (m1.getWriter("foobar") instanceof Basic)); 84 } 85 86 public void testWriting() { 87 OutputStream output = null; 91 Model m1 = createMemModel(); 92 try { 93 ByteArrayOutputStream out = new ByteArrayOutputStream() ; 94 output = out ; 95 m1.write(output, lang); 96 out.reset() ; 97 output.close() ; 98 } catch (Exception e) { 99 fail(e.getMessage()); 100 } finally { 101 if (output != null) 102 try { 103 output.close(); 104 } catch (Exception e) { } 105 } 106 } 107 108 } 109 137 | Popular Tags |