001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.xml;
017:
018: import java.io.File;
019: import java.net.URI;
020: import java.util.logging.Level;
021:
022: import javax.naming.OperationNotSupportedException;
023:
024: import junit.framework.TestCase;
025:
026: import org.geotools.TestData;
027: import org.geotools.xml.schema.Schema;
028: import org.xml.sax.SAXException;
029:
030: /**
031: * <p>
032: * DOCUMENT ME!
033: * </p>
034: * @
035: *
036: * @author dzwiers www.refractions.net
037: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/xml/src/test/java/org/geotools/xml/XMLParserTest.java $
038: */
039: public class XMLParserTest extends TestCase {
040: public void testMail() {
041: try {
042: String path = "xml/mails.xml";
043:
044: File f = TestData.copy(this , path);
045: TestData.copy(this , "xml/mails.xsd");
046: URI u = f.toURI();
047:
048: Object doc = DocumentFactory.getInstance(u, null,
049: Level.WARNING);
050:
051: assertNotNull("Document missing", doc);
052: System.out.println(doc);
053: } catch (SAXException e) {
054: e.printStackTrace();
055: fail(e.toString());
056: } catch (Throwable e) {
057: e.printStackTrace();
058: fail(e.toString());
059: }
060: }
061:
062: public void testMailWrite() {
063:
064: try {
065: String path = "xml/mails.xml";
066:
067: File f = TestData.copy(this , path);
068: TestData.copy(this , "xml/mails.xsd");
069:
070: Object doc = DocumentFactory.getInstance(f.toURI(), null,
071: Level.WARNING);
072: assertNotNull("Document missing", doc);
073:
074: Schema s = SchemaFactory.getInstance(new URI(
075: "http://mails/refractions/net"));
076:
077: path = "mails_out.xml";
078: f = TestData.temp(this , path);
079: if (f.exists())
080: f.delete();
081: f.createNewFile();
082:
083: DocumentWriter.writeDocument(doc, s, f, null);
084:
085: doc = DocumentFactory.getInstance(f.toURI(), null,
086: Level.WARNING);
087: assertNotNull("New Document missing", doc);
088:
089: assertTrue("file was not created +f", f.exists());
090: System.out.println(f);
091: } catch (SAXException e) {
092: e.printStackTrace();
093: fail(e.toString());
094: } catch (Throwable e) {
095: assertTrue(e instanceof OperationNotSupportedException);
096: // e.printStackTrace();
097: // fail(e.toString()); Operation not supported yet
098: }
099: }
100: }
|