KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > runtime > namedef > TestNameDefComposite


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.namedef;
25
26 import org.objectweb.jorm.api.PBinding;
27 import org.objectweb.jorm.api.PException;
28 import org.objectweb.jorm.naming.api.PBinder;
29 import org.objectweb.jorm.pobject.compositename.CompositeByteIdPNG;
30 import org.objectweb.jorm.pobject.compositename.CompositeObyteIdPNG;
31 import org.objectweb.jorm.pobject.compositename.CompositeShortIdPNG;
32 import org.objectweb.jorm.pobject.compositename.CompositeOshortIdPNG;
33 import org.objectweb.jorm.pobject.compositename.CompositeIntIdPNG;
34 import org.objectweb.jorm.pobject.compositename.CompositeOintIdPNG;
35 import org.objectweb.jorm.pobject.compositename.CompositeLongIdPNG;
36 import org.objectweb.jorm.pobject.compositename.CompositeOlongIdPNG;
37 import org.objectweb.jorm.pobject.compositename.CompositeStringIdPNG;
38 import org.objectweb.jorm.pobject.compositename.CompositeDateIdPNG;
39 import org.objectweb.jorm.pobject.compositename.CompositeBigDecimalIdPNG;
40 import org.objectweb.jorm.pobject.compositename.CompositeBigIntegerIdPNG;
41 import org.objectweb.jorm.pobject.compositename.CompositeCharIdPNG;
42 import org.objectweb.jorm.pobject.compositename.CompositeOcharIdPNG;
43 import org.objectweb.jorm.pobject.compositename.CompositeBytearrayIdPNG;
44 import org.objectweb.jorm.pobject.compositename.CompositeChararrayIdPNG;
45 import org.objectweb.jorm.runtime.TestRuntimeHelper;
46 import org.objectweb.util.monolog.api.BasicLevel;
47
48 import java.util.Date JavaDoc;
49 import java.math.BigDecimal JavaDoc;
50 import java.math.BigInteger JavaDoc;
51
52 /**
53  * @author S.Chassande-Barrioz
54  */

