KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > entity > A_EtypeOboolean


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: A_EtypeOboolean.java,v 1.4 2003/08/20 15:33:23 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.entity;
27
28 import java.util.Collection JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import javax.ejb.FinderException JavaDoc;
31
32 import org.objectweb.jonas.jtests.beans.etype.oboolean.Oboolean;
33 import org.objectweb.jonas.jtests.beans.etype.oboolean.ObooleanHome;
34 import org.objectweb.jonas.jtests.util.JTestCase;
35
36 /**
37  * This set of test are common to CMP version 1 and CMP version 2
38  * These are tests about java.lang.Boolean field of entity bean .
39  * Beans used: etype/oboolean
40  * @author Helene Joanin
41  */

42 public abstract class A_EtypeOboolean extends JTestCase {
43
44     public A_EtypeOboolean(String JavaDoc name) {
45         super(name);
46     }
47
48     protected void setUp() {
49         super.setUp();
50         useBeans("oboolean", true);
51     }
52
53     /**
54      * Return ObooleanHome, that can be either CMP version 1 or CMP version 2 bean.
55      */

56     abstract public ObooleanHome getHome();
57
58     /**
59      * findByPrimaryKey() test
60      */

61     public void testObjBooleanFindByPk() throws Exception JavaDoc {
62         String JavaDoc pk = "pk1";
63         Oboolean bean = getHome().findByPrimaryKey(pk);
64         assertEquals("Pk", pk, bean.getPk());
65     }
66
67     /**
68      * findByF1() test
69      */

70     public void testObjBooleanFindByF1() throws Exception JavaDoc {
71         boolean f1 = true;
72         Collection JavaDoc cBeans = getHome().findByF1(new Boolean JavaDoc(f1));
73         Iterator JavaDoc iBeans = cBeans.iterator();
74         while (iBeans.hasNext()) {
75             Oboolean bean = (Oboolean) javax.rmi.PortableRemoteObject.narrow(iBeans.next(),
76                                                                              Oboolean.class);
77             assertEquals("F1", f1, bean.getF1().booleanValue());
78         }
79     }
80
81     /**
82      * getF1() test
83      */

84     public void testObjBooleanGetF1() throws Exception JavaDoc {
85         String JavaDoc pk = "pk2";
86         Oboolean bean = getHome().findByPrimaryKey(pk);
87         Boolean JavaDoc f1 = bean.getF1();
88         assertEquals("Pk", pk, bean.getPk());
89         assertEquals("F1", true, f1.booleanValue());
90     }
91
92     /**
93      * getF1Null() test: f1 with a 'null' value
94      */

95     public void testObjBooleanGetF1Null() throws Exception JavaDoc {
96         String JavaDoc pk = "pknull";
97         Oboolean bean = getHome().findByPrimaryKey(pk);
98         Boolean JavaDoc f1 = bean.getF1();
99         assertEquals("Pk", pk, bean.getPk());
100         assertNull("F1 not null", f1);
101     }
102
103     /**
104      * setF1() test
105      */

106     public void testObjBooleanSetF1() throws Exception JavaDoc {
107         String JavaDoc pk = "pk3";
108         Oboolean bean = getHome().findByPrimaryKey(pk);
109         boolean f1 = true;
110         bean.setF1(new Boolean JavaDoc(f1));
111         assertEquals("Pk", pk, bean.getPk());
112         assertEquals("F1", f1, (bean.getF1()).booleanValue());
113     }
114
115     /**
116      * setF1Null() test: f1 with a 'null' value
117      */

118     public void testObjBooleanSetF1Null() throws Exception JavaDoc {
119         String JavaDoc pk = "pkchangenull";
120         Oboolean bean = getHome().findByPrimaryKey(pk);
121         bean.setF1(null);
122         assertEquals("Pk", pk, bean.getPk());
123         assertNull("F1", bean.getF1());
124     }
125
126     /**
127      * create() test
128      */

129     public void testObjBooleanCreate() throws Exception JavaDoc {
130         String JavaDoc pk = "pkcreated";
131         Boolean JavaDoc f1 = new Boolean JavaDoc(true);
132         Oboolean bean = getHome().create(pk, f1);
133         assertEquals("Pk", pk, bean.getPk());
134         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 testObjBooleanRemove() throws Exception JavaDoc {
144         String JavaDoc pk = "pktoremove";
145         Oboolean bean = getHome().findByPrimaryKey(pk);
146         Boolean JavaDoc f1 = bean.getF1();
147         bean.remove();
148         try {
149             getHome().findByPrimaryKey(pk);
150             fail("not removed");
151         } catch (FinderException JavaDoc e) {
152             // ok
153
}
154         // cleaning
155
getHome().create(pk, f1);
156     }
157
158 }
159
Popular Tags