KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > entity > A_BasicHomeInterfaceEC


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: A_BasicHomeInterfaceEC.java,v 1.11 2004/09/22 07:20:50 durieuxp Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.entity;
27
28 import java.util.Enumeration JavaDoc;
29
30 import javax.ejb.FinderException JavaDoc;
31
32 import org.objectweb.jonas.jtests.beans.ebasic.Simple;
33
34 /**
35  * This set of test are basic tests on CMP entity home interface.
36  * Only specific tests to CMP are here, all tests common to CMP and BMP
37  * are in the inherited class A_BasicHomeInterface.
38  * @author Philippe Coq, Philippe Durieux, Helene Joanin. (jonas team)
39  */

40 public abstract class A_BasicHomeInterfaceEC extends A_BasicHomeInterface {
41
42     public A_BasicHomeInterfaceEC(String JavaDoc name) {
43         super(name);
44     }
45   
46     // --------------------------------------------------------------------
47
// tests on clause where for CMP finder methods
48
// These tests are specific to CMP
49
// ---------------------------------------------------------------------
50

51     /**
52      * testFinderBetween verify a finder method that return a Enumeration
53      * whith a where clause :
54      * where ?1 <= c_info and c_info <= ?2 and ?1 <= c_numtest and c_numtest <= ?2
55      * the purpose of this test is to verify the correct interpretation of parameters
56      * ?1 ?2
57      */

58     public void testFinderBetween() throws Exception JavaDoc {
59         int value = 991959;
60         getHome().create("991959_1", value, value);
61         getHome().create("991959_2", value, value);
62         Simple entity = null;
63         Enumeration JavaDoc eList = null;
64         eList = getHome().findInfo_beetwen(value, value);
65         int nb = 0;
66         while (eList.hasMoreElements()) {
67             entity = (Simple) javax.rmi.PortableRemoteObject.narrow(eList.nextElement(), Simple.class);
68             nb++;
69             assertEquals("Wrong Info value", entity.getInfo(), value);
70             assertEquals("Wrong NumTest value", entity.getNumTest(), value);
71         }
72         assertEquals("Wrong number of entities found", 2, nb);
73         getHome().remove("991959_1");
74         getHome().remove("991959_2");
75     }
76
77     /**
78      * testFinderEqualOne verify a finder method that return a Enumeration
79      * whith a where clause :
80      * where c_info = ?1 and c_numtest = ?1
81      * the object of this test is to verify the correct interpretation of parameters
82      * ?1 ?2
83      */

84     public void testFinderEqualOne() throws Exception JavaDoc {
85         Simple entity = null;
86         Enumeration JavaDoc eList = null;
87         eList = getHome().findEqualOne(80);
88         int nb = 0;
89         while (eList.hasMoreElements()) {
90             entity = (Simple) javax.rmi.PortableRemoteObject.narrow(eList.nextElement(), Simple.class);
91             nb++;
92             assertEquals(80, entity.getInfo());
93             assertEquals(80, entity.getNumTest());
94         }
95         assertEquals(2, nb);
96     }
97
98     /**
99      * testFinderEqualTwo verify a finder method that return a Enumeration
100      * whith a where clause :
101      * where c_info = ? and c_numtest = ?
102      * the object of this test is to verify the correct interpretation of parameters
103      * ?1 ?2
104      */

105     public void testFinderEqualTwo() throws Exception JavaDoc {
106         Simple entity = null;
107         Enumeration JavaDoc eList = null;
108         eList = getHome().findEqualTwo(100, 90);
109         int nb = 0;
110         while (eList.hasMoreElements()) {
111             entity = (Simple) javax.rmi.PortableRemoteObject.narrow(eList.nextElement(), Simple.class);
112             nb++;
113             assertEquals(100, entity.getInfo());
114             assertEquals(90, entity.getNumTest());
115         }
116         assertEquals(1, nb);
117     }
118
119     /**
120      * Execute an finder method defined to expect a single object with the result
121      * set that returns more than one.
122      * Ensure that a FinderException is thrown.
123      */

124     public void testFindOneByNum() throws Exception JavaDoc {
125         try {
126             Simple p = getHome().findOneByNum(4);
127         } catch (FinderException JavaDoc e) {
128             // Pass
129
return;
130         }
131         fail("FinderException not thrown as expected");
132     }
133
134     /**
135      * testManyOperations verify many various operation calls.
136      * N times (create, finderXXX, getXXX, remove)
137      * (do not launch systematicaly this test because it's long)
138      */

139     public void testManyOperations() throws Exception JavaDoc {
140         for (int i = 0; i < 100; i++) {
141             getHome().create("pkmany" + i, 20, 6);
142             Simple entity2 = getHome().findByTestName("pkmany" + i);
143             assertEquals(20, entity2.getInfo());
144             // cleaning
145
entity2.remove();
146         }
147     }
148
149     /**
150      * test of allowed operation on home method
151      * THis test fails today (bug #300413)
152      */

153     public void testHomeMethod() throws Exception JavaDoc {
154         getHome().globalOpe();
155     }
156 }
157
Popular Tags