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_EtypeOser.java 7533 2005-10-19 15:55:05Z 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.oser.Name;
033: import org.objectweb.jonas.jtests.beans.etype.oser.Oser;
034: import org.objectweb.jonas.jtests.beans.etype.oser.OserHome;
035: import org.objectweb.jonas.jtests.util.JTestCase;
036:
037: /**
038: * This set of test are common to CMP version 1 and CMP version 2
039: * These are tests about java.lang.Boolean field of entity bean .
040: * Beans used: etype/oser
041: * @author Helene Joanin
042: */
043: public abstract class A_EtypeOser extends JTestCase {
044:
045: public A_EtypeOser(String name) {
046: super (name);
047: }
048:
049: protected boolean isInit = false;
050:
051: protected void setUp() {
052: super .setUp();
053: useBeans("oser", true);
054: if (!isInit) {
055: OserHome home = getHome();
056: // check if tables have been initialized
057: try {
058: home.findByPrimaryKey("pk1");
059: } catch (Exception e) {
060: // init here tables
061: try {
062: home.create("pk1", new Name("fn_1", "ln_1"));
063: home.create("pk2", new Name("fn_2", "ln_2"));
064: home.create("pk3", new Name("fn_3", "ln_3"));
065: home.create("pk4", new Name("fn_4", "ln_4"));
066: home.create("pk5", new Name("fn_5", "ln_5"));
067: home.create("pk5bis", new Name("fn_5", "ln_5"));
068: home.create("pktoremove", new Name("fn_remove",
069: "ln_remove"));
070: home.create("pknull", (Name) null);
071: home.create("pkchangenull", new Name(
072: "fn_changenull", "ln_changenull"));
073: } catch (Exception i) {
074: fail("InitialState creation problem: " + i);
075: }
076: }
077: isInit = true;
078: }
079: }
080:
081: /**
082: * Return OserHome, that can be either CMP version 1 or CMP version 2 bean.
083: */
084: abstract public OserHome getHome();
085:
086: /**
087: * findByPrimaryKey() test
088: */
089: public void testSerializableFindByPk() throws Exception {
090: String pk = "pk1";
091: Oser bean = getHome().findByPrimaryKey(pk);
092: assertEquals("Pk", pk, bean.getPk());
093: }
094:
095: /**
096: * findByF1() test
097: */
098: public void testSerializableFindByF1() throws Exception {
099: Name f1 = new Name("fn_5", "ln_5");
100: Collection cBeans = getHome().findByF1(f1);
101: Iterator iBeans = cBeans.iterator();
102: int nb = 0;
103: while (iBeans.hasNext()) {
104: Oser bean = (Oser) javax.rmi.PortableRemoteObject.narrow(
105: iBeans.next(), Oser.class);
106: assertEquals("F1", f1, bean.getF1());
107: nb++;
108: }
109: assertEquals("Beans number: ", 2, nb);
110: }
111:
112: /**
113: * getF1() test
114: */
115: public void testSerializableGetF1() throws Exception {
116: String pk = "pk2";
117: Oser bean = getHome().findByPrimaryKey(pk);
118: Name f1 = bean.getF1();
119: assertEquals("Pk", pk, bean.getPk());
120: assertEquals("F1", new Name("fn_2", "ln_2"), f1);
121: }
122:
123: /**
124: * getF1Null() test: f1 with a 'null' value
125: */
126: public void testSerializableGetF1Null() throws Exception {
127: String pk = "pknull";
128: Oser bean = getHome().findByPrimaryKey(pk);
129: Name f1 = bean.getF1();
130: assertEquals("Pk", pk, bean.getPk());
131: assertNull("F1 not null", f1);
132: }
133:
134: /**
135: * setF1() test
136: */
137: public void testSerializableSetF1() throws Exception {
138: String pk = "pk3";
139: Oser bean = getHome().findByPrimaryKey(pk);
140: Name f1 = new Name("fn_3_bis", "ln_3_bis");
141: bean.setF1(f1);
142: assertEquals("Pk", pk, bean.getPk());
143: assertEquals("F1", f1, bean.getF1());
144: }
145:
146: /**
147: * setF1Null() test: f1 with a 'null' value
148: */
149: public void testSerializableSetF1Null() throws Exception {
150: String pk = "pkchangenull";
151: Oser bean = getHome().findByPrimaryKey(pk);
152: bean.setF1(null);
153: assertEquals("Pk", pk, bean.getPk());
154: assertNull("F1", bean.getF1());
155: }
156:
157: /**
158: * create() test
159: */
160: public void testSerializableCreate() throws Exception {
161: String pk = "pkcreated";
162: Name f1 = new Name("fn_created", "ln_created");
163: Oser bean = getHome().create(pk, f1);
164: assertEquals("Pk", pk, bean.getPk());
165: assertEquals("F1", f1, bean.getF1());
166: bean = getHome().findByPrimaryKey(pk);
167: // cleaning
168: bean.remove();
169: }
170:
171: /**
172: * remove() test
173: */
174: public void testSerializableRemove() throws Exception {
175: String pk = "pktoremove";
176: Oser bean = getHome().findByPrimaryKey(pk);
177: Name f1 = bean.getF1();
178: bean.remove();
179: try {
180: getHome().findByPrimaryKey(pk);
181: fail("not removed");
182: } catch (FinderException e) {
183: // ok
184: }
185: // cleaning
186: getHome().create(pk, f1);
187: }
188:
189: }
|