1 22 package org.jboss.ejb3.test.standalone.servicepojo.unit; 23 24 import javax.management.MBeanServerConnection ; 25 import javax.management.ObjectName ; 26 import javax.naming.InitialContext ; 27 28 import junit.extensions.TestSetup; 29 import junit.framework.Test; 30 import junit.framework.TestCase; 31 import junit.framework.TestSuite; 32 33 import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap; 34 import org.jboss.ejb3.test.standalone.servicepojo.ServiceOneLocal; 35 import org.jboss.ejb3.test.standalone.servicepojo.ServiceTwoLocal; 36 import org.jboss.mx.util.MBeanServerLocator; 37 38 public class ServicePOJOTestCase extends TestCase 39 { 40 public ServicePOJOTestCase(String name) 41 { 42 super(name); 43 } 44 45 private static MBeanServerConnection getServer() 46 { 47 return MBeanServerLocator.locate(); 48 } 49 50 public void testLocalInterface() throws Exception 51 { 52 InitialContext ctx = new InitialContext (); 53 ServiceOneLocal service = (ServiceOneLocal) ctx.lookup("ServiceOneBean/local"); 54 service.setAttribute(1); 55 } 56 57 public void testManagementInterface() throws Exception 58 { 59 MBeanServerConnection server = getServer(); 60 ObjectName name = new ObjectName ("jboss.j2ee:jar=embedded-servicepojo,name=ServiceOneBean,service=EJB3,type=ManagementInterface"); 61 Object params[] = { "me" }; 62 String signature[] = { String .class.getName() }; 63 String result = (String ) server.invoke(name, "sayHello", params, signature); 64 assertEquals("Hello me", result); 65 } 66 67 public void testPartialManagementInterface() throws Exception 68 { 69 MBeanServerConnection server = getServer(); 70 ObjectName name = new ObjectName ("jboss.j2ee:jar=embedded-servicepojo,name=ServiceTwoBean,service=EJB3,type=ManagementInterface"); 71 Object params[] = { "me" }; 72 String signature[] = { String .class.getName() }; 73 String result = (String ) server.invoke(name, "sayHello", params, signature); 74 assertEquals("Hello me", result); 75 } 76 77 public void testStateOne() throws Exception 78 { 79 InitialContext ctx = new InitialContext (); 80 ServiceOneLocal service = (ServiceOneLocal) ctx.lookup("ServiceOneBean/local"); 81 int actualState = service.getState(); 82 assertEquals(2, actualState); 83 } 84 85 public void testStateTwo() throws Exception 86 { 87 InitialContext ctx = new InitialContext (); 88 ServiceTwoLocal service = (ServiceTwoLocal) ctx.lookup("ServiceTwoBean/local"); 89 int actualState = service.getState(); 90 assertEquals(1, actualState); 91 } 92 93 public static Test suite() throws Exception 94 { 95 TestSuite suite = new TestSuite(); 96 suite.addTestSuite(ServicePOJOTestCase.class); 97 98 TestSetup wrapper = new TestSetup(suite) 100 { 101 protected void setUp() 102 { 103 startupEmbeddedJboss(); 104 } 105 106 protected void tearDown() 107 { 108 shutdownEmbeddedJboss(); 109 } 110 }; 111 112 return wrapper; 113 } 114 115 public static void startupEmbeddedJboss() 116 { 117 EJB3StandaloneBootstrap.boot(null); 118 EJB3StandaloneBootstrap.scanClasspath("embedded-servicepojo.jar"); 119 } 120 121 public static void shutdownEmbeddedJboss() 122 { 123 EJB3StandaloneBootstrap.shutdown(); 124 } 125 } 126 | Popular Tags |