001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: /*
021: * SchemaTest.java
022: * JUnit based test
023: *
024: * Created on January 31, 2007, 6:25 PM
025: */
026:
027: package org.netbeans.modules.wsdlextensions.ftp.validator;
028:
029: import java.net.URL;
030: import javax.xml.XMLConstants;
031: import javax.xml.transform.Source;
032: import javax.xml.transform.stream.StreamSource;
033: import javax.xml.validation.Schema;
034: import javax.xml.validation.SchemaFactory;
035: import junit.framework.*;
036: import org.xml.sax.ErrorHandler;
037: import org.xml.sax.SAXException;
038: import org.xml.sax.SAXParseException;
039:
040: /**
041: *
042: * @author radval
043: */
044: public class SchemaTest extends TestCase {
045:
046: private Exception mLastError;
047:
048: private URL schemaUrl = SchemaTest.class
049: .getResource("/org/netbeans/modules/wsdlextensions/ftp/resources/ftp_ext.xsd");
050:
051: public SchemaTest(String testName) {
052: super (testName);
053: }
054:
055: protected void setUp() throws Exception {
056: }
057:
058: protected void tearDown() throws Exception {
059: }
060:
061: // TODO add test methods here. The name must begin with 'test'. For example:
062: // public void testHello() {}
063:
064: public void testSchema() throws Exception {
065: MyErrorHandler errorHandler = new MyErrorHandler();
066: SchemaFactory sf = SchemaFactory
067: .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
068: sf.setErrorHandler(errorHandler);
069: FTPBCValidatorSchemaFactory fac = new FTPBCValidatorSchemaFactory();
070: Source s = fac.getSchemaSource();
071: Schema schema = sf.newSchema(s);
072:
073: assertNotNull("schema should not be null", schema);
074:
075: assertNull("No exception should occur in schema parsing",
076: mLastError);
077:
078: }
079:
080: class MyErrorHandler implements ErrorHandler {
081:
082: public void error(SAXParseException exception)
083: throws SAXException {
084: mLastError = exception;
085: exception.printStackTrace();
086: }
087:
088: public void fatalError(SAXParseException exception)
089: throws SAXException {
090: mLastError = exception;
091: exception.printStackTrace();
092: }
093:
094: public void warning(SAXParseException exception)
095: throws SAXException {
096: exception.printStackTrace();
097: }
098:
099: }
100: }
|