001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/test/junit/org/deegree/framework/xml/schema/XSDocumentTest.java $
002: /*---------------- FILE HEADER ------------------------------------------
003:
004: This file is part of deegree.
005: Copyright (C) 2001-2008 by:
006: EXSE, Department of Geography, University of Bonn
007: http://www.giub.uni-bonn.de/deegree/
008: lat/lon GmbH
009: http://www.lat-lon.de
010:
011: This library is free software; you can redistribute it and/or
012: modify it under the terms of the GNU Lesser General Public
013: License as published by the Free Software Foundation; either
014: version 2.1 of the License, or (at your option) any later version.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: Contact:
026:
027: Andreas Poth
028: lat/lon GmbH
029: Aennchenstr. 19
030: 53115 Bonn
031: Germany
032: E-Mail: poth@lat-lon.de
033:
034: Prof. Dr. Klaus Greve
035: Department of Geography
036: University of Bonn
037: Meckenheimer Allee 166
038: 53115 Bonn
039: Germany
040: E-Mail: greve@giub.uni-bonn.de
041:
042:
043: ---------------------------------------------------------------------------*/
044:
045: package org.deegree.framework.xml.schema;
046:
047: import java.net.URI;
048: import java.net.URISyntaxException;
049: import java.net.URL;
050:
051: import junit.framework.TestCase;
052:
053: import org.deegree.datatypes.QualifiedName;
054: import org.deegree.framework.xml.XMLParsingException;
055:
056: import alltests.AllTests;
057: import alltests.Configuration;
058:
059: public class XSDocumentTest extends TestCase {
060:
061: private static final String XSD_FILE = "xml/schema/Philosopher.xsd";
062:
063: private static URI NAMESPACE;
064: static {
065: try {
066: NAMESPACE = new URI("http://www.deegree.org/app");
067: } catch (URISyntaxException e) {
068: AllTests.LOG.logError("Invalid namespace URI: "
069: + e.getMessage(), e);
070: }
071: }
072:
073: private static final QualifiedName FT_PHILOSOPHER_NAME = new QualifiedName(
074: "Philosopher", NAMESPACE);
075:
076: private static final QualifiedName FT_PHILOSOPHER_TYPE = new QualifiedName(
077: "PhilosopherType", NAMESPACE);
078:
079: private static final QualifiedName FT_PLACE_TYPE = new QualifiedName(
080: "PlaceType", NAMESPACE);
081:
082: private XSDocument doc;
083:
084: protected void setUp() throws Exception {
085: super .setUp();
086: URL inputURL = new URL(Configuration.getResourceDir(), XSD_FILE);
087: doc = new XSDocument();
088: doc.load(inputURL);
089: }
090:
091: public void testParseSchema() throws XMLParsingException,
092: XMLSchemaException {
093: XMLSchema schema = doc.parseXMLSchema();
094:
095: ElementDeclaration[] elementDeclaration = schema
096: .getElementDeclarations();
097: assertNotNull(elementDeclaration);
098: assertEquals(4, elementDeclaration.length);
099:
100: ElementDeclaration singleElement = schema
101: .getElementDeclaration(FT_PHILOSOPHER_NAME);
102: assertNotNull(singleElement);
103: assertEquals("Philosopher", singleElement.getName()
104: .getPrefixedName());
105: assertEquals("app:PhilosopherType", singleElement.getType()
106: .getName().getPrefixedName());
107:
108: ComplexTypeDeclaration[] complexTypeDeclaration = schema
109: .getComplexTypeDeclarations();
110: assertNotNull(complexTypeDeclaration);
111: assertEquals(3, complexTypeDeclaration.length);
112:
113: ComplexTypeDeclaration singleComplexType = schema
114: .getComplexTypeDeclaration(FT_PHILOSOPHER_TYPE);
115: assertEquals(FT_PHILOSOPHER_TYPE, singleComplexType.getName());
116:
117: singleComplexType = schema
118: .getComplexTypeDeclaration(FT_PLACE_TYPE);
119: assertNotNull(singleComplexType);
120: assertEquals(FT_PLACE_TYPE, singleComplexType.getName());
121:
122: ElementDeclaration[] subElements = singleComplexType
123: .getExplicitElements();
124: assertNotNull(subElements);
125: assertEquals(3, subElements.length);
126: assertEquals("id", subElements[0].getName().getPrefixedName());
127: assertEquals("xsd:string", subElements[0].getType().getName()
128: .getPrefixedName());
129:
130: SimpleTypeDeclaration[] simpleTypeDeclaration = schema
131: .getSimpleTypeDeclarations();
132: assertNotNull(simpleTypeDeclaration);
133: assertEquals(0, simpleTypeDeclaration.length);
134: }
135: }
|