01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.rio.rdfxml;
07:
08: import java.io.IOException;
09: import java.io.StringReader;
10: import java.io.StringWriter;
11: import java.net.URL;
12:
13: import org.openrdf.repository.Repository;
14: import org.openrdf.repository.RepositoryConnection;
15: import org.openrdf.repository.RepositoryException;
16: import org.openrdf.repository.sail.SailRepository;
17: import org.openrdf.repository.util.RepositoryUtil;
18: import org.openrdf.rio.RDFFormat;
19: import org.openrdf.rio.RDFHandlerException;
20: import org.openrdf.rio.RDFParseException;
21: import org.openrdf.rio.RDFParserFactory;
22: import org.openrdf.rio.RDFWriter;
23: import org.openrdf.rio.RDFWriterFactory;
24: import org.openrdf.rio.RDFWriterTest;
25: import org.openrdf.sail.memory.MemoryStore;
26:
27: public class RDFXMLWriterTest extends RDFWriterTest {
28:
29: public RDFXMLWriterTest() {
30: this (new RDFXMLWriterFactory(), new RDFXMLParserFactory());
31: }
32:
33: protected RDFXMLWriterTest(RDFWriterFactory writerF,
34: RDFParserFactory parserF) {
35: super (writerF, parserF);
36: }
37:
38: public void testWrite() throws RepositoryException,
39: RDFParseException, IOException, RDFHandlerException {
40: Repository rep1 = new SailRepository(new MemoryStore());
41: rep1.initialize();
42:
43: RepositoryConnection con1 = rep1.getConnection();
44:
45: URL ciaScheme = this .getClass().getResource(
46: "/cia-factbook/CIA-onto-enhanced.rdf");
47: URL ciaFacts = this .getClass().getResource(
48: "/cia-factbook/CIA-facts-enhanced.rdf");
49:
50: con1.add(ciaScheme, ciaScheme.toExternalForm(), RDFFormat
51: .forFileName(ciaScheme.toExternalForm()));
52: con1.add(ciaFacts, ciaFacts.toExternalForm(), RDFFormat
53: .forFileName(ciaFacts.toExternalForm()));
54:
55: StringWriter writer = new StringWriter();
56: RDFWriter rdfWriter = rdfWriterFactory.getWriter(writer);
57: con1.export(rdfWriter);
58:
59: con1.close();
60:
61: Repository rep2 = new SailRepository(new MemoryStore());
62: rep2.initialize();
63:
64: RepositoryConnection con2 = rep2.getConnection();
65:
66: con2.add(new StringReader(writer.toString()), "foo:bar",
67: RDFFormat.RDFXML);
68: con2.close();
69:
70: assertTrue(
71: "result of serialization and re-upload should be equal to original",
72: RepositoryUtil.equals(rep1, rep2));
73: }
74: }
|