[jboss-cvs] JBoss Messaging SVN: r2769 - in trunk/tests/src/org/jboss/test/messaging: tools/jmx and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jun 8 08:58:49 EDT 2007
Author: sergeypk
Date: 2007-06-08 08:58:49 -0400 (Fri, 08 Jun 2007)
New Revision: 2769
Added:
trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceConfigHelper.java
Modified:
trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/ClusteredPersistenceServiceConfigFileJChannelFactory.java
trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java
trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/LocalTestServer.java
Log:
Merge and move the code that loads MBean configuration into ServiceConfigHelper.
Modified: trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/ClusteredPersistenceServiceConfigFileJChannelFactory.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/ClusteredPersistenceServiceConfigFileJChannelFactory.java 2007-06-08 11:27:31 UTC (rev 2768)
+++ trunk/tests/src/org/jboss/test/messaging/core/plugin/postoffice/cluster/ClusteredPersistenceServiceConfigFileJChannelFactory.java 2007-06-08 12:58:49 UTC (rev 2769)
@@ -6,8 +6,6 @@
*/
package org.jboss.test.messaging.core.plugin.postoffice.cluster;
-import java.net.URL;
-
import javax.management.MBeanServer;
import javax.management.ObjectName;
@@ -17,6 +15,7 @@
import org.jboss.messaging.util.XMLUtil;
import org.jboss.test.messaging.tools.jboss.MBeanConfigurationElement;
import org.jboss.test.messaging.tools.jboss.ServiceDeploymentDescriptor;
+import org.jboss.test.messaging.tools.jmx.ServiceConfigHelper;
import org.jgroups.JChannel;
import org.w3c.dom.Element;
@@ -116,17 +115,8 @@
{
log.debug("using configuration file " + configFilePath);
- URL configFileURL = getClass().getClassLoader().getResource(configFilePath);
-
- if (configFileURL == null)
- {
- throw new Exception("Cannot find " + configFilePath + " in the classpath");
- }
-
- ServiceDeploymentDescriptor pdd = new ServiceDeploymentDescriptor(configFileURL);
-
MBeanConfigurationElement postOfficeConfig =
- (MBeanConfigurationElement)pdd.query("service", "PostOffice").iterator().next();
+ ServiceConfigHelper.loadServiceConfiguration(configFilePath, "PostOffice");
// first, we try to use a channel factory service, if we find one configured
String s = (String)postOfficeConfig.getAttributeValue("ChannelFactoryName");
Added: trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceConfigHelper.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceConfigHelper.java (rev 0)
+++ trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceConfigHelper.java 2007-06-08 12:58:49 UTC (rev 2769)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.messaging.tools.jmx;
+
+import java.net.URL;
+
+import org.jboss.test.messaging.tools.jboss.MBeanConfigurationElement;
+import org.jboss.test.messaging.tools.jboss.ServiceDeploymentDescriptor;
+
+/**
+ * A helper class for loading MBean configuration files.
+ *
+ * @author <a href="sergey.koshcheyev at jboss.com">Sergey Koshcheyev</a>
+ * @version <tt>$Revision$</tt>
+ *
+ * $Id$
+ */
+public class ServiceConfigHelper
+{
+ // Constants -----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ /**
+ * Load a service deployment descriptor from the specified file on
+ * the class path.
+ */
+ public static ServiceDeploymentDescriptor loadConfigFile(String configFile) throws Exception
+ {
+ URL url = ServiceConfigHelper.class.getClassLoader().getResource(configFile);
+ if (url == null)
+ {
+ throw new Exception("Cannot find " + configFile + " in the classpath");
+ }
+
+ return new ServiceDeploymentDescriptor(url);
+ }
+
+ /**
+ * Load the service deployment descriptor from the specified file on
+ * the class path and return the configuration element of the specified service.
+ */
+ public static MBeanConfigurationElement loadServiceConfiguration(String configFile, String serviceName) throws Exception
+ {
+ ServiceDeploymentDescriptor sdd = loadConfigFile(configFile);
+ return getServiceConfiguration(sdd, serviceName);
+ }
+
+ public static MBeanConfigurationElement getServiceConfiguration(ServiceDeploymentDescriptor descriptor, String serviceName)
+ {
+ return (MBeanConfigurationElement) descriptor.query("service", serviceName).get(0);
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Modified: trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java 2007-06-08 11:27:31 UTC (rev 2768)
+++ trunk/tests/src/org/jboss/test/messaging/tools/jmx/ServiceContainer.java 2007-06-08 12:58:49 UTC (rev 2769)
@@ -628,22 +628,14 @@
return "server/default/deploy/" + databaseName + "-persistence-service.xml";
}
}
-
+
public Properties getPersistenceManagerSQLProperties() throws Exception
{
String persistenceConfigFile = getPersistenceConfigFile(false);
log.info("Persistence config file: .... " + persistenceConfigFile);
- URL persistenceConfigFileURL = getClass().getClassLoader().getResource(persistenceConfigFile);
- if (persistenceConfigFileURL == null)
- {
- throw new Exception("Cannot find " + persistenceConfigFile + " in the classpath");
- }
-
- ServiceDeploymentDescriptor pdd = new ServiceDeploymentDescriptor(persistenceConfigFileURL);
-
MBeanConfigurationElement persistenceManagerConfig =
- (MBeanConfigurationElement)pdd.query("service", "PersistenceManager").iterator().next();
+ ServiceConfigHelper.loadServiceConfiguration(persistenceConfigFile, "PersistenceManager");
String props = persistenceManagerConfig.getAttributeValue("SqlProperties");
@@ -668,16 +660,8 @@
String persistenceConfigFile = getPersistenceConfigFile(false);
log.info("Peristence config file: .. " + persistenceConfigFile);
- URL persistenceConfigFileURL = getClass().getClassLoader().getResource(persistenceConfigFile);
- if (persistenceConfigFileURL == null)
- {
- throw new Exception("Cannot find " + persistenceConfigFile + " in the classpath");
- }
-
- ServiceDeploymentDescriptor pdd = new ServiceDeploymentDescriptor(persistenceConfigFileURL);
-
MBeanConfigurationElement postOfficeConfig =
- (MBeanConfigurationElement)pdd.query("service", "PostOffice").iterator().next();
+ ServiceConfigHelper.loadServiceConfiguration(persistenceConfigFile, "PostOffice");
String props = postOfficeConfig.getAttributeValue("SqlProperties");
@@ -702,16 +686,8 @@
String persistenceConfigFile = getPersistenceConfigFile(true);
log.info("Persistence config file: .... " + persistenceConfigFile);
- URL persistenceConfigFileURL = getClass().getClassLoader().getResource(persistenceConfigFile);
- if (persistenceConfigFileURL == null)
- {
- throw new Exception("Cannot find " + persistenceConfigFile + " in the classpath");
- }
-
- ServiceDeploymentDescriptor pdd = new ServiceDeploymentDescriptor(persistenceConfigFileURL);
-
MBeanConfigurationElement postOfficeConfig =
- (MBeanConfigurationElement)pdd.query("service", "PostOffice").iterator().next();
+ ServiceConfigHelper.loadServiceConfiguration(persistenceConfigFile, "PostOffice");
String props = postOfficeConfig.getAttributeValue("SqlProperties");
@@ -1564,8 +1540,7 @@
throw new Exception("Cannot find " + multiplexerCofigURL + " in the classpath");
}
- ServiceDeploymentDescriptor multiplexerDD =
- new ServiceDeploymentDescriptor(multiplexerCofigURL);
+ ServiceDeploymentDescriptor multiplexerDD = ServiceConfigHelper.loadConfigFile(multiplexerConfigFile);
List services = multiplexerDD.query("name", "Multiplexer");
@@ -1608,21 +1583,10 @@
public void deployConnectionFactories(String connFactoryConfigFile,
ServiceAttributeOverrides attrOverrides) throws Exception
{
-
- URL connFactoryConfigFileURL =
- getClass().getClassLoader().getResource(connFactoryConfigFile);
-
- if (connFactoryConfigFileURL == null)
- {
- throw new Exception("Cannot find " + connFactoryConfigFile + " in the classpath");
- }
-
connFactoryObjectNames.clear();
- ServiceDeploymentDescriptor cfdd =
- new ServiceDeploymentDescriptor(connFactoryConfigFileURL);
-
-
+ ServiceDeploymentDescriptor cfdd = ServiceConfigHelper.loadConfigFile(connFactoryConfigFile);
+
List connFactoryElements = cfdd.query("service", "ConnectionFactory");
for (Iterator i = connFactoryElements.iterator(); i.hasNext();)
Modified: trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/LocalTestServer.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/LocalTestServer.java 2007-06-08 11:27:31 UTC (rev 2768)
+++ trunk/tests/src/org/jboss/test/messaging/tools/jmx/rmi/LocalTestServer.java 2007-06-08 12:58:49 UTC (rev 2769)
@@ -49,6 +49,7 @@
import org.jboss.test.messaging.tools.jmx.MockJBossSecurityManager;
import org.jboss.test.messaging.tools.jmx.RemotingJMXWrapper;
import org.jboss.test.messaging.tools.jmx.ServiceAttributeOverrides;
+import org.jboss.test.messaging.tools.jmx.ServiceConfigHelper;
import org.jboss.test.messaging.tools.jmx.ServiceContainer;
import org.jboss.test.messaging.tools.jndi.Constants;
import org.w3c.dom.Element;
@@ -302,39 +303,24 @@
// src/etc/server/default/deploy. This will allow to test the default parameters we ship.
String mainConfigFile = "server/default/deploy/messaging-service.xml";
- URL mainConfigFileURL = getClass().getClassLoader().getResource(mainConfigFile);
- if (mainConfigFileURL == null)
- {
- throw new Exception("Cannot find " + mainConfigFile + " in the classpath");
- }
-
- String databaseName = sc.getDatabaseName();
+
String persistenceConfigFile = sc.getPersistenceConfigFile(clustered);
log.info(" Persistence config file .. " + persistenceConfigFile);
- URL persistenceConfigFileURL =
- getClass().getClassLoader().getResource(persistenceConfigFile);
+ ServiceDeploymentDescriptor mdd = ServiceConfigHelper.loadConfigFile(mainConfigFile);
+
+ ServiceDeploymentDescriptor pdd = ServiceConfigHelper.loadConfigFile(persistenceConfigFile);
- if (persistenceConfigFileURL == null)
- {
- throw new Exception("Cannot find " + persistenceConfigFile + " in the classpath");
- }
-
- ServiceDeploymentDescriptor mdd =
- new ServiceDeploymentDescriptor(mainConfigFileURL);
- ServiceDeploymentDescriptor pdd =
- new ServiceDeploymentDescriptor(persistenceConfigFileURL);
-
MBeanConfigurationElement persistenceManagerConfig =
- (MBeanConfigurationElement)pdd.query("service", "PersistenceManager").iterator().next();
+ ServiceConfigHelper.getServiceConfiguration(pdd, "PersistenceManager");
persistenceManagerObjectName = sc.registerAndConfigureService(persistenceManagerConfig);
overrideAttributes(persistenceManagerObjectName, attrOverrides);
sc.invoke(persistenceManagerObjectName, "create", new Object[0], new String[0]);
sc.invoke(persistenceManagerObjectName, "start", new Object[0], new String[0]);
MBeanConfigurationElement jmsUserManagerConfig =
- (MBeanConfigurationElement)pdd.query("service", "JMSUserManager").iterator().next();
+ ServiceConfigHelper.getServiceConfiguration(pdd, "JMSUserManager");
jmsUserManagerObjectName = sc.registerAndConfigureService(jmsUserManagerConfig);
overrideAttributes(jmsUserManagerObjectName, attrOverrides);
sc.invoke(jmsUserManagerObjectName, "create", new Object[0], new String[0]);
@@ -342,7 +328,7 @@
// register server peer as a service, dependencies are injected automatically
MBeanConfigurationElement serverPeerConfig =
- (MBeanConfigurationElement)mdd.query("service", "ServerPeer").iterator().next();
+ ServiceConfigHelper.getServiceConfiguration(mdd, "ServerPeer");
// overwrite the file configuration, if needed
serverPeerConfig.setConstructorArgumentValue(0, 0, String.valueOf(serverPeerID));
@@ -371,7 +357,7 @@
sc.invoke(serverPeerObjectName, "start", new Object[0], new String[0]);
MBeanConfigurationElement postOfficeConfig =
- (MBeanConfigurationElement)pdd.query("service", "PostOffice").iterator().next();
+ ServiceConfigHelper.getServiceConfiguration(pdd, "PostOffice");
postOfficeObjectName = sc.registerAndConfigureService(postOfficeConfig);
overrideAttributes(postOfficeObjectName, attrOverrides);
More information about the jboss-cvs-commits
mailing list