KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.File JavaDoc;
25 import java.net.InetAddress JavaDoc;
26 import java.net.URL JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Arrays JavaDoc;
29 import java.util.Collection JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.Set JavaDoc;
32 import javax.management.MBeanRegistrationException JavaDoc;
33 import javax.management.MalformedObjectNameException JavaDoc;
34 import javax.management.ObjectInstance JavaDoc;
35 import javax.management.ObjectName JavaDoc;
36 import javax.management.ReflectionException JavaDoc;
37 import javax.management.RuntimeMBeanException JavaDoc;
38 import javax.naming.Context JavaDoc;
39 import javax.naming.InitialContext JavaDoc;
40 import javax.naming.NamingEnumeration JavaDoc;
41 import javax.naming.NamingException JavaDoc;
42 import junit.framework.*;
43 import org.jboss.test.JBossTestCase;
44 import org.jboss.deployment.IncompleteDeploymentException;
45
46 /**
47  * @see <related>
48  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
49  * @version $Revision: 37406 $
50  */

51 public class MBeanDependsOnEJBUnitTestCase
52        extends JBossTestCase
53 {
54    // Constants -----------------------------------------------------
55
protected final static int INSTALLED = 0;
56    protected final static int CONFIGURED = 1;
57    protected final static int CREATED = 2;
58    protected final static int RUNNING = 3;
59    protected final static int FAILED = 4;
60    protected final static int STOPPED = 5;
61    protected final static int DESTROYED = 6;
62    protected final static int NOTYETINSTALLED = 7;
63    // Attributes ----------------------------------------------------
64

65    ObjectName JavaDoc serviceControllerName;
66    // Static --------------------------------------------------------
67
// Constructors --------------------------------------------------
68
/**
69     * Constructor for the DeployServiceUnitTestCase object
70     *
71     * @param name Test case name
72     */

73    public MBeanDependsOnEJBUnitTestCase(String JavaDoc name)
74    {
75       super(name);
76       try
77       {
78          serviceControllerName = new ObjectName JavaDoc("jboss.system:service=ServiceController");
79       }
80       catch (Exception JavaDoc e)
81       {
82       } // end of try-catch
83

84    }
85
86    // Public --------------------------------------------------------
87

88
89    /**
90     * <code>testMBeanDependsOnEJB</code> tests that an mbean can depend
91     * on an ejb. All classes are loaded, the mbean is deployed, checked
92     * that it has not started, then the ejb is deployed, and the mbean
93     * is checked that it has started.
94     *
95     * @exception Exception if an error occurs
96     */

97    public void testMBeanDependsOnEJB() throws Exception JavaDoc
98    {
99       String JavaDoc mBeancodeUrl = "testdeploy.sar";
100       String JavaDoc mBeanUrl = "testmbeandependsOnEjb-service.xml";
101       //random choice of ejb...
102
String JavaDoc ejbUrl = "jmxtest.jar";
103       getLog().debug("testUrls are : " + mBeanUrl + ", " + ejbUrl);
104       ObjectName JavaDoc objectNameMBean = new ObjectName JavaDoc("test:name=TestMBeanDependsOnEjb");
105       ObjectName JavaDoc objectNameEJB = new ObjectName JavaDoc("jboss.j2ee:service=EJB,name=test/TestDataSource");
106       //deploy jar
107
deploy(mBeancodeUrl);
108       try
109       {
110          deploy(mBeanUrl);
111          fail("suceeded in deploying mbean with unsatisfied dependency!");
112       }
113       catch (IncompleteDeploymentException e)
114       {
115          //This is what we expect
116
} // end of try-catch
117

118       //Double check state
119
try
120       {
121          assertTrue("MBean started!", !((String JavaDoc)getServer().getAttribute(objectNameMBean, "StateString")).equals("Started"));
122          deploy(ejbUrl);
123          try
124          {
125             assertTrue("MBean not started!", ((String JavaDoc)getServer().getAttribute(objectNameMBean, "StateString")).equals("Started"));
126          }
127          finally
128          {
129             undeploy(ejbUrl);
130             assertTrue("MBean started!", !((String JavaDoc)getServer().getAttribute(objectNameMBean, "StateString")).equals("Started"));
131          } // end of try-catch
132
}
133       finally
134       {
135          undeploy(mBeanUrl);
136          undeploy(mBeancodeUrl);
137       } // end of try-catch
138
}
139
140
141 }
142
Popular Tags