1 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 ; 51 import java.util.Map ; 52 import java.util.Iterator ; 53 import java.util.HashMap ; 54 import java.util.Collections ; 55 import java.util.Date ; 56 import java.math.BigDecimal ; 57 import java.math.BigInteger ; 58 59 import junit.framework.Assert; 60 import junit.framework.TestCase; 61 62 66 public class TestJormPathHelper extends TestCase { 67 68 public TestJormPathHelper(String s) throws Exception { 69 super(s); 70 } 71 72 public static char SEP = JormPathHelper.SEP; 73 74 MyMapper mapper ; 75 76 protected void setUp() throws Exception { 77 mapper = new MyMapper(); 78 } 79 80 protected void tearDown() throws Exception { 81 mapper = null; 82 } 83 84 public void testClass() { 85 PBinder binder = new MyBinder(); 86 String className = "com.foo.Bar"; 87 PClassMapping pcm = new MyPCM(className, 88 Collections.EMPTY_MAP, 89 Collections.EMPTY_MAP, 90 binder, 91 mapper); 92 String 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 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 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 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 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 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 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 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 name2pcm; 169 170 public MyMapper() { 171 name2pcm = new HashMap (); 172 } 173 174 public MyMapper(Map 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 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 conn, PClassMapping pcm) { 193 name2pcm.put(pcm.getClassName(), pcm); 194 } 195 196 public void map(Object conn, PClassMapping pcm, boolean loadmeta) { 197 name2pcm.put(pcm.getClassName(), pcm); 198 } 199 200 public void closeConnection(Object conn) throws PException { 201 } 202 203 public String cn2mn(String cn) { 204 return null; 205 } 206 207 public Object getConnection() throws PException { 208 return null; 209 } 210 211 public Object getConnection(Object ctxt) throws PException { 212 return null; 213 } 214 215 public Object getConnection(Object connectionContext, Object user) throws PException { 216 return null; 217 } 218 219 public String getMapperName() { 220 return null; 221 } 222 223 public PMappingStructuresManager getPMappingStructuresManager() { 224 return null; 225 } 226 227 public void setConnectionFactory(Object cf) throws PException { 228 } 229 230 public Object 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 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 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 jcname) throws PException { 281 return null; 282 } 283 284 public Collection getPMapClusters() { 285 return null; 286 } 287 288 public void addDependency(String jcname1, String jcname2) throws PException { 289 } 290 291 public void classDefined(String jcname) throws PException { 292 } 293 294 public void declareClass(String jcname) { 295 } 296 } 297 298 public class MyPCM implements PClassMapping { 299 String className; 300 Map pncs; 301 Map gcms; 302 PClassMapping pcm; 303 PBinder binder; 304 PMapper mapper; 305 306 public MyPCM(String className, 307 Map pncs, 308 Map 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 getClassName() { 327 return className; 328 } 329 330 public String getProjectName() { 331 return null; 332 } 333 334 public PNameCoder getClassPNameCoder() { 335 return binder; 336 } 337 338 public PClassMapping getGenClassMapping() throws UnsupportedOperationException { 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 fn) 345 throws UnsupportedOperationException { 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 { 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 fn) 373 throws UnsupportedOperationException { 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 conn) throws PException { 382 return null; 383 } 384 385 public PNameIterator getPNameIterator(Object conn, 386 boolean withSubType, 387 boolean prefetching, 388 Object txctx) throws PException { 389 return null; 390 } 391 392 public PType getPType() { 393 return null; 394 } 395 396 public boolean isConform(String 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 { 406 } 407 408 public boolean exist(PBinding pb, Object conn) throws PException { 409 return false; 410 } 411 public void read(PBinding pb, Object conn, PAccessor pa, Object txctx) 412 throws PException { 413 } 414 public void read(PBinding pb, Object conn, PAccessor pa) 415 throws PException { 416 } 417 public void write(PBinding pb, Object conn, PAccessor pa) 418 throws PException { 419 } 420 public void addAssociation(PClassMapping targetClass, int[] indexes) { 421 } 422 public HashMap 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 436 public MyGCM() { 437 super(); 438 } 439 440 441 public MyGCM(PNameCoder pnc) { 442 super(); 443 if (pnc != null) { 444 try { 445 setPNameCoder(pnc); 446 } catch (Exception e) { 447 fail(e.getMessage()); 448 } 449 } 450 } 451 452 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 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 conn) throws PException { 472 return null; 473 } 474 475 public PNameIterator getPNameIterator(Object conn, 476 boolean withSubType, 477 boolean prefetching, 478 Object txctx) throws PException { 479 return null; 480 } 481 482 public boolean isConform(String mappername) { 483 return false; 484 } 485 public boolean exist(PBinding pb, Object conn) throws PException { 486 return false; 487 } 488 public void read(PBinding pb, Object conn, PAccessor pa, Object txctx) 489 throws PException { 490 } 491 public void read(PBinding pb, Object conn, PAccessor pa) 492 throws PException { 493 } 494 public void write(PBinding pb, Object conn, PAccessor pa) 495 throws PException { 496 } 497 498 public void addAssociation(PClassMapping targetClass, int[] indexes) { 499 } 500 public HashMap 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 conn, Object infoitem) throws PException { 537 return null; 538 } 539 540 public PName export(Object conn, Object infoitem, Object hints) 541 throws PException { 542 return null; 543 } 544 545 public void unexport(Object conn, PName pn) throws PException { 546 } 547 548 public void unexport(Object conn, PName pn, Object 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 en, Object context) throws PExceptionNaming, UnsupportedOperationException { 560 return null; 561 } 562 563 public PName decodeByte(byte en) throws PExceptionNaming, UnsupportedOperationException { 564 return null; 565 } 566 567 public PName decodeObyte(Byte en) throws PExceptionNaming, UnsupportedOperationException { 568 return null; 569 } 570 571 public PName decodeChar(char en) throws PExceptionNaming, UnsupportedOperationException { 572 return null; 573 } 574 575 public PName decodeOchar(Character en) throws PExceptionNaming, UnsupportedOperationException { 576 return null; 577 } 578 579 public PName decodeInt(int en) throws PExceptionNaming, UnsupportedOperationException { 580 return null; 581 } 582 583 public PName decodeOint(Integer en) throws PExceptionNaming, UnsupportedOperationException { 584 return null; 585 } 586 587 public PName decodeLong(long en) throws PExceptionNaming, UnsupportedOperationException { 588 return null; 589 } 590 591 public PName decodeOlong(Long en) throws PExceptionNaming, UnsupportedOperationException { 592 return null; 593 } 594 595 public PName decodeShort(short en) throws PExceptionNaming, UnsupportedOperationException { 596 return null; 597 } 598 599 public PName decodeOshort(Short en) throws PExceptionNaming, UnsupportedOperationException { 600 return null; 601 } 602 603 public PName decodeString(String 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 en) throws PExceptionNaming { 612 return null; 613 } 614 615 public PName decodeBigDecimal(BigDecimal en) throws PExceptionNaming { 616 return null; 617 } 618 619 public PName decodeBigInteger(BigInteger 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 encodeAbstract(PName pn) throws PExceptionNaming, UnsupportedOperationException { 628 return null; 629 } 630 631 public byte encodeByte(PName pn) throws PExceptionNaming, UnsupportedOperationException { 632 return 0; 633 } 634 635 public Byte encodeObyte(PName pn) throws PExceptionNaming, UnsupportedOperationException { 636 return null; 637 } 638 639 public char encodeChar(PName pn) throws PExceptionNaming, UnsupportedOperationException { 640 return 0; 641 } 642 643 public Character encodeOchar(PName pn) throws PExceptionNaming, UnsupportedOperationException { 644 return null; 645 } 646 647 public int encodeInt(PName pn) throws PExceptionNaming, UnsupportedOperationException { 648 return 0; 649 } 650 651 public Integer encodeOint(PName pn) throws PExceptionNaming, UnsupportedOperationException { 652 return null; 653 } 654 655 public long encodeLong(PName pn) throws PExceptionNaming, UnsupportedOperationException { 656 return 0; 657 } 658 659 public Long encodeOlong(PName pn) throws PExceptionNaming, UnsupportedOperationException { 660 return null; 661 } 662 663 public short encodeShort(PName pn) throws PExceptionNaming, UnsupportedOperationException { 664 return 0; 665 } 666 667 public Short encodeOshort(PName pn) throws PExceptionNaming, UnsupportedOperationException { 668 return null; 669 } 670 671 public String 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 encodeDate(PName pn) throws PExceptionNaming { 680 return null; 681 } 682 683 public BigDecimal encodeBigDecimal(PName pn) throws PExceptionNaming { 684 return null; 685 } 686 687 public BigInteger encodeBigInteger(PName pn) throws PExceptionNaming { 688 return null; 689 } 690 691 public PName getNull() { 692 return null; 693 } 694 695 public void setNullPName(Object o) throws PException { 696 } 697 698 public boolean supportDynamicComposite() { 699 return false; 700 } 701 702 public boolean supportCompositeField(String 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 |