From: Bill D. <bde...@jb...> - 2006-01-25 23:42:20
|
User: bdecoste Date: 06/01/25 18:42:16 Added: src/test/org/jboss/ejb3/test/schema/unit SchemaTestCase.java Log: 3.0 schema validity Revision Changes Path 1.1 date: 2006/01/25 23:42:16; author: bdecoste; state: Exp;jboss-ejb3/src/test/org/jboss/ejb3/test/schema/unit/SchemaTestCase.java Index: SchemaTestCase.java =================================================================== /* * JBoss, Home of Professional Open Source * Copyright 2005, JBoss Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a * full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.ejb3.test.schema.unit; import org.jboss.logging.Logger; import org.jboss.test.JBossTestCase; import junit.framework.Test; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import java.io.File; import org.w3c.dom.Document; import org.xml.sax.ErrorHandler; import org.xml.sax.SAXParseException; /** * * @version <tt>$Revision: 1.1 $</tt> * @author <a href="mailto:bde...@jb...">William DeCoste</a> */ public class SchemaTestCase extends JBossTestCase implements ErrorHandler { Exception caughtException = null; private static final Logger log = Logger .getLogger(SchemaTestCase.class); public SchemaTestCase(String name) { super(name); } public void testLifecycle() throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setAttribute("http://apache.org/xml/features/validation/schema", true); factory.setValidating(true); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(this); validateFile("../src/resources/test/bank/META-INF/ejb-jar.xml", builder); validateFile("../src/resources/test/interceptors2/META-INF/ejb-jar.xml", builder); if (caughtException != null) throw caughtException; } public void testEjbClassOptional() throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setAttribute("http://apache.org/xml/features/validation/schema", true); factory.setValidating(true); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(this); validateFile("../src/resources/test/dd/override/META-INF/ejb-jarC.xml", builder); validateFile("../src/resources/test/dd/override/META-INF/ejb-jarD.xml", builder); validateFile("../src/resources/test/enventry/META-INF/ejb-jar.xml", builder); validateFile("../src/resources/test/mail/META-INF/ejb-jar.xml", builder); validateFile("../src/resources/test/reference21_30/META-INF/ejb-jar3.xml", builder); } public void testTests() throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setAttribute("http://apache.org/xml/features/validation/schema", true); factory.setValidating(true); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(this); validateFile("../src/resources/test/bmt/META-INF/ejb-jar.xml", builder); validateFile("../src/resources/test/dd/mdb/META-INF/ejb-jar.xml", builder); validateFile("../src/resources/test/dd/override/META-INF/ejb-jar.xml", builder); validateFile("../src/resources/test/dd/override/META-INF/ejb-jarA.xml", builder); validateFile("../src/resources/test/dd/override/META-INF/ejb-jarB.xml", builder); validateFile("../src/resources/test/interceptors/META-INF/ejb-jar.xml", builder); validateFile("../src/resources/test/jca/inflow/META-INF/ejb-jar.xml", builder); validateFile("../src/resources/test/jms/managed/META-INF/ejb-jar.xml", builder); validateFile("../src/resources/test/microbench/META-INF/ejb-jar.xml", builder); validateFile("../src/resources/test/naming/META-INF/ejb-jar.xml", builder); validateFile("../src/resources/test/securitydomain/META-INF/ejb-jar.xml", builder); validateFile("../src/resources/test/service/META-INF/ejb-jar.xml", builder); validateFile("../src/resources/test/stateful/META-INF/ejb-jar.xml", builder); validateFile("../src/resources/test/txexceptions/META-INF/ejb-jar.xml", builder); } public void testTutorials() throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setAttribute("http://apache.org/xml/features/validation/schema", true); factory.setValidating(true); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(this); validateFile("../docs/tutorial/ejb21_client_adaptors/META-INF/ejb-jar.xml", builder); validateFile("../docs/tutorial/interceptor/META-INF/ejb-jar.xml", builder); validateFile("../docs/tutorial/jboss_deployment_descriptor/META-INF/ejb-jar.xml", builder); validateFile("../docs/tutorial/jboss_resource_ref/META-INF/ejb-jar.xml", builder); validateFile("../docs/tutorial/jca/inflow/swiftmq/resources/META-INF/ejb-jar.xml", builder); validateFile("../docs/tutorial/mdb_deployment_descriptor/META-INF/ejb-jar.xml", builder); validateFile("../docs/tutorial/stateful_deployment_descriptor/META-INF/ejb-jar.xml", builder); validateFile("../docs/tutorial/stateless_deployment_descriptor/META-INF/ejb-jar.xml", builder); } private void validateFile(String filename, DocumentBuilder builder) throws Exception { File xmlFile = new File(filename); System.out.println("Parsing and validating " + filename); Document dom = builder.parse(xmlFile); if (caughtException != null) throw caughtException; System.out.println("Success parsing " + filename); } public static Test suite() throws Exception { return getDeploySetup(SchemaTestCase.class, ""); } public void fatalError(SAXParseException e) { caughtException = e; } public void error(SAXParseException e) { caughtException = e; } public void warning(SAXParseException e) { } } |