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_EtypePboolean.java 3233 2003-09-11 09:11:20Z 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.pboolean.Pboolean;
035: import org.objectweb.jonas.jtests.beans.etype.pboolean.PbooleanHome;
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 'boolean' field of entity bean .
041: * Beans used: etype/pboolean
042: * @author Helene Joanin
043: */
044: public abstract class A_EtypePboolean extends JTestCase {
045:
046: public A_EtypePboolean(String name) {
047: super (name);
048: }
049:
050: protected void setUp() {
051: super .setUp();
052: useBeans("pboolean", true);
053: }
054:
055: /**
056: * Return PbooleanHome, that can be either CMP version 1 or CMP version 2 bean.
057: */
058: abstract public PbooleanHome getHome();
059:
060: /**
061: * findByPrimaryKey() test
062: */
063: public void testPrimBooleanFindByPk() throws Exception {
064: String pk = "pk1";
065: Pboolean bean = getHome().findByPrimaryKey(pk);
066: Assert.assertEquals("Pk", pk, bean.getPk());
067: }
068:
069: /**
070: * findByF1() test
071: */
072: public void testPrimBooleanFindByF1() throws Exception {
073: boolean f1 = true;
074: Collection cBeans = getHome().findByF1(f1);
075: Iterator iBeans = cBeans.iterator();
076: while (iBeans.hasNext()) {
077: Pboolean bean = (Pboolean) javax.rmi.PortableRemoteObject
078: .narrow(iBeans.next(), Pboolean.class);
079: Assert.assertEquals("F1", f1, bean.getF1());
080: }
081: }
082:
083: /**
084: * findByF1LiteralTrue() test
085: */
086: public void testPrimBooleanFindByF1LiteralTrue() throws Exception {
087: Collection cBeans = getHome().findByF1LiteralTrue();
088: Iterator iBeans = cBeans.iterator();
089: while (iBeans.hasNext()) {
090: Pboolean bean = (Pboolean) javax.rmi.PortableRemoteObject
091: .narrow(iBeans.next(), Pboolean.class);
092: Assert.assertEquals("F1 of " + bean.getPk() + ": ", true,
093: bean.getF1());
094: }
095: }
096:
097: /**
098: * getF1() test
099: */
100: public void testPrimBooleanGetF1() throws Exception {
101: String pk = "pk2";
102: Pboolean bean = getHome().findByPrimaryKey(pk);
103: boolean f1 = bean.getF1();
104: Assert.assertEquals("Pk", pk, bean.getPk());
105: Assert.assertEquals("F1", true, f1);
106: }
107:
108: /**
109: * setF1() test
110: */
111: public void testPrimBooleanSetF1() throws Exception {
112: String pk = "pk3";
113: Pboolean bean = getHome().findByPrimaryKey(pk);
114: boolean f1 = true;
115: bean.setF1(f1);
116: Assert.assertEquals("Pk", pk, bean.getPk());
117: Assert.assertEquals("F1", f1, bean.getF1());
118: }
119:
120: /**
121: * create() test
122: */
123: public void testPrimBooleanCreate() throws Exception {
124: String pk = "pkcreated";
125: boolean f1 = false;
126: Pboolean bean = getHome().create(pk, f1);
127: Assert.assertEquals("Pk", pk, bean.getPk());
128: Assert.assertEquals("F1", f1, bean.getF1());
129: bean = getHome().findByPrimaryKey(pk);
130: // cleaning
131: bean.remove();
132: }
133:
134: /**
135: * remove() test
136: */
137: public void testPrimBooleanRemove() throws Exception {
138: String pk = "pktoremove";
139: Pboolean bean = getHome().findByPrimaryKey(pk);
140: boolean f1 = bean.getF1();
141: bean.remove();
142: try {
143: getHome().findByPrimaryKey(pk);
144: fail("not removed");
145: } catch (FinderException e) {
146: // ok
147: }
148: // cleaning
149: getHome().create(pk, f1);
150: }
151:
152: }
|