1 17 18 package org.apache.geronimo.schema; 19 20 import java.util.ArrayList ; 21 import java.util.List ; 22 import java.net.URL ; 23 24 import javax.xml.namespace.QName ; 25 26 import org.apache.xmlbeans.XmlCursor; 27 import org.apache.xmlbeans.XmlObject; 28 import org.apache.geronimo.xbeans.j2ee.EjbJarType; 29 import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil; 30 import org.apache.geronimo.testsupport.XmlBeansTestSupport; 31 32 import org.apache.commons.logging.Log; 33 import org.apache.commons.logging.LogFactory; 34 35 41 public class SchemaConversionUtilsTest extends XmlBeansTestSupport { 42 private static final Log log = LogFactory.getLog(SchemaConversionUtilsTest.class); 43 44 private ClassLoader classLoader = this.getClass().getClassLoader(); 45 46 63 65 67 public void testOrderDescriptionGroup() throws Exception { 68 URL srcXml = classLoader.getResource("j2ee_1_3dtd/DescriptionGroupTestSource.xml"); 69 URL expectedOutputXml = classLoader.getResource("j2ee_1_3dtd/DescriptionGroupTestExpected.xml"); 70 XmlObject srcObject = XmlObject.Factory.parse(srcXml); 71 XmlCursor srcCursor = srcObject.newCursor(); 72 XmlCursor moveable = srcObject.newCursor(); 73 try { 74 srcCursor.toFirstChild(); 75 srcCursor.toFirstChild(); 76 assertTrue(srcCursor.getName().toString(), "filter".equals(srcCursor.getName().getLocalPart())); 77 do { 78 srcCursor.push(); 79 srcCursor.toFirstChild(); 80 SchemaConversionUtils.convertToDescriptionGroup(SchemaConversionUtils.J2EE_NAMESPACE, srcCursor, moveable); 81 srcCursor.pop(); 82 } while (srcCursor.toNextSibling()); 83 } finally { 84 srcCursor.dispose(); 85 } 86 XmlObject expected = XmlObject.Factory.parse(expectedOutputXml); 88 List problems = new ArrayList (); 89 boolean ok = compareXmlObjects(srcObject, expected, problems); 90 assertTrue("Differences: " + problems, ok); 91 } 92 93 public void testOrderJNDIEnvironmentRefsGroup() throws Exception { 94 URL srcXml = classLoader.getResource("j2ee_1_3dtd/JNDIEnvironmentRefsGroupTestSource.xml"); 95 URL expectedOutputXml = classLoader.getResource("j2ee_1_3dtd/JNDIEnvironmentRefsGroupTestExpected.xml"); 96 XmlObject srcObject = XmlObject.Factory.parse(srcXml); 97 XmlCursor srcCursor = srcObject.newCursor(); 98 XmlCursor moveable = srcObject.newCursor(); 99 try { 100 srcCursor.toFirstChild(); 101 srcCursor.toFirstChild(); 102 assertTrue(srcCursor.getName().toString(), "web-app".equals(srcCursor.getName().getLocalPart())); 103 do { 104 srcCursor.push(); 105 srcCursor.toFirstChild(); 106 srcCursor.toNextSibling(); 107 srcCursor.toNextSibling(); 108 moveable.toCursor(srcCursor); 109 SchemaConversionUtils.convertToJNDIEnvironmentRefsGroup(SchemaConversionUtils.J2EE_NAMESPACE, srcCursor, moveable); 110 srcCursor.pop(); 111 } while (srcCursor.toNextSibling()); 112 } finally { 113 srcCursor.dispose(); 114 } 115 XmlObject expected = XmlObject.Factory.parse(expectedOutputXml); 117 List problems = new ArrayList (); 118 boolean ok = compareXmlObjects(srcObject, expected, problems); 119 assertTrue("Differences: " + problems, ok); 120 } 121 122 public void testGeronimoNamingNamespaceChange() throws Exception { 123 URL srcXml = classLoader.getResource("geronimo/ejb-naming-pre.xml"); 124 URL expectedOutputXml = classLoader.getResource("geronimo/ejb-naming-post.xml"); 125 XmlObject xmlObject = XmlBeansUtil.parse(srcXml, this.getClass().getClassLoader()); 126 XmlCursor cursor = xmlObject.newCursor(); 127 try { 128 SchemaConversionUtils.convertToGeronimoSubSchemas(cursor); 129 log.debug(xmlObject.toString()); 130 131 XmlObject expected = XmlObject.Factory.parse(expectedOutputXml); 132 log.debug(expected.toString()); 133 134 List problems = new ArrayList (); 135 boolean ok = compareXmlObjects(xmlObject, expected, problems); 136 assertTrue("Differences: " + problems, ok); 137 SchemaConversionUtils.convertToGeronimoSubSchemas(cursor); 138 boolean ok2 = compareXmlObjects(xmlObject, expected, problems); 139 assertTrue("Differences: " + problems, ok2); 140 } finally { 141 cursor.dispose(); 142 } 143 } 144 public void testGetNestedObjectAsType() throws Exception { 146 URL srcXml = classLoader.getResource("geronimo/ejb-naming-pre.xml"); 147 XmlObject xmlObject = XmlObject.Factory.parse(srcXml); 149 xmlObject = SchemaConversionUtils.getNestedObjectAsType(xmlObject, new QName ("http://www.openejb.org/xml/ns/openejb-jar-2.1", "openejb-jar"), EjbJarType.type); 151 } 153 154 public void testSecurityElementConverter() throws Exception { 155 URL srcXml = classLoader.getResource("geronimo/security-pre.xml"); 156 URL expectedOutputXml = classLoader.getResource("geronimo/security-post.xml"); 157 XmlObject xmlObject = XmlObject.Factory.parse(srcXml); 158 ElementConverter elementConverter = new SecurityElementConverter(); 159 XmlCursor cursor = xmlObject.newCursor(); 160 XmlCursor end = cursor.newCursor(); 161 try { 162 elementConverter.convertElement(cursor, end); 163 XmlObject expected = XmlObject.Factory.parse(expectedOutputXml); 165 List problems = new ArrayList (); 166 boolean ok = compareXmlObjects(xmlObject, expected, problems); 167 assertTrue("Differences: " + problems, ok); 168 SchemaConversionUtils.convertToGeronimoSubSchemas(cursor); 169 boolean ok2 = compareXmlObjects(xmlObject, expected, problems); 170 assertTrue("Differences: " + problems, ok2); 171 } finally { 172 cursor.dispose(); 173 end.dispose(); 174 } 175 176 } 177 178 public void testGBeanElementConverter() throws Exception { 179 URL srcXml = classLoader.getResource("geronimo/gbean-pre.xml"); 180 URL expectedOutputXml = classLoader.getResource("geronimo/gbean-post.xml"); 181 XmlObject xmlObject = XmlObject.Factory.parse(srcXml); 182 ElementConverter elementConverter = new GBeanElementConverter(); 183 XmlCursor cursor = xmlObject.newCursor(); 184 XmlCursor end = cursor.newCursor(); 185 try { 186 elementConverter.convertElement(cursor, end); 187 XmlObject expected = XmlObject.Factory.parse(expectedOutputXml); 189 List problems = new ArrayList (); 190 boolean ok = compareXmlObjects(xmlObject, expected, problems); 191 assertTrue("Differences: " + problems, ok); 192 SchemaConversionUtils.convertToGeronimoSubSchemas(cursor); 193 boolean ok2 = compareXmlObjects(xmlObject, expected, problems); 194 assertTrue("Differences: " + problems, ok2); 195 } finally { 196 cursor.dispose(); 197 end.dispose(); 198 } 199 200 } 201 202 public void testQNameConverter1() throws Exception { 203 URL srcXml = classLoader.getResource("geronimo/qname1-pre.xml"); 204 URL expectedOutputXml = classLoader.getResource("geronimo/qname1-post.xml"); 205 XmlObject xmlObject = XmlObject.Factory.parse(srcXml); 206 ElementConverter elementConverter = new QNameConverter("import", "http://geronimo.apache.org/xml/ns/deployment-1.0", "parent"); 207 XmlCursor cursor = xmlObject.newCursor(); 208 XmlCursor end = cursor.newCursor(); 209 try { 210 elementConverter.convertElement(cursor, end); 211 XmlObject expected = XmlObject.Factory.parse(expectedOutputXml); 213 List problems = new ArrayList (); 214 boolean ok = compareXmlObjects(xmlObject, expected, problems); 215 assertTrue("Differences: " + problems, ok); 216 SchemaConversionUtils.convertToGeronimoSubSchemas(cursor); 217 boolean ok2 = compareXmlObjects(xmlObject, expected, problems); 218 assertTrue("Differences: " + problems, ok2); 219 } finally { 220 cursor.dispose(); 221 end.dispose(); 222 } 223 224 } 225 public void testQNameConverter2() throws Exception { 226 URL srcXml = classLoader.getResource("geronimo/qname2-pre.xml"); 227 URL expectedOutputXml = classLoader.getResource("geronimo/qname2-post.xml"); 228 XmlObject xmlObject = XmlObject.Factory.parse(srcXml); 229 ElementConverter elementConverter = new QNameConverter("import", "http://geronimo.apache.org/xml/ns/deployment-1.0", "parent"); 230 XmlCursor cursor = xmlObject.newCursor(); 231 XmlCursor end = cursor.newCursor(); 232 try { 233 elementConverter.convertElement(cursor, end); 234 XmlObject expected = XmlObject.Factory.parse(expectedOutputXml); 236 List problems = new ArrayList (); 237 boolean ok = compareXmlObjects(xmlObject, expected, problems); 238 assertTrue("Differences: " + problems, ok); 239 SchemaConversionUtils.convertToGeronimoSubSchemas(cursor); 240 boolean ok2 = compareXmlObjects(xmlObject, expected, problems); 241 assertTrue("Differences: " + problems, ok2); 242 } finally { 243 cursor.dispose(); 244 end.dispose(); 245 } 246 247 } 248 public void testWebMessageDestination1() throws Exception { 249 URL srcXml = classLoader.getResource("geronimo/web-md-pre.xml"); 250 URL expectedOutputXml = classLoader.getResource("geronimo/web-md-post.xml"); 251 XmlObject xmlObject = XmlBeansUtil.parse(srcXml, this.getClass().getClassLoader()); 252 XmlCursor cursor = xmlObject.newCursor(); 253 try { 254 SchemaConversionUtils.convertToGeronimoSubSchemas(cursor); 255 log.debug(xmlObject.toString()); 256 257 XmlObject expected = XmlObject.Factory.parse(expectedOutputXml); 258 log.debug(expected.toString()); 259 260 List problems = new ArrayList (); 261 boolean ok = compareXmlObjects(xmlObject, expected, problems); 262 assertTrue("Differences: " + problems, ok); 263 SchemaConversionUtils.convertToGeronimoSubSchemas(cursor); 264 boolean ok2 = compareXmlObjects(xmlObject, expected, problems); 265 assertTrue("Differences: " + problems, ok2); 266 } finally { 267 cursor.dispose(); 268 } 269 270 } 271 272 } 273 | Popular Tags |