KickJava   Java API By Example, From Geeks To Geeks.

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


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_EtypePboolean.java,v 1.4 2003/09/11 09:11:20 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 junit.framework.Assert;
33
34 import org.objectweb.jonas.jtests.beans.etype.pboolean.Pboolean;
35 import org.objectweb.jonas.jtests.beans.etype.pboolean.PbooleanHome;
36 import org.objectweb.jonas.jtests.util.JTestCase;
37
38 /**
39  * This set of test are common to CMP version 1 and CMP version 2
40  * These are tests about 'boolean' field of entity bean .
41  * Beans used: etype/pboolean
42  * @author Helene Joanin
43  */

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

58     abstract public PbooleanHome getHome();
59
60     /**
61      * findByPrimaryKey() test
62      */

63     public void testPrimBooleanFindByPk() throws Exception JavaDoc {
64         String JavaDoc pk = "pk1";
65         Pboolean bean = getHome().findByPrimaryKey(pk);
66         Assert.assertEquals("Pk", pk, bean.getPk());
67     }
68
69     /**
70      * findByF1() test
71      */

72     public void testPrimBooleanFindByF1() throws Exception JavaDoc {
73         boolean f1 = true;
74         Collection JavaDoc cBeans = getHome().findByF1(f1);
75         Iterator JavaDoc iBeans = cBeans.iterator();
76         while (iBeans.hasNext()) {
77             Pboolean bean = (Pboolean) javax.rmi.PortableRemoteObject.narrow(iBeans.next(),
78                                                                              Pboolean.class);
79             Assert.assertEquals("F1", f1, bean.getF1());
80         }
81     }
82
83     /**
84      * findByF1LiteralTrue() test
85      */

86     public void testPrimBooleanFindByF1LiteralTrue() throws Exception JavaDoc {
87         Collection JavaDoc cBeans = getHome().findByF1LiteralTrue();
88         Iterator JavaDoc iBeans = cBeans.iterator();
89         while (iBeans.hasNext()) {
90             Pboolean bean = (Pboolean) javax.rmi.PortableRemoteObject.narrow(iBeans.next(),
91                                                                              Pboolean.class);
92             Assert.assertEquals("F1 of " + bean.getPk() + ": "
93                                 , true, bean.getF1());
94         }
95     }
96
97     /**
98      * getF1() test
99      */

100     public void testPrimBooleanGetF1() throws Exception JavaDoc {
101         String JavaDoc 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 JavaDoc {
112         String JavaDoc 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 JavaDoc {
124         String JavaDoc 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 JavaDoc {
138         String JavaDoc 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 JavaDoc e) {
146             // ok
147
}
148         // cleaning
149
getHome().create(pk, f1);
150     }
151
152 }
153
Popular Tags