001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: A_BasicHomeInterfaceEC.java 5474 2004-09-22 07:20:50Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.entity;
027:
028: import java.util.Enumeration;
029:
030: import javax.ejb.FinderException;
031:
032: import org.objectweb.jonas.jtests.beans.ebasic.Simple;
033:
034: /**
035: * This set of test are basic tests on CMP entity home interface.
036: * Only specific tests to CMP are here, all tests common to CMP and BMP
037: * are in the inherited class A_BasicHomeInterface.
038: * @author Philippe Coq, Philippe Durieux, Helene Joanin. (jonas team)
039: */
040: public abstract class A_BasicHomeInterfaceEC extends
041: A_BasicHomeInterface {
042:
043: public A_BasicHomeInterfaceEC(String name) {
044: super (name);
045: }
046:
047: // --------------------------------------------------------------------
048: // tests on clause where for CMP finder methods
049: // These tests are specific to CMP
050: // ---------------------------------------------------------------------
051:
052: /**
053: * testFinderBetween verify a finder method that return a Enumeration
054: * whith a where clause :
055: * where ?1 <= c_info and c_info <= ?2 and ?1 <= c_numtest and c_numtest <= ?2
056: * the purpose of this test is to verify the correct interpretation of parameters
057: * ?1 ?2
058: */
059: public void testFinderBetween() throws Exception {
060: int value = 991959;
061: getHome().create("991959_1", value, value);
062: getHome().create("991959_2", value, value);
063: Simple entity = null;
064: Enumeration eList = null;
065: eList = getHome().findInfo_beetwen(value, value);
066: int nb = 0;
067: while (eList.hasMoreElements()) {
068: entity = (Simple) javax.rmi.PortableRemoteObject.narrow(
069: eList.nextElement(), Simple.class);
070: nb++;
071: assertEquals("Wrong Info value", entity.getInfo(), value);
072: assertEquals("Wrong NumTest value", entity.getNumTest(),
073: value);
074: }
075: assertEquals("Wrong number of entities found", 2, nb);
076: getHome().remove("991959_1");
077: getHome().remove("991959_2");
078: }
079:
080: /**
081: * testFinderEqualOne verify a finder method that return a Enumeration
082: * whith a where clause :
083: * where c_info = ?1 and c_numtest = ?1
084: * the object of this test is to verify the correct interpretation of parameters
085: * ?1 ?2
086: */
087: public void testFinderEqualOne() throws Exception {
088: Simple entity = null;
089: Enumeration eList = null;
090: eList = getHome().findEqualOne(80);
091: int nb = 0;
092: while (eList.hasMoreElements()) {
093: entity = (Simple) javax.rmi.PortableRemoteObject.narrow(
094: eList.nextElement(), Simple.class);
095: nb++;
096: assertEquals(80, entity.getInfo());
097: assertEquals(80, entity.getNumTest());
098: }
099: assertEquals(2, nb);
100: }
101:
102: /**
103: * testFinderEqualTwo verify a finder method that return a Enumeration
104: * whith a where clause :
105: * where c_info = ? and c_numtest = ?
106: * the object of this test is to verify the correct interpretation of parameters
107: * ?1 ?2
108: */
109: public void testFinderEqualTwo() throws Exception {
110: Simple entity = null;
111: Enumeration eList = null;
112: eList = getHome().findEqualTwo(100, 90);
113: int nb = 0;
114: while (eList.hasMoreElements()) {
115: entity = (Simple) javax.rmi.PortableRemoteObject.narrow(
116: eList.nextElement(), Simple.class);
117: nb++;
118: assertEquals(100, entity.getInfo());
119: assertEquals(90, entity.getNumTest());
120: }
121: assertEquals(1, nb);
122: }
123:
124: /**
125: * Execute an finder method defined to expect a single object with the result
126: * set that returns more than one.
127: * Ensure that a FinderException is thrown.
128: */
129: public void testFindOneByNum() throws Exception {
130: try {
131: Simple p = getHome().findOneByNum(4);
132: } catch (FinderException e) {
133: // Pass
134: return;
135: }
136: fail("FinderException not thrown as expected");
137: }
138:
139: /**
140: * testManyOperations verify many various operation calls.
141: * N times (create, finderXXX, getXXX, remove)
142: * (do not launch systematicaly this test because it's long)
143: */
144: public void testManyOperations() throws Exception {
145: for (int i = 0; i < 100; i++) {
146: getHome().create("pkmany" + i, 20, 6);
147: Simple entity2 = getHome().findByTestName("pkmany" + i);
148: assertEquals(20, entity2.getInfo());
149: // cleaning
150: entity2.remove();
151: }
152: }
153:
154: /**
155: * test of allowed operation on home method
156: * THis test fails today (bug #300413)
157: */
158: public void testHomeMethod() throws Exception {
159: getHome().globalOpe();
160: }
161: }
|