1 22 package org.jboss.ejb3.test.ejbthree655.unit; 23 24 import javax.management.MBeanServerConnection ; 25 import javax.management.ObjectName ; 26 import javax.naming.NameNotFoundException ; 27 28 import junit.framework.Test; 29 30 import org.jboss.ejb3.test.ejbthree655.AbstractStateChecker; 31 import org.jboss.ejb3.test.ejbthree655.MyService; 32 import org.jboss.test.JBossTestCase; 33 34 40 public class ServiceManagementUnitTestCase extends JBossTestCase 41 { 42 public ServiceManagementUnitTestCase(String name) 43 { 44 super(name); 45 } 46 47 public void testHasCreateBeenCalled() throws Exception 48 { 49 MyService session = (MyService) getInitialContext().lookup("MyServiceBean/remote"); 50 session.sayHelloTo("me"); 51 52 AbstractStateChecker.State expected = AbstractStateChecker.State.STARTED; 53 assertEquals(expected, session.getState()); 54 } 55 56 public void test2() throws Exception 57 { 58 MyService session = (MyService) getInitialContext().lookup("MyManagedServiceBean/remote"); 59 session.sayHelloTo("me"); 60 61 AbstractStateChecker.State expected = AbstractStateChecker.State.STARTED; 62 assertEquals(expected, session.getState()); 63 } 64 65 public void testRestartContainer() throws Exception 66 { 67 MBeanServerConnection server = getServer(); 68 ObjectName name = new ObjectName ("jboss.j2ee:jar=ejbthree655.jar,name=MyManagedServiceBean,service=EJB3,type=ManagementInterface"); 69 Object params[] = { }; 70 String signature[] = { }; 71 server.invoke(name, "stop", params, signature); 72 73 { 74 AbstractStateChecker.State expected = AbstractStateChecker.State.STOPPED; 75 assertEquals(expected, server.getAttribute(name, "State")); 76 } 77 78 try 79 { 80 MyService session = (MyService) getInitialContext().lookup("MyManagedServiceBean/remote"); 81 session.sayHelloTo("me"); 82 83 fail("should have failed"); 84 } 85 catch(NameNotFoundException e) 86 { 87 String expected = "MyManagedServiceBean not bound"; 88 assertEquals(expected, e.getMessage()); 89 } 90 91 server.invoke(name, "start", params, signature); 92 93 { 94 AbstractStateChecker.State expected = AbstractStateChecker.State.STARTED; 95 assertEquals(expected, server.getAttribute(name, "State")); 96 } 97 } 98 99 public static Test suite() throws Exception 100 { 101 return getDeploySetup(ServiceManagementUnitTestCase.class, "ejbthree655.jar"); 102 } 103 } 104 | Popular Tags |