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