55 public class TestNameDefComposite
56     extends TestRuntimeHelper {
57
58     private final static String JavaDoc LOGGER_NAME
59         = "test.org.objectweb.jorm.compositename";
60
61     public TestNameDefComposite(String JavaDoc s) throws Exception JavaDoc {
62         super(s);
63     }
64
65     protected String JavaDoc getLoggerName() {
66         return LOGGER_NAME;
67     }
68
69     protected PBinder getBinder(String JavaDoc className) throws Exception JavaDoc {
70         int idx = className.lastIndexOf('.');
71         String JavaDoc cn = className.substring(idx + 1);
72         if (!cn.startsWith("AComposite")) {
73             throw new Exception JavaDoc(
74                 "Unable to find a binder for the class: " + className);
75         }
76         String JavaDoc bcn = className.substring(0, idx) + "." + cn.substring(1) + "Binder";
77         logger.log(BasicLevel.DEBUG, "Allocating the Binder " + bcn
78             + " to manage the class " + className);
79         PBinder binder = (PBinder) Class.forName(bcn).newInstance();
80         if (CNBYTE.equals(className)) {
81             binder.setNullPName(new ByteIdPNG(new Byte JavaDoc((byte) -1)));
82         } else if (CNOBYTE.equals(className)) {
83             binder.setNullPName(new ObyteIdPNG(null));
84         } else if (CNSHORT.equals(className)) {
85             binder.setNullPName(new ShortIdPNG(new Short JavaDoc((short) -1)));
86         } else if (CNOSHORT.equals(className)) {
87             binder.setNullPName(new OshortIdPNG(null));
88         } else if (CNINT.equals(className)) {
89             binder.setNullPName(new IntIdPNG(new Integer JavaDoc(-1)));
90         } else if (CNOINT.equals(className)) {
91             binder.setNullPName(new OintIdPNG(null));
92         } else if (CNLONG.equals(className)) {
93             binder.setNullPName(new LongIdPNG(new Long JavaDoc(-1)));
94         } else if (CNOLONG.equals(className)) {
95             binder.setNullPName(new OlongIdPNG(null));
96         } else if (CNCHAR.equals(className)) {
97             binder.setNullPName(new CharIdPNG(new Character JavaDoc('0')));
98         } else if (CNOCHAR.equals(className)) {
99             binder.setNullPName(new OcharIdPNG(null));
100         } else if (CNSTRING.equals(className)) {
101             binder.setNullPName(new StringIdPNG(null));
102         } else if (CNDATE.equals(className)) {
103             binder.setNullPName(new DateIdPNG(null));
104         } else if (CNBIGDECIMAL.equals(className)) {
105             binder.setNullPName(new BigDecimalIdPNG(null));
106         } else if (CNBIGINTEGER.equals(className)) {
107             binder.setNullPName(new BigIntegerIdPNG(null));
108         } else if (CNCHARARRAY.equals(className)) {
109             binder.setNullPName(new ChararrayIdPNG(null));
110         } else if (CNBYTEARRAY.equals(className)) {
111             binder.setNullPName(new BytearrayIdPNG(null));
112         }
113         return binder;
114     }
115
116     private static int f1 = 0;
117
118     private static synchronized int getF1() {
119         return f1++;
120     }
121
122     private final static String JavaDoc CNBYTE = "org.objectweb.jorm.pobject.compositename.ACompositeByteId";
123     class ByteIdPNG implements CompositeByteIdPNG {
124         public Byte JavaDoc val;
125
126         public ByteIdPNG(Byte JavaDoc val) {
127             this.val = val;
128         }
129
130         public byte pnGetCnf1(Object JavaDoc ctx) throws PException {
131             return val.byteValue();
132         }
133     }
134     public void testByte() throws Exception JavaDoc {
135         changeLogger(LOGGER_NAME + ".byte");
136         logger.log(BasicLevel.DEBUG, "testByte begin");
137         int f = getF1();
138         Byte JavaDoc val = new Byte JavaDoc((byte) 56);
139         NameDefAccessor acc2 = new NameDefAccessor();
140         ByteIdPNG png = new ByteIdPNG(val);
141         logger.log(BasicLevel.DEBUG, "export");
142         PBinding pb = export(CNBYTE, png);
143         NameDefAccessor acc1 = new NameDefAccessor(f, val,
144                 pb.getPClassMapping().getPBinder().getNull(), pb.getPName());
145         assertEquals("Bad pname encoded value",
146             png.val.byteValue(), pb.getPName().encodeByte());
147         assertEquals("Bad pname encoded value",
148             png.val.byteValue(), ((CompositeByteIdPNG) pb.getPName().encodeAbstract()).pnGetCnf1(null));
149         logger.log(BasicLevel.DEBUG, "create and read");
150         writeRead(pb, acc1, acc2);
151         assertEquals("bad f1 value", f, acc2.f1);
152         assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1);
153         assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2);
154         NameDefAccessor acc3 = new NameDefAccessor(-f, val,
155                 pb.getPName(), pb.getPClassMapping().getPBinder().getNull());
156         logger.log(BasicLevel.DEBUG, "update and read");
157         writeRead(pb, acc3, acc2);
158         assertEquals("bad f1 value", -f, acc2.f1);
159         assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1);
160         assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2);
161         logger.log(BasicLevel.DEBUG, "remove");
162         unexport(pb, acc1);
163         logger.log(BasicLevel.DEBUG, "testByte end");
164     }
165
166     private final static String JavaDoc CNOBYTE = "org.objectweb.jorm.pobject.compositename.ACompositeObyteId";
167     class ObyteIdPNG implements CompositeObyteIdPNG {
168         public Byte JavaDoc val;
169
170         public ObyteIdPNG(Byte JavaDoc val) {
171             this.val = val;
172         }
173
174         public Byte JavaDoc pnGetCnf1(Object JavaDoc ctx) throws PException {
175             return val;
176         }
177     }
178     public void testObyte() throws Exception JavaDoc {
179         changeLogger(LOGGER_NAME + ".byte");
180         logger.log(BasicLevel.DEBUG, "testObyte begin");
181         int f = getF1();
182         Byte JavaDoc val = new Byte JavaDoc((byte) 56);
183         NameDefAccessor acc2 = new NameDefAccessor();
184         ObyteIdPNG png = new ObyteIdPNG(val);
185         logger.log(BasicLevel.DEBUG, "export");
186         PBinding pb = export(CNOBYTE, png);
187         NameDefAccessor acc1 = new NameDefAccessor(f, val,
188                 pb.getPClassMapping().getPBinder().getNull(), pb.getPName());
189         assertEquals("Bad pname encoded value",
190             png.val, pb.getPName().encodeObyte());
191         assertEquals("Bad pname encoded value",
192             png.val, ((CompositeObyteIdPNG) pb.getPName().encodeAbstract()).pnGetCnf1(null));
193         logger.log(BasicLevel.DEBUG, "create and read");
194         writeRead(pb, acc1, acc2);
195         assertEquals("bad f1 value", f, acc2.f1);
196         assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1);
197         assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2);
198         NameDefAccessor acc3 = new NameDefAccessor(-f, val,
199                 pb.getPName(), pb.getPClassMapping().getPBinder().getNull());
200         logger.log(BasicLevel.DEBUG, "update and read");
201         writeRead(pb, acc3, acc2);
202         assertEquals("bad f1 value", -f, acc2.f1);
203         assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1);
204         assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2);
205         logger.log(BasicLevel.DEBUG, "remove");
206         unexport(pb, acc1);
207         logger.log(BasicLevel.DEBUG, "testObyte end");
208     }
209
210     private final static String JavaDoc CNCHAR = "org.objectweb.jorm.pobject.compositename.ACompositeCharId";
211     class CharIdPNG implements CompositeCharIdPNG {
212         public Character JavaDoc val;
213
214         public CharIdPNG(Character JavaDoc val) {
215             this.val = val;
216         }
217
218         public char pnGetCnf1(Object JavaDoc ctx) throws PException {
219             return val.charValue();
220         }
221     }
222     public void testChar() throws Exception JavaDoc {
223         changeLogger(LOGGER_NAME + ".char");
224         logger.log(BasicLevel.DEBUG, "testChar begin");
225         int f = getF1();
226         Character JavaDoc val = new Character JavaDoc('e');
227         NameDefAccessor acc2 = new NameDefAccessor();
228         CharIdPNG png = new CharIdPNG(val);
229         logger.log(BasicLevel.DEBUG, "export");
230         PBinding pb = export(CNCHAR, png);
231         NameDefAccessor acc1 = new NameDefAccessor(f, val,
232                 pb.getPClassMapping().getPBinder().getNull(), pb.getPName());
233         assertEquals("Bad pname encoded value",
234             png.val.charValue(), pb.getPName().encodeChar());
235         assertEquals("Bad pname encoded value",
236             png.val.charValue(), ((CompositeCharIdPNG) pb.getPName().encodeAbstract()).pnGetCnf1(null));
237         logger.log(BasicLevel.DEBUG, "create and read");
238         writeRead(pb, acc1, acc2);
239         assertEquals("bad f1 value", f, acc2.f1);
240         assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1);
241         assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2);
242         NameDefAccessor acc3 = new NameDefAccessor(-f, val,
243                 pb.getPName(), pb.getPClassMapping().getPBinder().getNull());
244         logger.log(BasicLevel.DEBUG, "update and read");
245         writeRead(pb, acc3, acc2);
246         assertEquals("bad f1 value", -f, acc2.f1);
247         assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1);
248         assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2);
249         logger.log(BasicLevel.DEBUG, "remove");
250         unexport(pb, acc1);
251         logger.log(BasicLevel.DEBUG, "testChar end");
252     }
253
254     private final static String JavaDoc CNOCHAR = "org.objectweb.jorm.pobject.compositename.ACompositeOcharId";
255     class OcharIdPNG implements CompositeOcharIdPNG {
256         public Character JavaDoc val;
257
258         public OcharIdPNG(Character JavaDoc val) {
259             this.val = val;
260         }
261
262         public Character JavaDoc pnGetCnf1(Object JavaDoc ctx) throws PException {
263             return val;
264         }
265     }
266     public void testOchar() throws Exception JavaDoc {
267         changeLogger(LOGGER_NAME + ".char");
268         logger.log(BasicLevel.DEBUG, "testOchar begin");
269         int f = getF1();
270         Character JavaDoc val = new Character JavaDoc('e');
271         NameDefAccessor acc2 = new NameDefAccessor();
272         OcharIdPNG png = new OcharIdPNG(val);
273         logger.log(BasicLevel.DEBUG, "export");
274         PBinding pb = export(CNOCHAR, png);
275         NameDefAccessor acc1 = new NameDefAccessor(f, val,
276                 pb.getPClassMapping().getPBinder().getNull(), pb.getPName());
277         assertEquals("Bad pname encoded value",
278             png.val, pb.getPName().encodeOchar());
279         assertEquals("Bad pname encoded value",
280             png.val, ((CompositeOcharIdPNG) pb.getPName().encodeAbstract()).pnGetCnf1(null));
281         logger.log(BasicLevel.DEBUG, "create and read");
282         writeRead(pb, acc1, acc2);
283         assertEquals("bad f1 value", f, acc2.f1);
284         assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1);
285         assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2);
286         NameDefAccessor acc3 = new NameDefAccessor(-f, val,
287                 pb.getPName(), pb.getPClassMapping().getPBinder().getNull());
288         logger.log(BasicLevel.DEBUG, "update and read");
289         writeRead(pb, acc3, acc2);
290         assertEquals("bad f1 value", -f, acc2.f1);
291         assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1);
292         assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2);
293         logger.log(BasicLevel.DEBUG, "remove");
294         unexport(pb, acc1);
295         logger.log(BasicLevel.DEBUG, "testOchar end");
296     }
297
298     private final static String JavaDoc CNSHORT = "org.objectweb.jorm.pobject.compositename.ACompositeShortId";
299     class ShortIdPNG implements CompositeShortIdPNG {
300         public Short JavaDoc val;
301
302         public ShortIdPNG(Short JavaDoc val) {
303             this.val = val;
304         }
305
306         public short pnGetCnf1(Object JavaDoc ctx) throws PException {
307             return val.shortValue();
308         }
309     }
310     public void testShort() throws Exception JavaDoc {
311         changeLogger(LOGGER_NAME + ".short");
312         logger.log(BasicLevel.DEBUG, "testShort begin");
313         int f = getF1();
314         Short JavaDoc val = new Short JavaDoc((short) 5600);
315         NameDefAccessor acc2 = new NameDefAccessor();
316         ShortIdPNG png = new ShortIdPNG(val);
317         logger.log(BasicLevel.DEBUG, "export");
318         PBinding pb = export(CNSHORT, png);
319         NameDefAccessor acc1 = new NameDefAccessor(f, val,
320                 pb.getPClassMapping().getPBinder().getNull(), pb.getPName());
321         assertEquals("Bad pname encoded value",
322             png.val.shortValue(), pb.getPName().encodeShort());
323         assertEquals("Bad pname encoded value",
324             png.val.shortValue(), ((CompositeShortIdPNG) pb.getPName().encodeAbstract()).pnGetCnf1(null));
325         logger.log(BasicLevel.DEBUG, "create and read");
326         writeRead(pb, acc1, acc2);
327         assertEquals("bad f1 value", f, acc2.f1);
328         assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1);
329         assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2);
330         NameDefAccessor acc3 = new NameDefAccessor(-f, val,
331                 pb.getPName(), pb.getPClassMapping().getPBinder().getNull());
332         logger.log(BasicLevel.DEBUG, "update and read");
333         writeRead(pb, acc3, acc2);
334         assertEquals("bad f1 value", -f, acc2.f1);
335         assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1);
336         assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2);
337         logger.log(BasicLevel.DEBUG, "remove");
338         unexport(pb, acc1);
339         logger.log(BasicLevel.DEBUG, "testShort end");
340     }
341
342     private final static String JavaDoc CNOSHORT = "org.objectweb.jorm.pobject.compositename.ACompositeOshortId";
343     class OshortIdPNG implements CompositeOshortIdPNG {
344         public Short JavaDoc val;
345
346         public OshortIdPNG(Short JavaDoc val) {
347             this.val = val;
348         }
349
350         public Short JavaDoc pnGetCnf1(Object JavaDoc ctx) throws PException {
351             return val;
352         }
353     }
354     public void testOshort() throws Exception JavaDoc {
355         changeLogger(LOGGER_NAME + ".short");
356         logger.log(BasicLevel.DEBUG, "testOshort begin");
357         int f = getF1();
358         Short JavaDoc val = new Short JavaDoc((short) 5600);
359         NameDefAccessor acc2 = new NameDefAccessor();
360         OshortIdPNG png = new OshortIdPNG(val);
361         logger.log(BasicLevel.DEBUG, "export");
362         PBinding pb = export(CNOSHORT, png);
363         NameDefAccessor acc1 = new NameDefAccessor(f, val,
364                 pb.getPClassMapping().getPBinder().getNull(), pb.getPName());
365         assertEquals("Bad pname encoded value",
366             png.val, pb.getPName().encodeOshort());
367         assertEquals("Bad pname encoded value",
368             png.val, ((CompositeOshortIdPNG) pb.getPName().encodeAbstract()).pnGetCnf1(null));
369         logger.log(BasicLevel.DEBUG, "create and read");
370         writeRead(pb, acc1, acc2);
371         assertEquals("bad f1 value", f, acc2.f1);
372         assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1);
373         assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2);
374         NameDefAccessor acc3 = new NameDefAccessor(-f, val,
375                 pb.getPName(), pb.getPClassMapping().getPBinder().getNull());
376         logger.log(BasicLevel.DEBUG, "update and read");
377         writeRead(pb, acc3, acc2);
378         assertEquals("bad f1 value", -f, acc2.f1);
379         assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1);
380         assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2);
381         logger.log(BasicLevel.DEBUG, "remove");
382         unexport(pb, acc1);
383         logger.log(BasicLevel.DEBUG, "testOshort end");
384     }
385
386     private final static String JavaDoc CNINT = "org.objectweb.jorm.pobject.compositename.ACompositeIntId";
387     class IntIdPNG implements CompositeIntIdPNG {
388         public Integer JavaDoc val;
389
390         public IntIdPNG(Integer JavaDoc val) {
391             this.val = val;
392         }
393
394         public int pnGetCnf1(Object JavaDoc ctx) throws PException {
395             return val.intValue();
396         }
397     }
398     public void testInt() throws Exception JavaDoc {
399         changeLogger(LOGGER_NAME + ".int");
400         logger.log(BasicLevel.DEBUG, "testInt begin");
401         int f = getF1();
402         Integer JavaDoc val = new Integer JavaDoc(560000);
403         NameDefAccessor acc2 = new NameDefAccessor();
404         IntIdPNG png = new IntIdPNG(val);
405         logger.log(BasicLevel.DEBUG, "export");
406         PBinding pb = export(CNINT, png);
407         NameDefAccessor acc1 = new NameDefAccessor(f, val,
408                 pb.getPClassMapping().getPBinder().getNull(), pb.getPName());
409         assertEquals("Bad pname encoded value",
410             png.val.intValue(), pb.getPName().encodeInt());
411         assertEquals("Bad pname encoded value",
412             png.val.intValue(), ((CompositeIntIdPNG) pb.getPName().encodeAbstract()).pnGetCnf1(null));
413         logger.log(BasicLevel.DEBUG, "create and read");
414         writeRead(pb, acc1, acc2);
415         assertEquals("bad f1 value", f, acc2.f1);
416         assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1);
417         assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2);
418         NameDefAccessor acc3 = new NameDefAccessor(-f, val,
419                 pb.getPName(), pb.getPClassMapping().getPBinder().getNull());
420         logger.log(BasicLevel.DEBUG, "update and read");
421         writeRead(pb, acc3, acc2);
422         assertEquals("bad f1 value", -f, acc2.f1);
423         assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1);
424         assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2);
425         logger.log(BasicLevel.DEBUG, "remove");
426         unexport(pb, acc1);
427         logger.log(BasicLevel.DEBUG, "testInt end");
428     }
429
430     private final static String JavaDoc CNOINT = "org.objectweb.jorm.pobject.compositename.ACompositeOintId";
431     class OintIdPNG implements CompositeOintIdPNG {
432         public Integer JavaDoc val;
433
434         public OintIdPNG(Integer JavaDoc val) {
435             this.val = val;
436         }
437
438         public Integer JavaDoc pnGetCnf1(Object JavaDoc ctx) throws PException {
439             return val;
440         }
441     }
442     public void testOint() throws Exception JavaDoc {
443         changeLogger(LOGGER_NAME + ".int");
444         logger.log(BasicLevel.DEBUG, "testOint begin");
445         int f = getF1();
446         Integer JavaDoc val = new Integer JavaDoc(560000);
447         NameDefAccessor acc2 = new NameDefAccessor();
448         OintIdPNG png = new OintIdPNG(val);
449         logger.log(BasicLevel.DEBUG, "export");
450         PBinding pb = export(CNOINT, png);
451         NameDefAccessor acc1 = new NameDefAccessor(f, val,
452                 pb.getPClassMapping().getPBinder().getNull(), pb.getPName());
453         assertEquals("Bad pname encoded value",
454             png.val, pb.getPName().encodeOint());
455         assertEquals("Bad pname encoded value",
456             png.val, ((CompositeOintIdPNG) pb.getPName().encodeAbstract()).pnGetCnf1(null));
457         logger.log(BasicLevel.DEBUG, "create and read");
458         writeRead(pb, acc1, acc2);
459         assertEquals("bad f1 value", f, acc2.f1);
460         assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1);
461         assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2);
462         NameDefAccessor acc3 = new NameDefAccessor(-f, val,
463                 pb.getPName(), pb.getPClassMapping().getPBinder().getNull());
464         logger.log(BasicLevel.DEBUG, "update and read");
465         writeRead(pb, acc3, acc2);
466         assertEquals("bad f1 value", -f, acc2.f1);
467         assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1);
468         assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2);
469         logger.log(BasicLevel.DEBUG, "remove");
470         unexport(pb, acc1);
471         logger.log(BasicLevel.DEBUG, "testOint end");
472     }
473
474     private final static String JavaDoc CNLONG = "org.objectweb.jorm.pobject.compositename.ACompositeLongId";
475     class LongIdPNG implements CompositeLongIdPNG {
476         public Long JavaDoc val;
477
478         public LongIdPNG(Long JavaDoc val) {
479             this.val = val;
480         }
481
482         public long pnGetCnf1(Object JavaDoc ctx) throws PException {
483             return val.longValue();
484         }
485     }
486     public void testLong() throws Exception JavaDoc {
487         changeLogger(LOGGER_NAME + ".long");
488         logger.log(BasicLevel.DEBUG, "testLong begin");
489         int f = getF1();
490         Long JavaDoc val = new Long JavaDoc(56000000);
491         NameDefAccessor acc2 = new NameDefAccessor();
492         LongIdPNG png = new LongIdPNG(val);
493         logger.log(BasicLevel.DEBUG, "export");
494         PBinding pb = export(CNLONG, png);
495         NameDefAccessor acc1 = new NameDefAccessor(f, val,
496                 pb.getPClassMapping().getPBinder().getNull(), pb.getPName());
497         assertEquals("Bad pname encoded value",
498             png.val.longValue(), pb.getPName().encodeLong());
499         assertEquals("Bad pname encoded value",
500             png.val.longValue(), ((CompositeLongIdPNG) pb.getPName().encodeAbstract()).pnGetCnf1(null));
501         logger.log(BasicLevel.DEBUG, "create and read");
502         writeRead(pb, acc1, acc2);
503         assertEquals("bad f1 value", f, acc2.f1);
504         assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1);
505         assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2);
506         NameDefAccessor acc3 = new NameDefAccessor(-f, val,
507                 pb.getPName(), pb.getPClassMapping().getPBinder().getNull());
508         logger.log(BasicLevel.DEBUG, "update and read");
509         writeRead(pb, acc3, acc2);
510         assertEquals("bad f1 value", -f, acc2.f1);
511         assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1);
512         assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2);
513         logger.log(BasicLevel.DEBUG, "remove");
514         unexport(pb, acc1);
515         logger.log(BasicLevel.DEBUG, "testLong end");
516     }
517
518     private final static String JavaDoc CNOLONG = "org.objectweb.jorm.pobject.compositename.ACompositeOlongId";
519     class OlongIdPNG implements CompositeOlongIdPNG {
520         public Long JavaDoc val;
521
522         public OlongIdPNG(Long JavaDoc val) {
523             this.val = val;
524         }
525
526         public Long JavaDoc pnGetCnf1(Object JavaDoc ctx) throws PException {
527             return val;
528         }
529     }
530     public void testOlong() throws Exception JavaDoc {
531         changeLogger(LOGGER_NAME + ".long");
532         logger.log(BasicLevel.DEBUG, "testOlong begin");
533         int f = getF1();
534         Long JavaDoc val = new Long JavaDoc(56000000);
535         NameDefAccessor acc2 = new NameDefAccessor();
536         OlongIdPNG png = new OlongIdPNG(val);
537         logger.log(BasicLevel.DEBUG, "export");
538         PBinding pb = export(CNOLONG, png);
539         NameDefAccessor acc1 = new NameDefAccessor(f, val,
540                 pb.getPClassMapping().getPBinder().getNull(), pb.getPName());
541         assertEquals("Bad pname encoded value",
542             png.val, pb.getPName().encodeOlong());
543         assertEquals("Bad pname encoded value",
544             png.val, ((CompositeOlongIdPNG) pb.getPName().encodeAbstract()).pnGetCnf1(null));
545         logger.log(BasicLevel.DEBUG, "create and read");
546         writeRead(pb, acc1, acc2);
547         assertEquals("bad f1 value", f, acc2.f1);
548         assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1);
549         assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2);
550         NameDefAccessor acc3 = new NameDefAccessor(-f, val,
551                 pb.getPName(), pb.getPClassMapping().getPBinder().getNull());
552         logger.log(BasicLevel.DEBUG, "update and read");
553         writeRead(pb, acc3, acc2);
554         assertEquals("bad f1 value", -f, acc2.f1);
555         assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1);
556         assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2);
557         logger.log(BasicLevel.DEBUG, "remove");
558         unexport(pb, acc1);
559         logger.log(BasicLevel.DEBUG, "testOlong end");
560     }
561
562     private final static String JavaDoc CNSTRING = "org.objectweb.jorm.pobject.compositename.ACompositeStringId";
563     class StringIdPNG implements CompositeStringIdPNG {
564         public String JavaDoc val;
565
566         public StringIdPNG(String JavaDoc val) {
567             this.val = val;
568         }
569
570         public String JavaDoc pnGetCnf1(Object JavaDoc ctx) throws PException {
571             return val;
572         }
573     }
574     public void testString() throws Exception JavaDoc {
575         changeLogger(LOGGER_NAME + ".string");
576         logger.log(BasicLevel.DEBUG, "testString begin");
577         int f = getF1();
578         String JavaDoc val = "azerty";
579         NameDefAccessor acc2 = new NameDefAccessor();
580         StringIdPNG png = new StringIdPNG(val);
581         logger.log(BasicLevel.DEBUG, "export");
582         PBinding pb = export(CNSTRING, png);
583         NameDefAccessor acc1 = new NameDefAccessor(f, val,
584                 pb.getPClassMapping().getPBinder().getNull(), pb.getPName());
585         assertEquals("Bad pname encoded value",
586             png.val, ((CompositeStringIdPNG) pb.getPName().encodeAbstract()).pnGetCnf1(null));
587         logger.log(BasicLevel.DEBUG, "create and read");
588         writeRead(pb, acc1, acc2);
589         assertEquals("bad f1 value", f, acc2.f1);
590         assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1);
591         assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2);
592         NameDefAccessor acc3 = new NameDefAccessor(-f, val,
593                 pb.getPName(), pb.getPClassMapping().getPBinder().getNull());
594         logger.log(BasicLevel.DEBUG, "update and read");
595         writeRead(pb, acc3, acc2);
596         assertEquals("bad f1 value", -f, acc2.f1);
597         assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1);
598         assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2);
599         logger.log(BasicLevel.DEBUG, "remove");
600         unexport(pb, acc1);
601         logger.log(BasicLevel.DEBUG, "testString end");
602     }
603
604     private final static String JavaDoc CNDATE = "org.objectweb.jorm.pobject.compositename.ACompositeDateId";
605     class DateIdPNG implements CompositeDateIdPNG {
606         public Date JavaDoc val;
607
608         public DateIdPNG(Date JavaDoc val) {
609             this.val = val;
610         }
611
612         public Date JavaDoc pnGetCnf1(Object JavaDoc ctx) throws PException {
613             return val;
614         }
615     }
616     public void testDate() throws Exception JavaDoc {
617         changeLogger(LOGGER_NAME + ".date");
618         logger.log(BasicLevel.DEBUG, "testDate begin");
619         int f = getF1();
620         Date JavaDoc val = getTime();
621         NameDefAccessor acc2 = new NameDefAccessor();
622         DateIdPNG png = new DateIdPNG(val);
623         logger.log(BasicLevel.DEBUG, "export");
624         PBinding pb = export(CNDATE, png);
625         NameDefAccessor acc1 = new NameDefAccessor(f, val,
626                 pb.getPClassMapping().getPBinder().getNull(), pb.getPName());
627         assertEquals("Bad pname encoded value",
628             png.val, pb.getPName().encodeDate());
629         assertEquals("Bad pname encoded value",
630             png.val, ((CompositeDateIdPNG) pb.getPName().encodeAbstract()).pnGetCnf1(null));
631         logger.log(BasicLevel.DEBUG, "create and read");
632         writeRead(pb, acc1, acc2);
633         assertEquals("bad f1 value", f, acc2.f1);
634         assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1);
635         assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2);
636         NameDefAccessor acc3 = new NameDefAccessor(-f, val,
637                 pb.getPName(), pb.getPClassMapping().getPBinder().getNull());
638         logger.log(BasicLevel.DEBUG, "update and read");
639         writeRead(pb, acc3, acc2);
640         assertEquals("bad f1 value", -f, acc2.f1);
641         assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1);
642         assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2);
643         logger.log(BasicLevel.DEBUG, "remove");
644         unexport(pb, acc1);
645         logger.log(BasicLevel.DEBUG, "testDate end");
646     }
647
648     private final static String JavaDoc CNBIGDECIMAL = "org.objectweb.jorm.pobject.compositename.ACompositeBigDecimalId";
649     class BigDecimalIdPNG implements CompositeBigDecimalIdPNG {
650         public BigDecimal JavaDoc val;
651
652         public BigDecimalIdPNG(BigDecimal JavaDoc val) {
653             this.val = val;
654         }
655
656         public BigDecimal JavaDoc pnGetCnf1(Object JavaDoc ctx) throws PException {
657             return val;
658         }
659     }
660     public void testBigDecimal() throws Exception JavaDoc {
661         changeLogger(LOGGER_NAME + ".bigdecimal");
662         logger.log(BasicLevel.DEBUG, "testBigDecimal begin");
663         int f = getF1();
664         BigDecimal JavaDoc val = new BigDecimal JavaDoc("123456789.45");
665         NameDefAccessor acc2 = new NameDefAccessor();
666         BigDecimalIdPNG png = new BigDecimalIdPNG(val);
667         logger.log(BasicLevel.DEBUG, "export");
668         PBinding pb = export(CNBIGDECIMAL, png);
669         NameDefAccessor acc1 = new NameDefAccessor(f, val,
670                 pb.getPClassMapping().getPBinder().getNull(), pb.getPName());
671         assertEquals("Bad pname encoded value",
672             png.val, pb.getPName().encodeBigDecimal());
673         assertEquals("Bad pname encoded value",
674             png.val, ((CompositeBigDecimalIdPNG) pb.getPName().encodeAbstract()).pnGetCnf1(null));
675         logger.log(BasicLevel.DEBUG, "create and read");
676         writeRead(pb, acc1, acc2);
677         assertEquals("bad f1 value", f, acc2.f1);
678         assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1);
679         assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2);
680         NameDefAccessor acc3 = new NameDefAccessor(-f, val,
681                 pb.getPName(), pb.getPClassMapping().getPBinder().getNull());
682         logger.log(BasicLevel.DEBUG, "update and read");
683         writeRead(pb, acc3, acc2);
684         assertEquals("bad f1 value", -f, acc2.f1);
685         assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1);
686         assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2);
687         logger.log(BasicLevel.DEBUG, "remove");
688         unexport(pb, acc1);
689         logger.log(BasicLevel.DEBUG, "testBigDecimal end");
690     }
691
692     private final static String JavaDoc CNBIGINTEGER = "org.objectweb.jorm.pobject.compositename.ACompositeBigIntegerId";
693     class BigIntegerIdPNG implements CompositeBigIntegerIdPNG {
694         public BigInteger JavaDoc val;
695
696         public BigIntegerIdPNG(BigInteger JavaDoc val) {
697             this.val = val;
698         }
699
700         public BigInteger JavaDoc pnGetCnf1(Object JavaDoc ctx) throws PException {
701             return val;
702         }
703     }
704     public void testBigInteger() throws Exception JavaDoc {
705         changeLogger(LOGGER_NAME + ".biginteger");
706         logger.log(BasicLevel.DEBUG, "testBigInteger begin");
707         int f = getF1();
708         BigInteger JavaDoc val = new BigInteger JavaDoc("123456789");
709         NameDefAccessor acc2 = new NameDefAccessor();
710         BigIntegerIdPNG png = new BigIntegerIdPNG(val);
711         logger.log(BasicLevel.DEBUG, "export");
712         PBinding pb = export(CNBIGINTEGER, png);
713         NameDefAccessor acc1 = new NameDefAccessor(f, val,
714                 pb.getPClassMapping().getPBinder().getNull(), pb.getPName());
715         assertEquals("Bad pname encoded value",
716             png.val, pb.getPName().encodeBigInteger());
717         assertEquals("Bad pname encoded value",
718             png.val, ((CompositeBigIntegerIdPNG) pb.getPName().encodeAbstract()).pnGetCnf1(null));
719         logger.log(BasicLevel.DEBUG, "create and read");
720         writeRead(pb, acc1, acc2);
721         assertEquals("bad f1 value", f, acc2.f1);
722         assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1);
723         assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2);
724         NameDefAccessor acc3 = new NameDefAccessor(-f, val,
725                 pb.getPName(), pb.getPClassMapping().getPBinder().getNull());
726         logger.log(BasicLevel.DEBUG, "update and read");
727         writeRead(pb, acc3, acc2);
728         assertEquals("bad f1 value", -f, acc2.f1);
729         assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1);
730         assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2);
731         logger.log(BasicLevel.DEBUG, "remove");
732         unexport(pb, acc1);
733         logger.log(BasicLevel.DEBUG, "testBigInteger end");
734     }
735
736     private final static String JavaDoc CNBYTEARRAY = "org.objectweb.jorm.pobject.compositename.ACompositeBytearrayId";
737     class BytearrayIdPNG implements CompositeBytearrayIdPNG {
738         public byte[] val;
739
740         public BytearrayIdPNG(byte[] val) {
741             this.val = val;
742         }
743
744         public byte[] pnGetCnf1(Object JavaDoc ctx) throws PException {
745             return val;
746         }
747     }
748     public void testBytearray() throws Exception JavaDoc {
749         changeLogger(LOGGER_NAME + ".bytearray");
750         logger.log(BasicLevel.DEBUG, "testBytearray begin");
751         int f = getF1();
752         byte[] val = "azerty".getBytes();
753         NameDefAccessor acc2 = new NameDefAccessor();
754         BytearrayIdPNG png = new BytearrayIdPNG(val);
755         logger.log(BasicLevel.DEBUG, "export");
756         PBinding pb = export(CNBYTEARRAY, png);
757         NameDefAccessor acc1 = new NameDefAccessor(f, val,
758                 pb.getPClassMapping().getPBinder().getNull(), pb.getPName());
759 //TODO: support direct encoding for the composite names which have only one byte[] field
760
//assertEquals("Bad pname encoded value", png.val, pb.getPName().encode());
761
assertEquals("Bad pname encoded value",
762             png.val, ((CompositeBytearrayIdPNG) pb.getPName().encodeAbstract()).pnGetCnf1(null));
763         logger.log(BasicLevel.DEBUG, "create and read");
764         writeRead(pb, acc1, acc2);
765         assertEquals("bad f1 value", f, acc2.f1);
766         assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1);
767         assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2);
768         NameDefAccessor acc3 = new NameDefAccessor(-f, val,
769                 pb.getPName(), pb.getPClassMapping().getPBinder().getNull());
770         logger.log(BasicLevel.DEBUG, "update and read");
771         writeRead(pb, acc3, acc2);
772         assertEquals("bad f1 value", -f, acc2.f1);
773         assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1);
774         assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2);
775         logger.log(BasicLevel.DEBUG, "remove");
776         unexport(pb, acc1);
777         logger.log(BasicLevel.DEBUG, "testBytearray end");
778     }
779
780     private final static String JavaDoc CNCHARARRAY = "org.objectweb.jorm.pobject.compositename.ACompositeChararrayId";
781     class ChararrayIdPNG implements CompositeChararrayIdPNG {
782         public char[] val;
783
784         public ChararrayIdPNG(char[] val) {
785             this.val = val;
786         }
787
788         public char[] pnGetCnf1(Object JavaDoc ctx) throws PException {
789             return val;
790         }
791     }
792     public void testChararray() throws Exception JavaDoc {
793         changeLogger(LOGGER_NAME + ".chararray");
794         logger.log(BasicLevel.DEBUG, "testChararray begin");
795         int f = getF1();
796         char[] val = new char[]{'a', 'z', 'e', 'r', 't', 'y'};
797         NameDefAccessor acc2 = new NameDefAccessor();
798         ChararrayIdPNG png = new ChararrayIdPNG(val);
799         logger.log(BasicLevel.DEBUG, "export");
800         PBinding pb = export(CNCHARARRAY, png);
801         NameDefAccessor acc1 = new NameDefAccessor(f, val,
802                 pb.getPClassMapping().getPBinder().getNull(), pb.getPName());
803         assertEquals("Bad pname encoded value",
804             png.val, pb.getPName().encodeCharArray());
805         assertEquals("Bad pname encoded value",
806             png.val, ((CompositeChararrayIdPNG) pb.getPName().encodeAbstract()).pnGetCnf1(null));
807         logger.log(BasicLevel.DEBUG, "create and read");
808         writeRead(pb, acc1, acc2);
809         assertEquals("bad f1 value", f, acc2.f1);
810         assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1);
811         assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2);
812         NameDefAccessor acc3 = new NameDefAccessor(-f, val,
813                 pb.getPName(), pb.getPClassMapping().getPBinder().getNull());
814         logger.log(BasicLevel.DEBUG, "update and read");
815         writeRead(pb, acc3, acc2);
816         assertEquals("bad f1 value", -f, acc2.f1);
817         assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1);
818         assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2);
819         logger.log(BasicLevel.DEBUG, "remove");
820         unexport(pb, acc1);
821         logger.log(BasicLevel.DEBUG, "testChararray end");
822     }
823 }
Popular Tags