001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-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;
009: * version 2.1 of the License.
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.xs;
017:
018: import java.lang.reflect.Field;
019:
020: import javax.xml.namespace.QName;
021:
022: import org.eclipse.xsd.XSDSimpleTypeDefinition;
023: import org.geotools.xml.ElementInstance;
024: import org.geotools.xs.bindings.XS;
025:
026: public class TestSchemaTest extends TestSchema {
027: public void testInitialize() {
028: assertNotNull(url);
029: assertNotNull(schema);
030: assertNotNull(factory);
031: }
032:
033: public void testStratagyQName() throws Exception {
034: assertNotNull(stratagy(XS.ANYSIMPLETYPE));
035: }
036:
037: public void testStratagyName() throws Exception {
038: assertNotNull(stratagy("anySimpleType"));
039:
040: try {
041: stratagy("bork");
042: fail("bork should not be found");
043: } catch (Exception expected) {
044: // good!
045: }
046: }
047:
048: public void testXS() throws Exception {
049: assertEquals(XS.ANYSIMPLETYPE, xs("anySimpleType"));
050:
051: try {
052: xs("bork");
053: fail("bork should not be found");
054: } catch (Exception expected) {
055: // good!
056: }
057: }
058:
059: public void testSchemaIdentiy() {
060: assertNotNull(schema);
061: assertNotNull(xsd);
062: assertEquals("1.0", xsd.getVersion());
063: }
064:
065: /** Look into "builtin" schema for schema (aka xsd ?) */
066: public void testXSDSimpleTypes() throws Exception {
067: XSDSimpleTypeDefinition any = xsdSimple("anySimpleType");
068: assertNotNull("Found", any);
069: }
070:
071: /** Look into parsed schema - should agree with XMLSchema */
072: public void testSchemaSimpleTypes() throws Exception {
073: XSDSimpleTypeDefinition any = xsdSimple("anySimpleType");
074: assertNotNull("Found", any);
075: }
076:
077: public void testAllSimpleTypes() throws Exception {
078: Class xs = XS.class;
079: Field[] fields = xs.getFields();
080:
081: for (int i = 0; i < fields.length; i++) {
082: Field field = fields[i];
083:
084: if (field.getType() != QName.class) {
085: continue;
086: }
087:
088: QName name = (QName) field.get(null);
089: XSDSimpleTypeDefinition aXsd = xsdSimple(name
090: .getLocalPart());
091:
092: if (aXsd == null) {
093: //System.out.println( "Could not find binding for " + name.getLocalPart() );
094: }
095: }
096: }
097:
098: public void testElement() {
099: ElementInstance element = element(" hello world ",
100: XS.ANYSIMPLETYPE);
101: assertEquals(" hello world ", element.getText());
102: assertEquals(xsdSimple(XS.ANYSIMPLETYPE.getLocalPart()),
103: element.getElementDeclaration().getType());
104: }
105:
106: protected QName getQName() {
107: // TODO Auto-generated method stub
108: return null;
109: }
110: }
|