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.ejb3.test;
023:
024: import java.util.StringTokenizer;
025:
026: import junit.framework.Test;
027: import junit.framework.TestSuite;
028:
029: import org.jboss.test.JBossTestCase;
030:
031: /**
032: * This test case will use custom.jndi.properties to find the deployer.
033: *
034: * @author <a href="mailto:carlo.dewolf@jboss.com">Carlo de Wolf</a>
035: * @version $Revision: $
036: */
037: public class CustomJNDIJBossTestCase extends JBossTestCase {
038:
039: public CustomJNDIJBossTestCase(String name) {
040: super (name);
041: }
042:
043: @Override
044: public void initDelegate() {
045: delegate = new CustomJNDIJBossTestServices(getClass().getName());
046: try {
047: delegate.init();
048: } catch (Exception e) {
049: log.error("Failed to init delegate", e);
050: }
051: }
052:
053: /**
054: * Get a JBossTestSetup that does login and deployment in setUp/tearDown
055: *
056: * @param test a Test
057: * @param jarNames is a comma seperated list of deployments
058: */
059: public static Test getDeploySetup(final Test test,
060: final String jarNames) throws Exception {
061: CustomJNDIJBossTestSetup wrapper = new CustomJNDIJBossTestSetup(
062: test) {
063: protected void setUp() throws Exception {
064: deploymentException = null;
065: try {
066: this .delegate.init();
067:
068: if (this .getDelegate().isSecureTest())
069: this .delegate.login();
070:
071: if (jarNames == null)
072: return;
073:
074: // deploy the comma seperated list of jars
075: StringTokenizer st = new StringTokenizer(jarNames,
076: ", ");
077: while (st != null && st.hasMoreTokens()) {
078: String jarName = st.nextToken();
079: this .redeploy(jarName);
080: this .getLog().debug(
081: "deployed package: " + jarName);
082: }
083: } catch (Exception ex) {
084: // Throw this in testServerFound() instead.
085: deploymentException = ex;
086: }
087: }
088:
089: protected void tearDown() throws Exception {
090: if (jarNames == null)
091: return; //Nothing to Undeploy
092:
093: // undeploy the comma seperated list of jars
094: StringTokenizer st = new StringTokenizer(jarNames, ", ");
095: String[] depoyments = new String[st.countTokens()];
096: for (int i = depoyments.length - 1; i >= 0; i--)
097: depoyments[i] = st.nextToken();
098: for (int i = 0; i < depoyments.length; i++) {
099: String jarName = depoyments[i];
100: this .undeploy(jarName);
101: this .getLog().debug(
102: "undeployed package: " + jarName);
103: }
104:
105: if (this .getDelegate().isSecureTest())
106: this .delegate.logout();
107: }
108: };
109: return wrapper;
110: }
111:
112: public static Test getDeploySetup(final Class clazz,
113: final String jarName) throws Exception {
114: TestSuite suite = new TestSuite();
115: suite.addTest(new TestSuite(clazz));
116: return getDeploySetup(suite, jarName);
117: }
118: }
|