KickJava   Java API By Example, From Geeks To Geeks.

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


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_EtypePfloat.java,v 1.4 2003/08/20 15:33:23 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.entity;
27
28 import java.util.Collection JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import javax.ejb.FinderException JavaDoc;
31
32 import junit.framework.Assert;
33
34 import org.objectweb.jonas.jtests.beans.etype.pfloat.Pfloat;
35 import org.objectweb.jonas.jtests.beans.etype.pfloat.PfloatHome;
36 import org.objectweb.jonas.jtests.util.JTestCase;
37
38 /**
39  * This set of test are common to CMP version 1 and CMP version 2
40  * These are tests about 'float' field of entity bean .
41  * Beans used: etype/pfloat
42  * @author Helene Joanin
43  */

44 public abstract class A_EtypePfloat extends JTestCase {
45
46     private static final float DELTA = 0.01f;
47
48     public A_EtypePfloat(String JavaDoc name) {
49         super(name);
50     }
51
52     protected void setUp() {
53         super.setUp();
54         useBeans("pfloat", true);
55     }
56
57     /**
58      * Return PfloatHome, that can be either CMP version 1 or CMP version 2 bean.
59      */

60     abstract public PfloatHome getHome();
61
62     /**
63      * findByPrimaryKey() test
64      */

65     public void testPrimFloatFindByPk() throws Exception JavaDoc {
66         String JavaDoc pk = "pk1";
67         Pfloat bean = getHome().findByPrimaryKey(pk);
68         Assert.assertEquals("Pk", pk, bean.getPk());
69     }
70
71     /**
72      * findByF1() test
73      */

74     public void testPrimFloatFindByF1() throws Exception JavaDoc {
75         float f1 = 5.0f;
76         Collection JavaDoc cBeans = getHome().findByF1(f1 - DELTA, f1 + DELTA);
77         int nb = 0;
78         Iterator JavaDoc iBeans = cBeans.iterator();
79         while (iBeans.hasNext()) {
80             Pfloat bean = (Pfloat) javax.rmi.PortableRemoteObject.narrow(iBeans.next(),
81                                                                          Pfloat.class);
82             Assert.assertEquals("F1", f1, bean.getF1(), DELTA);
83             nb++;
84         }
85         assertEquals("Beans number: ", 2, nb);
86     }
87
88     /**
89      * findByF1Literal5() test
90      */

91     public void testPrimFloatFindByF1Literal5() throws Exception JavaDoc {
92         float f1 = 5.0f;
93         Collection JavaDoc cBeans = getHome().findByF1Literal5();
94         int nb = 0;
95         Iterator JavaDoc iBeans = cBeans.iterator();
96         while (iBeans.hasNext()) {
97             Pfloat bean = (Pfloat) javax.rmi.PortableRemoteObject.narrow(iBeans.next(),
98                                                                          Pfloat.class);
99             Assert.assertEquals("F1", f1, bean.getF1(), DELTA);
100             nb++;
101         }
102         assertEquals("Beans number: ", 2, nb);
103     }
104
105     /**
106      * getF1() test
107      */

108     public void testPrimFloatGetF1() throws Exception JavaDoc {
109         String JavaDoc pk = "pk2";
110         Pfloat bean = getHome().findByPrimaryKey(pk);
111         float f1 = bean.getF1();
112         Assert.assertEquals("Pk", pk, bean.getPk());
113         Assert.assertEquals("F1", 2.0, f1, DELTA);
114     }
115
116     /**
117      * setF1() test
118      */

119     public void testPrimFloatSetF1() throws Exception JavaDoc {
120         String JavaDoc pk = "pk3";
121         Pfloat bean = getHome().findByPrimaryKey(pk);
122         float f1 = 30.0f;
123         bean.setF1(f1);
124         Assert.assertEquals("Pk", pk, bean.getPk());
125         Assert.assertEquals("F1", f1, bean.getF1(), DELTA);
126     }
127
128     /**
129      * create() test
130      */

131     public void testPrimFloatCreate() throws Exception JavaDoc {
132         String JavaDoc pk = "pkcreated";
133         float f1 = 1959.65f;
134         Pfloat bean = getHome().create(pk, f1);
135         Assert.assertEquals("Pk", pk, bean.getPk());
136         Assert.assertEquals("F1", f1, bean.getF1(), DELTA);
137         bean = getHome().findByPrimaryKey(pk);
138         // cleaning
139
bean.remove();
140     }
141
142     /**
143      * remove() test
144      */

145     public void testPrimFloatRemove() throws Exception JavaDoc {
146         String JavaDoc pk = "pktoremove";
147         Pfloat bean = getHome().findByPrimaryKey(pk);
148         float f1 = bean.getF1();
149         bean.remove();
150         try {
151             getHome().findByPrimaryKey(pk);
152             fail("not removed");
153         } catch (FinderException JavaDoc e) {
154             // ok
155
}
156         // cleaning
157
getHome().create(pk, f1);
158     }
159
160 }
161
Popular Tags