01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08: *
09: * 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.wsdlextensions.jms.validator;
28:
29: import java.net.URL;
30: import javax.xml.XMLConstants;
31: import javax.xml.transform.Source;
32: import javax.xml.validation.Schema;
33: import javax.xml.validation.SchemaFactory;
34: import junit.framework.*;
35: import org.xml.sax.ErrorHandler;
36: import org.xml.sax.SAXException;
37: import org.xml.sax.SAXParseException;
38:
39: /**
40: *
41: * @author radval
42: */
43: public class SchemaTest extends TestCase {
44:
45: private Exception mLastError;
46:
47: private URL schemaUrl = SchemaTest.class
48: .getResource("/org/netbeans/modules/wsdlextensions/jms/resources/jms-ext.xsd");
49:
50: public SchemaTest(String testName) {
51: super (testName);
52: }
53:
54: protected void setUp() throws Exception {
55: }
56:
57: protected void tearDown() throws Exception {
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 {
64: MyErrorHandler errorHandler = new MyErrorHandler();
65: SchemaFactory sf = SchemaFactory
66: .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
67: sf.setErrorHandler(errorHandler);
68: JMSValidatorSchemaFactory fac = new JMSValidatorSchemaFactory();
69: Source s = fac.getSchemaSource();
70: Schema schema = sf.newSchema(s);
71:
72: assertNotNull("schema should not be null", schema);
73:
74: assertNull("No exception should occur in schema parsing",
75: mLastError);
76:
77: }
78:
79: class MyErrorHandler implements ErrorHandler {
80:
81: public void error(SAXParseException exception)
82: throws SAXException {
83: mLastError = exception;
84: exception.printStackTrace();
85: }
86:
87: public void fatalError(SAXParseException exception)
88: throws SAXException {
89: mLastError = exception;
90: exception.printStackTrace();
91: }
92:
93: public void warning(SAXParseException exception)
94: throws SAXException {
95: exception.printStackTrace();
96: }
97:
98: }
99: }
|