KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > lib > TestJormPathHelper


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 package org.objectweb.jorm.lib;
24
25 import org.objectweb.jorm.naming.api.PBinder;
26 import org.objectweb.jorm.naming.api.PNameCoder;
27 import org.objectweb.jorm.naming.api.PName;
28 import org.objectweb.jorm.naming.api.PExceptionNaming;
29 import org.objectweb.jorm.api.PAccessor;
30 import org.objectweb.jorm.api.PMapper;
31 import org.objectweb.jorm.api.PException;
32 import org.objectweb.jorm.api.PMappingStructuresManager;
33 import org.objectweb.jorm.api.PClassMapping;
34 import org.objectweb.jorm.api.PMapperListener;
35 import org.objectweb.jorm.api.PMapCluster;
36 import org.objectweb.jorm.api.PBinding;
37 import org.objectweb.jorm.api.PMappingCallback;
38 import org.objectweb.jorm.api.PBindingCtrl;
39 import org.objectweb.jorm.api.PNameIterator;
40 import org.objectweb.jorm.metainfo.api.Manager;
41 import org.objectweb.jorm.metainfo.api.MetaObject;
42 import org.objectweb.jorm.xml2mi.api.Parser;
43 import org.objectweb.jorm.type.api.PTypeSpace;
44 import org.objectweb.jorm.type.api.PType;
45 import org.objectweb.jorm.genclass.lib.GenClassMapping;
46 import org.objectweb.perseus.cache.api.CacheManager;
47 import org.objectweb.medor.eval.prefetch.api.PrefetchCache;
48 import org.objectweb.util.monolog.api.Logger;
49
50 import java.util.Collection JavaDoc;
51 import java.util.Map JavaDoc;
52 import java.util.Iterator JavaDoc;
53 import java.util.HashMap JavaDoc;
54 import java.util.Collections JavaDoc;
55 import java.util.Date JavaDoc;
56 import java.math.BigDecimal JavaDoc;
57 import java.math.BigInteger JavaDoc;
58
59 import junit.framework.Assert;
60 import junit.framework.TestCase;
61
62 /**
63  *
64  * @author S.Chassande-Barrioz
65  */

