1 22 package org.jboss.test.common; 23 24 import java.io.InputStream ; 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 ; 31 32 38 public class JBossEntityResolverTest extends TestCase 39 { 40 41 private JBossEntityResolver toTest = null; 42 43 47 protected void setUp() throws Exception 48 { 49 super.setUp(); 50 } 52 53 57 protected void tearDown() throws Exception 58 { 59 super.tearDown(); 60 toTest = null; 61 62 } 63 64 68 public void testResolveEntity_usingOasisCatog() throws Exception 69 { 70 if (true) return; 71 InputSource 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 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 114 public void testResolveEntity_usingOldMap() throws Exception 115 { 116 if (true) return; 117 this.toTest.registerLocalEntity("-//JBoss//DTD JBOSS XMBEAN 500//EN", "dtd/jboss_xmbean_1_0.dtd"); 118 119 InputSource input = this.toTest.resolveEntity("-//JBoss//DTD JBOSS XMBEAN 500//EN", null); 120 assertNotNull(input); 121 String 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 133 public void testEntityResolved_singleThread() throws Exception 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 stream2String(InputSource input) throws Exception 145 { 146 final JBossStringBuilder back = new JBossStringBuilder(); 147 byte[] tmp = new byte[255]; 148 InputStream rd = input.getByteStream(); 149 150 while (rd.read(tmp) != -1) 151 { 152 back.append(new String (tmp)); 153 } 154 155 return back.toString(); 156 157 } 158 159 } 160 | Popular Tags |