KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > container > unit > ContainerTestCase


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.ejb3.test.container.unit;
23
24 import javax.management.MBeanServerConnection JavaDoc;
25 import javax.management.ObjectName JavaDoc;
26 import javax.naming.InitialContext JavaDoc;
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 /**
42  * @author <a HREF="mailto:bdecoste@jboss.com">William DeCoste</a>
43  */

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 JavaDoc name)
53    {
54       super(name);
55    }
56
57    public void testInvocationStatistics() throws Exception JavaDoc
58    {
59       InitialContext JavaDoc jndiContext = new InitialContext JavaDoc();
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 JavaDoc server = getServer();
72       
73       ObjectName JavaDoc objectName = new ObjectName JavaDoc("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 JavaDoc("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 JavaDoc("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 JavaDoc
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