KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > runtime > basictype > TestAllTypes


1 /**
2  * JORM: an implementation of a generic mapping system for persistent Java
3  * objects. Two mapping are supported: to RDBMS and to binary files.
4  * Copyright (C) 2001-2003 France Telecom R&D - INRIA
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 of the License, or (at your option) 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 USA
19  *
20  * Contact: jorm-team@objectweb.org
21  *
22  */

23
24 package org.objectweb.jorm.runtime.basictype;
25
26 import org.objectweb.jorm.runtime.TestRuntimeHelper;
27 import org.objectweb.jorm.naming.api.PBinder;
28 import org.objectweb.jorm.facility.naming.basidir.BasidBinder;
29 import org.objectweb.jorm.api.PClassMapping;
30 import org.objectweb.jorm.api.PException;
31
32 /**
33  *
34  * @author S.Chassande-Barrioz
35  */

36 public class TestAllTypes extends TestRuntimeHelper {
37
38     private final static String JavaDoc LOGGER_NAME
39             = "test.org.objectweb.jorm.basictype.alltypes";
40
41     private final static String JavaDoc CN_ALL_TYPES = "org.objectweb.jorm.pobject.basictype.AllTypes";
42
43     public TestAllTypes(String JavaDoc name) throws Exception JavaDoc {
44         super(name);
45     }
46
47     protected String JavaDoc getLoggerName() {
48         return LOGGER_NAME;
49     }
50
51     protected PBinder getBinder(String JavaDoc className) throws Exception JavaDoc {
52         try {
53             return new BasidBinder(mapper,
54                     "org.objectweb.jorm.runtime.basictype.TestBasicType",
55                     PClassMapping.CLEANUP_REMOVEALL);
56         } catch (PException e) {
57             Exception JavaDoc current = e;
58             while (current instanceof PException
59                     && ((PException) current).getNestedException() != null) {
60                 current = ((PException) current).getNestedException();
61             }
62             throw current;
63         }
64     }
65
66     public void test1() {
67         AllTypesAcc acc1 = new AllTypesAcc();
68         acc1.booleanValue1 = true;
69         acc1.booleanValue2 = false;
70         acc1.obooleanValue1 = Boolean.TRUE;
71         acc1.obooleanValue2 = Boolean.FALSE;
72         acc1.byteValue1 = 1;
73         acc1.byteValue2 = 2;
74         acc1.obyteValue1 = new Byte JavaDoc((byte) 1);
75         acc1.obyteValue2 = new Byte JavaDoc((byte) 2);
76         acc1.charValue1 = 'a';
77         acc1.charValue2 = 'b';
78         acc1.ocharValue1 = new Character JavaDoc('a');
79         acc1.ocharValue2 = new Character JavaDoc('b');
80         acc1.shortValue1 = 1;
81         acc1.shortValue2 = 2;
82         acc1.oshortValue1 = new Short JavaDoc((short) 1);
83         acc1.oshortValue2 = new Short JavaDoc((short) 2);
84         acc1.intValue1 = 1;
85         acc1.intValue2 = 2;
86         acc1.ointValue1 = new Integer JavaDoc(1);
87         acc1.ointValue2 = new Integer JavaDoc(2);
88         acc1.longValue1 = 1;
89         acc1.longValue2 = 2;
90         acc1.olongValue1 = new Long JavaDoc(1);
91         acc1.olongValue2 = new Long JavaDoc(2);
92         acc1.floatValue1 = 1;
93         acc1.floatValue2 = 2;
94         acc1.ofloatValue1 = new Float JavaDoc(1);
95         acc1.ofloatValue2 = new Float JavaDoc(2);
96         acc1.doubleValue1 = 1;
97         acc1.doubleValue2 = 2;
98         acc1.odoubleValue1 = new Double JavaDoc(1);
99         acc1.odoubleValue2 = new Double JavaDoc(2);
100         acc1.chararrayValue1 = new char[]{'a', 'z', 'e', 'r', 't', 'y'};
101         acc1.chararrayValue2 = new char[]{'q', 's', 'd', 'f', 'g', 'h'};
102         acc1.bytearrayValue1 = "azerty".getBytes();
103         acc1.bytearrayValue2 = "qsdfgh".getBytes();
104         acc1.stringValue1 = "azerty";
105         acc1.stringValue2 = "qsdfgh";
106         acc1.dateValue1 = getTime();
107         try {
108             Thread.sleep(1000);
109         } catch (InterruptedException JavaDoc e) {
110         }
111         acc1.dateValue2 = getTime();
112
113         AllTypesAcc acc2 = new AllTypesAcc();
114         performIO(CN_ALL_TYPES, acc1, acc2);
115         assertEquals("Bad booleanValue1", acc1.booleanValue1, acc2.booleanValue1);
116         assertEquals("Bad booleanValue2", acc1.booleanValue2, acc2.booleanValue2);
117         assertEquals("Bad obooleanValue1", acc1.obooleanValue1, acc2.obooleanValue1);
118         assertEquals("Bad obooleanValue2", acc1.obooleanValue2, acc2.obooleanValue2);
119
120         assertEquals("Bad byteValue1", acc1.byteValue1, acc2.byteValue1);
121         assertEquals("Bad byteValue1", acc1.byteValue1, acc2.byteValue1);
122         assertEquals("Bad obyteValue1", acc1.obyteValue1, acc2.obyteValue1);
123         assertEquals("Bad obyteValue1", acc1.obyteValue1, acc2.obyteValue1);
124
125         assertEquals("Bad charValue1", acc1.charValue1, acc2.charValue1);
126         assertEquals("Bad charValue2", acc1.charValue2, acc2.charValue2);
127         assertEquals("Bad ocharValue1", acc1.ocharValue1, acc2.ocharValue1);
128         assertEquals("Bad ocharValue2", acc1.ocharValue2, acc2.ocharValue2);
129
130         assertEquals("Bad shortValue1", acc1.shortValue1, acc2.shortValue1);
131         assertEquals("Bad shortValue2", acc1.shortValue2, acc2.shortValue2);
132         assertEquals("Bad oshortValue1", acc1.oshortValue1, acc2.oshortValue1);
133         assertEquals("Bad oshortValue2", acc1.oshortValue2, acc2.oshortValue2);
134
135         assertEquals("Bad intValue1", acc1.intValue1, acc2.intValue1);
136         assertEquals("Bad intValue2", acc1.intValue2, acc2.intValue2);
137         assertEquals("Bad ointValue1", acc1.ointValue1, acc2.ointValue1);
138         assertEquals("Bad ointValue2", acc1.ointValue2, acc2.ointValue2);
139
140         assertEquals("Bad longValue1", acc1.longValue1, acc2.longValue1);
141         assertEquals("Bad longValue2", acc1.longValue2, acc2.longValue2);
142         assertEquals("Bad olongValue1", acc1.olongValue1, acc2.olongValue1);
143         assertEquals("Bad olongValue2", acc1.olongValue2, acc2.olongValue2);
144
145         assertEquals("Bad floatValue1", acc1.floatValue1, acc2.floatValue1, (float) 0);
146         assertEquals("Bad floatValue2", acc1.floatValue2, acc2.floatValue2, (float) 0);
147         assertEquals("Bad ofloatValue1", acc1.ofloatValue1, acc2.ofloatValue1);
148         assertEquals("Bad ofloatValue2", acc1.ofloatValue2, acc2.ofloatValue2);
149
150         assertEquals("Bad doubleValue1", acc1.doubleValue1, acc2.doubleValue1, (double) 0);
151         assertEquals("Bad doubleValue2", acc1.doubleValue2, acc2.doubleValue2, (double) 0);
152         assertEquals("Bad odoubleValue1", acc1.odoubleValue1, acc2.odoubleValue1);
153         assertEquals("Bad odoubleValue2", acc1.odoubleValue2, acc2.odoubleValue2);
154
155         assertEqual("chararrayValue1 ", acc1.chararrayValue1, acc2.chararrayValue1);
156         assertEqual("chararrayValue2 ", acc1.chararrayValue2, acc2.chararrayValue2);
157         assertEqual("bytearrayValue1 ", acc1.bytearrayValue1, acc2.bytearrayValue1);
158         assertEqual("bytearrayValue2 ", acc1.bytearrayValue2, acc2.bytearrayValue2);
159
160         assertEquals("Bad stringValue1", acc1.stringValue1, acc2.stringValue1);
161         assertEquals("Bad stringValue1", acc1.stringValue2, acc2.stringValue2);
162
163         if (acc1.dateValue1 == null) {
164             assertNull("dateValue1 must be null", acc2.dateValue1);
165         } else {
166             assertNotNull("dateValue1 must not be null", acc2.dateValue1);
167             assertEquals("Bad dateValue1",
168                     acc1.dateValue1.getTime(), acc2.dateValue1.getTime());
169         }
170         if (acc1.dateValue2 == null) {
171             assertNull("dateValue2 must be null", acc2.dateValue2);
172         } else {
173             assertNotNull("dateValue2 must not be null", acc2.dateValue2);
174             assertEquals("Bad dateValue2",
175                     acc1.dateValue2.getTime(), acc2.dateValue2.getTime());
176         }
177     }
178 }
179
Popular Tags