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.foedeployer.test;
023:
024: import java.io.IOException;
025: import java.net.InetAddress;
026: import java.rmi.RemoteException;
027: import java.util.Set;
028: import javax.ejb.CreateException;
029: import javax.ejb.Handle;
030: import javax.management.ObjectName;
031: import javax.naming.InitialContext;
032: import javax.naming.NamingException;
033: import javax.rmi.PortableRemoteObject;
034:
035: import junit.extensions.TestSetup;
036: import junit.framework.Test;
037: import junit.framework.TestCase;
038: import junit.framework.TestSuite;
039:
040: import org.jboss.test.JBossTestCase;
041: import org.jboss.test.JBossTestSetup;
042:
043: import org.jboss.test.foedeployer.ejb.simple.SecretManager;
044: import org.jboss.test.foedeployer.ejb.simple.SecretManagerHome;
045:
046: /**
047: * Test of a simple WebLogic Application Conversion
048: *
049: * @author <a href="mailto:andreas@jboss.org">Andreas Schaefer</a>.
050: * @author <a href="mailto:loubyansky@hotmail.com">Alex Loubyansky</a>
051: * @version $Revision: 57211 $
052: */
053: public class SimpleConversionTestCase extends JBossTestCase {
054: // Constants -----------------------------------------------------
055: public static final String FOE_DEPLOYER = "foe-deployer-3.2.sar";
056: public static final String FOE_DEPLOYER_NAME = "jboss:service=FoeDeployer";
057: public static final String CONVERTOR_DEPLOYER_QUERY_NAME = "jboss:service=Convertor,*";
058: public static final String SIMPLE_APPLICATION = "foe-deployer-simple-test";
059: public static final String SECRET_SESSION_JNDI_NAME = "ejb/SecretManager";
060:
061: // Static --------------------------------------------------------
062: /**
063: * Setup the test suite.
064: */
065: public static Test suite() throws Exception {
066: TestSuite lSuite = new TestSuite();
067: lSuite.addTest(new TestSuite(SimpleConversionTestCase.class));
068:
069: // Create an initializer for the test suite
070: TestSetup lWrapper = new JBossTestSetup(lSuite) {
071: protected void setUp() throws Exception {
072: super .setUp();
073: }
074:
075: protected void tearDown() throws Exception {
076: super .tearDown();
077: }
078: };
079: return lWrapper;
080: }
081:
082: // Constructors --------------------------------------------------
083: public SimpleConversionTestCase(String pName) {
084: super (pName);
085: }
086:
087: // Public --------------------------------------------------------
088: /**
089: * Test a simple conversion
090: **/
091: public void testSimpleConversion() throws Exception {
092: try {
093: log.debug("+++ testSimpleConversion");
094:
095: // First check if foe-deployer is deployed
096: boolean lIsInitiallyDeployed = getServer().isRegistered(
097: new ObjectName(FOE_DEPLOYER_NAME));
098: if (!lIsInitiallyDeployed)
099: deploy(FOE_DEPLOYER);
100:
101: boolean lIsDeployed = getServer().isRegistered(
102: new ObjectName(FOE_DEPLOYER_NAME));
103: assertTrue("Foe-Deployer is not deployed", lIsDeployed);
104:
105: // Count number of convertors (must be a list one)
106: int lCount = getServer()
107: .queryNames(
108: new ObjectName(
109: CONVERTOR_DEPLOYER_QUERY_NAME),
110: null).size();
111: assertTrue("No Convertor found on web server", lCount > 0);
112:
113: // Deploy the simple application
114: deploy(SIMPLE_APPLICATION + ".wlar");
115:
116: // Because the Foe-Deployer copies the converted JAR back to the original place
117: // it has to be deployed from here again
118: deploy(SIMPLE_APPLICATION + ".jar");
119:
120: // Access the Session Bean and invoke some methods on it
121: SecretManager session = getSecretManagerEJB();
122: String key = "xxx";
123: String secret = "the sun is shining brightly";
124:
125: session.createSecret(key, secret);
126: assertTrue("the secret read is not equal to secret set",
127: secret.equals(session.getSecret(key)));
128: session.removeSecret(key);
129:
130: // Undeploy converted application to clean up
131: undeploy(SIMPLE_APPLICATION + ".jar");
132: // undeploy wlar (though it should work without it)
133: undeploy(SIMPLE_APPLICATION + ".wlar");
134:
135: // Only undeploy if deployed here
136: if (!lIsInitiallyDeployed)
137: undeploy(FOE_DEPLOYER);
138: } catch (Exception e) {
139: e.printStackTrace();
140: throw e;
141: }
142: }
143:
144: // Private -------------------------------------------------------
145: private SecretManager getSecretManagerEJB() throws Exception {
146: log.debug("+++ getSecretManagerEJB()");
147: Object lObject = getInitialContext().lookup(
148: SECRET_SESSION_JNDI_NAME);
149: SecretManagerHome lHome = (SecretManagerHome) PortableRemoteObject
150: .narrow(lObject, SecretManagerHome.class);
151: log.debug("Found SecretManagerBean");
152: return lHome.create();
153: }
154: }
|