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;
023:
024: import java.util.StringTokenizer;
025:
026: import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
027:
028: import junit.framework.Test;
029: import junit.framework.TestSuite;
030:
031: /**
032: * Derived implementation of JBossTestCase for cluster testing.
033: *
034: * @author <a href="mailto:sacha.labourey@cogito-info.ch">Sacha Labourey</a>.
035: * @author Scott.Stark@jboss.org
036: * @version $Revision: 60704 $
037: * @see org.jboss.test.JBossTestCase
038: */
039: public class JBossClusteredTestCase extends JBossTestCase {
040: JBossTestClusteredServices clusterServices;
041:
042: public JBossClusteredTestCase(String name) {
043: super (name);
044: }
045:
046: public void initDelegate() {
047: clusterServices = new JBossTestClusteredServices(getClass()
048: .getName());
049: delegate = clusterServices;
050: }
051:
052: // Public --------------------------------------------------------
053:
054: public void testServerFound() throws Exception {
055: if (deploymentException != null)
056: throw deploymentException;
057: assertTrue("Server was not found", getServers() != null);
058: }
059:
060: public RMIAdaptor[] getAdaptors() throws Exception {
061: return clusterServices.getAdaptors();
062: }
063:
064: public String[] getServers() throws Exception {
065: return clusterServices.getServers();
066: }
067:
068: public String[] getNamingURLs() throws Exception {
069: return clusterServices.getNamingURLs();
070: }
071:
072: public String[] getHANamingURLs() throws Exception {
073: return clusterServices.getHANamingURLs();
074: }
075:
076: public String[] getHttpURLs() throws Exception {
077: return clusterServices.getHttpURLs();
078: }
079:
080: protected void deploy(RMIAdaptor server, String name)
081: throws Exception {
082: clusterServices.deploy(server, name);
083: }
084:
085: protected void redeploy(RMIAdaptor server, String name)
086: throws Exception {
087: clusterServices.redeploy(server, name);
088: }
089:
090: protected void undeploy(RMIAdaptor server, String name)
091: throws Exception {
092: clusterServices.undeploy(server, name);
093: }
094:
095: public static Test getDeploySetup(final Test test,
096: final String jarNames) throws Exception {
097: JBossTestSetup wrapper = new JBossTestClusteredSetup(test) {
098:
099: protected void setUp() throws Exception {
100: if (jarNames == null)
101: return;
102: deploymentException = null;
103: try {
104: // deploy the comma seperated list of jars
105: StringTokenizer st = new StringTokenizer(jarNames,
106: ", ");
107: while (st != null && st.hasMoreTokens()) {
108: String jarName = st.nextToken();
109: this .redeploy(jarName);
110: this .getLog().debug(
111: "deployed package: " + jarName);
112: }
113: } catch (Exception ex) {
114: // Throw this in testServerFound() instead.
115: deploymentException = ex;
116: }
117:
118: // wait a few seconds so that the cluster stabilize
119: synchronized (this ) {
120: wait(2000);
121: }
122: }
123:
124: protected void tearDown() throws Exception {
125: if (jarNames != null) {
126: // deploy the comma seperated list of jars
127: StringTokenizer st = new StringTokenizer(jarNames,
128: ", ");
129: String[] depoyments = new String[st.countTokens()];
130: for (int i = depoyments.length - 1; i >= 0; i--)
131: depoyments[i] = st.nextToken();
132: for (int i = 0; i < depoyments.length; i++) {
133: String jarName = depoyments[i];
134: this .getLog().debug(
135: "Attempt undeploy of " + jarName);
136: this .undeploy(jarName);
137: this .getLog().debug(
138: "undeployed package: " + jarName);
139: }
140: }
141: }
142: };
143: return wrapper;
144: }
145:
146: public static Test getDeploySetup(final Class clazz,
147: final String jarName) throws Exception {
148: TestSuite suite = new TestSuite();
149: suite.addTest(new TestSuite(clazz));
150: return getDeploySetup(suite, jarName);
151: }
152:
153: /**
154: * anil
155: */
156: public void setServerNames(String[] snames) throws Exception {
157: ((JBossTestClusteredServices) delegate).setServerNames(snames);
158: }
159:
160: // Private -------------------------------------------------------
161:
162: // Inner classes -------------------------------------------------
163:
164: }
|