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.pobject.compositename.CompositeAllTypesIdBinder; 29 import org.objectweb.jorm.pobject.compositename.CompositeAllTypesIdPNG; 30 import org.objectweb.jorm.api.PException; 31 import org.objectweb.jorm.api.PBinding; 32 import org.objectweb.util.monolog.api.BasicLevel; 33 34 import java.util.Date ; 35 36 40 public class TestAllTypes 41 extends TestRuntimeHelper { 42 43 private final static String LOGGER_NAME 44 = "test.org.objectweb.jorm.compositename.alltypes"; 45 46 public final static String CN 47 = "org.objectweb.jorm.pobject.compositename.ACompositeAllTypesId"; 48 49 public TestAllTypes(String s) throws Exception { 50 super(s); 51 } 52 53 protected String getLoggerName() { 54 return LOGGER_NAME; 55 } 56 57 protected PBinder getBinder(String className) throws Exception { 58 if (CN.equals(className)) { 59 PBinder binder = new CompositeAllTypesIdBinder(); 60 binder.setNullPName(new PNG()); 61 return binder; 62 } else { 63 throw new Exception ("Unmanaged class: " + className); 64 } 65 } 66 67 public void test() throws Exception { 68 logger.log(BasicLevel.DEBUG, "test begin"); 69 AllTypesAccessor acc2 = new AllTypesAccessor(); 70 PNG png = new PNG(); 71 png.byte1 = 1; 72 png.byte2 = 2; 73 png.bytearray1 = "2".getBytes(); 74 png.bytearray1 = "3".getBytes(); 75 png.char1 = '4'; 76 png.char1 = '5'; 77 png.oChar1 = new Character ('6'); 78 png.oChar2 = new Character ('7'); 79 png.chararray1 = new char[]{'8'}; 80 png.chararray2 = new char[]{'9'}; 81 png.date1 = getTime(); 82 Thread.sleep(1000); 83 png.date2 = getTime(); 84 png.int1 = 10; 85 png.int2 = 11; 86 png.long1 = 12; 87 png.long2 = 13; 88 png.oByte1 = new Byte ((byte) 14); 89 png.oByte2 = new Byte ((byte) 15); 90 png.oInt1 = new Integer (16); 91 png.oInt2 = new Integer (17); 92 png.oLong1 = new Long (18); 93 png.oLong2 = new Long (19); 94 png.oShort1 = new Short ((short) 20); 95 png.oShort2 = new Short ((short) 21); 96 png.short1 = 22; 97 png.short2 = 23; 98 png.string1 = "24"; 99 png.string2 = "25"; 100 logger.log(BasicLevel.DEBUG, "export"); 101 PBinding pb = export(CN, png); 102 assertEquals("Bad pname encoded value", 103 png, pb.getPName().encodeAbstract()); 104 105 int f = 43534; 106 AllTypesAccessor acc1 = new AllTypesAccessor(); 107 acc1.f1 = f; 108 acc1.setNameValues(pb.getPName()); 109 acc1.setMyself1(pb.getPClassMapping().getPBinder().getNull()); 110 acc1.setMyself2(pb.getPName()); 111 logger.log(BasicLevel.DEBUG, "create and read"); 112 writeRead(pb, acc1, acc2); 113 assertEquals("bad f1 value", f, acc2.f1); 114 assertEquals("Bad myself1 value", acc1.myself1, acc2.myself1); 115 assertEquals("Bad myself2 value", acc1.myself2, acc2.myself2); 116 117 AllTypesAccessor acc3 = new AllTypesAccessor(); 118 acc3.f1 = -f; 119 acc3.setNameValues(pb.getPName()); 120 acc3.setMyself1(pb.getPName()); 121 acc3.setMyself2(pb.getPClassMapping().getPBinder().getNull()); 122 logger.log(BasicLevel.DEBUG, "update and read"); 123 writeRead(pb, acc3, acc2); 124 assertEquals("bad f1 value", -f, acc2.f1); 125 assertEquals("Bad myself1 value", acc3.myself1, acc2.myself1); 126 assertEquals("Bad myself2 value", acc3.myself2, acc2.myself2); 127 128 logger.log(BasicLevel.DEBUG, "remove"); 129 unexport(pb, acc1); 130 logger.log(BasicLevel.DEBUG, "test end"); 131 } 132 133 public class PNG implements CompositeAllTypesIdPNG { 134 public byte byte1 = -1; 135 public byte byte2 = -1; 136 public char char1 = '0'; 137 public char char2 = '0'; 138 public short short1 = -1; 139 public short short2 = -1; 140 public int int1 = -1; 141 public int int2 = -1; 142 public long long1 = -1; 143 public long long2 = -1; 144 public Byte oByte1 = null; 145 public Byte oByte2 = null; 146 public Character oChar1 = null; 147 public Character oChar2 = null; 148 public Short oShort1 = null; 149 public Short oShort2 = null; 150 public Integer oInt1 = null; 151 public Integer oInt2 = null; 152 public Long oLong1 = null; 153 public Long oLong2 = null; 154 public String string1 = null; 155 public String string2 = null; 156 public Date date1 = null; 157 public Date date2 = null; 158 public byte[] bytearray1 = null; 159 public byte[] bytearray2 = null; 160 public char[] chararray1 = null; 161 public char[] chararray2 = null; 162 163 public PNG() { 164 } 165 166 public boolean equals(Object o) { 167 if (o instanceof CompositeAllTypesIdPNG) { 168 CompositeAllTypesIdPNG png = (CompositeAllTypesIdPNG) o; 169 try { 170 return byte1 == png.pnGetByteF1(null) && 171 byte2 == png.pnGetByteF2(null) && 172 char1 == png.pnGetCharF1(null) && 173 char2 == png.pnGetCharF2(null) && 174 short1 == png.pnGetShortF1(null) && 175 short2 == png.pnGetShortF2(null) && 176 int1 == png.pnGetIntF1(null) && 177 int2 == png.pnGetIntF2(null) && 178 long1 == png.pnGetLongF1(null) && 179 long2 == png.pnGetLongF2(null) && 180 oByte1 == png.pnGetOByteF1(null) && 181 oByte2 == png.pnGetOByteF2(null) && 182 oChar1 == png.pnGetOCharF1(null) && 183 oChar2 == png.pnGetOCharF2(null) && 184 oShort1 == png.pnGetOShortF1(null) && 185 oShort2 == png.pnGetOShortF2(null) && 186 oInt1 == png.pnGetOIntF1(null) && 187 oInt2 == png.pnGetOIntF2(null) && 188 oLong1 == png.pnGetOLongF1(null) && 189 oLong2 == png.pnGetOLongF2(null) && 190 string1 == png.pnGetStringF1(null) && 191 string2 == png.pnGetStringF2(null) && 192 date1 == png.pnGetDateF1(null) && 193 date2 == png.pnGetDateF2(null) && 194 bytearray1 == png.pnGetByteArrayF1(null) && 195 bytearray2 == png.pnGetByteArrayF2(null) && 196 chararray1 == png.pnGetCharArrayF1(null) && 197 chararray2 == png.pnGetCharArrayF2(null); 198 } catch (PException e) { 199 e.printStackTrace(); 200 return false; 201 } 202 } 203 return false; 204 } 205 206 public void setNameValue(AllTypesAccessor a) { 207 byte1 = a.byte1Name; 208 byte2 = a.byte2Name; 209 char1 = a.char1Name; 210 char2 = a.char2Name; 211 short1 = a.short1Name; 212 short2 = a.short2Name; 213 int1 = a.int1Name; 214 int2 = a.int2Name; 215 long1 = a.long1Name; 216 long2 = a.long2Name; 217 oByte1 = a.oByte1Name; 218 oByte2 = a.oByte2Name; 219 oChar1 = a.oChar1Name; 220 oChar2 = a.oChar2Name; 221 oShort1 = a.oShort1Name; 222 oShort2 = a.oShort2Name; 223 oInt1 = a.oInt1Name; 224 oInt2 = a.oInt2Name; 225 oLong1 = a.oLong1Name; 226 oLong2 = a.oLong2Name; 227 string1 = a.string1Name; 228 string2 = a.string2Name; 229 date1 = a.date1Name; 230 date2 = a.date2Name; 231 bytearray1 = a.bytearray1Name; 232 bytearray2 = a.bytearray2Name; 233 chararray1 = a.chararray1Name; 234 chararray2 = a.chararray2Name; 235 } 236 237 public void setMyself1Value(AllTypesAccessor a) { 238 byte1 = a.byte1Myself1; 239 byte2 = a.byte2Myself1; 240 char1 = a.char1Myself1; 241 char2 = a.char2Myself1; 242 short1 = a.short1Myself1; 243 short2 = a.short2Myself1; 244 int1 = a.int1Myself1; 245 int2 = a.int2Myself1; 246 long1 = a.long1Myself1; 247 long2 = a.long2Myself1; 248 oByte1 = a.oByte1Myself1; 249 oByte2 = a.oByte2Myself1; 250 oChar1 = a.oChar1Myself1; 251 oChar2 = a.oChar2Myself1; 252 oShort1 = a.oShort1Myself1; 253 oShort2 = a.oShort2Myself1; 254 oInt1 = a.oInt1Myself1; 255 oInt2 = a.oInt2Myself1; 256 oLong1 = a.oLong1Myself1; 257 oLong2 = a.oLong2Myself1; 258 string1 = a.string1Myself1; 259 string2 = a.string2Myself1; 260 date1 = a.date1Myself1; 261 date2 = a.date2Myself1; 262 bytearray1 = a.bytearray1Myself1; 263 bytearray2 = a.bytearray2Myself1; 264 chararray1 = a.chararray1Myself1; 265 chararray2 = a.chararray2Myself1; 266 } 267 268 public void setMyself2Value(AllTypesAccessor a) { 269 byte1 = a.byte1Myself2; 270 byte2 = a.byte2Myself2; 271 char1 = a.char1Myself2; 272 char2 = a.char2Myself2; 273 short1 = a.short1Myself2; 274 short2 = a.short2Myself2; 275 int1 = a.int1Myself2; 276 int2 = a.int2Myself2; 277 long1 = a.long1Myself2; 278 long2 = a.long2Myself2; 279 oByte1 = a.oByte1Myself2; 280 oByte2 = a.oByte2Myself2; 281 oChar1 = a.oChar1Myself2; 282 oChar2 = a.oChar2Myself2; 283 oShort1 = a.oShort1Myself2; 284 oShort2 = a.oShort2Myself2; 285 oInt1 = a.oInt1Myself2; 286 oInt2 = a.oInt2Myself2; 287 oLong1 = a.oLong1Myself2; 288 oLong2 = a.oLong2Myself2; 289 string1 = a.string1Myself2; 290 string2 = a.string2Myself2; 291 date1 = a.date1Myself2; 292 date2 = a.date2Myself2; 293 bytearray1 = a.bytearray1Myself2; 294 bytearray2 = a.bytearray2Myself2; 295 chararray1 = a.chararray1Myself2; 296 chararray2 = a.chararray2Myself2; 297 } 298 299 300 303 public char[] pnGetCharArrayF2(Object ctx) throws PException { 304 return chararray2; 305 } 306 307 public char[] pnGetCharArrayF1(Object ctx) throws PException { 308 return chararray1; 309 } 310 311 public int pnGetIntF2(Object ctx) throws PException { 312 return int2; 313 } 314 315 public int pnGetIntF1(Object ctx) throws PException { 316 return int1; 317 } 318 319 public Long pnGetOLongF2(Object ctx) throws PException { 320 return oLong2; 321 } 322 323 public Long pnGetOLongF1(Object ctx) throws PException { 324 return oLong1; 325 } 326 327 public short pnGetShortF2(Object ctx) throws PException { 328 return short2; 329 } 330 331 public short pnGetShortF1(Object ctx) throws PException { 332 return short1; 333 } 334 335 public byte[] pnGetByteArrayF2(Object ctx) throws PException { 336 return bytearray2; 337 } 338 339 public byte[] pnGetByteArrayF1(Object ctx) throws PException { 340 return bytearray1; 341 } 342 343 public byte pnGetByteF2(Object ctx) throws PException { 344 return byte2; 345 } 346 347 public char pnGetCharF2(Object ctx) throws PException { 348 return char2; 349 } 350 351 public byte pnGetByteF1(Object ctx) throws PException { 352 return byte1; 353 } 354 355 public char pnGetCharF1(Object ctx) throws PException { 356 return char1; 357 } 358 359 public Short pnGetOShortF2(Object ctx) throws PException { 360 return oShort2; 361 } 362 363 public Short pnGetOShortF1(Object ctx) throws PException { 364 return oShort1; 365 } 366 367 public Character pnGetOCharF2(Object ctx) throws PException { 368 return oChar2; 369 } 370 371 public Byte pnGetOByteF2(Object ctx) throws PException { 372 return oByte2; 373 } 374 375 public long pnGetLongF2(Object ctx) throws PException { 376 return long2; 377 } 378 379 public Character pnGetOCharF1(Object ctx) throws PException { 380 return oChar1; 381 } 382 383 public Byte pnGetOByteF1(Object ctx) throws PException { 384 return oByte1; 385 } 386 387 public String pnGetStringF2(Object ctx) throws PException { 388 return string2; 389 } 390 391 public long pnGetLongF1(Object ctx) throws PException { 392 return long1; 393 } 394 395 public String pnGetStringF1(Object ctx) throws PException { 396 return string1; 397 } 398 399 public Integer pnGetOIntF2(Object ctx) throws PException { 400 return oInt2; 401 } 402 403 public Date pnGetDateF2(Object ctx) throws PException { 404 return date2; 405 } 406 407 public Integer pnGetOIntF1(Object ctx) throws PException { 408 return oInt1; 409 } 410 411 public Date pnGetDateF1(Object ctx) throws PException { 412 return date1; 413 } 414 } 415 } 416 | Popular Tags |