1 22 package org.jboss.ejb3.test.schema.unit; 23 24 import org.jboss.logging.Logger; 25 import org.jboss.test.JBossTestCase; 26 import org.jboss.util.xml.JBossEntityResolver; 27 28 import junit.framework.Test; 29 30 import javax.xml.parsers.DocumentBuilder ; 31 import javax.xml.parsers.DocumentBuilderFactory ; 32 import java.io.File ; 33 import org.w3c.dom.Document ; 34 import org.xml.sax.ErrorHandler ; 35 import org.xml.sax.SAXParseException ; 36 37 42 public class SchemaTestCase 43 extends JBossTestCase 44 implements ErrorHandler 45 { 46 Exception caughtException = null; 47 48 private static final Logger log = Logger 49 .getLogger(SchemaTestCase.class); 50 51 public SchemaTestCase(String name) 52 { 53 super(name); 54 } 55 56 public void testEjbClassOptionalEjbJar() throws Exception 57 { 58 DocumentBuilder builder = getDocumentBuilder(); 59 60 validateFile("../src/resources/test/dd/override/META-INF/ejb-jarC.xml", builder); 61 validateFile("../src/resources/test/dd/override/META-INF/ejb-jarD.xml", builder); 62 validateFile("../src/resources/test/enventry/META-INF/ejb-jar.xml", builder); 63 validateFile("../src/resources/test/mail/META-INF/ejb-jar.xml", builder); 64 validateFile("../src/resources/test/reference21_30/META-INF/ejb-jar3.xml", builder); 65 } 66 67 public void testTestEjbJar() throws Exception 68 { 69 DocumentBuilder builder = getDocumentBuilder(); 70 71 validateFile("../src/resources/test/bank/META-INF/ejb-jar.xml", builder); 72 validateFile("../src/resources/test/bmt/META-INF/ejb-jar.xml", builder); 73 validateFile("../src/resources/test/dd/mdb/META-INF/ejb-jar.xml", builder); 74 validateFile("../src/resources/test/dd/override/META-INF/ejb-jar.xml", builder); 75 validateFile("../src/resources/test/dd/override/META-INF/ejb-jarA.xml", builder); 76 validateFile("../src/resources/test/dd/override/META-INF/ejb-jarB.xml", builder); 77 validateFile("../src/resources/test/factoryxml/session1/META-INF/ejb-jar.xml", builder); 78 validateFile("../src/resources/test/factoryxml/session2/META-INF/ejb-jar.xml", builder); 79 validateFile("../src/resources/test/interceptors/META-INF/ejb-jar.xml", builder); 80 validateFile("../src/resources/test/interceptors2/META-INF/ejb-jar.xml", builder); 81 validateFile("../src/resources/test/jca/inflow/META-INF/ejb-jar.xml", builder); 82 validateFile("../src/resources/test/jms/managed/META-INF/ejb-jar.xml", builder); 83 validateFile("../src/resources/test/microbench/META-INF/ejb-jar.xml", builder); 84 validateFile("../src/resources/test/naming/META-INF/ejb-jar.xml", builder); 85 validateFile("../src/resources/test/securitydomain/META-INF/ejb-jar.xml", builder); 86 validateFile("../src/resources/test/service/META-INF/ejb-jar.xml", builder); 87 validateFile("../src/resources/test/stateful/META-INF/ejb-jar.xml", builder); 88 validateFile("../src/resources/test/txexceptions/META-INF/ejb-jar.xml", builder); 89 validateFile("../src/resources/test/webservices/META-INF/ejb-jar.xml", builder); 90 } 91 92 public void testTutorialEjbJar() throws Exception 93 { 94 DocumentBuilder builder = getDocumentBuilder(); 95 96 validateFile("../docs/tutorial/ejb21_client_adaptors/META-INF/ejb-jar.xml", builder); 97 validateFile("../docs/tutorial/interceptor/META-INF/ejb-jar.xml", builder); 98 validateFile("../docs/tutorial/jboss_deployment_descriptor/META-INF/ejb-jar.xml", builder); 99 validateFile("../docs/tutorial/jboss_resource_ref/META-INF/ejb-jar.xml", builder); 100 validateFile("../docs/tutorial/jca/inflow/swiftmq/resources/META-INF/ejb-jar.xml", builder); 101 validateFile("../docs/tutorial/mdb_deployment_descriptor/META-INF/ejb-jar.xml", builder); 102 validateFile("../docs/tutorial/stateful_deployment_descriptor/META-INF/ejb-jar.xml", builder); 103 validateFile("../docs/tutorial/stateless_deployment_descriptor/META-INF/ejb-jar.xml", builder); 104 } 105 106 public void testTestJBoss() throws Exception 107 { 108 DocumentBuilder builder = getDocumentBuilder(); 109 110 validateFile("../src/resources/test/bank/META-INF/jboss.xml", builder); 111 validateFile("../src/resources/test/clusteredsession/META-INF/jboss.xml", builder); 112 validateFile("../src/resources/test/consumer/META-INF/jboss.xml", builder); 113 validateFile("../src/resources/test/dd/mdb/META-INF/jboss.xml", builder); 114 validateFile("../src/resources/test/dd/web/META-INF/jboss.xml", builder); 115 validateFile("../src/resources/test/dependency/META-INF/jboss.xml", builder); 116 validateFile("../src/resources/test/interceptors2/META-INF/jboss.xml", builder); 117 validateFile("../src/resources/test/jca/inflow/META-INF/jboss.xml", builder); 118 validateFile("../src/resources/test/mail/META-INF/jboss.xml", builder); 119 validateFile("../src/resources/test/microbench/META-INF/jboss.xml", builder); 120 validateFile("../src/resources/test/naming/META-INF/jboss1.xml", builder); 121 validateFile("../src/resources/test/naming/META-INF/jboss1.xml", builder); 122 validateFile("../src/resources/test/reference21_30/META-INF/jboss3.xml", builder); 123 validateFile("../src/resources/test/reference21_30/META-INF/jboss-reference.xml", builder); 124 validateFile("../src/resources/test/securitydomain/META-INF/jboss.xml", builder); 125 validateFile("../src/resources/test/service/META-INF/jboss.xml", builder); 126 validateFile("../src/resources/test/ssladvanced/META-INF/jboss.xml", builder); 127 validateFile("../src/resources/test/strictpool/META-INF/jboss.xml", builder); 128 } 129 130 public void testTutorialJBoss() throws Exception 131 { 132 DocumentBuilder builder = getDocumentBuilder(); 133 134 validateFile("../docs/tutorial/consumer_deployment_descriptor/META-INF/jboss.xml", builder); 135 validateFile("../docs/tutorial/dependency/META-INF/jboss.xml", builder); 136 validateFile("../docs/tutorial/ejb21_client_adaptors/META-INF/jboss.xml", builder); 137 validateFile("../docs/tutorial/jboss_deployment_descriptor/META-INF/jboss.xml", builder); 138 validateFile("../docs/tutorial/jboss_resource_ref/META-INF/jboss.xml", builder); 139 validateFile("../docs/tutorial/jca/inflow/swiftmq/resources/META-INF/jboss.xml", builder); 140 validateFile("../docs/tutorial/mdb_deployment_descriptor/META-INF/jboss.xml", builder); 141 validateFile("../docs/tutorial/service_deployment_descriptor/META-INF/jboss.xml", builder); 142 validateFile("../docs/tutorial/stateful_deployment_descriptor/META-INF/jboss.xml", builder); 143 validateFile("../docs/tutorial/stateless_deployment_descriptor/META-INF/jboss.xml", builder); 144 } 145 146 private void validateFile(String filename, DocumentBuilder builder) throws Exception 147 { 148 File xmlFile = new File (filename); 149 System.out.println("Parsing and validating " + filename); 150 Document dom = builder.parse(xmlFile); 151 152 if (caughtException != null) 153 throw caughtException; 154 155 System.out.println("Success parsing " + filename); 156 } 157 158 private DocumentBuilder getDocumentBuilder() throws Exception 159 { 160 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 161 factory.setAttribute("http://apache.org/xml/features/validation/schema", true); 162 163 factory.setValidating(true); 164 factory.setNamespaceAware(true); 165 166 DocumentBuilder builder = factory.newDocumentBuilder(); 167 builder.setErrorHandler(this); 168 169 JBossEntityResolver entityResolver = new JBossEntityResolver(); 170 builder.setEntityResolver(entityResolver); 171 172 return builder; 173 } 174 175 public static Test suite() throws Exception 176 { 177 return getDeploySetup(SchemaTestCase.class, ""); 178 } 179 180 public void fatalError(SAXParseException e) 181 { 182 System.out.println("fatalError " + e); 183 caughtException = e; 184 } 185 186 public void error(SAXParseException e) 187 { 188 System.out.println("Error " + e); 189 caughtException = e; 190 } 191 192 public void warning(SAXParseException e) 193 { 194 System.out.println("Warning " + e); 195 } 196 197 } 198 | Popular Tags |