1 19 20 26 27 package org.netbeans.modules.xml.wsdlextui.property; 28 29 import java.net.URL ; 30 import javax.xml.XMLConstants ; 31 import javax.xml.transform.Source ; 32 import javax.xml.transform.stream.StreamSource ; 33 import javax.xml.validation.Schema ; 34 import javax.xml.validation.SchemaFactory ; 35 import junit.framework.*; 36 37 import org.xml.sax.ErrorHandler ; 38 import org.xml.sax.SAXException ; 39 import org.xml.sax.SAXParseException ; 40 41 45 public class SchemaTest extends TestCase { 46 47 private Exception mLastError; 48 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 63 public void testSchema() throws Exception { 64 MyErrorHandler errorHandler = new MyErrorHandler(); 65 SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 66 sf.setErrorHandler(errorHandler); 67 SOAPValidatorSchemaFactory fac = new SOAPValidatorSchemaFactory(); 68 Source s = fac.getSchemaSource(); 69 Schema 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 { 78 79 public void error(SAXParseException exception) throws SAXException { 80 mLastError = exception; 81 exception.printStackTrace(); 82 } 83 84 public void fatalError(SAXParseException exception) throws SAXException { 85 mLastError = exception; 86 exception.printStackTrace(); 87 } 88 89 public void warning(SAXParseException exception) throws SAXException { 90 exception.printStackTrace(); 91 } 92 93 94 95 } 96 } 97 | Popular Tags |