KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > deployers > AbstractDeploymentTest


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2006, Red Hat Middleware LLC, and individual contributors
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.test.deployers;
23
24 import java.net.URL JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Set JavaDoc;
27
28 import javax.management.MBeanServerConnection JavaDoc;
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 /**
36  * Abstract deployment test.
37  *
38  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
39  * @author Scott.Stark@jboss.org
40  * @version $Revision: 58276 $
41  */

42 public class AbstractDeploymentTest extends JBossTestCase
43 {
44    public static final String JavaDoc ear1Deployment = "testdeployers-ear1.ear";
45    public static final String JavaDoc ear1DeploymentUnpacked = "unpacked-ear1.ear";
46    public static final String JavaDoc ear2DeploymentUnpacked = "unpacked-ear2.ear";
47    public static final String JavaDoc earNoAppXml = "testdeployers-ear-noappxml.ear";
48    public static final String JavaDoc bean1Deployment = "testdeployers-bean1ejb.jar";
49    public static final String JavaDoc bean1DeploymentUnpacked = "unpacked-bean1ejb.jar";
50    public static final String JavaDoc notBean1Deployment = "bean1ejb-not.ajar";
51    public static final String JavaDoc notBean1DeploymentUnpacked = "unpacked-bean1ejb-not.ajar";
52    public static final String JavaDoc web1Deployment = "testdeployers-web1.war";
53    public static final String JavaDoc web1DeploymentUnpacked = "unpacked-web1.war";
54    public static final String JavaDoc notWeb1Deployment = "web1-not.awar";
55    public static final String JavaDoc notWeb1DeploymentUnpacked = "unpacked-web1-not.awar";
56    public static final String JavaDoc rar1Deployment = "testdeployers-mcf1.rar";
57    public static final String JavaDoc rar1DeploymentUnpacked = "unpacked-mcf1.rar";
58    public static final String JavaDoc notRar1Deployment = "mcf1-not.arar";
59    public static final String JavaDoc notRar1DeploymentUnpacked = "unpacked-mcf1-not.arar";
60    public static final String JavaDoc rarjar1Deployment = "testdeployers-mcf1.jar";
61    public static final String JavaDoc client1Deployment = "testdeployers-client1.jar";
62    public static final String JavaDoc client1DeploymentUnpacked = "unpacked-client1.jar";
63    public static final String JavaDoc notClient1Deployment = "client1-not.ajar";
64    public static final String JavaDoc notClient1DeploymentUnpacked = "unpacked-client1-not.ajar";
65    public static final String JavaDoc ds1Deployment = "testdeployers-mcf1-ds.xml";
66    public static final String JavaDoc ds1DeploymentUnpacked = "unpacked-mcf1-ds.xml";
67    public static final String JavaDoc ds1DeploymentUnpacked2 = "unpacked2-mcf1-ds.xml";
68    public static final String JavaDoc service1Deployment = "testdeployers-1-service.xml";
69    public static final String JavaDoc sar1Deployment = "testdeployers-mbean1.sar";
70    public static final String JavaDoc sar1DeploymentUnpacked = "unpacked-mbean1.sar";
71    public static final String JavaDoc notSar1Deployment = "mbean1-not.asar";
72    public static final String JavaDoc notSar1DeploymentUnpacked = "unpacked-mbean1-not.asar";
73    
74    protected DeploymentContext assertDeployed(String JavaDoc deployment) throws Exception JavaDoc
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 JavaDoc deployment, Set JavaDoc expected) throws Exception JavaDoc
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 JavaDoc deployment) throws Exception JavaDoc
90    {
91       DeploymentContext result = getDeploymentInfo(deployment);
92       assertNull("Should not be deployed " + result, result);
93    }
94    
95    protected DeploymentContext getDeploymentInfo(String JavaDoc deployment) throws Exception JavaDoc
96    {
97       MBeanServerConnection JavaDoc server = getServer();
98       URL JavaDoc deployURL = getDeployURL(deployment);
99       String JavaDoc[] sig = { URL JavaDoc.class.getName() };
100       Object JavaDoc[] args = {deployURL};
101       DeploymentContext dc = (DeploymentContext) server.invoke(MainDeployerMBean.OBJECT_NAME, "getDeployment", args, sig);
102       return dc;
103    }
104    
105    public AbstractDeploymentTest(String JavaDoc 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 JavaDoc<DeploymentContext> subDeployments = info.getChildren();
122          if (subDeployments == null || subDeployments.size() == 0)
123             return;
124          
125          for (Iterator JavaDoc 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 JavaDoc expected;
140       
141       public CheckExpectedDeploymentInfoVisitor(Set JavaDoc expected)
142       {
143          this.expected = expected;
144       }
145       
146       public void visit(DeploymentContext info)
147       {
148          String JavaDoc 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    /**
161     * A utility method that takes a deployment unit name and strips it down to the base war
162     * name without the .war suffix.
163     * @param name - the DeploymentUnit name.
164     */

165    public static String JavaDoc shortNameFromDeploymentName(String JavaDoc name)
166    {
167       String JavaDoc shortName = name.trim();
168       String JavaDoc[] 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