KickJava   Java API By Example, From Geeks To Geeks.

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


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_EtypePdouble.java,v 1.3 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.pdouble.Pdouble;
35 import org.objectweb.jonas.jtests.beans.etype.pdouble.PdoubleHome;
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 'double' field of entity bean .
41  * Beans used: etype/pdouble
42  * @author Helene Joanin
43  */

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

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

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

74     public void testPrimDoubleFindByF1() throws Exception JavaDoc {
75         double f1 = 5.0d;
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             Pdouble bean = (Pdouble) javax.rmi.PortableRemoteObject.narrow(iBeans.next(),
81                                                                            Pdouble.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 testPrimDoubleFindByF1Literal5() throws Exception JavaDoc {
92         double f1 = 5.0d;
93         Collection JavaDoc cBeans = getHome().findByF1Literal5();
94         int nb = 0;
95         Iterator JavaDoc iBeans = cBeans.iterator();
96         while (iBeans.hasNext()) {
97             Pdouble bean = (Pdouble) javax.rmi.PortableRemoteObject.narrow(iBeans.next(),
98                                                                            Pdouble.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 testPrimDoubleGetF1() throws Exception JavaDoc {
109         String JavaDoc pk = "pk2";
110         Pdouble bean = getHome().findByPrimaryKey(pk);
111         double f1 = bean.getF1();
112         Assert.assertEquals("Pk", pk, bean.getPk());
113         Assert.assertEquals("F1", 2.0d, f1, DELTA);
114     }
115
116     /**
117      * setF1() test
118      */

119     public void testPrimDoubleSetF1() throws Exception JavaDoc {
120         String JavaDoc pk = "pk3";
121         Pdouble bean = getHome().findByPrimaryKey(pk);
122         double f1 = 30.0d;
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 testPrimDoubleCreate() throws Exception JavaDoc {
132         String JavaDoc pk = "pkcreated";
133         double f1 = 1959.65d;
134         Pdouble 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 testPrimDoubleRemove() throws Exception JavaDoc {
146         String JavaDoc pk = "pktoremove";
147         Pdouble bean = getHome().findByPrimaryKey(pk);
148         double 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