KickJava   Java API By Example, From Geeks To Geeks.

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


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

7
8 // Package
9
///////////////
10
package com.hp.hpl.jena.xmloutput.test;
11
12 // Imports
13
///////////////
14

15 import com.hp.hpl.jena.rdf.model.*;
16 import com.hp.hpl.jena.rdf.model.test.*;
17 import com.hp.hpl.jena.ontology.*;
18 //import com.hp.hpl.jena.vocabulary.*;
19
//import java.util.*;
20

21 import org.apache.oro.text.awk.AwkCompiler;
22 import org.apache.oro.text.awk.AwkMatcher;
23 import org.apache.oro.text.regex.MalformedPatternException;
24
25 import java.io.*;
26
27 /**
28  * JUnit regression tests for the Jena DAML model.
29  *
30  * @author Jeremy Carroll
31  * @version CVS info: $Id: PrettyWriterTest.java,v 1.9 2005/02/21 12:22:52 andy_seaborne Exp $,
32  */

33
34 public class PrettyWriterTest extends ModelTestBase {
35
36     /**
37      * Constructor requires that all tests be named
38      *
39      * @param name The name of this test
40      */

41     public PrettyWriterTest(String JavaDoc name) {
42         super(name);
43     }
44
45     // Test cases
46
/////////////
47
static AwkCompiler awk = new AwkCompiler();
48     static AwkMatcher matcher = new AwkMatcher();
49
50     /**
51      *
52      * @param filename Read this file, write it out, read it in.
53      * @param regex Written file must match this.
54      */

55     private void check(String JavaDoc filename, String JavaDoc regex)
56         throws IOException, MalformedPatternException {
57         String JavaDoc contents = null;
58         try {
59             Model m = createMemModel();
60             m.read(filename);
61             StringWriter sw = new StringWriter();
62             m.write(sw, "RDF/XML-ABBREV", filename);
63             sw.close();
64             contents = sw.toString();
65             Model m2 = createMemModel();
66             m2.read(new StringReader(contents), filename);
67             assertTrue(m.isIsomorphicWith(m2));
68             assertTrue(
69                 "Looking for /" + regex + "/",
70                 matcher.contains(contents, awk.compile(regex)));
71             contents = null;
72         } finally {
73             if (contents != null) {
74                 System.err.println("Incorrect contents:");
75                 System.err.println(contents);
76             }
77         }
78     }
79
80     public void testAnonDamlClass()
81         throws IOException, MalformedPatternException {
82         check(
83             "file:testing/abbreviated/daml.rdf",
84             "rdf:parseType=[\"']daml:collection[\"']");
85     }
86
87     public void testRDFCollection()
88         throws IOException, MalformedPatternException {
89         check(
90             "file:testing/abbreviated/collection.rdf",
91             "rdf:parseType=[\"']Collection[\"']");
92     }
93
94     public void testOWLPrefix() throws IOException, MalformedPatternException {
95         // check(
96
// "file:testing/abbreviated/collection.rdf",
97
// "xmlns:owl=[\"']http://www.w3.org/2002/07/owl#[\"']");
98
}
99
100     public void testLi() throws IOException, MalformedPatternException {
101         check(
102             "file:testing/abbreviated/container.rdf",
103             "<rdf:li.*<rdf:li.*<rdf:li.*<rdf:li");
104     }
105     public void test803804() {
106         String JavaDoc sourceT =
107             "<rdf:RDF "
108                 + " xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'"
109                 + " xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'"
110                 + " xmlns:owl=\"http://www.w3.org/2002/07/owl#\">"
111                 + " <owl:ObjectProperty rdf:about="
112                 + "'http://example.org/foo#p'>"
113                 + " </owl:ObjectProperty>"
114                 + "</rdf:RDF>";
115
116         OntModel m =
117             ModelFactory.createOntologyModel(
118                 OntModelSpec.OWL_MEM_RULE_INF,
119                 null);
120         m.read(
121             new ByteArrayInputStream(sourceT.getBytes()),
122             "http://example.org/foo");
123
124         Model m0 = ModelFactory.createModelForGraph(m.getGraph());
125         /*
126               Set copyOfm0 = new HashSet();
127               Set blankNodes = new HashSet();
128               Iterator it = m0.listStatements();
129               while (it.hasNext()) {
130                 Statement st = (Statement)it.next();
131                   copyOfm0.add(st);
132                   Resource subj = st.getSubject();
133                   if (subj.isAnon())
134                     blankNodes.add(subj);
135               }
136               
137               it = blankNodes.iterator();
138               while (it.hasNext()) {
139                 Resource b = (Resource)it.next();
140                 Statement st = m0.createStatement(b,OWL.sameAs,b);
141             // assertEquals(m0.contains(st),copyOfm0.contains(st));
142               }
143         */

144         TestXMLFeatures.blockLogger();
145         try {
146             m0.write(new OutputStream() {
147                 public void write(int b) throws IOException {
148                 }
149             }, "RDF/XML-ABBREV");
150
151         } finally {
152             // This will need to change when the bug is finally fixed.
153

154             assertTrue(TestXMLFeatures.unblockLogger());
155         }
156     }
157 }
158
159 /*****************************************************************************
160  * Source code information
161  * -----------------------
162  * Original author Jeremy Carroll, HP Labs Bristol
163  * Author email jjc@hpl.hp.com
164  * Package Jena
165  * Created 10 Nov 2000
166  * Filename $RCSfile: PrettyWriterTest.java,v $
167  * Revision $Revision: 1.9 $
168  *
169  * Last modified on $Date: 2005/02/21 12:22:52 $
170  * by $Author: andy_seaborne $
171  *
172  * (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
173  * All rights reserved.
174  *
175  * Redistribution and use in source and binary forms, with or without
176  * modification, are permitted provided that the following conditions
177  * are met:
178  * 1. Redistributions of source code must retain the above copyright
179  * notice, this list of conditions and the following disclaimer.
180  * 2. Redistributions in binary form must reproduce the above copyright
181  * notice, this list of conditions and the following disclaimer in the
182  * documentation and/or other materials provided with the distribution.
183  * 3. The name of the author may not be used to endorse or promote products
184  * derived from this software without specific prior written permission.
185  *
186  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
187  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
188  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
189  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
190  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
191  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
192  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
193  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
194  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
195  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
196  *****************************************************************************/

197
Popular Tags