KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > common > JBossEntityResolverTest


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.test.common;
23
24 import java.io.InputStream JavaDoc;
25
26 import junit.framework.TestCase;
27
28 import org.jboss.util.JBossStringBuilder;
29 import org.jboss.util.xml.JBossEntityResolver;
30 import org.xml.sax.InputSource JavaDoc;
31
32 /**
33  * A JBossEntityResolverTest.
34  *
35  * @author <a HREF="wiesed@gmail.com">Daniel Wiese</a>
36  * @version $Revision: 43551 $
37  */

38 public class JBossEntityResolverTest extends TestCase
39 {
40
41    private JBossEntityResolver toTest = null;
42
43    /**
44     * Setup the test.
45     * @throws Exception - in error case
46     */

47    protected void setUp() throws Exception JavaDoc
48    {
49       super.setUp();
50       //toTest = new JBossEntityResolver();
51
}
52
53    /**
54     * Clenup method.
55     * @throws Exception - in error case
56     */

57    protected void tearDown() throws Exception JavaDoc
58    {
59       super.tearDown();
60       toTest = null;
61
62    }
63
64    /**
65     * Test method for 'org.jboss.util.xml.JBossEntityResolver.resolveEntity(String, String)'.
66     * @throws Exception - in error case
67     */

68    public void testResolveEntity_usingOasisCatog() throws Exception JavaDoc
69    {
70       if (true) return;
71       InputSource JavaDoc input = this.toTest.resolveEntity("-//JBoss//DTD JBOSS XMBEAN 1.1//EN",
72             "http://www.jboss.org/j2ee/dtd/jboss_xmbean_1_1.dtd");
73       assertNotNull(input);
74       String JavaDoc back = this.stream2String(input);
75       assertNotNull(back);
76       assertTrue(back.startsWith("<?xml version='1.0' encoding='UTF-8' ?>"));
77       assertTrue(back.indexOf("<!ELEMENT mbean") > 0);
78
79       input = this.toTest.resolveEntity("-//JBoss//DTD JBOSS XMBEAN 1.2//EN",
80             "http://www.jboss.org/j2ee/dtd/jboss_xmbean_1_2.dtd");
81       assertNotNull(input);
82       back = this.stream2String(input);
83       assertNotNull(input);
84       assertNotNull(back);
85       assertTrue(back.startsWith("<?xml version='1.0' encoding='UTF-8' ?>"));
86       assertTrue(back.indexOf("<!ELEMENT mbean") > 0);
87
88       input = this.toTest.resolveEntity(" -//JBoss//DTD JBOSS Security Config 3.0//EN",
89             "http://www.jboss.org/j2ee/dtd/security_config.dtd");
90       assertNotNull(input);
91       back = this.stream2String(input);
92       assertNotNull(input);
93       assertNotNull(back);
94       assertTrue(back.startsWith("<?xml version='1.0' encoding='UTF-8' ?>"));
95       assertTrue(back.indexOf("<login-module code") > 0);
96
97       input = this.toTest.resolveEntity(" -//JBoss//DTD JBOSSCMP-JDBC 4.0//EN",
98             "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_4_0.dtd");
99       assertNotNull(input);
100       back = this.stream2String(input);
101       assertNotNull(input);
102       assertNotNull(back);
103       assertTrue(back.startsWith("<?xml version='1.0' encoding='UTF-8' ?>"));
104       assertTrue(back.indexOf("<!ELEMENT jbosscmp-jdbc") > 0);
105
106    }
107
108
109    /**
110     * Test the old backward compatibility resolution technique
111     *
112     * @throws Exception - in error case
113     */

114    public void testResolveEntity_usingOldMap() throws Exception JavaDoc
115    {
116       if (true) return;
117       this.toTest.registerLocalEntity("-//JBoss//DTD JBOSS XMBEAN 500//EN", "dtd/jboss_xmbean_1_0.dtd");
118
119       InputSource JavaDoc input = this.toTest.resolveEntity("-//JBoss//DTD JBOSS XMBEAN 500//EN", null);
120       assertNotNull(input);
121       String JavaDoc back = this.stream2String(input);
122       assertNotNull(back);
123       assertTrue(back.startsWith("<?xml version='1.0' encoding='UTF-8' ?>"));
124       assertTrue(back.indexOf("<!ELEMENT mbean") > 0);
125
126    }
127    
128    /**
129     * Test the old backward compatibility resolution technique
130     *
131     * @throws Exception - in error case
132     */

133    public void testEntityResolved_singleThread() throws Exception JavaDoc
134    {
135       if (true) return;
136       this.toTest.resolveEntity(null, null);
137       assertFalse(this.toTest.isEntityResolved());
138       this.toTest.resolveEntity("-//JBoss//DTD JBOSS XMBEAN 1.2//EN",
139       "http://www.jboss.org/j2ee/dtd/jboss_xmbean_1_2.dtd");
140       assertTrue(this.toTest.isEntityResolved());
141       
142    }
143
144    private String JavaDoc stream2String(InputSource JavaDoc input) throws Exception JavaDoc
145    {
146       final JBossStringBuilder back = new JBossStringBuilder();
147       byte[] tmp = new byte[255];
148       InputStream JavaDoc rd = input.getByteStream();
149
150       while (rd.read(tmp) != -1)
151       {
152          back.append(new String JavaDoc(tmp));
153       }
154
155       return back.toString();
156
157    }
158
159 }
160
Popular Tags