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 java.util.Collection;
029: import javax.ejb.CreateException;
030: import javax.ejb.Handle;
031: import javax.management.ObjectName;
032: import javax.naming.InitialContext;
033: import javax.naming.NamingException;
034: import javax.rmi.PortableRemoteObject;
035:
036: import junit.extensions.TestSetup;
037: import junit.framework.Test;
038: import junit.framework.TestCase;
039: import junit.framework.TestSuite;
040:
041: import org.jboss.test.JBossTestCase;
042: import org.jboss.test.JBossTestSetup;
043:
044: import org.jboss.test.foedeployer.ejb.m2mb.M2MBManager;
045: import org.jboss.test.foedeployer.ejb.m2mb.M2MBManagerHome;
046:
047: /**
048: * Test of relationships conversion
049: *
050: * @author <a href="mailto:aloubyansky@hotmail.com">Alex Loubyansky</a>
051: * @version $Revision: 57211 $
052: */
053: public class M2MBConversionTestCase 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 APPLICATION = "foe-deployer-m2mb-test";
059: public static final String MANAGER_SESSION_JNDI_NAME = "M2MBManagerEJB.M2MBManagerHome";
060:
061: // Static --------------------------------------------------------
062: /**
063: * Setup the test suite.
064: */
065: public static Test suite() throws Exception {
066: TestSuite suite = new TestSuite();
067: suite.addTest(new TestSuite(M2MBConversionTestCase.class));
068:
069: // Create an initializer for the test suite
070: TestSetup wrapper = new JBossTestSetup(suite) {
071: protected void setUp() throws Exception {
072: super .setUp();
073: }
074:
075: protected void tearDown() throws Exception {
076: super .tearDown();
077: }
078: };
079: return wrapper;
080: }
081:
082: // Constructors --------------------------------------------------
083: public M2MBConversionTestCase(String name) {
084: super (name);
085: }
086:
087: // Public --------------------------------------------------------
088: /**
089: * Test a simple conversion
090: **/
091: public void testSimpleConversion() throws Exception {
092: try {
093: log.debug("+++ testM2MBConversion");
094:
095: // First check if foe-deployer is deployed
096: boolean isInitiallyDeployed = getServer().isRegistered(
097: new ObjectName(FOE_DEPLOYER_NAME));
098: if (!isInitiallyDeployed)
099: deploy(FOE_DEPLOYER);
100:
101: boolean isDeployed = getServer().isRegistered(
102: new ObjectName(FOE_DEPLOYER_NAME));
103: assertTrue("Foe-Deployer is not deployed", isDeployed);
104:
105: // Count number of convertors (must be a list one)
106: int count = getServer()
107: .queryNames(
108: new ObjectName(
109: CONVERTOR_DEPLOYER_QUERY_NAME),
110: null).size();
111: assertTrue("No Convertor found on web server", count > 0);
112:
113: // Deploy the simple application
114: deploy(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(APPLICATION + ".jar");
119:
120: // Access the Session Bean and invoke some methods on it
121: int i;
122: String[] projects = { "JBoss", "Xdoclet", "WebWork" };
123: String[] developers = { "Ivanov", "Petrov", "Sidorov" };
124:
125: M2MBManager manager = getM2MBManager();
126:
127: log.debug("cleaning the database");
128: i = 0;
129: while (i < projects.length)
130: manager.removeProjectIfExists(projects[i++]);
131: i = 0;
132: while (i < developers.length)
133: manager.removeDeveloperIfExists(developers[i++]);
134:
135: // create all projects
136: i = 0;
137: while (i < projects.length) {
138: log.debug("creating project: " + projects[i]);
139: manager.createProject(projects[i++]);
140: }
141:
142: // create all developers
143: i = 0;
144: while (i < developers.length) {
145: log.debug("creating developer: " + developers[i]);
146: manager.createDeveloper(developers[i++]);
147: }
148:
149: // adding projects except the last one to developer 0
150: i = 0;
151: while (i < projects.length - 1) {
152: log.debug("adding project " + projects[i]
153: + " to developer " + developers[0]);
154: manager.addProjectToDeveloper(developers[0],
155: projects[i++]);
156: }
157:
158: log.debug("developer " + developers[0] + " have projects: "
159: + manager.getProjectsForDeveloper(developers[0]));
160:
161: // adding developer 0 to the last project
162: log.debug("adding developer " + developers[0]
163: + " to project " + projects[projects.length - 1]);
164: manager.addDeveloperToProject(
165: projects[projects.length - 1], developers[0]);
166:
167: // check whether the developer have all the projects
168: Collection prjs = manager
169: .getProjectsForDeveloper(developers[0]);
170: log.debug("developer " + developers[0] + " have projects: "
171: + prjs);
172: for (i = 0; i < projects.length; ++i) {
173: assertTrue("Developer '" + developers[0]
174: + "' doesn't have project '" + projects[i]
175: + "'", prjs.contains(projects[i]));
176: }
177:
178: // Undeploy converted application to clean up
179: undeploy(APPLICATION + ".jar");
180: // undeploy wlar (though it should work without it)
181: undeploy(APPLICATION + ".wlar");
182:
183: // Only undeploy if deployed here
184: if (!isInitiallyDeployed)
185: undeploy(FOE_DEPLOYER);
186: } catch (Exception e) {
187: e.printStackTrace();
188: throw e;
189: }
190: }
191:
192: // Private -------------------------------------------------------
193: private M2MBManager getM2MBManager() throws Exception {
194: log.debug("looking for M2MBManager");
195: Object ref = getInitialContext().lookup(
196: MANAGER_SESSION_JNDI_NAME);
197: M2MBManagerHome home = (M2MBManagerHome) PortableRemoteObject
198: .narrow(ref, M2MBManagerHome.class);
199: return home.create();
200: }
201: }
|