KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jmx > test > UndeployBrokenPackageUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
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.jmx.test;
23
24 import java.io.File JavaDoc;
25 import javax.management.ObjectName JavaDoc;
26 import javax.naming.InitialContext JavaDoc;
27 import javax.naming.NamingException JavaDoc;
28
29 import org.jboss.test.JBossTestCase;
30 import org.jboss.test.jmx.eardeployment.a.interfaces.SessionA;
31 import org.jboss.test.jmx.eardeployment.a.interfaces.SessionAHome;
32 import org.jboss.test.jmx.eardeployment.b.interfaces.SessionB;
33 import org.jboss.test.jmx.eardeployment.b.interfaces.SessionBHome;
34 import org.jboss.deployment.DeploymentException;
35 import org.jboss.deployment.IncompleteDeploymentException;
36 import org.jboss.util.file.Files;
37
38 /** Tests of reployment of bad deployment packages
39  *
40  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
41  * @author Scott.Stark@jboss.org
42  * @version $Revision: 37406 $
43  */

44
45 public class UndeployBrokenPackageUnitTestCase extends JBossTestCase
46 {
47    public UndeployBrokenPackageUnitTestCase(String JavaDoc name)
48    {
49       super(name);
50    }
51
52    public void testBrokenPackageRedeployment() throws Exception JavaDoc
53    {
54       getLog().info("+++ testBrokenPackageRedeployment");
55       String JavaDoc testPackage = "undeploybroken.jar";
56       String JavaDoc missingDatasource = "test-service.xml";
57       ObjectName JavaDoc entityAName = new ObjectName JavaDoc("jboss.j2ee:service=EJB,jndiName=EntityA");
58       ObjectName JavaDoc entityBName = new ObjectName JavaDoc("jboss.j2ee:service=EJB,jndiName=EntityB");
59       getLog().info("testPackage is : " + testPackage);
60       try
61       {
62          try
63          {
64             deploy(testPackage);
65             fail("test package " + testPackage + " deployed successfully without needed datasource!");
66          }
67          catch (IncompleteDeploymentException e)
68          {
69             log.info("caught exception as expected", e);
70          } // end of try-catch
71
undeploy(testPackage);
72          getLog().info("Undeployed testPackage");
73          deploy(missingDatasource);
74          getLog().info("Deployed missing datasource");
75          deploy(testPackage);
76       }
77       finally
78       {
79          try
80          {
81             undeploy(testPackage);
82          }
83          catch (Throwable JavaDoc e)
84          {
85          } // end of try-catch
86
try
87          {
88             undeploy(missingDatasource);
89          }
90          catch (Throwable JavaDoc e)
91          {
92          } // end of try-catch
93

94       } // end of try-catch
95
try
96       {
97          getInitialContext().lookup("EntityA");
98          fail("EntityA found after undeployment");
99       }
100       catch (NamingException JavaDoc e)
101       {
102          log.info("caught exception as expected", e);
103       } // end of try-catch
104
try
105       {
106          getInitialContext().lookup("EntityB");
107          fail("EntityB found after undeployment");
108       }
109       catch (NamingException JavaDoc e)
110       {
111          log.info("caught exception as expected", e);
112       } // end of try-catch
113
assertTrue("EntityA mbean is registered!", !getServer().isRegistered(entityAName));
114       assertTrue("EntityB mbean is registered!", !getServer().isRegistered(entityBName));
115
116    }
117
118    /** Deploy an ejb that has an invalid ejb-jar.xml descriptor and then
119     reploy a valid version after undeploying the invalid jar.
120     */

121    public void testBadEjbRedeployment() throws Exception JavaDoc
122    {
123       getLog().info("+++ testBadEjbRedeployment");
124       String JavaDoc testPackage = "ejbredeploy.jar";
125       // Move the bad jar into ejbredeploy.jar
126
String JavaDoc deployDir = System.getProperty("jbosstest.deploy.dir");
127       File JavaDoc thejar = new File JavaDoc(deployDir, "ejbredeploy.jar");
128       File JavaDoc badjar = new File JavaDoc(deployDir, "ejbredeploy-bad.jar");
129       File JavaDoc goodjar = new File JavaDoc(deployDir, "ejbredeploy-good.jar");
130
131       thejar.delete();
132       Files.copy(badjar, thejar);
133       getLog().info("Deploying testPackage: " + testPackage);
134       try
135       {
136          deploy(testPackage);
137          fail("test package " + testPackage + " deployed successfully with bad descriptor!");
138       }
139       catch (DeploymentException e)
140       {
141          log.info("caught exception as expected", e);
142       }
143       undeploy(testPackage);
144       getLog().info("Undeployed bad testPackage");
145
146       thejar.delete();
147       Files.copy(goodjar, thejar);
148       getLog().info("Redeploying testPackage: " + testPackage);
149       deploy(testPackage);
150       Object JavaDoc home = getInitialContext().lookup("EntityA");
151       getLog().info("Found EntityA home");
152       undeploy(testPackage);
153    }
154
155    /** Deploy an ejb that has an invalid ejb-jar.xml descriptor and then
156     deploy a completely unrelated service to test that the failed deployment
157     does not prevent deployment of the unrelated service.
158     */

159    public void testBadSideAffects() throws Exception JavaDoc
160    {
161       getLog().info("+++ testBadSideAffects");
162       getLog().info("Deploying testPackage: ejbredeploy-bad.jar");
163       try
164       {
165          deploy("ejbredeploy-bad.jar");
166          fail("test package deployed successfully with bad descriptor!");
167       }
168       catch (DeploymentException e)
169       {
170          log.info("caught exception as expected", e);
171       }
172
173       try
174       {
175          getLog().info("Deploying testPackage: test-service.xml");
176          deploy("test-service.xml");
177          getLog().info("Deployed test-service.xml");
178          ObjectName JavaDoc serviceName = new ObjectName JavaDoc("jboss.test:service=TestService,test=jmx");
179          assertTrue("test-service.xml mbean is registered", getServer().isRegistered(serviceName));
180       }
181       finally
182       {
183          try
184          {
185             undeploy("test-service.xml");
186          }
187          catch(Throwable JavaDoc t)
188          {
189          }
190          try
191          {
192             undeploy("ejbredeploy-bad.jar");
193          }
194          catch(Throwable JavaDoc t)
195          {
196          }
197       }
198    }
199
200 }// UndeployBrokenPackageUnitTestCase
201

202
Popular Tags