KickJava   Java API By Example, From Geeks To Geeks.

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


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_VariousPKEC.java,v 1.4 2004/03/19 11:57:15 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.entity;
27
28 import java.util.Collection JavaDoc;
29
30 import javax.ejb.FinderException JavaDoc;
31
32 import junit.framework.Assert;
33
34 import org.objectweb.jonas.jtests.beans.ebasic.Account;
35 import org.objectweb.jonas.jtests.beans.ebasic.AccountHome;
36 import org.objectweb.jonas.jtests.beans.ebasic.Person;
37 import org.objectweb.jonas.jtests.beans.ebasic.PersonHome;
38 import org.objectweb.jonas.jtests.util.JTestCase;
39
40 /**
41  * This set of test are all tests common to CMP version 1 and CMP version 2
42  * These are tests about the different cases of the primary key type:
43  * - primary key that maps to a single field in the entity bean class (java.lang.Integer),
44  * - unknown primary key class at the bean development phase,
45  * (defered primary key type specification to the deployment phase).
46  * Note that the compilation of this kind of bean is already a good test !!
47  * The case of the primary key maps to multiple fields in the entity bean class
48  * is already tested in the "inherit" test.
49  * Beans used: ebasic/Account, ebasic/Person
50  * @author Helene Joanin (jonas team)
51  */

52 public abstract class A_VariousPKEC extends JTestCase {
53
54     public A_VariousPKEC(String JavaDoc name) {
55         super(name);
56     }
57
58     protected void setUp() {
59         super.setUp();
60         useBeans("ebasic", true);
61     }
62
63     /**
64      * Return AccountHome, that can be either CMP version 1 or CMP version 2 bean.
65      */

66     abstract public AccountHome getAccountHome();
67
68     /**
69      * Return PersonHome, that can be either CMP version 1 or CMP version 2 bean.
70      */

71     abstract public PersonHome getPersonHome();
72
73
74     /**
75      * Creation of a bean with PK that maps a single field
76      */

77     public void testSpkCreate() throws Exception JavaDoc {
78         int num = 1000;
79         String JavaDoc customer = "Gertrude";
80
81         Account acc = getAccountHome().create(num, customer);
82         Assert.assertEquals("Number", num, acc.getNumberPrimitive());
83         Assert.assertEquals("Customer", customer, acc.getCustomer());
84
85         // cleaning
86
acc.remove();
87     
88     }
89
90     /**
91      * Remove of a bean with PK that maps a single field
92      */

93     public void testSpkRemove() throws Exception JavaDoc {
94         int num = 0;
95         Account acc = null;
96
97         getAccountHome().remove(new Integer JavaDoc(num));
98         try {
99             acc = getAccountHome().findByNumber(num);
100             fail("bean already exists after a remove !!");
101         } catch (FinderException JavaDoc e) {
102         }
103
104         // cleaning
105
getAccountHome().create(num, "to be removed");
106     
107     }
108
109     /**
110      * findByPrimaryKey of a bean with PK that maps a single field
111      */

112     public void testSpkFindByPrimaryKey() throws Exception JavaDoc {
113         int num = 10;
114
115         Account acc = getAccountHome().findByPrimaryKey(new Integer JavaDoc(num));
116         Assert.assertEquals("Number", num, acc.getNumberPrimitive());
117     
118     }
119
120     /**
121      * findAll beans with PK that maps a single field
122      */

123     public void testSpkFindAll() throws Exception JavaDoc {
124         Collection JavaDoc col = getAccountHome().findAll();
125     }
126
127     /**
128      * Creation of a bean with unknown PK class at the bean development phase
129      */

130     public void testUpkCreate() throws Exception JavaDoc {
131         int num = 1000;
132         String JavaDoc name = "Gertrude";
133
134         Person prs = getPersonHome().create(num, name);
135         Assert.assertEquals("Number", num, prs.getNumberPrimitive());
136         Assert.assertEquals("Customer", name, prs.getName());
137
138         // cleaning
139
prs.remove();
140     
141     }
142
143     /**
144      * Remove of a bean with unknown PK class at the bean development phase
145      */

146     public void testUpkRemove() throws Exception JavaDoc {
147         int num = 0;
148         Person prs = null;
149
150         getPersonHome().remove(new Integer JavaDoc(num));
151         try {
152             prs = getPersonHome().findByNumber(num);
153             fail("bean already exists after a remove !!");
154         } catch (FinderException JavaDoc e) {
155         }
156
157         // cleaning
158
getPersonHome().create(num, "to be removed");
159     
160     }
161
162     /**
163      * findByPrimaryKey of a bean with unknown PK class at the bean development phase
164      */

165     public void testUpkFindByPrimaryKey() throws Exception JavaDoc {
166         int num = 10;
167
168         Person prs = getPersonHome().findByPrimaryKey(new Integer JavaDoc(num));
169         Assert.assertEquals("Number", num, prs.getNumberPrimitive());
170     
171     }
172
173     /**
174      * findAll beans with unknown PK class at the bean development phase
175      */

176     public void testUpkFindAll() throws Exception JavaDoc {
177         Collection JavaDoc col = getPersonHome().findAll();
178     }
179
180 }
181
Popular Tags