KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > regression > testNTripleReader


1 /*
2  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * $Id: testNTripleReader.java,v 1.9 2005/02/21 12:18:40 andy_seaborne Exp $
28  */

29
30 package com.hp.hpl.jena.regression;
31
32 import com.hp.hpl.jena.rdf.model.*;
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35
36 /**
37  *
38  * @author bwm
39  * @version $Revision: 1.9 $
40  */

41 public class testNTripleReader extends Object JavaDoc {
42    
43     
44     protected static void doTest(Model m1) {
45         (new testNTripleReader()).test(m1);
46     }
47     
48     protected static Log logger = LogFactory.getLog( testNTripleReader.class );
49     
50     void test(Model m1) {
51
52         String JavaDoc test = "testNTripleReader";
53         String JavaDoc filebase = "modules/rdf/regression/" + test + "/";
54     // System.out.println("Beginning " + test);
55
int n = 0;
56         try {
57                  empty(m1);
58             n++; m1.read(ResourceReader.getInputStream(filebase + "1.nt"), "", "N-TRIPLE");
59                  if (m1.size() != 5) error(test, n);
60                  StmtIterator iter =
61                      m1.listStatements( null, null, "foo\"\\\n\r\tbar" );
62             n++; if (! iter.hasNext()) error(test, n);
63         } catch (Exception JavaDoc e) {
64             inError = true;
65             logger.error( " test " + test + "[" + n + "]", e);
66         }
67   // System.out.println("End of " + test);
68
}
69     
70     protected void empty(Model m) {
71         StmtIterator iter = m.listStatements();
72         while (iter.hasNext()) {
73             iter.nextStatement();
74             iter.remove();
75         }
76     }
77     private boolean inError = false;
78        
79     protected void error(String JavaDoc test, int n) {
80         System.out.println(test + ": failed test " + Integer.toString(n));
81         inError = true;
82     }
83     
84     public boolean getErrors() {
85         return inError;
86     }
87      
88 }
89
Popular Tags