1 22 package org.jboss.ejb3.test.container.unit; 23 24 import javax.management.MBeanServerConnection ; 25 import javax.management.ObjectName ; 26 import javax.naming.InitialContext ; 27 28 import org.jboss.ejb3.test.reference21_30.Test2; 29 import org.jboss.ejb3.test.reference21_30.Test2Home; 30 import org.jboss.ejb3.test.reference21_30.Test3; 31 import org.jboss.ejb3.test.service.ServiceSixRemote; 32 import org.jboss.ejb3.test.stateful.ProxyFactoryInterface; 33 import org.jboss.ejb3.test.stateful.Stateful; 34 import org.jboss.ejb3.statistics.InvocationStatistics; 35 import org.jboss.logging.Logger; 36 import org.jboss.security.SecurityAssociation; 37 import org.jboss.security.SimplePrincipal; 38 import org.jboss.test.JBossTestCase; 39 import junit.framework.Test; 40 41 44 public class ContainerTestCase 45 extends JBossTestCase 46 { 47 private static final Logger log = Logger.getLogger(ContainerTestCase.class); 48 49 static boolean deployed = false; 50 static int test = 0; 51 52 public ContainerTestCase(String name) 53 { 54 super(name); 55 } 56 57 public void testInvocationStatistics() throws Exception 58 { 59 InitialContext jndiContext = new InitialContext (); 60 61 Test3 test3 = (Test3)jndiContext.lookup("Test3"); 62 assertNotNull(test3); 63 test3.testAccess(); 64 65 Test2Home home = (Test2Home)jndiContext.lookup("Test2"); 66 assertNotNull(home); 67 Test2 test2 = home.create(); 68 assertNotNull(test2); 69 test2.testAccess(); 70 71 MBeanServerConnection server = getServer(); 72 73 ObjectName objectName = new ObjectName ("jboss.j2ee:jar=multideploy-ejb3.jar,name=Test3,service=EJB3"); 74 InvocationStatistics stats = (InvocationStatistics)server.getAttribute(objectName, "InvokeStats"); 75 System.out.println("Stats \n" + stats); 76 assertTrue(stats.toString().contains("testAccess")); 77 78 ServiceSixRemote test = (ServiceSixRemote) getInitialContext().lookup("serviceSix/remote"); 79 test.setCalled(false); 80 81 objectName = new ObjectName ("jboss.j2ee:jar=service-test.jar,name=ServiceSix,service=EJB3"); 82 stats = (InvocationStatistics)server.getAttribute(objectName, "InvokeStats"); 83 System.out.println("Stats \n" + stats); 84 assertTrue(stats.toString().contains("setCalled")); 85 86 SecurityAssociation.setPrincipal(new SimplePrincipal("somebody")); 87 SecurityAssociation.setCredential("password".toCharArray()); 88 89 Stateful stateful = (Stateful)getInitialContext().lookup("Stateful"); 90 assertNotNull(stateful); 91 stateful.getState(); 92 93 objectName = new ObjectName ("jboss.j2ee:jar=stateful-test.jar,name=StatefulBean,service=EJB3"); 94 stats = (InvocationStatistics)server.getAttribute(objectName, "InvokeStats"); 95 System.out.println("Stats \n" + stats); 96 assertTrue(stats.toString().contains("getState")); 97 98 } 99 100 public static Test suite() throws Exception 101 { 102 return getDeploySetup(ContainerTestCase.class, "multideploy.jar, multideploy-ejb3.jar, service-test.sar, service-test.jar, stateful-test.jar"); 103 } 104 105 } 106 | Popular Tags |