KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > schema > unit > SchemaTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

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 JavaDoc;
31 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
32 import java.io.File JavaDoc;
33 import org.w3c.dom.Document JavaDoc;
34 import org.xml.sax.ErrorHandler JavaDoc;
35 import org.xml.sax.SAXParseException JavaDoc;
36
37 /**
38  *
39  * @version <tt>$Revision: 45046 $</tt>
40  * @author <a HREF="mailto:bdecoste@jboss.com">William DeCoste</a>
41  */

42 public class SchemaTestCase
43     extends JBossTestCase
44     implements ErrorHandler JavaDoc
45 {
46    Exception JavaDoc caughtException = null;
47    
48    private static final Logger log = Logger
49          .getLogger(SchemaTestCase.class);
50
51    public SchemaTestCase(String JavaDoc name)
52    {
53       super(name);
54    }
55    
56    public void testEjbClassOptionalEjbJar() throws Exception JavaDoc
57    {
58       DocumentBuilder JavaDoc 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 JavaDoc
68    {
69       DocumentBuilder JavaDoc 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 JavaDoc
93    {
94       DocumentBuilder JavaDoc 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 JavaDoc
107    {
108       DocumentBuilder JavaDoc 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 JavaDoc
131    {
132       DocumentBuilder JavaDoc 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 JavaDoc filename, DocumentBuilder JavaDoc builder) throws Exception JavaDoc
147    {
148       File JavaDoc xmlFile = new File JavaDoc(filename);
149       System.out.println("Parsing and validating " + filename);
150       Document JavaDoc 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 JavaDoc getDocumentBuilder() throws Exception JavaDoc
159    {
160       DocumentBuilderFactory JavaDoc 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 JavaDoc 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 JavaDoc
176    {
177       return getDeploySetup(SchemaTestCase.class, "");
178    }
179    
180    public void fatalError(SAXParseException JavaDoc e)
181    {
182       System.out.println("fatalError " + e);
183       caughtException = e;
184    }
185    
186    public void error(SAXParseException JavaDoc e)
187    {
188       System.out.println("Error " + e);
189       caughtException = e;
190    }
191    
192    public void warning(SAXParseException JavaDoc e)
193    {
194       System.out.println("Warning " + e);
195    }
196
197 }
198  
Popular Tags