001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999-2004 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_EtypeOfloat4pk.java 5398 2004-09-09 13:59:14Z joaninh $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.jtests.clients.entity;
025:
026: import java.util.Collection;
027: import java.util.Iterator;
028: import javax.ejb.FinderException;
029:
030: import org.objectweb.jonas.jtests.beans.etype.ofloat4pk.Ofloat4pk;
031: import org.objectweb.jonas.jtests.beans.etype.ofloat4pk.Ofloat4pkHome;
032: import org.objectweb.jonas.jtests.util.JTestCase;
033:
034: /**
035: * This set of test are common to CMP version 1 and CMP version 2
036: * These are tests about java.lang.Float field of entity bean .
037: * Beans used: etype/ofloat4pk
038: * @author Helene Joanin
039: */
040: public abstract class A_EtypeOfloat4pk extends JTestCase {
041:
042: private static final float DELTA = 0.01f;
043:
044: public A_EtypeOfloat4pk(String name) {
045: super (name);
046: }
047:
048: protected void setUp() {
049: super .setUp();
050: useBeans("ofloat4pk", false);
051: }
052:
053: /**
054: * Return Ofloat4pkHome, that can be either CMP version 1 or CMP version 2 bean.
055: */
056: abstract public Ofloat4pkHome getHome();
057:
058: /**
059: * findByPrimaryKey() test
060: */
061: public void testObjFloat4pkFindByPk() throws Exception {
062: Float pk = new Float(1.0);
063: Ofloat4pk bean = getHome().findByPrimaryKey(pk);
064: assertEquals("Pk", pk, bean.getPk());
065: }
066:
067: /**
068: * findByF1() test
069: */
070: public void testObjFloat4pkFindByF1() throws Exception {
071: float f1 = 5.0f;
072: Collection cBeans = getHome().findByF1(new Float(f1 - DELTA),
073: new Float(f1 + DELTA));
074: int nb = 0;
075: Iterator iBeans = cBeans.iterator();
076: while (iBeans.hasNext()) {
077: Ofloat4pk bean = (Ofloat4pk) javax.rmi.PortableRemoteObject
078: .narrow(iBeans.next(), Ofloat4pk.class);
079: assertEquals("F1", f1, (bean.getF1()).floatValue(), DELTA);
080: nb++;
081: }
082: assertEquals("Beans number: ", 2, nb);
083: }
084:
085: /**
086: * getF1() test
087: */
088: public void testObjFloat4pkGetF1() throws Exception {
089: Float pk = new Float(2.0);
090: Ofloat4pk bean = getHome().findByPrimaryKey(pk);
091: Float f1 = bean.getF1();
092: assertEquals("Pk", pk, bean.getPk());
093: assertEquals("F1", 2.0, f1.floatValue(), DELTA);
094: }
095:
096: /**
097: * setF1() test
098: */
099: public void testObjFloat4pkSetF1() throws Exception {
100: Float pk = new Float(3.0);
101: Ofloat4pk bean = getHome().findByPrimaryKey(pk);
102: float f1 = 30.0f;
103: bean.setF1(new Float(f1));
104: assertEquals("Pk", pk, bean.getPk());
105: assertEquals("F1", f1, (bean.getF1()).floatValue(), DELTA);
106: }
107:
108: /**
109: * create() test
110: */
111: public void testObjFloat4pkCreate() throws Exception {
112: float f1 = 1959.65f;
113: Float pk = new Float(f1);
114: Ofloat4pk bean = getHome().create(pk, new Float(f1));
115: assertEquals("Pk", pk, bean.getPk());
116: assertEquals("F1", f1, (bean.getF1()).floatValue(), DELTA);
117: bean = getHome().findByPrimaryKey(pk);
118: // cleaning
119: bean.remove();
120: }
121:
122: /**
123: * remove() test
124: */
125: public void testObjFloat4pkRemove() throws Exception {
126: Float pk = new Float(10000.0);
127: Ofloat4pk bean = getHome().findByPrimaryKey(pk);
128: Float f1 = bean.getF1();
129: bean.remove();
130: try {
131: getHome().findByPrimaryKey(pk);
132: fail("not removed");
133: } catch (FinderException e) {
134: // ok
135: }
136: // cleaning
137: getHome().create(pk, f1);
138: }
139:
140: }
|