KickJava   Java API By Example, From Geeks To Geeks.

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


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: testReaderInterface.java,v 1.14 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 com.hp.hpl.jena.rdf.model.impl.*;
34
35 import java.net.*;
36 import java.io.*;
37
38 import com.hp.hpl.jena.shared.*;
39
40 import org.apache.commons.logging.Log;
41 import org.apache.commons.logging.LogFactory;
42
43 /**
44  *
45  * @author bwm
46  * @version $Revision: 1.14 $
47  */

48 public class testReaderInterface extends Object JavaDoc {
49
50
51     protected static void doTest(Model m1) {
52         (new testReaderInterface()).test(m1);
53     }
54
55     protected static Log logger = LogFactory.getLog( testReaderInterface.class );
56     
57     void test(Model m1) {
58
59         String JavaDoc test = "testReaderInterface";
60         String JavaDoc filebase = "modules/rdf/regression/" + test + "/";
61     // System.out.println("Beginning " + test);
62
int n = 0;
63         try {
64             n++; RDFReader reader = m1.getReader();
65
66             /*
67             if (! (reader instanceof com.hp.hpl.jena.rdf.arp.JenaReader ))
68                  error(test, n);
69
70             n++; reader = m1.getReader("RDF/XML");
71             if (! (reader instanceof com.hp.hpl.jena.rdf.arp.JenaReader ))
72                  error(test, n);
73             */

74
75             n++; reader = m1.getReader("N-TRIPLE");
76                  if (! (reader instanceof NTripleReader)) error(test, n);
77
78             n++; try {
79                     m1.setReaderClassName("foobar", "");
80                     reader = m1.getReader("foobar");
81                     error(test, n);
82                  } catch (NoReaderForLangException jx) {
83                      // that's what we expect
84
}
85
86             n++; m1.setReaderClassName("foobar",
87                                        com.hp.hpl.jena.rdf.arp.JenaReader.class.getName());
88                  reader = m1.getReader("foobar");
89                  if (! (reader instanceof com.hp.hpl.jena.rdf.arp.JenaReader)) error(test, n);
90
91                  try {
92
93                 n++; m1.read("http://www.w3.org/2000/10/rdf-tests/rdfcore/"
94                           + "rdf-containers-syntax-vs-schema/test001.rdf");
95
96                 n++; m1.read("http://www.w3.org/2000/10/rdf-tests/rdfcore/"
97                           + "rdf-containers-syntax-vs-schema/test001.nt",
98                              "N-TRIPLE");
99                 } catch (JenaException jx)
100                     {
101                     if (jx.getCause() instanceof NoRouteToHostException
102                         || jx.getCause() instanceof UnknownHostException
103                         || jx.getCause() instanceof ConnectException
104                         || jx.getCause() instanceof IOException
105                         )
106                         {logger.warn("Cannot access public internet - part of test not executed" );
107                         }
108                     else
109                         throw jx;
110                     }
111
112
113             n++; m1.read(ResourceReader.getInputStream(filebase + "1.rdf"), "http://example.org/");
114
115             n++; m1.read(
116                     ResourceReader.getInputStream(filebase + "2.nt"), "", "N-TRIPLE");
117
118
119         } catch (Exception JavaDoc e) {
120             inError = true;
121             logger.error( " test " + test + "[" + n + "]", e);
122         }
123       // System.out.println("End of " + test);
124
}
125     private boolean inError = false;
126
127     protected void error(String JavaDoc test, int n) {
128         System.out.println(test + ": failed test " + Integer.toString(n));
129         inError = true;
130     }
131
132     public boolean getErrors() {
133         return inError;
134     }
135
136 }
137
Popular Tags