1 17 package org.apache.geronimo.jetty6.deployment; 18 19 import java.io.File ; 20 import java.net.URL ; 21 import java.util.ArrayList ; 22 import java.util.Collections ; 23 import java.util.HashSet ; 24 import java.util.jar.JarFile ; 25 26 import org.apache.geronimo.deployment.util.UnpackedJarFile; 27 import org.apache.geronimo.deployment.service.GBeanBuilder; 28 import org.apache.geronimo.deployment.xbeans.ArtifactType; 29 import org.apache.geronimo.deployment.xbeans.EnvironmentType; 30 import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil; 31 import org.apache.geronimo.gbean.AbstractName; 32 import org.apache.geronimo.gbean.AbstractNameQuery; 33 import org.apache.geronimo.j2ee.deployment.WebServiceBuilder; 34 import org.apache.geronimo.j2ee.deployment.NamingBuilderCollection; 35 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 36 import org.apache.geronimo.kernel.Jsr77Naming; 37 import org.apache.geronimo.kernel.Naming; 38 import org.apache.geronimo.kernel.repository.Artifact; 39 import org.apache.geronimo.kernel.repository.Environment; 40 import org.apache.geronimo.schema.SchemaConversionUtils; 41 import org.apache.geronimo.security.deployment.GeronimoSecurityBuilderImpl; 42 import org.apache.geronimo.testsupport.XmlBeansTestSupport; 43 import org.apache.geronimo.web.deployment.GenericToSpecificPlanConverter; 44 import org.apache.geronimo.xbeans.geronimo.naming.GerResourceRefType; 45 import org.apache.geronimo.xbeans.geronimo.web.jetty.JettyWebAppDocument; 46 import org.apache.geronimo.xbeans.geronimo.web.jetty.JettyWebAppType; 47 import org.apache.geronimo.xbeans.geronimo.web.jetty.config.GerJettyDocument; 48 import org.apache.geronimo.xbeans.javaee.WebAppDocument; 49 import org.apache.geronimo.xbeans.javaee.WebAppType; 50 import org.apache.xmlbeans.XmlCursor; 51 import org.apache.xmlbeans.XmlObject; 52 53 55 public class PlanParsingTest extends XmlBeansTestSupport { 56 57 private ClassLoader classLoader = this.getClass().getClassLoader(); 58 59 private Naming naming = new Jsr77Naming(); 60 private Artifact baseId = new Artifact("test", "base", "1", "car"); 61 private AbstractName baseRootName = naming.createRootName(baseId, "root", NameFactory.SERVICE_MODULE); 62 private AbstractNameQuery jettyContainerObjectName = new AbstractNameQuery(naming.createChildName(baseRootName, "jettyContainer", NameFactory.GERONIMO_SERVICE)); 63 private AbstractName pojoWebServiceTemplate = null; 64 private WebServiceBuilder webServiceBuilder = null; 65 private Environment defaultEnvironment = new Environment(); 66 private JettyModuleBuilder builder; 67 68 public PlanParsingTest() throws Exception { 69 builder = new JettyModuleBuilder(defaultEnvironment, 70 new Integer (1800), 71 null, 72 jettyContainerObjectName, 73 null, new HashSet (), 74 new HashSet (), 75 new HashSet (), 76 pojoWebServiceTemplate, 77 Collections.singleton(webServiceBuilder), 78 null, 79 Collections.singleton(new GeronimoSecurityBuilderImpl()), 80 Collections.singleton(new GBeanBuilder(null, null)), 81 new NamingBuilderCollection(null, null), 82 new MockResourceEnvironmentSetter(), 83 null); 84 } 85 86 public void testContents() throws Exception { 87 URL resourcePlan = classLoader.getResource("plans/plan1.xml"); 88 assertTrue(resourcePlan != null); 89 JettyWebAppType jettyWebApp = builder.getJettyWebApp(new File (resourcePlan.getFile()), null, true, null, null); 90 assertEquals(1, jettyWebApp.getResourceRefArray().length); 91 } 93 94 public void testMoveSecurity1() throws Exception { 95 URL resourcePlan = classLoader.getResource("plans/plan1A.xml"); 96 assertTrue(resourcePlan != null); 97 JettyWebAppType jettyWebApp = builder.getJettyWebApp(new File (resourcePlan.getFile()), null, true, null, null); 98 assertEquals(1, jettyWebApp.getResourceRefArray().length); 99 } 101 102 public void testMoveSecurity2() throws Exception { 103 URL resourcePlan = classLoader.getResource("plans/plan1B.xml"); 104 assertTrue(resourcePlan != null); 105 JettyWebAppType jettyWebApp = builder.getJettyWebApp(new File (resourcePlan.getFile()), null, true, null, null); 106 assertEquals(1, jettyWebApp.getResourceRefArray().length); 107 } 109 110 public void testMoveSecurity3() throws Exception { 111 URL resourcePlan = classLoader.getResource("plans/plan1C.xml"); 112 assertTrue(resourcePlan != null); 113 JettyWebAppType jettyWebApp = builder.getJettyWebApp(new File (resourcePlan.getFile()), null, true, null, null); 114 } 117 118 public void testOldFormat() throws Exception { 119 URL resourcePlan = classLoader.getResource("plans/plan2.xml"); 120 assertTrue(resourcePlan != null); 121 JettyWebAppType jettyWebApp = builder.getJettyWebApp(new File (resourcePlan.getFile()), null, true, null, null); 122 assertEquals(1, jettyWebApp.getResourceRefArray().length); 123 } 125 126 public void testOldFormatExploded() throws Exception { 127 URL war = classLoader.getResource("deployables/war5"); 128 assertTrue(war != null); 129 UnpackedJarFile moduleFile = new UnpackedJarFile(new File (war.getFile())); 130 JettyWebAppType jettyWebApp = builder.getJettyWebApp(null, moduleFile, true, null, null); 131 moduleFile.close(); 132 assertEquals(1, jettyWebApp.getResourceRefArray().length); 133 } 134 135 public void XtestOldFormatPackaged() throws Exception { 136 URL war = classLoader.getResource("deployables/war6.war"); 137 assertTrue(war != null); 138 JarFile moduleFile = new JarFile (new File (war.getFile())); 139 JettyWebAppType jettyWebApp = builder.getJettyWebApp(null, moduleFile, true, null, null); 140 moduleFile.close(); 141 assertEquals(1, jettyWebApp.getResourceRefArray().length); 142 } 143 144 public void testConstructPlan() throws Exception { 145 JettyWebAppDocument jettyWebAppDoc = JettyWebAppDocument.Factory.newInstance(); 146 JettyWebAppType webApp = jettyWebAppDoc.addNewWebApp(); 147 addEnvironment(webApp); 148 GerResourceRefType ref = webApp.addNewResourceRef(); 149 ref.setRefName("ref"); 150 ref.setResourceLink("target"); 151 152 XmlBeansUtil.validateDD(webApp); 153 log.debug(webApp.toString()); 154 } 155 156 private void addEnvironment(JettyWebAppType webApp) { 157 EnvironmentType environmentType = webApp.addNewEnvironment(); 158 ArtifactType configId = environmentType.addNewModuleId(); 159 configId.setGroupId("g"); 160 configId.setArtifactId("a"); 161 configId.setVersion("1"); 162 configId.setType("car"); 163 } 164 165 172 public void testContextRootWithPlanAndContextSet() throws Exception { 173 174 JettyWebAppDocument jettyWebAppDoc = JettyWebAppDocument.Factory.newInstance(); 175 JettyWebAppType webApp = jettyWebAppDoc.addNewWebApp(); 176 addEnvironment(webApp); 177 webApp.setContextRoot("myContextRoot"); 178 179 URL war = classLoader.getResource("deployables/war2.war"); 180 assertTrue(war != null); 181 JarFile dummyFile = new JarFile (new File (war.getFile())); 182 183 webApp = builder.getJettyWebApp(webApp, dummyFile, true, null, null); 184 185 assertEquals("myContextRoot", webApp.getContextRoot()); 186 187 } 188 189 public void testContextRootWithoutPlanStandAlone() throws Exception { 190 191 URL war = classLoader.getResource("deployables/war2.war"); 192 assertTrue(war != null); 193 JarFile dummyFile = new JarFile (new File (war.getFile())); 194 JettyWebAppType GerWebAppType = builder.getJettyWebApp(null, dummyFile, true, null, null); 195 196 assertEquals("/war2", GerWebAppType.getContextRoot()); 197 198 } 199 200 public void testContextRootWithoutPlanAndTargetPath() throws Exception { 201 202 URL war = classLoader.getResource("deployables/war2.war"); 203 assertTrue(war != null); 204 JarFile dummyFile = new JarFile (new File (war.getFile())); 205 JettyWebAppType GerWebAppType = builder.getJettyWebApp(null, dummyFile, false, "myTargetPath", null); 206 207 assertEquals("myTargetPath", GerWebAppType.getContextRoot()); 208 209 } 210 211 public void testContextRootWithoutPlanButWebApp() throws Exception { 212 213 WebAppDocument webAppDocument = WebAppDocument.Factory.newInstance(); 214 WebAppType webAppType = webAppDocument.addNewWebApp(); 215 webAppType.setId("myId"); 216 217 URL war = classLoader.getResource("deployables/war2.war"); 218 assertTrue(war != null); 219 JarFile dummyFile = new JarFile (new File (war.getFile())); 220 JettyWebAppType GerWebAppType = builder.getJettyWebApp(null, dummyFile, false, "myTargetPath", webAppType); 221 222 assertEquals("myId", GerWebAppType.getContextRoot()); 223 224 } 225 226 public void testParseSpecDD() { 227 228 } 229 230 public void xtestConvertToJettySchema() throws Exception { 231 URL resourcePlan = classLoader.getResource("plans/plan4.xml"); 232 assertTrue(resourcePlan != null); 233 XmlObject rawPlan = XmlBeansUtil.parse(resourcePlan, getClass().getClassLoader()); 234 XmlObject webPlan = new GenericToSpecificPlanConverter(GerJettyDocument.type.getDocumentElementName().getNamespaceURI(), 235 JettyWebAppDocument.type.getDocumentElementName().getNamespaceURI(), "jetty").convertToSpecificPlan(rawPlan); 236 URL ConvertedPlan = classLoader.getResource("plans/plan4-converted.xml"); 237 assertTrue(ConvertedPlan != null); 238 XmlObject converted = XmlBeansUtil.parse(ConvertedPlan, getClass().getClassLoader()); 239 XmlCursor c = converted.newCursor(); 240 SchemaConversionUtils.findNestedElement(c, JettyWebAppDocument.type.getDocumentElementName()); 241 c.toFirstChild(); 242 ArrayList problems = new ArrayList (); 243 compareXmlObjects(webPlan, c.getObject(), problems); 244 assertEquals("problems: " + problems, 0, problems.size()); 245 } 246 247 } 248 | Popular Tags |