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_EtypeOboolean.java 8669 2006-06-21 14:33:51Z durieuxp $
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.oboolean.Oboolean;
033: import org.objectweb.jonas.jtests.beans.etype.oboolean.ObooleanHome;
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.Boolean field of entity bean .
039: * Beans used: etype/oboolean
040: * @author Helene Joanin
041: */
042: public abstract class A_EtypeOboolean extends JTestCase {
043:
044: public A_EtypeOboolean(String name) {
045: super (name);
046: }
047:
048: protected void setUp() {
049: super .setUp();
050: }
051:
052: /**
053: * Return ObooleanHome, that can be either CMP version 1 or CMP version 2 bean.
054: */
055: abstract public ObooleanHome getHome();
056:
057: /**
058: * findByPrimaryKey() test
059: */
060: public void testObjBooleanFindByPk() throws Exception {
061: String pk = "pk1";
062: Oboolean bean = getHome().findByPrimaryKey(pk);
063: assertEquals("Pk", pk, bean.getPk());
064: }
065:
066: /**
067: * findByF1() test
068: */
069: public void testObjBooleanFindByF1() throws Exception {
070: boolean f1 = true;
071: Collection cBeans = getHome().findByF1(new Boolean(f1));
072: Iterator iBeans = cBeans.iterator();
073: while (iBeans.hasNext()) {
074: Oboolean bean = (Oboolean) javax.rmi.PortableRemoteObject
075: .narrow(iBeans.next(), Oboolean.class);
076: assertEquals("F1", f1, bean.getF1().booleanValue());
077: }
078: }
079:
080: /**
081: * getF1() test
082: */
083: public void testObjBooleanGetF1() throws Exception {
084: String pk = "pk2";
085: Oboolean bean = getHome().findByPrimaryKey(pk);
086: Boolean f1 = bean.getF1();
087: assertEquals("Pk", pk, bean.getPk());
088: assertEquals("F1", true, f1.booleanValue());
089: }
090:
091: /**
092: * getF1Null() test: f1 with a 'null' value
093: */
094: public void testObjBooleanGetF1Null() throws Exception {
095: String pk = "pknull";
096: Oboolean bean = getHome().findByPrimaryKey(pk);
097: Boolean f1 = bean.getF1();
098: assertEquals("Pk", pk, bean.getPk());
099: assertNull("F1 not null", f1);
100: }
101:
102: /**
103: * setF1() test
104: */
105: public void testObjBooleanSetF1() throws Exception {
106: String pk = "pk3";
107: Oboolean bean = getHome().findByPrimaryKey(pk);
108: boolean f1 = true;
109: bean.setF1(new Boolean(f1));
110: assertEquals("Pk", pk, bean.getPk());
111: assertEquals("F1", f1, (bean.getF1()).booleanValue());
112: }
113:
114: /**
115: * setF1Null() test: f1 with a 'null' value
116: */
117: public void testObjBooleanSetF1Null() throws Exception {
118: String pk = "pkchangenull";
119: Oboolean bean = getHome().findByPrimaryKey(pk);
120: bean.setF1(null);
121: assertEquals("Pk", pk, bean.getPk());
122: assertNull("F1", bean.getF1());
123: }
124:
125: /**
126: * create() test
127: */
128: public void testObjBooleanCreate() throws Exception {
129: String pk = "pkcreated";
130: Boolean f1 = new Boolean(true);
131: Oboolean bean = getHome().create(pk, f1);
132: assertEquals("Pk", pk, bean.getPk());
133: assertEquals("F1", f1, bean.getF1());
134: bean = getHome().findByPrimaryKey(pk);
135: // cleaning
136: bean.remove();
137: }
138:
139: /**
140: * remove() test
141: */
142: public void testObjBooleanRemove() throws Exception {
143: String pk = "pktoremove";
144: Oboolean bean = getHome().findByPrimaryKey(pk);
145: Boolean f1 = bean.getF1();
146: bean.remove();
147: try {
148: getHome().findByPrimaryKey(pk);
149: fail("not removed");
150: } catch (FinderException e) {
151: // ok
152: }
153: // cleaning
154: getHome().create(pk, f1);
155: }
156:
157: }
|