KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > foedeployer > test > QLConversionTestCase


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.test.foedeployer.test;
8
9 import java.io.IOException JavaDoc;
10 import java.net.InetAddress JavaDoc;
11 import java.rmi.RemoteException JavaDoc;
12 import java.util.Collection JavaDoc;
13 import javax.ejb.CreateException JavaDoc;
14 import javax.ejb.Handle JavaDoc;
15 import javax.management.ObjectName JavaDoc;
16 import javax.naming.InitialContext JavaDoc;
17 import javax.naming.NamingException JavaDoc;
18 import javax.rmi.PortableRemoteObject JavaDoc;
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 /**
32  * Test of a simple WebLogic QL conversion
33  *
34  * @author <a HREF="mailto:loubyansky@hotmail.com">Alex Loubyansky</a>
35  * @version $Revision: 1.3 $
36  */

37 public class QLConversionTestCase
38    extends JBossTestCase
39 {
40    // Constants -----------------------------------------------------
41
public static final String JavaDoc FOE_DEPLOYER = "foe-deployer-3.2.sar";
42    public static final String JavaDoc FOE_DEPLOYER_NAME = "jboss:service=FoeDeployer";
43    public static final String JavaDoc CONVERTOR_DEPLOYER_QUERY_NAME = "jboss:service=Convertor,*";
44    public static final String JavaDoc QL_APPLICATION = "foe-deployer-ql-test";
45    public static final String JavaDoc CAR_CATALOG_JNDI_NAME = "CarCatalogEJB.CarCatalogHome";
46
47    // Static --------------------------------------------------------
48
/**
49     * Setup the test suite.
50     */

51    public static Test suite() throws Exception JavaDoc
52    {
53       TestSuite lSuite = new TestSuite();
54       lSuite.addTest( new TestSuite( QLConversionTestCase.class ) );
55
56       // Create an initializer for the test suite
57
TestSetup lWrapper = new JBossTestSetup( lSuite )
58       {
59          protected void setUp() throws Exception JavaDoc
60          {
61             super.setUp();
62          }
63          protected void tearDown() throws Exception JavaDoc
64          {
65             super.tearDown();
66          }
67       };
68       return lWrapper;
69    }
70
71    // Constructors --------------------------------------------------
72
public QLConversionTestCase( String JavaDoc pName )
73    {
74       super( pName );
75    }
76
77    // Public --------------------------------------------------------
78
/**
79     * Test a simple conversion
80     **/

81    public void testQLConversion()
82       throws Exception JavaDoc
83    {
84       try
85       {
86          log.debug("+++ testQLConversion");
87
88          // First check if foe-deployer is deployed
89
boolean lIsInitiallyDeployed = getServer().isRegistered( new ObjectName JavaDoc( FOE_DEPLOYER_NAME ) );
90          if(!lIsInitiallyDeployed)
91             deploy(FOE_DEPLOYER);
92
93          boolean lIsDeployed = getServer().isRegistered(new ObjectName JavaDoc(FOE_DEPLOYER_NAME));
94          assertTrue("Foe-Deployer is not deployed", lIsDeployed);
95
96          // Count number of convertors (must be a list one)
97
int lCount = getServer().queryNames(new ObjectName JavaDoc(CONVERTOR_DEPLOYER_QUERY_NAME), null).size();
98          assertTrue("No Convertor found on web server", lCount > 0);
99
100          // Deploy the simple application
101
deploy(QL_APPLICATION + ".wlar");
102
103          // Because the Foe-Deployer copies the converted JAR back to the original place
104
// it has to be deployed from here again
105
deploy(QL_APPLICATION + ".jar");
106
107          // Create some data and test queries
108
int i;
109          String JavaDoc[] carNumbers = { "apache", "noch", "zzuk", "silvia" };
110          String JavaDoc[] carColors = { "red", "black", "red", "yellow" };
111          int[] carYears = { 1990, 1989, 2000, 1995 };
112
113          CarCatalog carCatalog = getCarCatalogEJB();
114
115          //getLog().debug( "clean the database" );
116
//i = -1;
117
//while( ++i < carNumbers.length )
118
// carCatalog.removeCarIfExists( carNumbers[ i ] );
119

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 JavaDoc 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 JavaDoc 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 converted application to clean up
162
undeploy(QL_APPLICATION + ".jar");
163
164          // also now should work without undeploying
165
undeploy(QL_APPLICATION + ".wlar");
166
167          // Only undeploy if deployed here
168
if(!lIsInitiallyDeployed)
169          {
170             undeploy(FOE_DEPLOYER);
171          }
172       }
173       catch(Exception JavaDoc e)
174       {
175          e.printStackTrace();
176          throw e;
177       }
178    }
179
180    // Private -------------------------------------------------------
181
private CarCatalog getCarCatalogEJB()
182       throws
183          Exception JavaDoc
184    {
185       getLog().debug("looking for CarCatalogHome");
186       Object JavaDoc 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