KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.hp.hpl.jena.n3.* ;
10 import junit.framework.* ;
11
12 import com.hp.hpl.jena.rdf.model.* ;
13 import com.hp.hpl.jena.util.FileManager;
14 /**
15  * @author Andy Seaborne
16  * @version $Id: N3JenaReaderTests.java,v 1.9 2005/02/21 12:04:09 andy_seaborne Exp $
17  */

18 public class N3JenaReaderTests extends N3ExternalTestsCom
19 {
20     static public boolean VERBOSE = false ;
21
22     public N3JenaReaderTests()
23     {
24         this("n3-reader-tests") ;
25     }
26     
27     public N3JenaReaderTests(String JavaDoc filename)
28     {
29         super("N3 Jena Reader tests", filename) ;
30     }
31
32     protected void makeTest(String JavaDoc n3File, String JavaDoc resultsFile)
33     {
34         String JavaDoc testName = n3File ;
35
36         if ( basedir != null )
37             n3File = basedir+"/"+n3File ;
38
39         if ( basedir != null && resultsFile != null && !resultsFile.equals("") )
40             resultsFile = basedir + "/" + resultsFile ;
41             
42         addTest(new Test(testName, n3File, resultsFile)) ;
43     }
44
45     static class Test extends TestCase
46     {
47         RDFReader reader = null ;
48         String JavaDoc basename = null ;
49         String JavaDoc n3File = null ;
50         String JavaDoc resultsFile = null ;
51         Model dModel = null ;
52         Model rModel = null ;
53         Reader rData = null ;
54         
55         Test(String JavaDoc testName, String JavaDoc _n3File, String JavaDoc _resultsFile)
56         {
57             super("N3 Jena Reader test: "+testName) ;
58             n3File = _n3File ;
59             resultsFile = _resultsFile ;
60             try {
61                 
62                 rData = makeReader(new FileInputStream(n3File)) ;
63
64                 // Check the files exist
65
dModel = ModelFactory.createDefaultModel() ;
66                 
67                 if ( resultsFile != null && !resultsFile.equals("") )
68                 {
69                     rModel = FileManager.get().loadModel(resultsFile, null) ;
70                     if ( rModel == null )
71                         System.err.println("Failed to find results file "+resultsFile) ;
72                 }
73                 
74                 // Manually create a jena reader while not fully integrated into Jena
75
reader = new N3JenaReader() ;
76                 int ind = n3File.lastIndexOf(File.pathSeparatorChar) ;
77                 if ( ind == -1 )
78                     // Not found: maybe UNIX syntax on windows.
79
ind = n3File.lastIndexOf('/') ;
80                 String JavaDoc x = n3File.substring(ind+1) ;
81                 // Use a fake basename to make this more portable.
82
// The tests results data knows this basename.
83
basename = "file:///base/"+x ;
84                 //basename = basename.replace('\\', '/') ;
85
} catch (IOException ioEx)
86             {
87                 System.err.println("IO Exception: "+ioEx) ;
88             }
89         }
90     
91         
92         protected void runTest() throws Throwable JavaDoc
93         {
94             reader.read(dModel, rData, basename) ;
95             if ( VERBOSE )
96             {
97                 PrintWriter w = makeWriter(System.out) ;
98                 BufferedReader r = makeReader(new FileInputStream(n3File)) ;
99                 w.println("+++++++ "+this.getName()) ;
100                 for ( String JavaDoc s = r.readLine(); s != null ; s = r.readLine())
101                     w.println(s) ;
102                 w.println("+++++++") ;
103                 dModel.write(w, "N-TRIPLE") ;
104                 w.println("+++++++") ;
105                 w.flush() ;
106             }
107             if ( rModel != null )
108             {
109                 if ( ! dModel.isIsomorphicWith(rModel) )
110                 {
111                     
112                     PrintWriter w = makeWriter(System.out) ;
113                     w.println("+++++++ "+super.getName()) ;
114                     w.println("---- Created") ;
115                     dModel.write(w, "N-TRIPLE") ;
116                     w.println("---- Expected ") ;
117                     rModel.write(w, "N-TRIPLE") ;
118                     w.println("+++++++"+super.getName()) ;
119                     w.flush() ;
120                     assertTrue("Model compare failed: "+super.getName(), false) ;
121                 }
122             }
123                 
124         }
125     }
126
127 }
128
129 /*
130  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
131  * All rights reserved.
132  *
133  * Redistribution and use in source and binary forms, with or without
134  * modification, are permitted provided that the following conditions
135  * are met:
136  * 1. Redistributions of source code must retain the above copyright
137  * notice, this list of conditions and the following disclaimer.
138  * 2. Redistributions in binary form must reproduce the above copyright
139  * notice, this list of conditions and the following disclaimer in the
140  * documentation and/or other materials provided with the distribution.
141  * 3. The name of the author may not be used to endorse or promote products
142  * derived from this software without specific prior written permission.
143  *
144  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
145  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
146  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
147  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
148  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
149  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
150  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
151  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
152  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
153  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
154  */

155
Popular Tags