001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.jmx.test;
023:
024: import java.io.File;
025: import java.net.InetAddress;
026: import java.net.URL;
027: import java.util.ArrayList;
028: import java.util.Arrays;
029: import java.util.Collection;
030: import java.util.Iterator;
031: import java.util.Set;
032: import javax.management.MBeanRegistrationException;
033: import javax.management.MalformedObjectNameException;
034: import javax.management.ObjectInstance;
035: import javax.management.ObjectName;
036: import javax.management.ReflectionException;
037: import javax.management.RuntimeMBeanException;
038: import javax.naming.Context;
039: import javax.naming.InitialContext;
040: import javax.naming.NamingEnumeration;
041: import javax.naming.NamingException;
042: import junit.framework.*;
043: import org.jboss.test.JBossTestCase;
044: import org.jboss.deployment.IncompleteDeploymentException;
045:
046: /**
047: * @see <related>
048: * @author <a href="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
049: * @version $Revision: 57211 $
050: */
051: public class MBeanDependsOnEJBUnitTestCase extends JBossTestCase {
052: // Constants -----------------------------------------------------
053: protected final static int INSTALLED = 0;
054: protected final static int CONFIGURED = 1;
055: protected final static int CREATED = 2;
056: protected final static int RUNNING = 3;
057: protected final static int FAILED = 4;
058: protected final static int STOPPED = 5;
059: protected final static int DESTROYED = 6;
060: protected final static int NOTYETINSTALLED = 7;
061: // Attributes ----------------------------------------------------
062:
063: ObjectName serviceControllerName;
064:
065: // Static --------------------------------------------------------
066: // Constructors --------------------------------------------------
067: /**
068: * Constructor for the DeployServiceUnitTestCase object
069: *
070: * @param name Test case name
071: */
072: public MBeanDependsOnEJBUnitTestCase(String name) {
073: super (name);
074: try {
075: serviceControllerName = new ObjectName(
076: "jboss.system:service=ServiceController");
077: } catch (Exception e) {
078: } // end of try-catch
079:
080: }
081:
082: // Public --------------------------------------------------------
083:
084: /**
085: * <code>testMBeanDependsOnEJB</code> tests that an mbean can depend
086: * on an ejb. All classes are loaded, the mbean is deployed, checked
087: * that it has not started, then the ejb is deployed, and the mbean
088: * is checked that it has started.
089: *
090: * @exception Exception if an error occurs
091: */
092: public void testMBeanDependsOnEJB() throws Exception {
093: String mBeancodeUrl = "testdeploy.sar";
094: String mBeanUrl = "testmbeandependsOnEjb-service.xml";
095: //random choice of ejb...
096: String ejbUrl = "jmxtest.jar";
097: getLog().debug("testUrls are : " + mBeanUrl + ", " + ejbUrl);
098: ObjectName objectNameMBean = new ObjectName(
099: "test:name=TestMBeanDependsOnEjb");
100: ObjectName objectNameEJB = new ObjectName(
101: "jboss.j2ee:service=EJB,name=test/TestDataSource");
102: //deploy jar
103: deploy(mBeancodeUrl);
104: try {
105: deploy(mBeanUrl);
106: fail("suceeded in deploying mbean with unsatisfied dependency!");
107: } catch (IncompleteDeploymentException e) {
108: //This is what we expect
109: } // end of try-catch
110:
111: //Double check state
112: try {
113: assertTrue("MBean started!", !((String) getServer()
114: .getAttribute(objectNameMBean, "StateString"))
115: .equals("Started"));
116: deploy(ejbUrl);
117: try {
118: assertTrue("MBean not started!", ((String) getServer()
119: .getAttribute(objectNameMBean, "StateString"))
120: .equals("Started"));
121: } finally {
122: undeploy(ejbUrl);
123: assertTrue("MBean started!", !((String) getServer()
124: .getAttribute(objectNameMBean, "StateString"))
125: .equals("Started"));
126: } // end of try-catch
127: } finally {
128: undeploy(mBeanUrl);
129: undeploy(mBeancodeUrl);
130: } // end of try-catch
131: }
132:
133: }
|