KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > web > test > ServletContextDestroyTestCase


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.web.test;
23
24 import java.io.File JavaDoc;
25
26 import javax.management.MBeanServerConnection JavaDoc;
27 import javax.management.ObjectName JavaDoc;
28
29 import org.jboss.test.JBossTestCase;
30
31 /**
32  * JBAS-850: Tomcat doesn't call contextDestroyed() on JBoss shutdown
33  * @author <mailto:Anil.Saldhana@jboss.org>Anil Saldhana
34  * @since Jan 10, 2006
35  * @version $Revision: 39855 $
36  */

37 public class ServletContextDestroyTestCase extends JBossTestCase
38 {
39    File JavaDoc tmpLocation = null;
40    
41    public void setup()
42    {
43       try
44       {
45          tmpLocation = getTmpLocation();
46          File JavaDoc file = new File JavaDoc(tmpLocation, "ServletContextDestroyed.txt");
47          if(file.exists())
48             file.delete();
49       }catch(Exception JavaDoc e)
50       {
51          fail(e.getLocalizedMessage());
52       }
53    }
54    
55    public ServletContextDestroyTestCase(String JavaDoc name)
56    {
57       super(name);
58    }
59    
60    public void testContextDestroyEvent() throws Exception JavaDoc
61    {
62       deploy("jbosstest-ctx-destroy.war");
63       undeploy("jbosstest-ctx-destroy.war");
64       File JavaDoc file = new File JavaDoc(getTmpLocation(), "ServletContextDestroyed.txt");
65       assertTrue("File ServletContextDestroyed.txt exists?", file.exists());
66       if(file.exists())
67          file.delete();
68    }
69    
70    public void testShutdownContextDestroy() throws Exception JavaDoc
71    {
72       tmpLocation = getTmpLocation();
73       deploy("jbosstest-ctx-destroy.war");
74       //Shutdown JBoss
75
shutDownJBoss();
76       this.sleep(20000);//20 secs
77
File JavaDoc file = new File JavaDoc(tmpLocation, "ServletContextDestroyed.txt");
78       assertTrue("File ServletContextDestroyed.txt exists?", file.exists());
79       if(file.exists())
80          file.delete();
81    }
82    
83    private File JavaDoc getTmpLocation() throws Exception JavaDoc
84    {
85       MBeanServerConnection JavaDoc server = this.getServer();
86       ObjectName JavaDoc oname = new ObjectName JavaDoc("jboss.system:type=ServerConfig");
87       return (File JavaDoc)server.getAttribute(oname,"ServerTempDir");
88    }
89    
90    private void shutDownJBoss() throws Exception JavaDoc
91    {
92       MBeanServerConnection JavaDoc server = this.getServer();
93       ObjectName JavaDoc oname = new ObjectName JavaDoc("jboss.system:type=Server");
94       server.invoke(oname,"shutdown", new Object JavaDoc[]{}, new String JavaDoc[]{});
95    }
96 }
97
Popular Tags