01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.xml;
17:
18: import java.io.File;
19: import java.io.IOException;
20: import java.net.URI;
21: import java.util.logging.Level;
22:
23: import javax.xml.parsers.SAXParser;
24: import javax.xml.parsers.SAXParserFactory;
25:
26: import org.geotools.test.TestData;
27: import org.geotools.xml.schema.Schema;
28:
29: import junit.framework.TestCase;
30:
31: /**
32: * @author dzwiers
33: *
34: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/xml/src/test/java/org/geotools/xml/SchemaMergeTest.java $
35: */
36: public class SchemaMergeTest extends TestCase {
37:
38: protected SAXParser parser;
39:
40: /*
41: * @see TestCase#setUp()
42: */
43: protected void setUp() throws Exception {
44: super .setUp();
45:
46: SAXParserFactory spf = SAXParserFactory.newInstance();
47: spf.setNamespaceAware(true);
48: spf.setValidating(false);
49: parser = spf.newSAXParser();
50: }
51:
52: public void testMergeSchema() {
53: // will load a doc that includes two schema docs which duplicate definitions
54:
55: File f;
56: try {
57: f = TestData.file(this , "merge.xsd");
58: URI u = f.toURI();
59: XSISAXHandler contentHandler = new XSISAXHandler(u);
60: XSISAXHandler.setLogLevel(Level.WARNING);
61:
62: try {
63: parser.parse(f, contentHandler);
64: } catch (Exception e) {
65: e.printStackTrace();
66: fail(e.toString());
67: }
68:
69: try {
70: assertNotNull("Schema missing", contentHandler
71: .getSchema());
72: System.out.println(contentHandler.getSchema());
73:
74: Schema schema = contentHandler.getSchema();
75:
76: assertTrue("Should only have 2 elements, had "
77: + schema.getElements().length, schema
78: .getElements().length == 2);
79: assertTrue("Should only have 1 complexType, had "
80: + schema.getComplexTypes().length, schema
81: .getComplexTypes().length == 1);
82:
83: } catch (Exception e) {
84: e.printStackTrace();
85: fail(e.toString());
86: }
87: } catch (IOException e1) {
88: e1.printStackTrace();
89: fail(e1.toString());
90: }
91: }
92: }
|