001: /*
002: (c) Copyright 2001, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: All rights reserved.
004: [See end of file]
005: $Id: testWriterInterface.java,v 1.16 2008/01/02 12:06:48 andy_seaborne Exp $
006: */
007:
008: package com.hp.hpl.jena.xmloutput.test;
009:
010: import java.io.ByteArrayOutputStream;
011: import java.io.OutputStream;
012: import java.io.StringWriter;
013:
014: import com.hp.hpl.jena.Jena;
015: import com.hp.hpl.jena.rdf.model.Model;
016: import com.hp.hpl.jena.rdf.model.impl.NTripleWriter;
017: import com.hp.hpl.jena.rdf.model.test.ModelTestBase;
018: import com.hp.hpl.jena.shared.NoWriterForLangException;
019: import com.hp.hpl.jena.xmloutput.impl.Abbreviated;
020: import com.hp.hpl.jena.xmloutput.impl.Basic;
021:
022: /**
023: *
024: * @author bwm, jjc
025: * @version $Revision: 1.16 $
026: */
027: public class testWriterInterface extends ModelTestBase {
028: private String lang;
029:
030: /**
031: * Constructor requires that all tests be named
032: *
033: * @param name The name of this test
034: */
035: public testWriterInterface(String name, String lang) {
036: super (name);
037: this .lang = lang;
038: //if ( lang!=null)
039: //setName(name+"("+lang+")");
040: //this.
041: }
042:
043: /**
044: Introduced to cope with bug 832682: double spacing on windows platforms.
045: Make sure the xmlns prefixes are introduced by the correct line separator.
046: (Java doesn't appear to understand that the notion of "line separator" should
047: be portable ... come back C, all is forgiven. Well, not *all* ...)
048: */
049: public void testLineSeparator() {
050: String newline = System.getProperty("line.separator");
051: String newline_XMLNS = newline + " xmlns";
052: Model m = modelWithStatements("http://eh/spoo thingies something");
053: m.setNsPrefix("eh", "http://eh/");
054: StringWriter sos = new StringWriter();
055: m.write(sos);
056: assertTrue(sos.toString().indexOf(newline_XMLNS) > -1);
057: }
058:
059: public void testInterface() {
060: Model m1 = createMemModel();
061: assertTrue("Default writer should be Basic.",
062: m1.getWriter() instanceof Basic);
063: assertTrue("RDF/XML writer should be Basic.",
064: m1.getWriter() instanceof Basic);
065: assertTrue("RDF/XML-ABBREV writer should be Abbreviated.", m1
066: .getWriter("RDF/XML-ABBREV") instanceof Abbreviated);
067: assertTrue("N-TRIPLE writer should be NTripleWriter.", m1
068: .getWriter("N-TRIPLE") instanceof NTripleWriter);
069: }
070:
071: public void testNoWriter() {
072: Model m1 = createMemModel();
073: try {
074: m1.setWriterClassName("foobar", "");
075: m1.getWriter("foobar");
076: fail("Missing Writer undetected.");
077: } catch (NoWriterForLangException jx) {
078: // that's what we expected
079: }
080: }
081:
082: public void testAnotherWriter() {
083: Model m1 = createMemModel();
084: m1.setWriterClassName("foobar", Jena.PATH
085: + ".xmloutput.impl.Basic");
086: assertTrue("Failed to access set writer", (m1
087: .getWriter("foobar") instanceof Basic));
088: }
089:
090: public void testWriting() {
091: // Changed to use "in-memory files" (ByteArrayOutputStream)
092: // Used to use temporary file.
093: //System.err.println(lang);
094: OutputStream output = null;
095: Model m1 = createMemModel();
096: try {
097: ByteArrayOutputStream out = new ByteArrayOutputStream();
098: output = out;
099: m1.write(output, lang);
100: out.reset();
101: output.close();
102: } catch (Exception e) {
103: fail(e.getMessage());
104: } finally {
105: if (output != null)
106: try {
107: output.close();
108: } catch (Exception e) {
109: }
110: }
111: }
112:
113: }
114: /*
115: * (c) Copyright 2001,2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
116: * All rights reserved.
117: *
118: * Redistribution and use in source and binary forms, with or without
119: * modification, are permitted provided that the following conditions
120: * are met:
121: * 1. Redistributions of source code must retain the above copyright
122: * notice, this list of conditions and the following disclaimer.
123: * 2. Redistributions in binary form must reproduce the above copyright
124: * notice, this list of conditions and the following disclaimer in the
125: * documentation and/or other materials provided with the distribution.
126: * 3. The name of the author may not be used to endorse or promote products
127: * derived from this software without specific prior written permission.
128:
129: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
130: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
131: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
132: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
133: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
134: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
135: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
136: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
137: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
138: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
139: *
140: * $Id: testWriterInterface.java,v 1.16 2008/01/02 12:06:48 andy_seaborne Exp $
141: */
|