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_EtypeOobj.java 7594 2005-10-24 20:37:41Z rhs $
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.oobj.Oobj;
033: import org.objectweb.jonas.jtests.beans.etype.oobj.OobjHome;
034: import org.objectweb.jonas.jtests.util.JTestCase;
035:
036: /**
037: * A_EtypeOobj
038: *
039: * @author Rafael H. Schloming <rhs@mit.edu>
040: **/
041:
042: public abstract class A_EtypeOobj extends JTestCase {
043:
044: public A_EtypeOobj(String name) {
045: super (name);
046: }
047:
048: abstract public OobjHome getHome();
049:
050: protected boolean isInit = false;
051:
052: protected void setUp() {
053: super .setUp();
054: useBeans("oobj", false);
055: if (!isInit) {
056: OobjHome home = getHome();
057: // check if tables have been initialized
058: try {
059: home.findByPrimaryKey("pk1");
060: } catch (Exception e) {
061: // init here tables
062: try {
063: home.create("pk1", "f_1");
064: home.create("pk2", "f_2");
065: home.create("pk3", "f_3");
066: home.create("pk4", "f_4");
067: home.create("pk5", "f_5");
068: home.create("pk5bis", "f_5");
069: home.create("pktoremove", "f_remove");
070: home.create("pknull", null);
071: home.create("pkchangenull", "f_changenull");
072: } catch (Exception i) {
073: fail("InitialState creation problem: " + i);
074: }
075: }
076: isInit = true;
077: }
078: }
079:
080: /**
081: * findByPrimaryKey() test
082: */
083: public void testObjectFindByPk() throws Exception {
084: String pk = "pk1";
085: Oobj bean = getHome().findByPrimaryKey(pk);
086: assertEquals("Pk", pk, bean.getPk());
087: }
088:
089: /**
090: * getF1() test
091: */
092: public void testObjectGetF1() throws Exception {
093: String pk = "pk2";
094: Oobj bean = getHome().findByPrimaryKey(pk);
095: String f1 = (String) bean.getF1();
096: assertEquals("Pk", pk, bean.getPk());
097: assertEquals("F1", "f_2", f1);
098: }
099:
100: /**
101: * getF1Null() test: f1 with a 'null' value
102: */
103: public void testObjectGetF1Null() throws Exception {
104: String pk = "pknull";
105: Oobj bean = getHome().findByPrimaryKey(pk);
106: Object f1 = bean.getF1();
107: assertEquals("Pk", pk, bean.getPk());
108: assertNull("F1 not null", f1);
109: }
110:
111: /**
112: * setF1() test
113: */
114: public void testObjectSetF1() throws Exception {
115: String pk = "pk3";
116: Oobj bean = getHome().findByPrimaryKey(pk);
117: String f1 = "f_3_bis";
118: bean.setF1(f1);
119: assertEquals("Pk", pk, bean.getPk());
120: assertEquals("F1", f1, bean.getF1());
121: }
122:
123: /**
124: * setF1Null() test: f1 with a 'null' value
125: */
126: public void testObjectSetF1Null() throws Exception {
127: String pk = "pkchangenull";
128: Oobj bean = getHome().findByPrimaryKey(pk);
129: bean.setF1(null);
130: assertEquals("Pk", pk, bean.getPk());
131: assertNull("F1", bean.getF1());
132: }
133:
134: /**
135: * create() test
136: */
137: public void testObjectCreate() throws Exception {
138: String pk = "pkcreated";
139: String f1 = "f_created";
140: Oobj bean = getHome().create(pk, f1);
141: assertEquals("Pk", pk, bean.getPk());
142: assertEquals("F1", f1, bean.getF1());
143: bean = getHome().findByPrimaryKey(pk);
144: // cleaning
145: bean.remove();
146: }
147:
148: /**
149: * remove() test
150: */
151: public void testObjectRemove() throws Exception {
152: String pk = "pktoremove";
153: Oobj bean = getHome().findByPrimaryKey(pk);
154: String f1 = (String) bean.getF1();
155: bean.remove();
156: try {
157: getHome().findByPrimaryKey(pk);
158: fail("not removed");
159: } catch (FinderException e) {
160: // ok
161: }
162: // cleaning
163: getHome().create(pk, f1);
164: }
165:
166: }
|