KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > standalone > servicepojo > unit > ServicePOJOTestCase


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.standalone.servicepojo.unit;
23
24 import javax.management.MBeanServerConnection JavaDoc;
25 import javax.management.ObjectName JavaDoc;
26 import javax.naming.InitialContext JavaDoc;
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 JavaDoc name)
41    {
42       super(name);
43    }
44    
45    private static MBeanServerConnection JavaDoc getServer()
46    {
47       return MBeanServerLocator.locate();
48    }
49    
50    public void testLocalInterface() throws Exception JavaDoc
51    {
52       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
53       ServiceOneLocal service = (ServiceOneLocal) ctx.lookup("ServiceOneBean/local");
54       service.setAttribute(1);
55    }
56    
57    public void testManagementInterface() throws Exception JavaDoc
58    {
59       MBeanServerConnection JavaDoc server = getServer();
60       ObjectName JavaDoc name = new ObjectName JavaDoc("jboss.j2ee:jar=embedded-servicepojo,name=ServiceOneBean,service=EJB3,type=ManagementInterface");
61       Object JavaDoc params[] = { "me" };
62       String JavaDoc signature[] = { String JavaDoc.class.getName() };
63       String JavaDoc result = (String JavaDoc) server.invoke(name, "sayHello", params, signature);
64       assertEquals("Hello me", result);
65    }
66    
67    public void testPartialManagementInterface() throws Exception JavaDoc
68    {
69       MBeanServerConnection JavaDoc server = getServer();
70       ObjectName JavaDoc name = new ObjectName JavaDoc("jboss.j2ee:jar=embedded-servicepojo,name=ServiceTwoBean,service=EJB3,type=ManagementInterface");
71       Object JavaDoc params[] = { "me" };
72       String JavaDoc signature[] = { String JavaDoc.class.getName() };
73       String JavaDoc result = (String JavaDoc) server.invoke(name, "sayHello", params, signature);
74       assertEquals("Hello me", result);
75    }
76    
77    public void testStateOne() throws Exception JavaDoc
78    {
79       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
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 JavaDoc
86    {
87       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
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 JavaDoc
94    {
95       TestSuite suite = new TestSuite();
96       suite.addTestSuite(ServicePOJOTestCase.class);
97
98       // setup test so that embedded JBoss is started/stopped once for all tests here.
99
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