1 package org.jboss.test.deployers; 2 3 import java.net.URL ; 4 import java.util.HashSet ; 5 import java.util.Iterator ; 6 import java.util.List ; 7 import java.util.Map ; 8 9 import org.jboss.deployers.plugins.deployer.AbstractDeploymentUnit; 10 import org.jboss.deployers.plugins.deployment.MainDeployerImpl; 11 import org.jboss.deployers.plugins.structure.AbstractDeploymentContext; 12 import org.jboss.deployers.spi.deployer.DeploymentUnit; 13 import org.jboss.deployers.spi.structure.DeploymentContext; 14 import org.jboss.deployers.spi.structure.StructureDetermined; 15 import org.jboss.metadata.EjbLocalRefMetaData; 16 import org.jboss.metadata.EnvEntryMetaData; 17 import org.jboss.metadata.WebMetaData; 18 import org.jboss.metadata.web.ParamValue; 19 import org.jboss.test.BaseTestCase; 20 import org.jboss.virtual.VFS; 21 import org.jboss.virtual.VirtualFile; 22 import org.jboss.deployment.JBossWebAppParsingDeployer; 23 import org.jboss.deployment.WebAppParsingDeployer; 24 25 35 public class WebAppParsingDeployerTestCase extends BaseTestCase 36 { 37 38 public WebAppParsingDeployerTestCase(String name) 39 { 40 super(name); 41 } 42 43 48 @Override 49 protected void setUp() throws Exception 50 { 51 System.setProperty("org.jboss.test.logging.LogginPlugin", 52 "org.jboss.test.logging.Log4jConsoleLoggingPlugin"); 53 super.setUp(); 54 } 55 56 60 public void testWebApp24Ex1() 61 throws Exception 62 { 63 log.info("testWebApp24Ex1"); 64 DeploymentUnit unit = createDeploymentUnit("org/jboss/test/deployers"); 65 WebAppParsingDeployer deployer = new WebAppParsingDeployer(); 66 67 deployer.setWebXmlPath("web24-ex1.xml"); 68 deployer.deploy(unit); 69 WebMetaData dd = unit.getAttachment(WebMetaData.class); 70 assertNotNull("WebMetaData dd", dd); 71 validateWebMetaData24Ex1(dd, false); 72 } 73 74 81 public void testWebAppJBossWebApp() 82 throws Exception 83 { 84 DeploymentUnit unit = createDeploymentUnit("org/jboss/test/deployers"); 85 MainDeployerImpl md = new MainDeployerImpl(); 86 WebAppParsingDeployer d1 = new WebAppParsingDeployer(); 87 d1.setWebXmlPath("web24-ex1.xml"); 88 md.addDeployer(d1); 89 JBossWebAppParsingDeployer d2 = new JBossWebAppParsingDeployer(); 90 md.addDeployer(d2); 91 d2.setWebXmlPath("jboss-web24-ex1.xml"); 92 DeploymentContext ctx = unit.getDeploymentContext(); 93 ctx.setStructureDetermined(StructureDetermined.PREDETERMINED); 94 md.addDeploymentContext(ctx); 95 md.process(); 96 97 WebMetaData dd = unit.getAttachment(WebMetaData.class); 98 assertNotNull("WebMetaData dd", dd); 99 validateWebMetaData24Ex1(dd, true); 100 } 101 102 110 protected void validateWebMetaData24Ex1(WebMetaData dd, boolean hasJBossWeb) 111 { 112 assertEquals("web-app/description", "Web App 2.4 Descriptor", dd.getDescription()); 113 assertEquals("web-app/display-name", "Web App 2.4 Descriptor on Display", dd.getDisplayName()); 114 assertEquals("web-app/distributable", true, dd.getDistributable()); 115 List <ParamValue> contextParams = dd.getContextParams(); 117 assertEquals("context-params.size = 1", 1, contextParams.size()); 118 ParamValue pv = contextParams.get(0); 119 assertEquals("pv.description", "A test context-param", pv.getDescription()); 120 assertEquals("pv.name", "contextParam1", pv.getName()); 121 assertEquals("pv.value", "contextParam1Value", pv.getValue()); 122 Map <String , EjbLocalRefMetaData> ejbLocalRefs = dd.getEjbLocalReferenceMap(); 124 assertEquals("ejb-local-ref.size = 1", 1, ejbLocalRefs.size()); 125 EjbLocalRefMetaData elrmd = ejbLocalRefs.get("SomeLocalEJB"); 126 assertNotNull("SomeLocalEJB", elrmd); 127 assertEquals("SomeLocalEJB", elrmd.getName()); 128 assertEquals("SomeLocalEJB.Local", "org.jboss.ejb.ISomeLocal", elrmd.getLocal()); 129 assertEquals("SomeLocalEJB.LocalHome", "org.jboss.ejb.ISomeLocalHome", elrmd.getLocalHome()); 130 assertEquals("SomeLocalEJB.Type", "Session", elrmd.getType()); 131 HashSet <String > expectedNames = new HashSet <String >(); 133 expectedNames.add("aString"); 134 expectedNames.add("anInt"); 135 Iterator <EnvEntryMetaData> envEntryIter = dd.getEnvironmentEntries(); 136 while( envEntryIter.hasNext() ) 137 { 138 EnvEntryMetaData entry = envEntryIter.next(); 139 if( entry.getName().endsWith("aString") ) 140 { 141 assertEquals("type is String", "java.lang.String", entry.getType()); 142 assertEquals("aStringValue", "aStringValue", entry.getValue()); 143 } 144 else if( entry.getName().endsWith("anInt") ) 145 { 146 assertEquals("type is Integer", "java.lang.Integer", entry.getType()); 147 assertEquals("aStringValue", "123456", entry.getValue()); 148 } 149 expectedNames.remove(entry.getName()); 150 } 151 assertEquals("All expected names seen", 0, expectedNames.size()); 152 if( hasJBossWeb == false ) 153 return; 154 155 String contextRoot = dd.getContextRoot(); 156 assertEquals("context-root", "testWebAppJBossWebApp", contextRoot); 157 } 158 159 166 protected VirtualFile getVirtualFile(String path) throws Exception 167 { 168 URL url = getClass().getProtectionDomain().getCodeSource().getLocation(); 169 log.debug("CodeSource: "+url); 170 return VFS.getVirtualFile(url, path); 171 } 172 protected DeploymentUnit createDeploymentUnit(String path) 173 throws Exception 174 { 175 VirtualFile file = getVirtualFile(path); 176 log.debug("Resolved path to: "+file); 177 AbstractDeploymentContext context = new AbstractDeploymentContext(file); 178 context.setMetaDataPath("/"); 180 AbstractDeploymentUnit unit = new AbstractDeploymentUnit(context); 181 return unit; 182 } 183 184 } 185 | Popular Tags |