1 22 package org.jboss.test.deployers; 23 24 import java.net.URL ; 25 import java.util.Iterator ; 26 import java.util.Set ; 27 28 import javax.management.MBeanServerConnection ; 29 30 import org.jboss.deployers.spi.structure.DeploymentContext; 31 import org.jboss.deployers.spi.structure.DeploymentState; 32 import org.jboss.deployment.MainDeployerMBean; 33 import org.jboss.test.JBossTestCase; 34 35 42 public class AbstractDeploymentTest extends JBossTestCase 43 { 44 public static final String ear1Deployment = "testdeployers-ear1.ear"; 45 public static final String ear1DeploymentUnpacked = "unpacked-ear1.ear"; 46 public static final String ear2DeploymentUnpacked = "unpacked-ear2.ear"; 47 public static final String earNoAppXml = "testdeployers-ear-noappxml.ear"; 48 public static final String bean1Deployment = "testdeployers-bean1ejb.jar"; 49 public static final String bean1DeploymentUnpacked = "unpacked-bean1ejb.jar"; 50 public static final String notBean1Deployment = "bean1ejb-not.ajar"; 51 public static final String notBean1DeploymentUnpacked = "unpacked-bean1ejb-not.ajar"; 52 public static final String web1Deployment = "testdeployers-web1.war"; 53 public static final String web1DeploymentUnpacked = "unpacked-web1.war"; 54 public static final String notWeb1Deployment = "web1-not.awar"; 55 public static final String notWeb1DeploymentUnpacked = "unpacked-web1-not.awar"; 56 public static final String rar1Deployment = "testdeployers-mcf1.rar"; 57 public static final String rar1DeploymentUnpacked = "unpacked-mcf1.rar"; 58 public static final String notRar1Deployment = "mcf1-not.arar"; 59 public static final String notRar1DeploymentUnpacked = "unpacked-mcf1-not.arar"; 60 public static final String rarjar1Deployment = "testdeployers-mcf1.jar"; 61 public static final String client1Deployment = "testdeployers-client1.jar"; 62 public static final String client1DeploymentUnpacked = "unpacked-client1.jar"; 63 public static final String notClient1Deployment = "client1-not.ajar"; 64 public static final String notClient1DeploymentUnpacked = "unpacked-client1-not.ajar"; 65 public static final String ds1Deployment = "testdeployers-mcf1-ds.xml"; 66 public static final String ds1DeploymentUnpacked = "unpacked-mcf1-ds.xml"; 67 public static final String ds1DeploymentUnpacked2 = "unpacked2-mcf1-ds.xml"; 68 public static final String service1Deployment = "testdeployers-1-service.xml"; 69 public static final String sar1Deployment = "testdeployers-mbean1.sar"; 70 public static final String sar1DeploymentUnpacked = "unpacked-mbean1.sar"; 71 public static final String notSar1Deployment = "mbean1-not.asar"; 72 public static final String notSar1DeploymentUnpacked = "unpacked-mbean1-not.asar"; 73 74 protected DeploymentContext assertDeployed(String deployment) throws Exception 75 { 76 DeploymentContext result = getDeploymentInfo(deployment); 77 assertNotNull("Unable to retrieve deployment info for " + deployment, result); 78 return result; 79 } 80 81 protected void assertDeployed(String deployment, Set expected) throws Exception 82 { 83 DeploymentContext topInfo = assertDeployed(deployment); 84 CheckExpectedDeploymentInfoVisitor visitor = new CheckExpectedDeploymentInfoVisitor(expected); 85 visitor.start(topInfo); 86 assertTrue("Expected subdeployments: " + expected, expected.isEmpty()); 87 } 88 89 protected void assertNotDeployed(String deployment) throws Exception 90 { 91 DeploymentContext result = getDeploymentInfo(deployment); 92 assertNull("Should not be deployed " + result, result); 93 } 94 95 protected DeploymentContext getDeploymentInfo(String deployment) throws Exception 96 { 97 MBeanServerConnection server = getServer(); 98 URL deployURL = getDeployURL(deployment); 99 String [] sig = { URL .class.getName() }; 100 Object [] args = {deployURL}; 101 DeploymentContext dc = (DeploymentContext) server.invoke(MainDeployerMBean.OBJECT_NAME, "getDeployment", args, sig); 102 return dc; 103 } 104 105 public AbstractDeploymentTest(String test) 106 { 107 super(test); 108 } 109 110 public static class DeploymentInfoVisitor 111 { 112 public void start(DeploymentContext topLevel) 113 { 114 doVisit(topLevel); 115 } 116 117 protected void doVisit(DeploymentContext info) 118 { 119 visit(info); 120 121 Set <DeploymentContext> subDeployments = info.getChildren(); 122 if (subDeployments == null || subDeployments.size() == 0) 123 return; 124 125 for (Iterator i = subDeployments.iterator(); i.hasNext(); ) 126 { 127 DeploymentContext child = (DeploymentContext) i.next(); 128 doVisit(child); 129 } 130 } 131 132 public void visit(DeploymentContext info) 133 { 134 } 135 } 136 137 public class CheckExpectedDeploymentInfoVisitor extends DeploymentInfoVisitor 138 { 139 protected Set expected; 140 141 public CheckExpectedDeploymentInfoVisitor(Set expected) 142 { 143 this.expected = expected; 144 } 145 146 public void visit(DeploymentContext info) 147 { 148 String shortName = shortNameFromDeploymentName(info.getName()); 149 log.info("Found deployment " + shortName); 150 boolean found = expected.remove(shortName); 151 if (found == false) 152 fail(shortName + " not expected, or duplicate?"); 153 else 154 { 155 DeploymentState state = info.getState(); 156 assertEquals("Should be fully deployed: " + shortName + " state=" + state, DeploymentState.DEPLOYED, state); 157 } 158 } 159 } 160 165 public static String shortNameFromDeploymentName(String name) 166 { 167 String shortName = name.trim(); 168 String [] parts = name.split("/|!"); 169 if( parts.length > 1 ) 170 { 171 shortName = parts[parts.length-1]; 172 } 173 return shortName; 174 } 175 176 } 177 | Popular Tags |