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_EtypeObyte.java 4040 2004-01-14 07:31:10Z 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.obyte.Obyte;
033: import org.objectweb.jonas.jtests.beans.etype.obyte.ObyteHome;
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.Byte field of entity bean .
039: * Beans used: etype/obyte
040: * @author Helene Joanin
041: */
042: public abstract class A_EtypeObyte extends JTestCase {
043:
044: public A_EtypeObyte(String name) {
045: super (name);
046: }
047:
048: protected void setUp() {
049: super .setUp();
050: useBeans("obyte", true);
051: }
052:
053: /**
054: * Return ObyteHome, that can be either CMP version 1 or CMP version 2 bean.
055: */
056: abstract public ObyteHome getHome();
057:
058: /**
059: * findByPrimaryKey() test
060: */
061: public void testObjByteFindByPk() throws Exception {
062: String pk = "pk1";
063: Obyte bean = getHome().findByPrimaryKey(pk);
064: assertEquals("Pk", pk, bean.getPk());
065: }
066:
067: /**
068: * findByF1() test
069: */
070: public void testObjByteFindByF1() throws Exception {
071: byte f1 = (byte) 5;
072: Collection cBeans = getHome().findByF1(new Byte(f1));
073: int nb = 0;
074: Iterator iBeans = cBeans.iterator();
075: while (iBeans.hasNext()) {
076: Obyte bean = (Obyte) javax.rmi.PortableRemoteObject.narrow(
077: iBeans.next(), Obyte.class);
078: assertEquals("F1", f1, bean.getF1().byteValue());
079: nb++;
080: }
081: assertEquals("Beans number: ", 2, nb);
082: }
083:
084: /**
085: * getF1() test
086: */
087: public void testObjByteGetF1() throws Exception {
088: String pk = "pk2";
089: Obyte bean = getHome().findByPrimaryKey(pk);
090: Byte f1 = bean.getF1();
091: assertEquals("Pk", pk, bean.getPk());
092: assertEquals("F1", 2, f1.byteValue());
093: }
094:
095: /**
096: * getF1Null() test: f1 with a 'null' value
097: */
098: public void testObjByteGetF1Null() throws Exception {
099: String pk = "pknull";
100: Obyte bean = getHome().findByPrimaryKey(pk);
101: Byte f1 = bean.getF1();
102: assertEquals("Pk", pk, bean.getPk());
103: assertNull("F1 not null", f1);
104: }
105:
106: /**
107: * setF1() test
108: */
109: public void testObjByteSetF1() throws Exception {
110: String pk = "pk3";
111: Obyte bean = getHome().findByPrimaryKey(pk);
112: byte f1 = (byte) 30;
113: bean.setF1(new Byte(f1));
114: assertEquals("Pk", pk, bean.getPk());
115: assertEquals("F1", f1, (bean.getF1()).byteValue());
116: }
117:
118: /**
119: * setF1Null() test: f1 with a 'null' value
120: */
121: public void testObjByteSetF1Null() throws Exception {
122: String pk = "pkchangenull";
123: Obyte bean = getHome().findByPrimaryKey(pk);
124: bean.setF1(null);
125: assertEquals("Pk", pk, bean.getPk());
126: assertNull("F1", bean.getF1());
127: }
128:
129: /**
130: * create() test
131: */
132: public void testObjByteCreate() throws Exception {
133: String pk = "pkcreated";
134: byte f1 = (byte) 59;
135: Obyte bean = getHome().create(pk, new Byte(f1));
136: assertEquals("Pk", pk, bean.getPk());
137: assertEquals("F1", f1, (bean.getF1()).byteValue());
138: bean = getHome().findByPrimaryKey(pk);
139: // cleaning
140: bean.remove();
141: }
142:
143: /**
144: * remove() test
145: */
146: public void testObjByteRemove() throws Exception {
147: String pk = "pktoremove";
148: Obyte bean = getHome().findByPrimaryKey(pk);
149: Byte f1 = bean.getF1();
150: bean.remove();
151: try {
152: getHome().findByPrimaryKey(pk);
153: fail("not removed");
154: } catch (FinderException e) {
155: // ok
156: }
157: // cleaning
158: getHome().create(pk, f1);
159: }
160:
161: }
|