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_EtypeObigdecimal.java 3064 2003-08-20 15:33:23Z joaninh $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.entity;
027:
028: import java.math.BigDecimal;
029: import java.util.Collection;
030: import java.util.Iterator;
031:
032: import javax.ejb.FinderException;
033:
034: import org.objectweb.jonas.jtests.beans.etype.obigd.Obigdecimal;
035: import org.objectweb.jonas.jtests.beans.etype.obigd.ObigdecimalHome;
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 java.math.BigDecimal field of entity bean .
041: * Beans used: etype/obigd
042: * @author Helene Joanin
043: */
044: public abstract class A_EtypeObigdecimal extends JTestCase {
045:
046: public A_EtypeObigdecimal(String name) {
047: super (name);
048: }
049:
050: protected void setUp() {
051: super .setUp();
052: useBeans("obigd", true);
053: }
054:
055: /**
056: * Return ObigdecimalHome, that can be either CMP version 1 or CMP version 2 bean.
057: */
058: abstract public ObigdecimalHome getHome();
059:
060: /**
061: * findByPrimaryKey() test
062: */
063: public void testBigDecimalFindByPk() throws Exception {
064: String pk = "pk1";
065: Obigdecimal bean = getHome().findByPrimaryKey(pk);
066: assertEquals("Pk", pk, bean.getPk());
067: }
068:
069: /**
070: * findByF1() test
071: */
072: public void testBigDecimalFindByF1() throws Exception {
073: BigDecimal f1 = new BigDecimal("5");
074: Collection cBeans = getHome().findByF1(f1);
075: int nb = 0;
076: Iterator iBeans = cBeans.iterator();
077: while (iBeans.hasNext()) {
078: Obigdecimal bean = (Obigdecimal) javax.rmi.PortableRemoteObject
079: .narrow(iBeans.next(), Obigdecimal.class);
080: assertEquals("F1", f1, bean.getF1());
081: nb++;
082: }
083: assertEquals("Beans number: ", 2, nb);
084: }
085:
086: /**
087: * getF1() test
088: */
089: public void testBigDecimalGetF1() throws Exception {
090: String pk = "pk2";
091: Obigdecimal bean = getHome().findByPrimaryKey(pk);
092: BigDecimal f1 = bean.getF1();
093: assertEquals("Pk", pk, bean.getPk());
094: assertEquals("F1", new BigDecimal("2"), f1);
095: }
096:
097: /**
098: * getF1Null() test: f1 with a 'null' value
099: */
100: public void testBigDecimalGetF1Null() throws Exception {
101: String pk = "pknull";
102: Obigdecimal bean = getHome().findByPrimaryKey(pk);
103: BigDecimal f1 = bean.getF1();
104: assertEquals("Pk", pk, bean.getPk());
105: assertNull("F1 not null", f1);
106: }
107:
108: /**
109: * setF1() test
110: */
111: public void testBigDecimalSetF1() throws Exception {
112: String pk = "pk3";
113: Obigdecimal bean = getHome().findByPrimaryKey(pk);
114: BigDecimal f1 = new BigDecimal("30");
115: bean.setF1(f1);
116: assertEquals("Pk", pk, bean.getPk());
117: assertEquals("F1", f1, bean.getF1());
118: }
119:
120: /**
121: * setF1Null() test: f1 with a 'null' value
122: */
123: public void testBigDecimalSetF1Null() throws Exception {
124: String pk = "pkchangenull";
125: Obigdecimal bean = getHome().findByPrimaryKey(pk);
126: bean.setF1(null);
127: assertEquals("Pk", pk, bean.getPk());
128: assertNull("F1", bean.getF1());
129: }
130:
131: /**
132: * create() test
133: */
134: public void testBigDecimalCreate() throws Exception {
135: String pk = "pkcreated";
136: BigDecimal f1 = new BigDecimal("1959");
137: Obigdecimal bean = getHome().create(pk, f1);
138: assertEquals("Pk", pk, bean.getPk());
139: assertEquals("F1", f1, bean.getF1());
140: bean = getHome().findByPrimaryKey(pk);
141: // cleaning
142: bean.remove();
143: }
144:
145: /**
146: * remove() test
147: */
148: public void testBigDecimalRemove() throws Exception {
149: String pk = "pktoremove";
150: Obigdecimal bean = getHome().findByPrimaryKey(pk);
151: BigDecimal f1 = bean.getF1();
152: bean.remove();
153: try {
154: getHome().findByPrimaryKey(pk);
155: fail("not removed");
156: } catch (FinderException e) {
157: // ok
158: }
159: // cleaning
160: getHome().create(pk, f1);
161: }
162:
163: }
|