KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 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_EtypeOfloat4pk.java,v 1.1 2004/09/09 13:59:14 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.ofloat4pk.Ofloat4pk;
33 import org.objectweb.jonas.jtests.beans.etype.ofloat4pk.Ofloat4pkHome;
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/ofloat4pk
40  * @author Helene Joanin
41  */

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

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

63     public void testObjFloat4pkFindByPk() throws Exception JavaDoc {
64         Float JavaDoc pk = new Float JavaDoc(1.0);
65         Ofloat4pk bean = getHome().findByPrimaryKey(pk);
66         assertEquals("Pk", pk, bean.getPk());
67     }
68
69     /**
70      * findByF1() test
71      */

72     public void testObjFloat4pkFindByF1() 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             Ofloat4pk bean = (Ofloat4pk) javax.rmi.PortableRemoteObject.narrow(iBeans.next(),
79                                                                          Ofloat4pk.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 testObjFloat4pkGetF1() throws Exception JavaDoc {
90         Float JavaDoc pk = new Float JavaDoc(2.0);
91         Ofloat4pk 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      * setF1() test
99      */

100     public void testObjFloat4pkSetF1() throws Exception JavaDoc {
101         Float JavaDoc pk = new Float JavaDoc(3.0);
102         Ofloat4pk bean = getHome().findByPrimaryKey(pk);
103         float f1 = 30.0f;
104         bean.setF1(new Float JavaDoc(f1));
105         assertEquals("Pk", pk, bean.getPk());
106         assertEquals("F1", f1, (bean.getF1()).floatValue(), DELTA);
107     }
108
109     /**
110      * create() test
111      */

112     public void testObjFloat4pkCreate() throws Exception JavaDoc {
113         float f1 = 1959.65f;
114         Float JavaDoc pk = new Float JavaDoc(f1);
115         Ofloat4pk bean = getHome().create(pk, new Float JavaDoc(f1));
116         assertEquals("Pk", pk, bean.getPk());
117         assertEquals("F1", f1, (bean.getF1()).floatValue(), DELTA);
118         bean = getHome().findByPrimaryKey(pk);
119         // cleaning
120
bean.remove();
121     }
122
123     /**
124      * remove() test
125      */

126     public void testObjFloat4pkRemove() throws Exception JavaDoc {
127         Float JavaDoc pk = new Float JavaDoc(10000.0);
128         Ofloat4pk bean = getHome().findByPrimaryKey(pk);
129         Float JavaDoc f1 = bean.getF1();
130         bean.remove();
131         try {
132             getHome().findByPrimaryKey(pk);
133             fail("not removed");
134         } catch (FinderException JavaDoc e) {
135             // ok
136
}
137         // cleaning
138
getHome().create(pk, f1);
139     }
140
141 }
142
Popular Tags