KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > xmloutput > test > testWriterInterface


1 /*
2     (c) Copyright 2001, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3     All rights reserved.
4     [See end of file]
5     $Id: testWriterInterface.java,v 1.12 2005/02/21 12:22:55 andy_seaborne Exp $
6 */

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 /**
20  *
21  * @author bwm, jjc
22  * @version $Revision: 1.12 $
23  */

24 public class testWriterInterface extends ModelTestBase {
25     private String JavaDoc lang;
26     /**
27      * Constructor requires that all tests be named
28      *
29      * @param name The name of this test
30      */

31     public testWriterInterface(String JavaDoc name, String JavaDoc lang) {
32         super(name);
33         this.lang = lang;
34         //if ( lang!=null)
35
//setName(name+"("+lang+")");
36
//this.
37
}
38
39     /**
40          Introduced to cope with bug 832682: double spacing on windows platforms.
41          Make sure the xmlns prefixes are introduced by the correct line separator.
42          (Java doesn't appear to understand that the notion of "line separator" should
43          be portable ... come back C, all is forgiven. Well, not *all* ...)
44     */

45     public void testLineSeparator() {
46         String JavaDoc newline = System.getProperty( "line.separator" );
47         String JavaDoc 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             // that's what we expected
75
}
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         // Changed to use "in-memory files" (ByteArrayOutputStream)
88
// Used to use temporary file.
89
//System.err.println(lang);
90
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 JavaDoc e) {
99             fail(e.getMessage());
100         } finally {
101             if (output != null)
102                 try {
103                     output.close();
104                 } catch (Exception JavaDoc e) { }
105         }
106     }
107
108 }
109 /*
110  * (c) Copyright 2001,2003, 2004, 2005 Hewlett-Packard Development Company, LP
111  * All rights reserved.
112  *
113  * Redistribution and use in source and binary forms, with or without
114  * modification, are permitted provided that the following conditions
115  * are met:
116  * 1. Redistributions of source code must retain the above copyright
117  * notice, this list of conditions and the following disclaimer.
118  * 2. Redistributions in binary form must reproduce the above copyright
119  * notice, this list of conditions and the following disclaimer in the
120  * documentation and/or other materials provided with the distribution.
121  * 3. The name of the author may not be used to endorse or promote products
122  * derived from this software without specific prior written permission.
123
124  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
125  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
126  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
127  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
128  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
129  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
130  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
131  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
132  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
133  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
134  *
135  * $Id: testWriterInterface.java,v 1.12 2005/02/21 12:22:55 andy_seaborne Exp $
136  */

137
Popular Tags