001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: A_EtypeOdouble.java 3064 2003-08-20 15:33:23Z joaninh $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.entity;
027:
028: import java.util.Collection;
029: import java.util.Iterator;
030: import javax.ejb.FinderException;
031:
032: import org.objectweb.jonas.jtests.beans.etype.odouble.Odouble;
033: import org.objectweb.jonas.jtests.beans.etype.odouble.OdoubleHome;
034: import org.objectweb.jonas.jtests.util.JTestCase;
035:
036: /**
037: * This set of test are common to CMP version 1 and CMP version 2
038: * These are tests about java.lang.Double field of entity bean .
039: * Beans used: etype/odouble
040: * @author Helene Joanin
041: */
042: public abstract class A_EtypeOdouble extends JTestCase {
043:
044: private static final double DELTA = 0.01d;
045:
046: public A_EtypeOdouble(String name) {
047: super (name);
048: }
049:
050: protected void setUp() {
051: super .setUp();
052: useBeans("odouble", true);
053: }
054:
055: /**
056: * Return OdoubleHome, that can be either CMP version 1 or CMP version 2 bean.
057: */
058: abstract public OdoubleHome getHome();
059:
060: /**
061: * findByPrimaryKey() test
062: */
063: public void testObjDoubleFindByPk() throws Exception {
064: String pk = "pk1";
065: Odouble bean = getHome().findByPrimaryKey(pk);
066: assertEquals("Pk", pk, bean.getPk());
067: }
068:
069: /**
070: * findByF1() test
071: */
072: public void testObjDoubleFindByF1() throws Exception {
073: double f1 = 5.0d;
074: Collection cBeans = getHome().findByF1(new Double(f1 - DELTA),
075: new Double(f1 + DELTA));
076: int nb = 0;
077: Iterator iBeans = cBeans.iterator();
078: while (iBeans.hasNext()) {
079: Odouble bean = (Odouble) javax.rmi.PortableRemoteObject
080: .narrow(iBeans.next(), Odouble.class);
081: assertEquals("F1", f1, (bean.getF1()).doubleValue(), DELTA);
082: nb++;
083: }
084: assertEquals("Beans number: ", 2, nb);
085: }
086:
087: /**
088: * getF1() test
089: */
090: public void testObjDoubleGetF1() throws Exception {
091: String pk = "pk2";
092: Odouble bean = getHome().findByPrimaryKey(pk);
093: Double f1 = bean.getF1();
094: assertEquals("Pk", pk, bean.getPk());
095: assertEquals("F1", 2.0d, f1.doubleValue(), DELTA);
096: }
097:
098: /**
099: * getF1Null() test: f1 with a 'null' value
100: */
101: public void testObjDoubleGetF1Null() throws Exception {
102: String pk = "pknull";
103: Odouble bean = getHome().findByPrimaryKey(pk);
104: Double f1 = bean.getF1();
105: assertEquals("Pk", pk, bean.getPk());
106: assertNull("F1 not null", f1);
107: }
108:
109: /**
110: * setF1() test
111: */
112: public void testObjDoubleSetF1() throws Exception {
113: String pk = "pk3";
114: Odouble bean = getHome().findByPrimaryKey(pk);
115: double f1 = 30.0d;
116: bean.setF1(new Double(f1));
117: assertEquals("Pk", pk, bean.getPk());
118: assertEquals("F1", f1, (bean.getF1()).doubleValue(), DELTA);
119: }
120:
121: /**
122: * setF1Null() test: f1 with a 'null' value
123: */
124: public void testObjDoubleSetF1Null() throws Exception {
125: String pk = "pkchangenull";
126: Odouble bean = getHome().findByPrimaryKey(pk);
127: bean.setF1(null);
128: assertEquals("Pk", pk, bean.getPk());
129: assertNull("F1", bean.getF1());
130: }
131:
132: /**
133: * create() test
134: */
135: public void testObjDoubleCreate() throws Exception {
136: String pk = "pkcreated";
137: double f1 = 1959.65d;
138: Odouble bean = getHome().create(pk, new Double(f1));
139: assertEquals("Pk", pk, bean.getPk());
140: assertEquals("F1", f1, (bean.getF1()).doubleValue(), DELTA);
141: bean = getHome().findByPrimaryKey(pk);
142: // cleaning
143: bean.remove();
144: }
145:
146: /**
147: * remove() test
148: */
149: public void testObjDoubleRemove() throws Exception {
150: String pk = "pktoremove";
151: Odouble bean = getHome().findByPrimaryKey(pk);
152: Double f1 = bean.getF1();
153: bean.remove();
154: try {
155: getHome().findByPrimaryKey(pk);
156: fail("not removed");
157: } catch (FinderException e) {
158: // ok
159: }
160: // cleaning
161: getHome().create(pk, f1);
162: }
163:
164: }
|