KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdlextui > property > SchemaTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * SchemaTest.java
22  * JUnit based test
23  *
24  * Created on January 31, 2007, 6:25 PM
25  */

26
27 package org.netbeans.modules.xml.wsdlextui.property;
28
29 import java.net.URL JavaDoc;
30 import javax.xml.XMLConstants JavaDoc;
31 import javax.xml.transform.Source JavaDoc;
32 import javax.xml.transform.stream.StreamSource JavaDoc;
33 import javax.xml.validation.Schema JavaDoc;
34 import javax.xml.validation.SchemaFactory JavaDoc;
35 import junit.framework.*;
36
37 import org.xml.sax.ErrorHandler JavaDoc;
38 import org.xml.sax.SAXException JavaDoc;
39 import org.xml.sax.SAXParseException JavaDoc;
40
41 /**
42  *
43  * @author radval
44  */

45 public class SchemaTest extends TestCase {
46     
47     private Exception JavaDoc mLastError;
48     
49     
50     public SchemaTest(String JavaDoc testName) {
51         super(testName);
52     }
53
54     protected void setUp() throws Exception JavaDoc {
55     }
56
57     protected void tearDown() throws Exception JavaDoc {
58     }
59     
60     // TODO add test methods here. The name must begin with 'test'. For example:
61
// public void testHello() {}
62

63     public void testSchema() throws Exception JavaDoc {
64         MyErrorHandler errorHandler = new MyErrorHandler();
65         SchemaFactory JavaDoc sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
66         sf.setErrorHandler(errorHandler);
67         SOAPValidatorSchemaFactory fac = new SOAPValidatorSchemaFactory();
68         Source JavaDoc s = fac.getSchemaSource();
69         Schema JavaDoc schema = sf.newSchema(s);
70         
71         assertNotNull("schema should not be null", schema);
72         
73         assertNull("No exception should occur in schema parsing", mLastError);
74         
75     }
76     
77     class MyErrorHandler implements ErrorHandler JavaDoc {
78         
79         public void error(SAXParseException JavaDoc exception) throws SAXException JavaDoc {
80             mLastError = exception;
81             exception.printStackTrace();
82         }
83
84         public void fatalError(SAXParseException JavaDoc exception) throws SAXException JavaDoc {
85             mLastError = exception;
86             exception.printStackTrace();
87         }
88
89         public void warning(SAXParseException JavaDoc exception) throws SAXException JavaDoc {
90             exception.printStackTrace();
91         }
92         
93
94
95     }
96 }
97
Popular Tags