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_EtypePdouble.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 junit.framework.Assert;
033:
034: import org.objectweb.jonas.jtests.beans.etype.pdouble.Pdouble;
035: import org.objectweb.jonas.jtests.beans.etype.pdouble.PdoubleHome;
036: import org.objectweb.jonas.jtests.util.JTestCase;
037:
038: /**
039: * This set of test are common to CMP version 1 and CMP version 2
040: * These are tests about 'double' field of entity bean .
041: * Beans used: etype/pdouble
042: * @author Helene Joanin
043: */
044: public abstract class A_EtypePdouble extends JTestCase {
045:
046: private static final double DELTA = 0.01d;
047:
048: public A_EtypePdouble(String name) {
049: super (name);
050: }
051:
052: protected void setUp() {
053: super .setUp();
054: useBeans("pdouble", true);
055: }
056:
057: /**
058: * Return PdoubleHome, that can be either CMP version 1 or CMP version 2 bean.
059: */
060: abstract public PdoubleHome getHome();
061:
062: /**
063: * findByPrimaryKey() test
064: */
065: public void testPrimDoubleFindByPk() throws Exception {
066: String pk = "pk1";
067: Pdouble bean = getHome().findByPrimaryKey(pk);
068: Assert.assertEquals("Pk", pk, bean.getPk());
069: }
070:
071: /**
072: * findByF1() test
073: */
074: public void testPrimDoubleFindByF1() throws Exception {
075: double f1 = 5.0d;
076: Collection cBeans = getHome().findByF1(f1 - DELTA, f1 + DELTA);
077: int nb = 0;
078: Iterator iBeans = cBeans.iterator();
079: while (iBeans.hasNext()) {
080: Pdouble bean = (Pdouble) javax.rmi.PortableRemoteObject
081: .narrow(iBeans.next(), Pdouble.class);
082: Assert.assertEquals("F1", f1, bean.getF1(), DELTA);
083: nb++;
084: }
085: assertEquals("Beans number: ", 2, nb);
086: }
087:
088: /**
089: * findByF1Literal5() test
090: */
091: public void testPrimDoubleFindByF1Literal5() throws Exception {
092: double f1 = 5.0d;
093: Collection cBeans = getHome().findByF1Literal5();
094: int nb = 0;
095: Iterator iBeans = cBeans.iterator();
096: while (iBeans.hasNext()) {
097: Pdouble bean = (Pdouble) javax.rmi.PortableRemoteObject
098: .narrow(iBeans.next(), Pdouble.class);
099: 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 {
109: String 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 {
120: String 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 {
132: String 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 {
146: String 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 e) {
154: // ok
155: }
156: // cleaning
157: getHome().create(pk, f1);
158: }
159:
160: }
|