1 7 package org.jboss.test.foedeployer.test; 8 9 import java.io.IOException ; 10 import java.net.InetAddress ; 11 import java.rmi.RemoteException ; 12 import java.util.Set ; 13 import java.util.Collection ; 14 import javax.ejb.CreateException ; 15 import javax.ejb.Handle ; 16 import javax.management.ObjectName ; 17 import javax.naming.InitialContext ; 18 import javax.naming.NamingException ; 19 import javax.rmi.PortableRemoteObject ; 20 21 import junit.extensions.TestSetup; 22 import junit.framework.Test; 23 import junit.framework.TestCase; 24 import junit.framework.TestSuite; 25 26 import org.jboss.test.JBossTestCase; 27 import org.jboss.test.JBossTestSetup; 28 29 import org.jboss.test.foedeployer.ejb.m2mb.M2MBManager; 30 import org.jboss.test.foedeployer.ejb.m2mb.M2MBManagerHome; 31 32 38 public class M2MBConversionTestCase 39 extends JBossTestCase 40 { 41 public static final String FOE_DEPLOYER = "foe-deployer-3.2.sar"; 43 public static final String FOE_DEPLOYER_NAME = "jboss:service=FoeDeployer"; 44 public static final String CONVERTOR_DEPLOYER_QUERY_NAME = "jboss:service=Convertor,*"; 45 public static final String APPLICATION = "foe-deployer-m2mb-test"; 46 public static final String MANAGER_SESSION_JNDI_NAME = "M2MBManagerEJB.M2MBManagerHome"; 47 48 52 public static Test suite() throws Exception 53 { 54 TestSuite suite = new TestSuite(); 55 suite.addTest( new TestSuite( M2MBConversionTestCase.class ) ); 56 57 TestSetup wrapper = new JBossTestSetup( suite ) 59 { 60 protected void setUp() throws Exception 61 { 62 super.setUp(); 63 } 64 protected void tearDown() throws Exception 65 { 66 super.tearDown(); 67 } 68 }; 69 return wrapper; 70 } 71 72 public M2MBConversionTestCase( String name ) 74 { 75 super( name ); 76 } 77 78 82 public void testSimpleConversion() 83 throws Exception 84 { 85 try 86 { 87 log.debug( "+++ testM2MBConversion" ); 88 89 boolean isInitiallyDeployed = getServer().isRegistered( new ObjectName ( FOE_DEPLOYER_NAME ) ); 91 if( !isInitiallyDeployed ) deploy(FOE_DEPLOYER); 92 93 boolean isDeployed = getServer().isRegistered(new ObjectName (FOE_DEPLOYER_NAME)); 94 assertTrue("Foe-Deployer is not deployed", isDeployed); 95 96 int count = getServer().queryNames(new ObjectName (CONVERTOR_DEPLOYER_QUERY_NAME), null).size(); 98 assertTrue("No Convertor found on web server", count > 0); 99 100 deploy(APPLICATION + ".wlar"); 102 103 deploy(APPLICATION + ".jar"); 106 107 int i; 109 String [] projects = {"JBoss", "Xdoclet", "WebWork"}; 110 String [] developers = {"Ivanov", "Petrov", "Sidorov"}; 111 112 M2MBManager manager = getM2MBManager(); 113 114 log.debug( "cleaning the database" ); 115 i = 0; 116 while( i < projects.length) 117 manager.removeProjectIfExists( projects[i++] ); 118 i = 0; 119 while( i < developers.length) 120 manager.removeDeveloperIfExists( developers[i++] ); 121 122 i = 0; 124 while( i < projects.length ) 125 { 126 log.debug("creating project: " + projects[i] ); 127 manager.createProject( projects[i++] ); 128 } 129 130 i = 0; 132 while( i < developers.length ) 133 { 134 log.debug("creating developer: " + developers[i] ); 135 manager.createDeveloper( developers[i++] ); 136 } 137 138 i = 0; 140 while( i < projects.length - 1 ) 141 { 142 log.debug("adding project " + projects[i] 143 + " to developer " + developers[0]); 144 manager.addProjectToDeveloper(developers[0], projects[i++]); 145 } 146 147 log.debug("developer " + developers[0] + " have projects: " 148 + manager.getProjectsForDeveloper(developers[0]) ); 149 150 log.debug("adding developer " + developers[0] 152 + " to project " + projects[ projects.length - 1 ]); 153 manager.addDeveloperToProject(projects[ projects.length-1 ], developers[0]); 154 155 Collection prjs = manager.getProjectsForDeveloper(developers[0]); 157 log.debug("developer " + developers[0] + " have projects: " + prjs); 158 for( i=0; i < projects.length; ++i ) 159 { 160 assertTrue( "Developer '" + developers[0] 161 + "' doesn't have project '" + projects[i] + "'", 162 prjs.contains(projects[i]) ); 163 } 164 165 undeploy(APPLICATION + ".jar"); 167 undeploy(APPLICATION + ".wlar"); 169 170 if(!isInitiallyDeployed) undeploy( FOE_DEPLOYER ); 172 } 173 catch(Exception e) 174 { 175 e.printStackTrace(); 176 throw e; 177 } 178 } 179 180 private M2MBManager getM2MBManager() 182 throws Exception 183 { 184 log.debug("looking for M2MBManager"); 185 Object ref = getInitialContext().lookup( MANAGER_SESSION_JNDI_NAME ); 186 M2MBManagerHome home = (M2MBManagerHome) PortableRemoteObject.narrow( 187 ref, M2MBManagerHome.class ); 188 return home.create(); 189 } 190 } 191 | Popular Tags |