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.io.IOException;
020: import java.net.URI;
021: import java.util.logging.Level;
022:
023: import javax.xml.parsers.SAXParser;
024: import javax.xml.parsers.SAXParserFactory;
025:
026: import junit.framework.TestCase;
027:
028: import org.geotools.TestData;
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/SchemaParserTest.java $
038: */
039: public class SchemaParserTest extends TestCase {
040: protected SAXParser parser;
041:
042: /*
043: * @see TestCase#setUp()
044: */
045: protected void setUp() throws Exception {
046: super .setUp();
047:
048: SAXParserFactory spf = SAXParserFactory.newInstance();
049: spf.setNamespaceAware(true);
050: spf.setValidating(false);
051: parser = spf.newSAXParser();
052: }
053:
054: public void testMail() {
055: runit("xml/mails.xsd");
056: }
057:
058: public void testWFS() {
059: runit("xml/wfs/WFS-basic.xsd");
060: }
061:
062: public void testGMLFeature() {
063: runit("xml/gml/feature.xsd");
064: }
065:
066: public void testGMLGeometry() {
067: runit("xml/gml/geometry.xsd");
068: }
069:
070: public void testGMLXLinks() {
071: runit("xml/gml/xlinks.xsd");
072: }
073:
074: private void runit(String path) {
075: File f;
076: try {
077: f = TestData.copy(this , path);
078: URI u = f.toURI();
079: XSISAXHandler contentHandler = new XSISAXHandler(u);
080: XSISAXHandler.setLogLevel(Level.WARNING);
081:
082: try {
083: parser.parse(f, contentHandler);
084: } catch (Exception e) {
085: e.printStackTrace();
086: fail(e.toString());
087: }
088:
089: try {
090: assertNotNull("Schema missing", contentHandler
091: .getSchema());
092: //System.out.println(contentHandler.getSchema());
093: } catch (Exception e) {
094: e.printStackTrace();
095: fail(e.toString());
096: }
097: } catch (IOException e1) {
098: e1.printStackTrace();
099: fail(e1.toString());
100: }
101: }
102: }
|