KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jmx > test > EarDeploymentUnitTestCase


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.test.jmx.test;
23
24 import javax.management.ObjectName JavaDoc;
25
26 import org.jboss.test.JBossTestCase;
27 import org.jboss.test.jmx.eardeployment.a.interfaces.SessionA;
28 import org.jboss.test.jmx.eardeployment.a.interfaces.SessionAHome;
29 import org.jboss.test.jmx.eardeployment.b.interfaces.SessionB;
30 import org.jboss.test.jmx.eardeployment.b.interfaces.SessionBHome;
31
32
33 /** Tests of ear deployment issues
34  *
35  *
36  * Created: Thu Feb 21 20:54:55 2002
37  *
38  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
39  * @author Scott.Stark@jboss.org
40  * @version $Revision: 37406 $
41  */

42
43 public class EarDeploymentUnitTestCase extends JBossTestCase
44 {
45    // Constants -----------------------------------------------------
46
protected final static int INSTALLED = 0;
47    protected final static int CONFIGURED = 1;
48    protected final static int CREATED = 2;
49    protected final static int RUNNING = 3;
50    protected final static int FAILED = 4;
51    protected final static int STOPPED = 5;
52    protected final static int DESTROYED = 6;
53    protected final static int NOTYETINSTALLED = 7;
54
55    private ObjectName JavaDoc serviceControllerName;
56
57    public EarDeploymentUnitTestCase(String JavaDoc name)
58    {
59       super(name);
60
61       try
62       {
63          serviceControllerName =
64             new ObjectName JavaDoc("jboss.system:service=ServiceController");
65       }
66       catch (Exception JavaDoc ignore)
67       {
68       }
69    }
70
71    /**
72     * The <code>testEarSubpackageVisibility</code> method tests if the classes in
73     * subpackages of an ear are visible to each other when ejb's are deployed.
74     * SessionA and SessionB are in different jars, and each refer to the other.
75     *
76     *
77     * @exception Exception if an error occurs
78     */

79    public void testEarSubpackageVisibility() throws Exception JavaDoc
80    {
81       getLog().info("+++ testEarSubpackageVisibility");
82       String JavaDoc testUrl = "eardeployment.ear";
83       deploy(testUrl);
84
85       try
86       {
87          SessionAHome aHome = (SessionAHome) getInitialContext().lookup("eardeployment/SessionA");
88          SessionBHome bHome = (SessionBHome) getInitialContext().lookup("eardeployment/SessionB");
89          SessionA a = aHome.create();
90          SessionB b = bHome.create();
91          assertTrue("a called b", a.callB());
92          assertTrue("b called a", b.callA());
93       }
94       finally
95       {
96          undeploy(testUrl);
97       }
98    }
99
100    public void testEarDepends() throws Exception JavaDoc
101    {
102       getLog().info("+++ testEarDepends");
103       String JavaDoc testUrl = "eardepends.ear";
104
105       ObjectName JavaDoc dependentAName =
106          new ObjectName JavaDoc("jboss.j2ee:jndiName=test/DependentA,service=EJB");
107       ObjectName JavaDoc dependentBName =
108          new ObjectName JavaDoc("jboss.j2ee:jndiName=test/DependentB,service=EJB");
109
110       ObjectName JavaDoc independentName =
111          new ObjectName JavaDoc("jboss.j2ee:jndiName=test/Independent,service=EJB");
112
113       ObjectName JavaDoc testName = new ObjectName JavaDoc("test:name=Test");
114
115       if (removeService(dependentAName))
116       {
117          log.warn(dependentAName + " is registered, removed");
118       }
119       if (removeService(dependentBName))
120       {
121          log.warn(dependentBName + " is registered, removed");
122       }
123
124       deploy(testUrl);
125
126       try
127       {
128          assertTrue(dependentAName + " is registered",
129             getServer().isRegistered(dependentAName));
130          assertTrue(dependentBName + " is registered",
131             getServer().isRegistered(dependentBName));
132
133          // Validate that all expected mbeans are in the running state
134
assertTrue(dependentAName + " in RUNNING state", checkState(dependentAName, RUNNING));
135          assertTrue(dependentBName + " in RUNNING state", checkState(dependentBName, RUNNING));
136          assertTrue(testName + " in RUNNING state", checkState(testName, RUNNING));
137          assertTrue(independentName + " in RUNNING state", checkState(independentName, RUNNING));
138       }
139       finally
140       {
141          undeploy(testUrl);
142       }
143
144       try
145       {
146          assertTrue(dependentAName + " is not registered",
147             !getServer().isRegistered(dependentAName));
148          assertTrue(dependentBName + " is not registered",
149             !getServer().isRegistered(dependentBName));
150       }
151       finally
152       {
153          removeService(dependentAName);
154          removeService(dependentBName);
155       }
156    }
157
158    protected boolean removeService(final ObjectName JavaDoc mbean) throws Exception JavaDoc
159    {
160       boolean isRegistered = getServer().isRegistered(mbean);
161       if (isRegistered)
162       {
163          Object JavaDoc[] args = {mbean};
164          String JavaDoc[] sig = {ObjectName JavaDoc.class.getName()};
165          invoke(serviceControllerName,
166             "remove",
167             args,
168             sig
169          );
170       }
171
172       return isRegistered;
173    }
174
175    protected boolean checkState(ObjectName JavaDoc mbean, int state) throws Exception JavaDoc
176    {
177       Integer JavaDoc mbeanState = (Integer JavaDoc) getServer().getAttribute(mbean, "State");
178       return state == mbeanState.intValue();
179    }
180
181 }// EarDeploymentUnitTestCase
182
Popular Tags