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.Collection;
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.ql.CarCatalog;
044: import org.jboss.test.foedeployer.ejb.ql.CarCatalogHome;
045:
046: /**
047: * Test of a simple WebLogic QL conversion
048: *
049: * @author <a href="mailto:loubyansky@hotmail.com">Alex Loubyansky</a>
050: * @version $Revision: 57211 $
051: */
052: public class QLConversionTestCase extends JBossTestCase {
053: // Constants -----------------------------------------------------
054: public static final String FOE_DEPLOYER = "foe-deployer-3.2.sar";
055: public static final String FOE_DEPLOYER_NAME = "jboss:service=FoeDeployer";
056: public static final String CONVERTOR_DEPLOYER_QUERY_NAME = "jboss:service=Convertor,*";
057: public static final String QL_APPLICATION = "foe-deployer-ql-test";
058: public static final String CAR_CATALOG_JNDI_NAME = "CarCatalogEJB.CarCatalogHome";
059:
060: // Static --------------------------------------------------------
061: /**
062: * Setup the test suite.
063: */
064: public static Test suite() throws Exception {
065: TestSuite lSuite = new TestSuite();
066: lSuite.addTest(new TestSuite(QLConversionTestCase.class));
067:
068: // Create an initializer for the test suite
069: TestSetup lWrapper = new JBossTestSetup(lSuite) {
070: protected void setUp() throws Exception {
071: super .setUp();
072: }
073:
074: protected void tearDown() throws Exception {
075: super .tearDown();
076: }
077: };
078: return lWrapper;
079: }
080:
081: // Constructors --------------------------------------------------
082: public QLConversionTestCase(String pName) {
083: super (pName);
084: }
085:
086: // Public --------------------------------------------------------
087: /**
088: * Test a simple conversion
089: **/
090: public void testQLConversion() throws Exception {
091: try {
092: log.debug("+++ testQLConversion");
093:
094: // First check if foe-deployer is deployed
095: boolean lIsInitiallyDeployed = getServer().isRegistered(
096: new ObjectName(FOE_DEPLOYER_NAME));
097: if (!lIsInitiallyDeployed)
098: deploy(FOE_DEPLOYER);
099:
100: boolean lIsDeployed = getServer().isRegistered(
101: new ObjectName(FOE_DEPLOYER_NAME));
102: assertTrue("Foe-Deployer is not deployed", lIsDeployed);
103:
104: // Count number of convertors (must be a list one)
105: int lCount = getServer()
106: .queryNames(
107: new ObjectName(
108: CONVERTOR_DEPLOYER_QUERY_NAME),
109: null).size();
110: assertTrue("No Convertor found on web server", lCount > 0);
111:
112: // Deploy the simple application
113: deploy(QL_APPLICATION + ".wlar");
114:
115: // Because the Foe-Deployer copies the converted JAR back to the original place
116: // it has to be deployed from here again
117: deploy(QL_APPLICATION + ".jar");
118:
119: // Create some data and test queries
120: int i;
121: String[] carNumbers = { "apache", "noch", "zzuk", "silvia" };
122: String[] carColors = { "red", "black", "red", "yellow" };
123: int[] carYears = { 1990, 1989, 2000, 1995 };
124:
125: CarCatalog carCatalog = getCarCatalogEJB();
126:
127: //getLog().debug( "clean the database" );
128: //i = -1;
129: //while( ++i < carNumbers.length )
130: // carCatalog.removeCarIfExists( carNumbers[ i ] );
131:
132: getLog().debug("manufacture cars");
133: i = -1;
134: while (++i < carNumbers.length) {
135: carCatalog.createCar(carNumbers[i], carColors[i],
136: carYears[i]);
137: getLog().debug("registered car: " + carNumbers[i]);
138: }
139:
140: getLog().debug("find all cars");
141: Collection numbersCol = carCatalog.getAllCarNumbers();
142: i = -1;
143: while (++i < carNumbers.length) {
144: assertTrue(
145: "Not all cars returned by converted findAll query",
146: numbersCol.contains(carNumbers[i]));
147: }
148:
149: getLog().debug("find cars with red color");
150: Collection cars = carCatalog.getCarsWithColor("red");
151: i = -1;
152: while (++i < carNumbers.length) {
153: if ("red".equals(carColors[i])) {
154: assertTrue("Not all red cars found", cars
155: .contains(carNumbers[i]));
156: }
157: }
158:
159: log.debug("find cars after 1993 year");
160: cars = carCatalog.getCarsAfterYear(1993);
161: i = -1;
162: while (++i < carNumbers.length) {
163: if (1993 < carYears[i]) {
164: assertTrue("Not all cars after year 1993 found",
165: cars.contains(carNumbers[i]));
166: }
167: }
168:
169: // Undeploy converted application to clean up
170: undeploy(QL_APPLICATION + ".jar");
171:
172: // also now should work without undeploying
173: undeploy(QL_APPLICATION + ".wlar");
174:
175: // Only undeploy if deployed here
176: if (!lIsInitiallyDeployed) {
177: undeploy(FOE_DEPLOYER);
178: }
179: } catch (Exception e) {
180: e.printStackTrace();
181: throw e;
182: }
183: }
184:
185: // Private -------------------------------------------------------
186: private CarCatalog getCarCatalogEJB() throws Exception {
187: getLog().debug("looking for CarCatalogHome");
188: Object ref = getInitialContext().lookup(CAR_CATALOG_JNDI_NAME);
189: CarCatalogHome home = (CarCatalogHome) PortableRemoteObject
190: .narrow(ref, CarCatalogHome.class);
191: getLog().debug("creating an instance of CarCatalog");
192: return home.create();
193: }
194: }
|