KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > n3 > test > N3JenaWriterTests


1 /*
2  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3  * [See end of file]
4  */

5
6 package com.hp.hpl.jena.n3.test ;
7
8 import java.io.* ;
9 import junit.framework.* ;
10
11 import com.hp.hpl.jena.n3.* ;
12 import com.hp.hpl.jena.rdf.model.*;
13
14 /**
15  * @author Andy Seaborne
16  * @version $Id: N3JenaWriterTests.java,v 1.12 2005/02/21 12:04:10 andy_seaborne Exp $
17  */

18 public class N3JenaWriterTests extends N3ExternalTestsCom
19 {
20     /* JUnit swingUI needed this */
21     static public TestSuite suite() {
22         return new N3JenaWriterTests() ;
23     }
24     
25     static final String JavaDoc uriBase = "http://host/base/" ;
26     
27     public N3JenaWriterTests()
28     {
29         this("n3-writer-tests") ;
30     }
31     
32     public N3JenaWriterTests(String JavaDoc filename)
33     {
34         super("N3 Jena Writer tests", filename) ;
35     }
36
37     
38     protected void makeTest(String JavaDoc inputFile, String JavaDoc resultsFile)
39     {
40         String JavaDoc testName = inputFile ;
41
42         if ( basedir != null )
43             inputFile = basedir+"/"+inputFile ;
44
45         if ( basedir != null && resultsFile != null && !resultsFile.equals("") )
46             resultsFile = basedir + "/" + resultsFile ;
47             
48         // Run on each of the writers
49
addTest(new Test(testName, inputFile, resultsFile,
50                          N3JenaWriter.n3WriterPrettyPrinter)) ;
51         addTest(new Test(testName, inputFile, resultsFile,
52                          N3JenaWriter.n3WriterPlain)) ;
53         addTest(new Test(testName, inputFile, resultsFile,
54                          N3JenaWriter.n3WriterTriples)) ;
55     }
56
57
58     static class Test extends TestCase
59     {
60         String JavaDoc writerName = null ;
61         String JavaDoc testName = null ;
62         String JavaDoc basename = null ;
63         String JavaDoc inputFile = null ;
64         String JavaDoc resultsFile = null ;
65         Reader data = null ;
66         
67         
68         Test(String JavaDoc _testName, String JavaDoc _inputFile, String JavaDoc _resultsFile, String JavaDoc wName)
69         {
70             super("N3 Jena Writer test: "+_testName+"-"+wName) ;
71             testName = _testName ;
72             inputFile = _inputFile ;
73             resultsFile = _resultsFile ;
74             writerName = wName ;
75         }
76         
77         protected void runTest() throws Throwable JavaDoc
78         {
79             try {
80                 data = makeReader(new FileInputStream(inputFile)) ;
81             } catch (IOException ioEx)
82             {
83                 fail("File does not exist: "+inputFile) ;
84                 return ;
85             }
86
87             // Test: write model to a string, read it again and see if same/isomorphic
88

89             Model model_1 = ModelFactory.createDefaultModel() ;
90             model_1.read(data, uriBase, "N3") ;
91             
92             StringWriter w = new StringWriter() ;
93             model_1.write(w, writerName, uriBase) ;
94             // Check we really are writing different things!
95
//model_1.write(System.out, writerName, uriBase) ;
96
w.close() ;
97             
98             StringReader r = new StringReader(w.toString()) ;
99             Model model_2 = ModelFactory.createDefaultModel() ;
100             model_2.read(r, uriBase, "N3") ;
101             
102             if ( ! model_1.isIsomorphicWith(model_2) )
103             {
104                 System.out.println("#### ---- "+testName+" ------------------------------") ;
105                 System.out.println("#### Model 1 ---- "+testName+" ------------------------------") ;
106                 model_1.write(System.out, "N3") ;
107                 System.out.println("#### Model 2 --- "+testName+" ------------------------------") ;
108                 model_2.write(System.out, "N3") ;
109                 assertTrue("Models don't match: "+testName, false) ;
110             }
111         }
112     }
113 }
114
115
116 /*
117  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
118  * All rights reserved.
119  *
120  * Redistribution and use in source and binary forms, with or without
121  * modification, are permitted provided that the following conditions
122  * are met:
123  * 1. Redistributions of source code must retain the above copyright
124  * notice, this list of conditions and the following disclaimer.
125  * 2. Redistributions in binary form must reproduce the above copyright
126  * notice, this list of conditions and the following disclaimer in the
127  * documentation and/or other materials provided with the distribution.
128  * 3. The name of the author may not be used to endorse or promote products
129  * derived from this software without specific prior written permission.
130  *
131  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
132  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
133  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
134  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
135  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
136  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
137  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
138  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
139  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
140  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
141  */

142
Popular Tags