1 package test.wsdd; 2 3 import junit.framework.Test; 4 import junit.framework.TestCase; 5 import junit.framework.TestSuite; 6 import org.w3c.dom.Document ; 7 8 import javax.xml.parsers.DocumentBuilder ; 9 import javax.xml.parsers.DocumentBuilderFactory ; 10 import java.io.File ; 11 12 15 public class TestXSD extends TestCase { 16 17 static final String JAXP_SCHEMA_LANGUAGE = 18 "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; 19 static final String W3C_XML_SCHEMA = 20 "http://www.w3.org/2001/XMLSchema"; 21 static final String JAXP_SCHEMA_SOURCE = 22 "http://java.sun.com/xml/jaxp/properties/schemaSource"; 23 24 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 25 26 public TestXSD(String name) { 27 super(name); 28 } 29 30 public static Test suite() { 31 return new TestSuite(TestXSD.class); 32 } 33 34 protected void setUp() throws Exception { 35 String schemaSource = "wsdd/WSDD.xsd"; 36 37 dbf.setNamespaceAware(true); 41 42 dbf.setValidating(true); 43 dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); 44 File f = new File (schemaSource); 46 dbf.setAttribute(JAXP_SCHEMA_SOURCE, f.toURL().toExternalForm()); 47 } 48 49 public static void main(String [] args) throws Exception { 50 TestXSD tester = new TestXSD("TestXSD"); 51 tester.setUp(); 52 tester.testWSDD(); 53 } 54 55 public void testWSDD() throws Exception { 56 File f = new File ("."); 57 recurse(f); 58 } 59 60 private void recurse(File f) throws Exception { 61 if (f.isDirectory()) { 62 File [] files = f.listFiles(); 63 for (int i = 0; i < files.length; i++) { 64 recurse(files[i]); 65 } 66 } else if (f.getName().endsWith(".wsdd")) { 67 checkValidity(f); 68 } 69 } 70 71 private void checkValidity(File f) throws Exception { 72 System.out.println("========== Checking " + f.getAbsolutePath() + "================="); 73 DocumentBuilder db = dbf.newDocumentBuilder(); 74 Document doc = db.parse(f); 75 assertTrue(doc != null); 76 } 77 } 78 | Popular Tags |