1 22 package org.jboss.test.web.test; 23 24 import java.io.File ; 25 26 import javax.management.MBeanServerConnection ; 27 import javax.management.ObjectName ; 28 29 import org.jboss.test.JBossTestCase; 30 31 37 public class ServletContextDestroyTestCase extends JBossTestCase 38 { 39 File tmpLocation = null; 40 41 public void setup() 42 { 43 try 44 { 45 tmpLocation = getTmpLocation(); 46 File file = new File (tmpLocation, "ServletContextDestroyed.txt"); 47 if(file.exists()) 48 file.delete(); 49 }catch(Exception e) 50 { 51 fail(e.getLocalizedMessage()); 52 } 53 } 54 55 public ServletContextDestroyTestCase(String name) 56 { 57 super(name); 58 } 59 60 public void testContextDestroyEvent() throws Exception 61 { 62 deploy("jbosstest-ctx-destroy.war"); 63 undeploy("jbosstest-ctx-destroy.war"); 64 File file = new File (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 71 { 72 tmpLocation = getTmpLocation(); 73 deploy("jbosstest-ctx-destroy.war"); 74 shutDownJBoss(); 76 this.sleep(20000); File file = new File (tmpLocation, "ServletContextDestroyed.txt"); 78 assertTrue("File ServletContextDestroyed.txt exists?", file.exists()); 79 if(file.exists()) 80 file.delete(); 81 } 82 83 private File getTmpLocation() throws Exception 84 { 85 MBeanServerConnection server = this.getServer(); 86 ObjectName oname = new ObjectName ("jboss.system:type=ServerConfig"); 87 return (File )server.getAttribute(oname,"ServerTempDir"); 88 } 89 90 private void shutDownJBoss() throws Exception 91 { 92 MBeanServerConnection server = this.getServer(); 93 ObjectName oname = new ObjectName ("jboss.system:type=Server"); 94 server.invoke(oname,"shutdown", new Object []{}, new String []{}); 95 } 96 } 97 | Popular Tags |