KickJava   Java API By Example, From Geeks To Geeks.

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


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_EtypeOfloat.java,v 1.5 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 org.objectweb.jonas.jtests.beans.etype.ofloat.Ofloat;
33 import org.objectweb.jonas.jtests.beans.etype.ofloat.OfloatHome;
34 import org.objectweb.jonas.jtests.util.JTestCase;
35
36 /**
37  * This set of test are common to CMP version 1 and CMP version 2
38  * These are tests about java.lang.Float field of entity bean .
39  * Beans used: etype/ofloat
40  * @author Helene Joanin
41  */

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

58     abstract public OfloatHome getHome();
59
60     /**
61      * findByPrimaryKey() test
62      */

63     public void testObjFloatFindByPk() throws Exception JavaDoc {
64         String JavaDoc pk = "pk1";
65         Ofloat bean = getHome().findByPrimaryKey(pk);
66         assertEquals("Pk", pk, bean.getPk());
67     }
68
69     /**
70      * findByF1() test
71      */

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

89     public void testObjFloatGetF1() throws Exception JavaDoc {
90         String JavaDoc pk = "pk2";
91         Ofloat bean = getHome().findByPrimaryKey(pk);
92         Float JavaDoc f1 = bean.getF1();
93         assertEquals("Pk", pk, bean.getPk());
94         assertEquals("F1", 2.0, f1.floatValue(), DELTA);
95     }
96
97     /**
98      * getF1Null() test: f1 with a 'null' value
99      */

100     public void testObjFloatGetF1Null() throws Exception JavaDoc {
101         String JavaDoc pk = "pknull";
102         Ofloat bean = getHome().findByPrimaryKey(pk);
103         Float JavaDoc f1 = bean.getF1();
104         assertEquals("Pk", pk, bean.getPk());
105         assertNull("F1 not null", f1);
106     }
107
108     /**
109      * setF1() test
110      */

111     public void testObjFloatSetF1() throws Exception JavaDoc {
112         String JavaDoc pk = "pk3";
113         Ofloat bean = getHome().findByPrimaryKey(pk);
114         float f1 = 30.0f;
115         bean.setF1(new Float JavaDoc(f1));
116         assertEquals("Pk", pk, bean.getPk());
117         assertEquals("F1", f1, (bean.getF1()).floatValue(), DELTA);
118     }
119
120     /**
121      * setF1Null() test: f1 with a 'null' value
122      */

123     public void testObjFloatSetF1Null() throws Exception JavaDoc {
124         String JavaDoc pk = "pkchangenull";
125         Ofloat bean = getHome().findByPrimaryKey(pk);
126         bean.setF1(null);
127         assertEquals("Pk", pk, bean.getPk());
128         assertNull("F1", bean.getF1());
129     }
130
131     /**
132      * create() test
133      */

134     public void testObjFloatCreate() throws Exception JavaDoc {
135         String JavaDoc pk = "pkcreated";
136         float f1 = 1959.65f;
137         Ofloat bean = getHome().create(pk, new Float JavaDoc(f1));
138         assertEquals("Pk", pk, bean.getPk());
139         assertEquals("F1", f1, (bean.getF1()).floatValue(), DELTA);
140         bean = getHome().findByPrimaryKey(pk);
141         // cleaning
142
bean.remove();
143     }
144
145     /**
146      * remove() test
147      */

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