66 public class TestJormPathHelper extends TestCase {
67
68     public TestJormPathHelper(String JavaDoc s) throws Exception JavaDoc {
69         super(s);
70     }
71
72     public static char SEP = JormPathHelper.SEP;
73
74     MyMapper mapper ;
75
76     protected void setUp() throws Exception JavaDoc {
77         mapper = new MyMapper();
78     }
79
80     protected void tearDown() throws Exception JavaDoc {
81         mapper = null;
82     }
83
84     public void testClass() {
85         PBinder binder = new MyBinder();
86         String JavaDoc className = "com.foo.Bar";
87         PClassMapping pcm = new MyPCM(className,
88                 Collections.EMPTY_MAP,
89                 Collections.EMPTY_MAP,
90                 binder,
91                 mapper);
92         String JavaDoc path = className;
93         Assert.assertEquals("Bad PCM with " + SEP, pcm,
94                 JormPathHelper.getPClassMapping(SEP + path, mapper));
95         Assert.assertEquals("Bad PCM without " + SEP, pcm,
96                 JormPathHelper.getPClassMapping(path, mapper));
97         Assert.assertEquals("Bad PNC with " + SEP, binder,
98                 JormPathHelper.getPNameCoder(SEP + path, mapper));
99         Assert.assertEquals("Bad PNC without " + SEP, binder,
100                 JormPathHelper.getPNameCoder(path, mapper));
101     }
102
103     public void testClassRefInClass() {
104         PBinder binder = new MyBinder();
105         String JavaDoc className = "com.foo.Bar";
106         PNameCoder pncRef1 = new MyBinder();
107         new MyPCM(className,
108                 Collections.singletonMap("ref1", pncRef1),
109                 Collections.EMPTY_MAP,
110                 binder,
111                 mapper);
112         String JavaDoc path = className + SEP + "ref1";
113         Assert.assertEquals("Bad PNC with " + SEP, pncRef1,
114                 JormPathHelper.getPNameCoder(SEP + path, mapper));
115         Assert.assertEquals("Bad PNC without " + SEP, pncRef1,
116                 JormPathHelper.getPNameCoder(path, mapper));
117     }
118
119     public void testGenClassRefInClass() {
120         PBinder binder = new MyBinder();
121         String JavaDoc className = "com.foo.Bar";
122         PNameCoder pncRef1 = new MyBinder();
123         MyGCM gcmRef1 = new MyGCM();
124         new MyPCM(className,
125                 Collections.singletonMap("ref1", pncRef1),
126                 Collections.singletonMap("ref1", gcmRef1),
127                 binder,
128                 mapper);
129         String JavaDoc path = className + SEP + "ref1";
130         Assert.assertEquals("Bad PCM with " + SEP, gcmRef1,
131                 JormPathHelper.getPClassMapping(SEP + path, mapper));
132         Assert.assertEquals("Bad PCM without " + SEP, gcmRef1,
133                 JormPathHelper.getPClassMapping(path, mapper));
134         Assert.assertEquals("Bad PNC with " + SEP, pncRef1,
135                 JormPathHelper.getPNameCoder(SEP + path, mapper));
136         Assert.assertEquals("Bad PNC without " + SEP, pncRef1,
137                 JormPathHelper.getPNameCoder(path, mapper));
138     }
139
140     public void testClassRefInGenClassRefInClass() {
141         String JavaDoc className2 = "com.foo.Bar2";
142         PBinder binder2 = new MyBinder();
143         new MyPCM(className2,
144                 Collections.EMPTY_MAP,
145                 Collections.EMPTY_MAP,
146                 binder2,
147                 mapper);
148
149         PBinder binder1 = new MyBinder();
150         String JavaDoc className1 = "com.foo.Bar1";
151         PNameCoder pncRef1 = new MyBinder();
152         MyGCM gcmRef1 = new MyGCM(binder2);
153         new MyPCM(className1,
154                 Collections.singletonMap("ref1", pncRef1),
155                 Collections.singletonMap("ref1", gcmRef1),
156                 binder1,
157                 mapper);
158
159         String JavaDoc path = className1 + SEP + "ref1" + SEP + "java.util.Set"
160                 + JormPathHelper.ELEMENT;
161         Assert.assertEquals("Bad PNC with " + SEP, binder2,
162                 JormPathHelper.getPNameCoder(SEP + path, mapper));
163         Assert.assertEquals("Bad PNC without " + SEP, binder2,
164                 JormPathHelper.getPNameCoder(path, mapper));
165     }
166
167     public class MyMapper implements PMapper {
168         Map JavaDoc name2pcm;
169
170         public MyMapper() {
171             name2pcm = new HashMap JavaDoc();
172         }
173
174         public MyMapper(Map JavaDoc m) {
175             name2pcm = m;
176         }
177
178         public void setLogger(Logger l) {
179         }
180
181         public void setPMapper(PMapper pm) {
182         }
183
184         public PClassMapping lookup(String JavaDoc classname) {
185             return (PClassMapping) name2pcm.get(classname);
186         }
187
188         public void map(PClassMapping pcm) {
189             name2pcm.put(pcm.getClassName(), pcm);
190         }
191
192         public void map(Object JavaDoc conn, PClassMapping pcm) {
193             name2pcm.put(pcm.getClassName(), pcm);
194         }
195
196         public void map(Object JavaDoc conn, PClassMapping pcm, boolean loadmeta) {
197             name2pcm.put(pcm.getClassName(), pcm);
198         }
199
200         public void closeConnection(Object JavaDoc conn) throws PException {
201         }
202
203         public String JavaDoc cn2mn(String JavaDoc cn) {
204             return null;
205         }
206
207         public Object JavaDoc getConnection() throws PException {
208             return null;
209         }
210
211         public Object JavaDoc getConnection(Object JavaDoc ctxt) throws PException {
212             return null;
213         }
214
215         public Object JavaDoc getConnection(Object JavaDoc connectionContext, Object JavaDoc user) throws PException {
216             return null;
217         }
218
219         public String JavaDoc getMapperName() {
220             return null;
221         }
222
223         public PMappingStructuresManager getPMappingStructuresManager() {
224             return null;
225         }
226
227         public void setConnectionFactory(Object JavaDoc cf) throws PException {
228         }
229
230         public Object JavaDoc getConnectionFactory() {
231             return null;
232         }
233
234         public void setPrefetchCache(PrefetchCache pc) throws PException {
235         }
236
237         public PrefetchCache getPrefetchCache() {
238             return null;
239         }
240
241         public void setMapperName(String JavaDoc mappername) {
242         }
243
244         public Manager getMetaInfoManager() {
245             return null;
246         }
247
248         public void setMetaInfoManager(Manager m) {
249         }
250
251         public void setParser(Parser p) {
252         }
253
254         public void setPTypeSpace(PTypeSpace pts) {
255         }
256
257         public PTypeSpace getPTypeSpace() {
258             return null;
259         }
260
261         public void start() throws PException {
262         }
263
264         public void stop() throws PException {
265         }
266
267         public void unmap(String JavaDoc classname) throws PException {
268         }
269
270         public void addMapperEventListener(PMapperListener listener) {
271         }
272
273         public void removeMapperEventListener(PMapperListener listener) {
274         }
275
276         public PClassMapping createGenClassMapping() throws PException {
277             return null;
278         }
279
280         public PMapCluster getPMapCluster(String JavaDoc jcname) throws PException {
281             return null;
282         }
283
284         public Collection JavaDoc getPMapClusters() {
285             return null;
286         }
287
288         public void addDependency(String JavaDoc jcname1, String JavaDoc jcname2) throws PException {
289         }
290
291         public void classDefined(String JavaDoc jcname) throws PException {
292         }
293
294         public void declareClass(String JavaDoc jcname) {
295         }
296     }
297
298     public class MyPCM implements PClassMapping {
299         String JavaDoc className;
300         Map JavaDoc pncs;
301         Map JavaDoc gcms;
302         PClassMapping pcm;
303         PBinder binder;
304         PMapper mapper;
305
306         public MyPCM(String JavaDoc className,
307                      Map JavaDoc pncs,
308                      Map JavaDoc gcms,
309                      PBinder binder,
310                      MyMapper mapper) {
311             this.className = className;
312             this.pncs = pncs;
313             this.gcms = gcms;
314             this.binder = binder;
315             this.mapper = mapper;
316             mapper.map(this);
317         }
318
319         public PBinding createPBinding() throws PException {
320             return null;
321         }
322
323         public void init(PMappingCallback mapper, MetaObject metaclass) throws PException {
324         }
325
326         public String JavaDoc getClassName() {
327             return className;
328         }
329
330         public String JavaDoc getProjectName() {
331             return null;
332         }
333
334         public PNameCoder getClassPNameCoder() {
335             return binder;
336         }
337
338         public PClassMapping getGenClassMapping() throws UnsupportedOperationException JavaDoc {
339             fail("Call the 'getGenClassMapping' method on a PClassMapping of the class '"
340                     + className + "' is not authorized");
341             return null;
342         }
343
344         public PClassMapping getGenClassMapping(String JavaDoc fn)
345                 throws UnsupportedOperationException JavaDoc {
346             PClassMapping pcm = (PClassMapping) gcms.get(fn);
347             if (pcm == null) {
348                 fail("No field '" + fn + "' availlable on the class '" + className + "'");
349             }
350             return pcm;
351        }
352
353         public MetaObject getMetaInfo() {
354             return null;
355         }
356
357         public PBinder getPBinder() {
358             return binder;
359         }
360
361         public PMapper getPMapper() {
362             return mapper;
363         }
364
365         public PNameCoder getPNameCoder()
366                 throws UnsupportedOperationException JavaDoc {
367             fail("Call the 'getPNameCoder' method on a PClassMapping of the class '"
368                     + className + "' is not authorized");
369             return null;
370         }
371
372         public PNameCoder getPNameCoder(String JavaDoc fn)
373                 throws UnsupportedOperationException JavaDoc {
374             PNameCoder pc = (PNameCoder) pncs.get(fn);
375             if (pc == null) {
376                 fail("No field '" + fn + "' availlable on the class '" + className +"'");
377             }
378             return pc;
379         }
380
381         public Iterator getPNameIterator(Object JavaDoc conn) throws PException {
382             return null;
383         }
384
385         public PNameIterator getPNameIterator(Object JavaDoc conn,
386                                               boolean withSubType,
387                                               boolean prefetching,
388                                               Object JavaDoc txctx) throws PException {
389             return null;
390         }
391
392         public PType getPType() {
393             return null;
394         }
395
396         public boolean isConform(String JavaDoc mappername) {
397             return false;
398         }
399
400         public void setPBinder(PBinder pb) throws PException {
401             binder = pb;
402         }
403
404         public void configureRefFields(PClassMapping.ReferenceConfigurator rc)
405                 throws PException, UnsupportedOperationException JavaDoc {
406         }
407         
408         public boolean exist(PBinding pb, Object JavaDoc conn) throws PException {
409             return false;
410         }
411         public void read(PBinding pb, Object JavaDoc conn, PAccessor pa, Object JavaDoc txctx)
412                 throws PException {
413         }
414         public void read(PBinding pb, Object JavaDoc conn, PAccessor pa)
415                 throws PException {
416         }
417         public void write(PBinding pb, Object JavaDoc conn, PAccessor pa)
418                 throws PException {
419         }
420         public void addAssociation(PClassMapping targetClass, int[] indexes) {
421         }
422         public HashMap JavaDoc getAssociationTable() {
423             return null;
424         }
425         public int[] getIndexesTable(PClassMapping targetClass) {
426             return null;
427         }
428         public PClassMapping[] getSubPCMs() throws PException {
429             return null;
430         }
431     }
432
433     public class MyGCM extends GenClassMapping {
434
435         /** Contains PrimitiveElement */
436         public MyGCM() {
437             super();
438         }
439
440         /** Contains ClassRef */
441         public MyGCM(PNameCoder pnc) {
442             super();
443             if (pnc != null) {
444                 try {
445                     setPNameCoder(pnc);
446                 } catch (Exception JavaDoc e) {
447                     fail(e.getMessage());
448                 }
449             }
450         }
451
452         /** Contains GenClassRef */
453         public MyGCM(PClassMapping pcm, PNameCoder pnc) {
454             super();
455             if (pcm != null) {
456                 setGenClassMapping(pcm);
457             }
458             if (pnc != null) {
459                 try {
460                     setPNameCoder(pnc);
461                 } catch (Exception JavaDoc e) {
462                     fail(e.getMessage());
463                 }
464             }
465         }
466
467         public PBinding createPBinding() throws PException {
468             return null;
469         }
470
471         public Iterator getPNameIterator(Object JavaDoc conn) throws PException {
472             return null;
473         }
474
475         public PNameIterator getPNameIterator(Object JavaDoc conn,
476                                               boolean withSubType,
477                                               boolean prefetching,
478                                               Object JavaDoc txctx) throws PException {
479             return null;
480         }
481
482         public boolean isConform(String JavaDoc mappername) {
483             return false;
484         }
485         public boolean exist(PBinding pb, Object JavaDoc conn) throws PException {
486             return false;
487         }
488         public void read(PBinding pb, Object JavaDoc conn, PAccessor pa, Object JavaDoc txctx)
489                 throws PException {
490         }
491         public void read(PBinding pb, Object JavaDoc conn, PAccessor pa)
492                 throws PException {
493         }
494         public void write(PBinding pb, Object JavaDoc conn, PAccessor pa)
495                 throws PException {
496         }
497         
498         public void addAssociation(PClassMapping targetClass, int[] indexes) {
499         }
500         public HashMap JavaDoc getAssociationTable() {
501             return null;
502         }
503         public int[] getIndexesTable(PClassMapping targetClass) {
504             return null;
505         }
506         public PClassMapping[] getSubPCMs() throws PException {
507             return null;
508         }
509     }
510
511     public class MyBinder implements PBinder {
512         public PBinding lookup(PName pn) throws PException {
513             return null;
514         }
515
516         public void bind(PName pn, PBindingCtrl pb) throws PException {
517         }
518
519         public PClassMapping getBinderClassMapping() {
520             return null;
521         }
522
523         public void setPClassMapping(PClassMapping pcm) {
524         }
525
526         public void unbind(PBindingCtrl pb) throws PException {
527         }
528
529         public CacheManager getCacheManager() {
530             return null;
531         }
532
533         public void setCacheManager(CacheManager cm) throws PException {
534         }
535
536         public PName export(Object JavaDoc conn, Object JavaDoc infoitem) throws PException {
537             return null;
538         }
539
540         public PName export(Object JavaDoc conn, Object JavaDoc infoitem, Object JavaDoc hints)
541                 throws PException {
542             return null;
543         }
544
545         public void unexport(Object JavaDoc conn, PName pn) throws PException {
546         }
547
548         public void unexport(Object JavaDoc conn, PName pn, Object JavaDoc hints) throws PException {
549         }
550
551         public boolean codingSupported(int codingtype) {
552             return false;
553         }
554
555         public PName decode(byte[] en) throws PExceptionNaming {
556             return null;
557         }
558
559         public PName decodeAbstract(Object JavaDoc en, Object JavaDoc context) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
560             return null;
561         }
562
563         public PName decodeByte(byte en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
564             return null;
565         }
566
567         public PName decodeObyte(Byte JavaDoc en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
568             return null;
569         }
570
571         public PName decodeChar(char en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
572             return null;
573         }
574
575         public PName decodeOchar(Character JavaDoc en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
576             return null;
577         }
578
579         public PName decodeInt(int en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
580             return null;
581         }
582
583         public PName decodeOint(Integer JavaDoc en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
584             return null;
585         }
586
587         public PName decodeLong(long en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
588             return null;
589         }
590
591         public PName decodeOlong(Long JavaDoc en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
592             return null;
593         }
594
595         public PName decodeShort(short en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
596             return null;
597         }
598
599         public PName decodeOshort(Short JavaDoc en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
600             return null;
601         }
602
603         public PName decodeString(String JavaDoc en) throws PExceptionNaming {
604             return null;
605         }
606
607         public PName decodeCharArray(char[] en) throws PExceptionNaming {
608             return null;
609         }
610
611         public PName decodeDate(Date JavaDoc en) throws PExceptionNaming {
612             return null;
613         }
614
615         public PName decodeBigDecimal(BigDecimal JavaDoc en) throws PExceptionNaming {
616             return null;
617         }
618
619         public PName decodeBigInteger(BigInteger JavaDoc en) throws PExceptionNaming {
620             return null;
621         }
622
623         public byte[] encode(PName pn) throws PExceptionNaming {
624             return new byte[0];
625         }
626
627         public Object JavaDoc encodeAbstract(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
628             return null;
629         }
630
631         public byte encodeByte(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
632             return 0;
633         }
634
635         public Byte JavaDoc encodeObyte(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
636             return null;
637         }
638
639         public char encodeChar(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
640             return 0;
641         }
642
643         public Character JavaDoc encodeOchar(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
644             return null;
645         }
646
647         public int encodeInt(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
648             return 0;
649         }
650
651         public Integer JavaDoc encodeOint(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
652             return null;
653         }
654
655         public long encodeLong(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
656             return 0;
657         }
658
659         public Long JavaDoc encodeOlong(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
660             return null;
661         }
662
663         public short encodeShort(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
664             return 0;
665         }
666
667         public Short JavaDoc encodeOshort(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
668             return null;
669         }
670
671         public String JavaDoc encodeString(PName pn) throws PExceptionNaming {
672             return null;
673         }
674
675         public char[] encodeCharArray(PName pn) throws PExceptionNaming {
676             return new char[0];
677         }
678
679         public Date JavaDoc encodeDate(PName pn) throws PExceptionNaming {
680             return null;
681         }
682
683         public BigDecimal JavaDoc encodeBigDecimal(PName pn) throws PExceptionNaming {
684             return null;
685         }
686
687         public BigInteger JavaDoc encodeBigInteger(PName pn) throws PExceptionNaming {
688             return null;
689         }
690
691         public PName getNull() {
692             return null;
693         }
694
695         public void setNullPName(Object JavaDoc o) throws PException {
696         }
697
698         public boolean supportDynamicComposite() {
699             return false;
700         }
701
702         public boolean supportCompositeField(String JavaDoc fn, PType ft) {
703             return false;
704         }
705
706         public boolean supportStaticComposite() {
707             return false;
708         }
709
710         public PType getPType() {
711             return null;
712         }
713
714         public void setPType(PType pt) {
715         }
716     }
717 }
718
719
720
Popular Tags