KickJava   Java API By Example, From Geeks To Geeks.

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


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_EtypePshort.java,v 1.3 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 junit.framework.Assert;
33
34 import org.objectweb.jonas.jtests.beans.etype.pshort.Pshort;
35 import org.objectweb.jonas.jtests.beans.etype.pshort.PshortHome;
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 'short' field of entity bean .
41  * Beans used: etype/pshort
42  * @author Helene Joanin
43  */

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

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

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

72     public void testPrimShortFindByF1() throws Exception JavaDoc {
73         short f1 = (short) 5;
74         Collection JavaDoc cBeans = getHome().findByF1(f1);
75         int nb = 0;
76         Iterator JavaDoc iBeans = cBeans.iterator();
77         while (iBeans.hasNext()) {
78             Pshort bean = (Pshort) javax.rmi.PortableRemoteObject.narrow(iBeans.next(),
79                                                                          Pshort.class);
80             Assert.assertEquals("F1", f1, bean.getF1());
81             nb++;
82         }
83         assertEquals("Beans number: ", 2, nb);
84     }
85
86     /**
87      * findByF1Literal5() test
88      */

89     public void testPrimShortFindByF1Literal5() throws Exception JavaDoc {
90         short f1 = (short) 5;
91         Collection JavaDoc cBeans = getHome().findByF1Literal5();
92         int nb = 0;
93         Iterator JavaDoc iBeans = cBeans.iterator();
94         while (iBeans.hasNext()) {
95             Pshort bean = (Pshort) javax.rmi.PortableRemoteObject.narrow(iBeans.next(),
96                                                                          Pshort.class);
97             Assert.assertEquals("F1", f1, bean.getF1());
98             nb++;
99         }
100         assertEquals("Beans number: ", 2, nb);
101     }
102
103     /**
104      * getF1() test
105      */

106     public void testPrimShortGetF1() throws Exception JavaDoc {
107         String JavaDoc pk = "pk2";
108         Pshort bean = getHome().findByPrimaryKey(pk);
109         short f1 = bean.getF1();
110         Assert.assertEquals("Pk", pk, bean.getPk());
111         Assert.assertEquals("F1", (short) 2, f1);
112     }
113
114     /**
115      * setF1() test
116      */

117     public void testPrimShortSetF1() throws Exception JavaDoc {
118         String JavaDoc pk = "pk3";
119         Pshort bean = getHome().findByPrimaryKey(pk);
120         short f1 = (short) 30;
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 testPrimShortCreate() throws Exception JavaDoc {
130         String JavaDoc pk = "pkcreated";
131         short f1 = (short) 1959;
132         Pshort 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 testPrimShortRemove() throws Exception JavaDoc {
144         String JavaDoc pk = "pktoremove";
145         Pshort bean = getHome().findByPrimaryKey(pk);
146         short 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