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.Collection ; 13 import javax.ejb.CreateException ; 14 import javax.ejb.Handle ; 15 import javax.management.ObjectName ; 16 import javax.naming.InitialContext ; 17 import javax.naming.NamingException ; 18 import javax.rmi.PortableRemoteObject ; 19 20 import junit.extensions.TestSetup; 21 import junit.framework.Test; 22 import junit.framework.TestCase; 23 import junit.framework.TestSuite; 24 25 import org.jboss.test.JBossTestCase; 26 import org.jboss.test.JBossTestSetup; 27 28 import org.jboss.test.foedeployer.ejb.ql.CarCatalog; 29 import org.jboss.test.foedeployer.ejb.ql.CarCatalogHome; 30 31 37 public class QLConversionTestCase 38 extends JBossTestCase 39 { 40 public static final String FOE_DEPLOYER = "foe-deployer-3.2.sar"; 42 public static final String FOE_DEPLOYER_NAME = "jboss:service=FoeDeployer"; 43 public static final String CONVERTOR_DEPLOYER_QUERY_NAME = "jboss:service=Convertor,*"; 44 public static final String QL_APPLICATION = "foe-deployer-ql-test"; 45 public static final String CAR_CATALOG_JNDI_NAME = "CarCatalogEJB.CarCatalogHome"; 46 47 51 public static Test suite() throws Exception 52 { 53 TestSuite lSuite = new TestSuite(); 54 lSuite.addTest( new TestSuite( QLConversionTestCase.class ) ); 55 56 TestSetup lWrapper = new JBossTestSetup( lSuite ) 58 { 59 protected void setUp() throws Exception 60 { 61 super.setUp(); 62 } 63 protected void tearDown() throws Exception 64 { 65 super.tearDown(); 66 } 67 }; 68 return lWrapper; 69 } 70 71 public QLConversionTestCase( String pName ) 73 { 74 super( pName ); 75 } 76 77 81 public void testQLConversion() 82 throws Exception 83 { 84 try 85 { 86 log.debug("+++ testQLConversion"); 87 88 boolean lIsInitiallyDeployed = getServer().isRegistered( new ObjectName ( FOE_DEPLOYER_NAME ) ); 90 if(!lIsInitiallyDeployed) 91 deploy(FOE_DEPLOYER); 92 93 boolean lIsDeployed = getServer().isRegistered(new ObjectName (FOE_DEPLOYER_NAME)); 94 assertTrue("Foe-Deployer is not deployed", lIsDeployed); 95 96 int lCount = getServer().queryNames(new ObjectName (CONVERTOR_DEPLOYER_QUERY_NAME), null).size(); 98 assertTrue("No Convertor found on web server", lCount > 0); 99 100 deploy(QL_APPLICATION + ".wlar"); 102 103 deploy(QL_APPLICATION + ".jar"); 106 107 int i; 109 String [] carNumbers = { "apache", "noch", "zzuk", "silvia" }; 110 String [] carColors = { "red", "black", "red", "yellow" }; 111 int[] carYears = { 1990, 1989, 2000, 1995 }; 112 113 CarCatalog carCatalog = getCarCatalogEJB(); 114 115 120 getLog().debug( "manufacture cars" ); 121 i = -1; 122 while( ++i < carNumbers.length ) 123 { 124 carCatalog.createCar( carNumbers[ i ], carColors[ i ], carYears[ i ] ); 125 getLog().debug("registered car: " + carNumbers[ i ] ); 126 } 127 128 getLog().debug( "find all cars" ); 129 Collection numbersCol = carCatalog.getAllCarNumbers(); 130 i = -1; 131 while( ++i < carNumbers.length) 132 { 133 assertTrue( "Not all cars returned by converted findAll query", 134 numbersCol.contains( carNumbers[ i ] ) ); 135 } 136 137 getLog().debug( "find cars with red color" ); 138 Collection cars = carCatalog.getCarsWithColor( "red" ); 139 i = -1; 140 while( ++i < carNumbers.length ) 141 { 142 if( "red".equals( carColors[i] ) ) 143 { 144 assertTrue( "Not all red cars found", 145 cars.contains(carNumbers[ i ]) ); 146 } 147 } 148 149 log.debug( "find cars after 1993 year" ); 150 cars = carCatalog.getCarsAfterYear( 1993 ); 151 i = -1; 152 while( ++i < carNumbers.length ) 153 { 154 if( 1993 < carYears[i] ) 155 { 156 assertTrue( "Not all cars after year 1993 found", 157 cars.contains(carNumbers[ i ]) ); 158 } 159 } 160 161 undeploy(QL_APPLICATION + ".jar"); 163 164 undeploy(QL_APPLICATION + ".wlar"); 166 167 if(!lIsInitiallyDeployed) 169 { 170 undeploy(FOE_DEPLOYER); 171 } 172 } 173 catch(Exception e) 174 { 175 e.printStackTrace(); 176 throw e; 177 } 178 } 179 180 private CarCatalog getCarCatalogEJB() 182 throws 183 Exception 184 { 185 getLog().debug("looking for CarCatalogHome"); 186 Object ref = getInitialContext().lookup( CAR_CATALOG_JNDI_NAME ); 187 CarCatalogHome home = (CarCatalogHome) 188 PortableRemoteObject.narrow( ref, CarCatalogHome.class ); 189 getLog().debug( "creating an instance of CarCatalog" ); 190 return home.create(); 191 } 192 } 193 | Popular Tags |