1 23 24 package org.objectweb.jorm.runtime.namedef; 25 26 import org.objectweb.jorm.runtime.TestRuntimeHelper; 27 import org.objectweb.jorm.naming.api.PBinder; 28 import org.objectweb.jorm.naming.api.PNameCoder; 29 import org.objectweb.jorm.naming.api.PName; 30 import org.objectweb.jorm.type.api.PType; 31 import org.objectweb.jorm.type.api.PTypeSpace; 32 import org.objectweb.jorm.facility.naming.basidir.BasidBinder; 33 import org.objectweb.jorm.api.PAccessor; 34 import org.objectweb.jorm.api.PClassMapping; 35 import org.objectweb.jorm.api.PBinding; 36 import org.objectweb.jorm.api.PException; 37 import org.objectweb.jorm.ExceptionHelper; 38 import org.objectweb.util.monolog.api.BasicLevel; 39 40 import java.util.Date ; 41 import java.math.BigDecimal ; 42 import java.math.BigInteger ; 43 44 48 public class TestNameDefSingle extends TestRuntimeHelper { 49 50 private final static String LOGGER_NAME 51 = "test.org.objectweb.jorm.singlename"; 52 53 public TestNameDefSingle(String name) throws Exception { 54 super(name); 55 } 56 57 protected String getLoggerName() { 58 return LOGGER_NAME; 59 } 60 61 protected PBinder getBinder(String className) throws Exception { 62 int idx = className.lastIndexOf('.'); 63 String cn = className.substring(idx + 1); 64 PType type = null; 65 int ct = -1; 66 Object nullvalue = null; 67 if (cn.equals("ASingleByteId")) { 68 type = PTypeSpace.BYTE; 69 ct = PNameCoder.CTBYTE; 70 nullvalue = new Byte ((byte) -1); 71 } else if (cn.equals("ASingleObyteId")) { 72 type = PTypeSpace.OBJBYTE; 73 ct = PNameCoder.CTOBYTE; 74 } else if (cn.equals("ASingleCharId")) { 75 type = PTypeSpace.CHAR; 76 ct = PNameCoder.CTCHAR; 77 nullvalue = new Character ('0'); 78 } else if (cn.equals("ASingleOcharId")) { 79 type = PTypeSpace.OBJCHAR; 80 ct = PNameCoder.CTOCHAR; 81 } else if (cn.equals("ASingleShortId")) { 82 type = PTypeSpace.SHORT; 83 ct = PNameCoder.CTSHORT; 84 nullvalue = new Short ((short) -1); 85 } else if (cn.equals("ASingleOshortId")) { 86 type = PTypeSpace.OBJSHORT; 87 ct = PNameCoder.CTOSHORT; 88 } else if (cn.equals("ASingleIntId")) { 89 type = PTypeSpace.INT; 90 ct = PNameCoder.CTINT; 91 nullvalue = new Integer (-1); 92 } else if (cn.equals("ASingleOintId")) { 93 type = PTypeSpace.OBJINT; 94 ct = PNameCoder.CTOINT; 95 } else if (cn.equals("ASingleLongId")) { 96 type = PTypeSpace.LONG; 97 ct = PNameCoder.CTLONG; 98 nullvalue = new Long (-1); 99 } else if (cn.equals("ASingleOlongId")) { 100 type = PTypeSpace.OBJLONG; 101 ct = PNameCoder.CTOLONG; 102 } else if (cn.equals("ASingleStringId")) { 103 type = PTypeSpace.STRING; 104 ct = PNameCoder.CTSTRING; 105 } else if (cn.equals("ASingleDateId")) { 106 type = PTypeSpace.DATE; 107 ct = PNameCoder.CTDATE; 108 } else if (cn.equals("ASingleBigDecimalId")) { 109 type = PTypeSpace.BIGDECIMAL; 110 ct = PNameCoder.CTBIGDECIMAL; 111 } else if (cn.equals("ASingleBigIntegerId")) { 112 type = PTypeSpace.BIGINTEGER; 113 ct = PNameCoder.CTBIGINTEGER; 114 } else if (cn.equals("ASingleBytearrayId")) { 115 type = PTypeSpace.BYTEARRAY; 116 ct = PNameCoder.CTBYTEARRAY; 117 } else if (cn.equals("ASingleChararrayId")) { 118 type = PTypeSpace.CHARARRAY; 119 ct = PNameCoder.CTCHARARRAY; 120 } else { 121 throw new Exception ( 122 "Unable to find the type of the binder for the class: " 123 + className); 124 } 125 logger.log(BasicLevel.DEBUG, "Allocate a BasidBinder to manage " 126 + type.getJormName()); 127 PBinder binder = new BasidBinder(); 128 binder.setNullPName(nullvalue); 129 ((BasidBinder) binder).setCodingType(ct); 130 return binder; 131 } 132 133 private static int f1 = 0; 134 135 private static synchronized int getF1() { 136 return f1++; 137 } 138 139 140 private final static String CNBYTE = "org.objectweb.jorm.pobject.singlename.ASingleByteId"; 141 142 public void testByte() throws Exception { 143 changeLogger(LOGGER_NAME + ".byte"); 144 logger.log(BasicLevel.DEBUG, "testByte begin"); 145 int f = getF1(); 146 NameDefAccessor acc2 = new NameDefAccessor(); 147 byte nv = 56; 148 PBinding pb = export(CNBYTE, new Byte (nv)); 149 NameDefAccessor acc1 = new NameDefAccessor(f, 150 pb.getPClassMapping().getPBinder().getNull(), pb.getPName()); 151 assertEquals("Bad pname encoded value", nv, pb.getPName().encodeByte()); 152 logger.log(BasicLevel.DEBUG, "create and read"); 153 writeRead(pb, acc1, acc2); 154 assertEquals("bad f1 value", f, acc2.f1); 155 assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1); 156 assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2); 157 NameDefAccessor acc3 = new NameDefAccessor(-f, 158 pb.getPName(), pb.getPClassMapping().getPBinder().getNull()); 159 logger.log(BasicLevel.DEBUG, "update and read"); 160 writeRead(pb, acc3, acc2); 161 assertEquals("bad f1 value", -f, acc2.f1); 162 assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1); 163 assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2); 164 logger.log(BasicLevel.DEBUG, "remove"); 165 unexport(pb, acc1); 166 logger.log(BasicLevel.DEBUG, "testByte end"); 167 } 168 169 private final static String CNOBYTE = "org.objectweb.jorm.pobject.singlename.ASingleObyteId"; 170 171 public void testObyte() throws Exception { 172 changeLogger(LOGGER_NAME + ".byte"); 173 logger.log(BasicLevel.DEBUG, "testObyte begin"); 174 int f = getF1(); 175 NameDefAccessor acc2 = new NameDefAccessor(); 176 Byte nv = new Byte ((byte) 56); 177 PBinding pb = export(CNOBYTE, nv); 178 NameDefAccessor acc1 = new NameDefAccessor(f, 179 pb.getPClassMapping().getPBinder().getNull(), pb.getPName()); 180 assertEquals("Bad pname encoded value", nv, pb.getPName().encodeObyte()); 181 logger.log(BasicLevel.DEBUG, "create and read"); 182 writeRead(pb, acc1, acc2); 183 assertEquals("bad f1 value", f, acc2.f1); 184 assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1); 185 assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2); 186 NameDefAccessor acc3 = new NameDefAccessor(-f, 187 pb.getPName(), pb.getPClassMapping().getPBinder().getNull()); 188 logger.log(BasicLevel.DEBUG, "update and read"); 189 writeRead(pb, acc3, acc2); 190 assertEquals("bad f1 value", -f, acc2.f1); 191 assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1); 192 assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2); 193 logger.log(BasicLevel.DEBUG, "remove"); 194 unexport(pb, acc1); 195 logger.log(BasicLevel.DEBUG, "testObyte end"); 196 } 197 198 private final static String CNSHORT = "org.objectweb.jorm.pobject.singlename.ASingleShortId"; 199 200 public void testShort() throws Exception { 201 changeLogger(LOGGER_NAME + ".short"); 202 int f = getF1(); 203 NameDefAccessor acc2 = new NameDefAccessor(); 204 short nv = 56; 205 PBinding pb = export(CNSHORT, new Short (nv)); 206 NameDefAccessor acc1 = new NameDefAccessor(f, 207 pb.getPClassMapping().getPBinder().getNull(), pb.getPName()); 208 assertEquals("Bad pname encoded value", nv, pb.getPName().encodeShort()); 209 logger.log(BasicLevel.DEBUG, "create and read"); 210 writeRead(pb, acc1, acc2); 211 assertEquals("bad f1 value", f, acc2.f1); 212 assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1); 213 assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2); 214 NameDefAccessor acc3 = new NameDefAccessor(-f, 215 pb.getPName(), pb.getPClassMapping().getPBinder().getNull()); 216 logger.log(BasicLevel.DEBUG, "update and read"); 217 writeRead(pb, acc3, acc2); 218 assertEquals("bad f1 value", -f, acc2.f1); 219 assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1); 220 assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2); 221 logger.log(BasicLevel.DEBUG, "remove"); 222 unexport(pb, acc1); 223 logger.log(BasicLevel.DEBUG, "testShort end"); 224 } 225 226 private final static String CNOSHORT = "org.objectweb.jorm.pobject.singlename.ASingleOshortId"; 227 228 public void testOshort() throws Exception { 229 changeLogger(LOGGER_NAME + ".short"); 230 int f = getF1(); 231 NameDefAccessor acc2 = new NameDefAccessor(); 232 Short nv = new Short ((short) 56); 233 PBinding pb = export(CNOSHORT, nv); 234 NameDefAccessor acc1 = new NameDefAccessor(f, 235 pb.getPClassMapping().getPBinder().getNull(), pb.getPName()); 236 assertEquals("Bad pname encoded value", nv, pb.getPName().encodeOshort()); 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, 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, "testOshort end"); 252 } 253 254 private final static String CNINT = "org.objectweb.jorm.pobject.singlename.ASingleIntId"; 255 256 public void testInt() throws Exception { 257 changeLogger(LOGGER_NAME + ".int"); 258 int f = getF1(); 259 NameDefAccessor acc2 = new NameDefAccessor(); 260 int nv = 56; 261 PBinding pb = export(CNINT, new Integer (nv)); 262 NameDefAccessor acc1 = new NameDefAccessor(f, 263 pb.getPClassMapping().getPBinder().getNull(), pb.getPName()); 264 assertEquals("Bad pname encoded value", nv, pb.getPName().encodeInt()); 265 logger.log(BasicLevel.DEBUG, "create and read"); 266 writeRead(pb, acc1, acc2); 267 assertEquals("bad f1 value", f, acc2.f1); 268 assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1); 269 assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2); 270 NameDefAccessor acc3 = new NameDefAccessor(-f, 271 pb.getPName(), pb.getPClassMapping().getPBinder().getNull()); 272 logger.log(BasicLevel.DEBUG, "update and read"); 273 writeRead(pb, acc3, acc2); 274 assertEquals("bad f1 value", -f, acc2.f1); 275 assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1); 276 assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2); 277 logger.log(BasicLevel.DEBUG, "remove"); 278 unexport(pb, acc1); 279 logger.log(BasicLevel.DEBUG, "testInt end"); 280 } 281 282 private final static String CNOINT = "org.objectweb.jorm.pobject.singlename.ASingleOintId"; 283 284 public void testOint() throws Exception { 285 changeLogger(LOGGER_NAME + ".int"); 286 int f = getF1(); 287 NameDefAccessor acc2 = new NameDefAccessor(); 288 Integer nv = new Integer (56); 289 PBinding pb = export(CNOINT, nv); 290 NameDefAccessor acc1 = new NameDefAccessor(f, 291 pb.getPClassMapping().getPBinder().getNull(), pb.getPName()); 292 assertEquals("Bad pname encoded value", nv, pb.getPName().encodeOint()); 293 logger.log(BasicLevel.DEBUG, "create and read"); 294 writeRead(pb, acc1, acc2); 295 assertEquals("bad f1 value", f, acc2.f1); 296 assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1); 297 assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2); 298 NameDefAccessor acc3 = new NameDefAccessor(-f, 299 pb.getPName(), pb.getPClassMapping().getPBinder().getNull()); 300 logger.log(BasicLevel.DEBUG, "update and read"); 301 writeRead(pb, acc3, acc2); 302 assertEquals("bad f1 value", -f, acc2.f1); 303 assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1); 304 assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2); 305 logger.log(BasicLevel.DEBUG, "remove"); 306 unexport(pb, acc1); 307 logger.log(BasicLevel.DEBUG, "testOint end"); 308 } 309 310 private final static String CNLONG = "org.objectweb.jorm.pobject.singlename.ASingleLongId"; 311 312 public void testLong() throws Exception { 313 changeLogger(LOGGER_NAME + ".long"); 314 int f = getF1(); 315 NameDefAccessor acc2 = new NameDefAccessor(); 316 long nv = 56; 317 PBinding pb = export(CNLONG, new Long (nv)); 318 NameDefAccessor acc1 = new NameDefAccessor(f, 319 pb.getPClassMapping().getPBinder().getNull(), pb.getPName()); 320 assertEquals("Bad pname encoded value", nv, pb.getPName().encodeLong()); 321 logger.log(BasicLevel.DEBUG, "create and read"); 322 writeRead(pb, acc1, acc2); 323 assertEquals("bad f1 value", f, acc2.f1); 324 assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1); 325 assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2); 326 NameDefAccessor acc3 = new NameDefAccessor(-f, 327 pb.getPName(), pb.getPClassMapping().getPBinder().getNull()); 328 logger.log(BasicLevel.DEBUG, "update and read"); 329 writeRead(pb, acc3, acc2); 330 assertEquals("bad f1 value", -f, acc2.f1); 331 assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1); 332 assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2); 333 logger.log(BasicLevel.DEBUG, "remove"); 334 unexport(pb, acc1); 335 logger.log(BasicLevel.DEBUG, "testLong end"); 336 } 337 338 private final static String CNOLONG = "org.objectweb.jorm.pobject.singlename.ASingleOlongId"; 339 340 public void testOlong() throws Exception { 341 changeLogger(LOGGER_NAME + ".long"); 342 int f = getF1(); 343 NameDefAccessor acc2 = new NameDefAccessor(); 344 Long nv = new Long (56); 345 PBinding pb = export(CNOLONG, nv); 346 NameDefAccessor acc1 = new NameDefAccessor(f, 347 pb.getPClassMapping().getPBinder().getNull(), pb.getPName()); 348 assertEquals("Bad pname encoded value", nv, pb.getPName().encodeOlong()); 349 logger.log(BasicLevel.DEBUG, "create and read"); 350 writeRead(pb, acc1, acc2); 351 assertEquals("bad f1 value", f, acc2.f1); 352 assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1); 353 assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2); 354 NameDefAccessor acc3 = new NameDefAccessor(-f, 355 pb.getPName(), pb.getPClassMapping().getPBinder().getNull()); 356 logger.log(BasicLevel.DEBUG, "update and read"); 357 writeRead(pb, acc3, acc2); 358 assertEquals("bad f1 value", -f, acc2.f1); 359 assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1); 360 assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2); 361 logger.log(BasicLevel.DEBUG, "remove"); 362 unexport(pb, acc1); 363 logger.log(BasicLevel.DEBUG, "testOlong end"); 364 } 365 366 private final static String CNCHAR = "org.objectweb.jorm.pobject.singlename.ASingleCharId"; 367 368 public void testChar() throws Exception { 369 changeLogger(LOGGER_NAME + ".char"); 370 int f = getF1(); 371 NameDefAccessor acc2 = new NameDefAccessor(); 372 char nv = 'e'; 373 PBinding pb = export(CNCHAR, new Character (nv)); 374 NameDefAccessor acc1 = new NameDefAccessor(f, 375 pb.getPClassMapping().getPBinder().getNull(), pb.getPName()); 376 assertEquals("Bad pname encoded value", nv, pb.getPName().encodeChar()); 377 logger.log(BasicLevel.DEBUG, "create and read"); 378 writeRead(pb, acc1, acc2); 379 assertEquals("bad f1 value", f, acc2.f1); 380 assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1); 381 assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2); 382 NameDefAccessor acc3 = new NameDefAccessor(-f, 383 pb.getPName(), pb.getPClassMapping().getPBinder().getNull()); 384 logger.log(BasicLevel.DEBUG, "update and read"); 385 writeRead(pb, acc3, acc2); 386 assertEquals("bad f1 value", -f, acc2.f1); 387 assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1); 388 assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2); 389 logger.log(BasicLevel.DEBUG, "remove"); 390 unexport(pb, acc1); 391 logger.log(BasicLevel.DEBUG, "testChar end"); 392 } 393 394 private final static String CNOCHAR = "org.objectweb.jorm.pobject.singlename.ASingleOcharId"; 395 396 public void testOchar() throws Exception { 397 changeLogger(LOGGER_NAME + ".char"); 398 int f = getF1(); 399 NameDefAccessor acc2 = new NameDefAccessor(); 400 Character nv = new Character ('e'); 401 PBinding pb = export(CNOCHAR, nv); 402 NameDefAccessor acc1 = new NameDefAccessor(f, 403 pb.getPClassMapping().getPBinder().getNull(), pb.getPName()); 404 assertEquals("Bad pname encoded value", nv, pb.getPName().encodeOchar()); 405 logger.log(BasicLevel.DEBUG, "create and read"); 406 writeRead(pb, acc1, acc2); 407 assertEquals("bad f1 value", f, acc2.f1); 408 assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1); 409 assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2); 410 NameDefAccessor acc3 = new NameDefAccessor(-f, 411 pb.getPName(), pb.getPClassMapping().getPBinder().getNull()); 412 logger.log(BasicLevel.DEBUG, "update and read"); 413 writeRead(pb, acc3, acc2); 414 assertEquals("bad f1 value", -f, acc2.f1); 415 assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1); 416 assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2); 417 logger.log(BasicLevel.DEBUG, "remove"); 418 unexport(pb, acc1); 419 logger.log(BasicLevel.DEBUG, "testOchar end"); 420 } 421 422 private final static String CNSTRING = "org.objectweb.jorm.pobject.singlename.ASingleStringId"; 423 424 public void testString() throws Exception { 425 changeLogger(LOGGER_NAME + ".string"); 426 int f = getF1(); 427 NameDefAccessor acc2 = new NameDefAccessor(); 428 String nv = "azerty"; 429 PBinding pb = export(CNSTRING, nv); 430 NameDefAccessor acc1 = new NameDefAccessor(f, 431 pb.getPClassMapping().getPBinder().getNull(), pb.getPName()); 432 assertEquals("Bad pname encoded value", nv, pb.getPName().encodeString()); 433 logger.log(BasicLevel.DEBUG, "create and read"); 434 writeRead(pb, acc1, acc2); 435 assertEquals("bad f1 value", f, acc2.f1); 436 assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1); 437 assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2); 438 NameDefAccessor acc3 = new NameDefAccessor(-f, 439 pb.getPName(), pb.getPClassMapping().getPBinder().getNull()); 440 logger.log(BasicLevel.DEBUG, "update and read"); 441 writeRead(pb, acc3, acc2); 442 assertEquals("bad f1 value", -f, acc2.f1); 443 assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1); 444 assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2); 445 logger.log(BasicLevel.DEBUG, "remove"); 446 unexport(pb, acc1); 447 logger.log(BasicLevel.DEBUG, "testString end"); 448 } 449 450 private final static String CNDATE = "org.objectweb.jorm.pobject.singlename.ASingleDateId"; 451 452 public void testDate() throws Exception { 453 changeLogger(LOGGER_NAME + ".date"); 454 int f = getF1(); 455 NameDefAccessor acc2 = new NameDefAccessor(); 456 Date nv = getTime(); 457 PBinding pb = export(CNDATE, nv); 458 NameDefAccessor acc1 = new NameDefAccessor(f, 459 pb.getPClassMapping().getPBinder().getNull(), pb.getPName()); 460 assertEquals("Bad pname encoded value", nv, pb.getPName().encodeDate()); 461 logger.log(BasicLevel.DEBUG, "create and read"); 462 writeRead(pb, acc1, acc2); 463 assertEquals("bad f1 value", f, acc2.f1); 464 assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1); 465 assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2); 466 NameDefAccessor acc3 = new NameDefAccessor(-f, 467 pb.getPName(), pb.getPClassMapping().getPBinder().getNull()); 468 logger.log(BasicLevel.DEBUG, "update and read"); 469 writeRead(pb, acc3, acc2); 470 assertEquals("bad f1 value", -f, acc2.f1); 471 assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1); 472 assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2); 473 logger.log(BasicLevel.DEBUG, "remove"); 474 unexport(pb, acc1); 475 logger.log(BasicLevel.DEBUG, "testDate end"); 476 } 477 478 private final static String CNBIGDECIMAL = "org.objectweb.jorm.pobject.singlename.ASingleBigDecimalId"; 479 480 public void testBigDecimal() throws Exception { 481 changeLogger(LOGGER_NAME + ".bigdecimal"); 482 int f = getF1(); 483 NameDefAccessor acc2 = new NameDefAccessor(); 484 BigDecimal nv = new BigDecimal ("123456789.45"); 485 PBinding pb = export(CNBIGDECIMAL, nv); 486 NameDefAccessor acc1 = new NameDefAccessor(f, 487 pb.getPClassMapping().getPBinder().getNull(), pb.getPName()); 488 assertEquals("Bad pname encoded value", nv, pb.getPName().encodeBigDecimal()); 489 logger.log(BasicLevel.DEBUG, "create and read"); 490 writeRead(pb, acc1, acc2); 491 assertEquals("bad f1 value", f, acc2.f1); 492 assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1); 493 assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2); 494 NameDefAccessor acc3 = new NameDefAccessor(-f, 495 pb.getPName(), pb.getPClassMapping().getPBinder().getNull()); 496 logger.log(BasicLevel.DEBUG, "update and read"); 497 writeRead(pb, acc3, acc2); 498 assertEquals("bad f1 value", -f, acc2.f1); 499 assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1); 500 assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2); 501 logger.log(BasicLevel.DEBUG, "remove"); 502 unexport(pb, acc1); 503 logger.log(BasicLevel.DEBUG, "testDate end"); 504 } 505 506 private final static String CNBIGINTEGER = "org.objectweb.jorm.pobject.singlename.ASingleBigIntegerId"; 507 508 public void testBigInteger() throws Exception { 509 changeLogger(LOGGER_NAME + ".biginteger"); 510 int f = getF1(); 511 NameDefAccessor acc2 = new NameDefAccessor(); 512 BigInteger nv = new BigInteger ("123456789"); 513 PBinding pb = export(CNBIGINTEGER, nv); 514 NameDefAccessor acc1 = new NameDefAccessor(f, 515 pb.getPClassMapping().getPBinder().getNull(), pb.getPName()); 516 assertEquals("Bad pname encoded value", nv, pb.getPName().encodeBigInteger()); 517 logger.log(BasicLevel.DEBUG, "create and read"); 518 writeRead(pb, acc1, acc2); 519 assertEquals("bad f1 value", f, acc2.f1); 520 assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1); 521 assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2); 522 NameDefAccessor acc3 = new NameDefAccessor(-f, 523 pb.getPName(), pb.getPClassMapping().getPBinder().getNull()); 524 logger.log(BasicLevel.DEBUG, "update and read"); 525 writeRead(pb, acc3, acc2); 526 assertEquals("bad f1 value", -f, acc2.f1); 527 assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1); 528 assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2); 529 logger.log(BasicLevel.DEBUG, "remove"); 530 unexport(pb, acc1); 531 logger.log(BasicLevel.DEBUG, "testDate end"); 532 } 533 534 private final static String CNBYTEARRAY = "org.objectweb.jorm.pobject.singlename.ASingleBytearrayId"; 535 536 public void testBytearray() throws Exception { 537 changeLogger(LOGGER_NAME + ".bytearray"); 538 int f = getF1(); 539 NameDefAccessor acc2 = new NameDefAccessor(); 540 byte[] nv = "azerty".getBytes(); 541 PBinding pb = export(CNBYTEARRAY, nv); 542 NameDefAccessor acc1 = new NameDefAccessor(f, 543 pb.getPClassMapping().getPBinder().getNull(), pb.getPName()); 544 assertEqual("Bad pname encoded value", nv, pb.getPName().encode()); 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 assertEqual("Bad myself2 value", 550 acc1.myself2.encode(), acc2.myself2.encode()); 551 assertEquals("Bad linked pnc value", 552 pb.getPClassMapping().getPBinder(), acc2.myself2.getPNameManager()); 553 NameDefAccessor acc3 = new NameDefAccessor(-f, 554 pb.getPName(), pb.getPClassMapping().getPBinder().getNull()); 555 logger.log(BasicLevel.DEBUG, "update and read"); 556 writeRead(pb, acc3, acc2); 557 assertEquals("bad f1 value", -f, acc2.f1); 558 assertEqual("Bad myself1 value", 559 acc3.myself1.encode(), acc2.myself1.encode()); 560 assertEquals("Bad linked pnc value", 561 pb.getPClassMapping().getPBinder(), acc2.myself1.getPNameManager()); 562 assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2); 563 logger.log(BasicLevel.DEBUG, "remove"); 564 unexport(pb, acc1); 565 logger.log(BasicLevel.DEBUG, "testBytearray end"); 566 } 567 568 private final static String CNCHARARRAY = "org.objectweb.jorm.pobject.singlename.ASingleChararrayId"; 569 570 public void testChararray() throws Exception { 571 changeLogger(LOGGER_NAME + ".chararray"); 572 int f = getF1(); 573 NameDefAccessor acc2 = new NameDefAccessor(); 574 char[] nv = new char[]{'a', 'z', 'e', 'r', 't', 'y'}; 575 PBinding pb = export(CNCHARARRAY, nv); 576 NameDefAccessor acc1 = new NameDefAccessor(f, 577 pb.getPClassMapping().getPBinder().getNull(), pb.getPName()); 578 assertEqual("Bad pname encoded value", nv, pb.getPName().encodeCharArray()); 579 assertEquals("Bad pname encoded value", 580 pb.getPClassMapping().getPBinder(), pb.getPName().getPNameManager()); 581 logger.log(BasicLevel.DEBUG, "create and read"); 582 writeRead(pb, acc1, acc2); 583 assertEquals("bad f1 value", f, acc2.f1); 584 assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1); 585 assertEqual("Bad myself2 encoded value", 586 acc1.myself2.encodeCharArray(), acc2.myself2.encodeCharArray()); 587 assertEquals("Bad linked pnc value", 588 pb.getPClassMapping().getPBinder(), acc2.myself2.getPNameManager()); 589 NameDefAccessor acc3 = new NameDefAccessor(-f, 590 pb.getPName(), pb.getPClassMapping().getPBinder().getNull()); 591 logger.log(BasicLevel.DEBUG, "update and read"); 592 writeRead(pb, acc3, acc2); 593 assertEquals("bad f1 value", -f, acc2.f1); 594 assertEqual("Bad myself1 value", 595 acc3.myself1.encodeCharArray(), acc2.myself1.encodeCharArray()); 596 assertEquals("Bad linked pnc value", 597 pb.getPClassMapping().getPBinder(), acc2.myself1.getPNameManager()); 598 assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2); 599 logger.log(BasicLevel.DEBUG, "remove"); 600 unexport(pb, acc1); 601 logger.log(BasicLevel.DEBUG, "testCharray end"); 602 } 603 } 604 | Popular Tags |