1 17 18 package org.apache.geronimo.web25.deployment; 19 20 import java.net.URL ; 21 import java.util.List ; 22 import java.util.ArrayList ; 23 import java.util.Collection ; 24 import java.util.jar.JarFile ; 25 26 import org.apache.geronimo.testsupport.XmlBeansTestSupport; 27 import org.apache.geronimo.j2ee.deployment.Module; 28 import org.apache.geronimo.j2ee.deployment.EARContext; 29 import org.apache.geronimo.gbean.AbstractName; 30 import org.apache.geronimo.kernel.Naming; 31 import org.apache.geronimo.kernel.Kernel; 32 import org.apache.geronimo.deployment.ModuleIDBuilder; 33 import org.apache.geronimo.common.DeploymentException; 34 import org.apache.xmlbeans.XmlObject; 35 import org.apache.xmlbeans.XmlException; 36 import org.apache.xmlbeans.XmlOptions; 37 38 41 public class SchemaConversionTest extends XmlBeansTestSupport { 42 43 private ClassLoader classLoader = this.getClass().getClassLoader(); 44 private XmlOptions options = new XmlOptions(); 45 private WebModuleBuilder webModuleBuilder = new WebModuleBuilder(null); 46 47 public void testWeb24To25Transform() throws Exception { 48 URL srcXml = classLoader.getResource("j2ee_1_4schema/web-2-24.xml"); 49 URL expectedOutputXml = classLoader.getResource("javaee_5schema/web-2-25.xml"); 50 XmlObject xmlObject = XmlObject.Factory.parse(srcXml, options); 51 xmlObject = webModuleBuilder.convertToServletSchema(xmlObject); 52 XmlObject expected = XmlObject.Factory.parse(expectedOutputXml); 53 System.out.println(xmlObject.toString()); 54 System.out.println(expected.toString()); 55 List problems = new ArrayList (); 56 boolean ok = compareXmlObjects(xmlObject, expected, problems); 57 assertTrue("Differences: " + problems, ok); 58 xmlObject = webModuleBuilder.convertToServletSchema(xmlObject); 59 boolean ok2 = compareXmlObjects(xmlObject, expected, problems); 60 assertTrue("Differences: " + problems, ok2); 61 } 62 63 public void testWeb23To25Transform() throws Exception { 64 URL srcXml = classLoader.getResource("j2ee_1_3dtd/web-23.xml"); 65 URL expectedOutputXml = classLoader.getResource("j2ee_1_3dtd/web-25.xml"); 66 XmlObject xmlObject = XmlObject.Factory.parse(srcXml); 67 xmlObject = webModuleBuilder.convertToServletSchema(xmlObject); 68 XmlObject expected = XmlObject.Factory.parse(expectedOutputXml); 69 System.out.println(xmlObject.toString()); 70 System.out.println(expected.toString()); 71 List problems = new ArrayList (); 72 boolean ok = compareXmlObjects(xmlObject, expected, problems); 73 assertTrue("Differences: " + problems, ok); 74 xmlObject = webModuleBuilder.convertToServletSchema(xmlObject); 75 boolean ok2 = compareXmlObjects(xmlObject, expected, problems); 76 assertTrue("Differences: " + problems, ok2); 77 } 78 79 public void testWeb23To25OtherTransform() throws Exception { 80 URL srcXml = classLoader.getResource("j2ee_1_3dtd/web-1-23.xml"); 81 URL expectedOutputXml = classLoader.getResource("j2ee_1_3dtd/web-1-25.xml"); 82 XmlObject xmlObject = XmlObject.Factory.parse(srcXml); 83 xmlObject = webModuleBuilder.convertToServletSchema(xmlObject); 84 XmlObject expected = XmlObject.Factory.parse(expectedOutputXml); 86 List problems = new ArrayList (); 87 boolean ok = compareXmlObjects(xmlObject, expected, problems); 88 assertTrue("Differences: " + problems, ok); 89 xmlObject = webModuleBuilder.convertToServletSchema(xmlObject); 90 boolean ok2 = compareXmlObjects(xmlObject, expected, problems); 91 assertTrue("Differences: " + problems, ok2); 92 } 93 94 public void testWeb22To25Transform1() throws Exception { 95 URL srcXml = classLoader.getResource("j2ee_1_2dtd/web-1-22.xml"); 96 URL expectedOutputXml = classLoader.getResource("j2ee_1_2dtd/web-1-25.xml"); 97 XmlObject xmlObject = XmlObject.Factory.parse(srcXml); 98 xmlObject = webModuleBuilder.convertToServletSchema(xmlObject); 99 XmlObject expected = XmlObject.Factory.parse(expectedOutputXml); 100 List problems = new ArrayList (); 103 boolean ok = compareXmlObjects(xmlObject, expected, problems); 104 assertTrue("Differences: " + problems, ok); 105 xmlObject = webModuleBuilder.convertToServletSchema(xmlObject); 106 boolean ok2 = compareXmlObjects(xmlObject, expected, problems); 107 assertTrue("Differences: " + problems, ok2); 108 } 109 110 public void testWebRejectBad25() throws Exception { 111 URL srcXml = classLoader.getResource("javaee_5schema/web-1-25.xml"); 112 XmlObject xmlObject = XmlObject.Factory.parse(srcXml); 113 try { 114 webModuleBuilder.convertToServletSchema(xmlObject); 115 fail("doc src/test-data/javaee_5schema/web-1-25.xml is invalid, should not have validated"); 116 } catch (XmlException e) { 117 } 119 } 120 121 public void testParseWeb25() throws Exception { 122 URL srcXml = classLoader.getResource("javaee_5schema/web-2-25.xml"); 123 XmlObject xmlObject = XmlObject.Factory.parse(srcXml); 124 webModuleBuilder.convertToServletSchema(xmlObject); 125 } 126 127 private static class WebModuleBuilder extends AbstractWebModuleBuilder { 128 129 protected WebModuleBuilder(Kernel kernel) { 130 super(kernel, null, null, null, null); 131 } 132 133 protected Module createModule(Object plan, JarFile moduleFile, String targetPath, URL specDDUrl, boolean standAlone, String contextRoot, AbstractName earName, Naming naming, ModuleIDBuilder idBuilder) throws DeploymentException { 134 return null; 135 } 136 137 public void initContext(EARContext earContext, Module module, ClassLoader classLoader) throws DeploymentException { 138 } 139 140 public void addGBeans(EARContext earContext, Module module, ClassLoader classLoader, Collection repositories) throws DeploymentException { 141 } 142 143 public String getSchemaNamespace() { 144 return null; 145 } 146 } 147 148 149 } 150 | Popular Tags |