KickJava   Java API By Example, From Geeks To Geeks.

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


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_EtypeByteArray.java,v 1.1 2003/08/20 12:27:49 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 import junit.framework.Assert;
32
33 import org.objectweb.jonas.jtests.beans.etype.bytearray.ByteArray;
34 import org.objectweb.jonas.jtests.beans.etype.bytearray.ByteArrayHome;
35 import org.objectweb.jonas.jtests.util.JTestCase;
36
37 /**
38  * This set of test are common to CMP version 1 and CMP version 2
39  * These are tests about byte array field of entity bean .
40  * Beans used: etype/bytearray
41  * @author Helene Joanin
42  */

43 public abstract class A_EtypeByteArray extends JTestCase {
44
45     public A_EtypeByteArray(String JavaDoc name) {
46         super(name);
47     }
48
49     protected static boolean isInit = false;
50
51     protected void setUp() {
52         super.setUp();
53         useBeans("bytearray", true);
54         if (!isInit) {
55             ByteArrayHome home = getHome();
56             // check if tables have been initialized
57
try {
58                 home.findByPrimaryKey("pk1");
59             } catch (Exception JavaDoc e) {
60                 // init here tables
61
try {
62                     home.create("pk1", new byte[] {1});
63                     home.create("pk2", new byte[] {2, 2});
64                     home.create("pk3", new byte[] {3, 3, 3});
65                     home.create("pk4", new byte[] {4, 4, 4, 4});
66                     home.create("pk5", new byte[] {5, 5, 5, 5, 5});
67                     home.create("pk5bis", new byte[] {5, 5, 5, 5, 5});
68                     home.create("pktoremove", new byte[] {100});
69                 } catch (Exception JavaDoc i) {
70                     fail("InitialState creation problem: "+i);
71                 }
72             }
73             isInit = true;
74         }
75     }
76
77     /**
78      * Return ByteArrayHome, that can be either CMP version 1 or CMP version 2 bean.
79      */

80     abstract public ByteArrayHome getHome();
81
82     /**
83      * findByPrimaryKey() test
84      */

85     public void testByteArrayFindByPk() throws Exception JavaDoc {
86         String JavaDoc pk = "pk1";
87         ByteArray bean = getHome().findByPrimaryKey(pk);
88         Assert.assertEquals("Pk", pk, bean.getPk());
89     }
90
91     /**
92      * findByF1() test
93      */

94     public void testByteArrayFindByF1() throws Exception JavaDoc {
95         byte[] f1 = new byte[] {5, 5, 5, 5, 5};
96         Collection JavaDoc cBeans = getHome().findByF1(f1);
97         int nb = 0;
98         Iterator JavaDoc iBeans = cBeans.iterator();
99         while (iBeans.hasNext()) {
100             ByteArray bean = (ByteArray) javax.rmi.PortableRemoteObject.narrow(iBeans.next(),
101                                                                                ByteArray.class);
102             Assert.assertEquals("F1", 5, bean.getF1().length);
103             nb++;
104         }
105         assertEquals("Beans number: ", 2, nb);
106     }
107
108     /**
109      * getF1() test
110      */

111     public void testByteArrayGetF1() throws Exception JavaDoc {
112         String JavaDoc pk = "pk2";
113         ByteArray bean = getHome().findByPrimaryKey(pk);
114         byte[] f1 = bean.getF1();
115         Assert.assertEquals("Pk", pk, bean.getPk());
116         Assert.assertEquals("F1", 2, f1.length);
117     }
118
119     /**
120      * setF1() test
121      */

122     public void testByteArraySetF1() throws Exception JavaDoc {
123         String JavaDoc pk = "pk3";
124         ByteArray bean = getHome().findByPrimaryKey(pk);
125         int nb = 30;
126         byte[] f1 = new byte[nb];
127         for (int i=0; i<nb; i++) {
128             f1[i] = 3;
129         }
130         bean.setF1(f1);
131         Assert.assertEquals("Pk", pk, bean.getPk());
132         Assert.assertEquals("F1", nb, bean.getF1().length);
133     }
134
135     /**
136      * create() test
137      */

138     public void testByteArrayCreate() throws Exception JavaDoc {
139         String JavaDoc pk = "pkcreated";
140         byte[] f1 = new byte[] {9, 9, 9, 9, 9, 9, 9, 9, 9};
141         ByteArray bean = getHome().create(pk, f1);
142         Assert.assertEquals("Pk", pk, bean.getPk());
143         Assert.assertEquals("F1", 9, bean.getF1().length);
144         bean = getHome().findByPrimaryKey(pk);
145         // cleaning
146
bean.remove();
147     }
148
149     /**
150      * remove() test
151      */

152     public void testByteArrayRemove() throws Exception JavaDoc {
153         String JavaDoc pk = "pktoremove";
154         ByteArray bean = getHome().findByPrimaryKey(pk);
155         byte[] f1 = bean.getF1();
156         bean.remove();
157         try {
158             getHome().findByPrimaryKey(pk);
159             fail("not removed");
160         } catch (FinderException JavaDoc e) {
161             // ok
162
}
163         // cleaning
164
getHome().create(pk, f1);
165     }
166
167 }
168
Popular Tags