1 16 package net.sf.dozer.util.mapping.util; 17 18 import java.math.BigDecimal ; 19 import java.util.ArrayList ; 20 import java.util.Calendar ; 21 import java.util.Date ; 22 import java.util.GregorianCalendar ; 23 import java.util.HashMap ; 24 import java.util.HashSet ; 25 import java.util.List ; 26 import java.util.Map ; 27 import java.util.Random ; 28 import java.util.Set ; 29 30 import org.apache.commons.lang.RandomStringUtils; 31 import org.apache.commons.lang.math.RandomUtils; 32 33 import net.sf.dozer.util.mapping.vo.*; 34 import net.sf.dozer.util.mapping.vo.deep.Address; 35 import net.sf.dozer.util.mapping.vo.deep.City; 36 import net.sf.dozer.util.mapping.vo.deep.House; 37 import net.sf.dozer.util.mapping.vo.deep.Person; 38 import net.sf.dozer.util.mapping.vo.deep.Room; 39 import net.sf.dozer.util.mapping.vo.deep.SrcDeepObj; 40 import net.sf.dozer.util.mapping.vo.deep.SrcNestedDeepObj; 41 import net.sf.dozer.util.mapping.vo.deep.SrcNestedDeepObj2; 42 import net.sf.dozer.util.mapping.vo.inheritance.AnotherSubClass; 43 import net.sf.dozer.util.mapping.vo.inheritance.S2Class; 44 import net.sf.dozer.util.mapping.vo.inheritance.SClass; 45 import net.sf.dozer.util.mapping.vo.perf.MyClassA; 46 47 52 public abstract class TestDataFactory { 53 54 55 public static SubClass getSubClass() 56 { 57 SubClass obj = new SubClass(); 58 59 obj.setAttribute( "subclass" ); 60 obj.setSuperAttribute( "superclass" ); 61 62 List superList = new ArrayList (); 63 superList.add( "one" ); 64 superList.add( "two" ); 65 superList.add( "three" ); 66 67 obj.setSuperList( superList ); 68 obj.setSuperSuperAttribute("supersuperattribute"); 69 obj.setSuperSuperSuperAttr( "toplevel" ); 70 71 obj.setTestObject( TestDataFactory.getInputGeneralMappingTestObject() ); 72 HydrateTestObject2 sourceObj = new HydrateTestObject2(); 73 74 TestCustomConverterObject cobj = new TestCustomConverterObject(); 75 CustomDoubleObjectIF doub = new CustomDoubleObject(); 76 doub.setTheDouble(15); 77 cobj.setAttribute(doub); 78 79 obj.setCustomConvert( cobj ); 80 81 obj.setHydrate( sourceObj ); 82 83 obj.setSuperFieldToExclude("superFieldToExclude"); 84 85 return obj; 86 } 87 88 public static SrcDeepObj getSrcDeepObj() { 89 SrcDeepObj result = new SrcDeepObj(); 90 SrcNestedDeepObj srcNested = new SrcNestedDeepObj(); 91 SrcNestedDeepObj2 srcNested2 = new SrcNestedDeepObj2(); 92 FurtherTestObjectPrime furtherObjectPrime = new FurtherTestObjectPrime(); 93 94 srcNested2.setSrc5("nestedsrc2field5"); 95 furtherObjectPrime.setOne("fjd"); 96 97 srcNested.setSrc1("nestedsrc1"); 98 srcNested.setSrc2(Integer.valueOf("5")); 99 srcNested.setSrc3(90); 100 srcNested.setSrc4(new String [] { "item1", "item2", "item3" }); 101 srcNested.setSrcNestedObj2(srcNested2); 102 srcNested.setSrc6(furtherObjectPrime); 103 104 List hintList = new ArrayList (); 106 hintList.add("1"); 107 hintList.add("2"); 108 srcNested.setHintList(hintList); 109 110 TheFirstSubClass hintList2Obj = new TheFirstSubClass(); 112 hintList2Obj.setS("test"); 113 114 TheFirstSubClass hintList2Obj2 = new TheFirstSubClass(); 115 hintList2Obj.setS("test2"); 116 117 List hintList2 = new ArrayList (); 118 hintList2.add(hintList2Obj); 119 hintList2.add(hintList2Obj2); 120 srcNested.setHintList2(hintList2); 121 122 result.setSrcNestedObj(srcNested); 123 result.setSameNameField("sameNameField"); 124 125 return result; 126 } 127 128 public static House getHouse() { 129 House house = new House(); 130 Address address = new Address(); 131 address.setStreet("1234 street"); 132 City city = new City(); 133 city.setName("Denver"); 134 address.setCity(city); 135 136 house.setAddress(address); 137 138 Person person = new Person(); 139 person.setName("Franz"); 140 141 house.setOwner(person); 142 143 house.setPrice(1000000); 144 145 Van van = new Van(); 146 van.setName("van"); 147 van.setTestValue("testValue"); 148 house.setVan(van); 149 150 Room living = new Room(); 151 living.setName("Living"); 152 Room kitchen = new Room(); 153 kitchen.setName("kitchen"); 154 155 List rooms = new ArrayList (); 156 rooms.add(living); 157 rooms.add(kitchen); 158 159 house.setRooms(rooms); 160 List custom = new ArrayList (); 161 Van van2 = new Van(); 162 van2.setName("van2"); 163 custom.add(van2); 164 house.setCustomSetGetMethod(custom); 165 166 return house; 167 } 168 169 public static HydrateTestObject getExpectedTestNoSourceValueIterateFieldMapHydrateTestObject() { 170 Car car = new Car(); 171 car.setName("Build by buildCar"); 172 HydrateTestObject hto = new HydrateTestObject(); 173 hto.setCarArray(new Car[0]); 177 return hto; 178 } 179 180 public static NoCustomMappingsObject getInputTestNoClassMappingsNoCustomMappingsObject() { 181 NoCustomMappingsObject custom = new NoCustomMappingsObject(); 182 custom.setStringDataType("stringDataType"); 183 return custom; 184 } 185 186 public static NoCustomMappingsObject getInputTestMapFieldWithMapNoCustomMappingsObject() { 187 NoCustomMappingsObject custom = new NoCustomMappingsObject(); 188 Map map = new HashMap (); 189 map.put("1", "1value"); 190 map.put("2", "2value"); 191 custom.setMapDataType(map); 192 return custom; 193 } 194 195 public static NoCustomMappingsObject getInputTestMapFieldWithEmptyMapNoCustomMappingsObject() { 196 NoCustomMappingsObject custom = new NoCustomMappingsObject(); 197 Map map = new HashMap (); 198 custom.setMapDataType(map); 199 return custom; 200 } 201 202 public static NoCustomMappingsObject getInputTestSetFieldWithSetNoCustomMappingsObject() { 203 NoCustomMappingsObject custom = new NoCustomMappingsObject(); 204 Set set = new HashSet (); 205 set.add("1value"); 206 set.add("2value"); 207 custom.setSetDataType(set); 208 return custom; 209 } 210 211 public static NoCustomMappingsObject getInputTestSetFieldWithSetEmptyCustomMappingsObject() { 212 NoCustomMappingsObject custom = new NoCustomMappingsObject(); 213 Set set = new HashSet (); 214 custom.setSetDataType(set); 215 return custom; 216 } 217 218 public static NoCustomMappingsObject getInputTestSetFieldComplexSetNoCustomMappingsObject() { 219 NoCustomMappingsObject custom = new NoCustomMappingsObject(); 220 Set set = new HashSet (); 221 set.add(getInputTestNoClassMappingsNoCustomMappingsObject()); 222 custom.setSetDataType(set); 223 return custom; 224 } 225 226 public static TestObject getInputTestListFieldEmptyListTestObject() { 227 TestObject custom = new TestObject(); 228 custom.setEqualNamedList(new ArrayList ()); 229 return custom; 230 } 231 232 public static TestObject getInputTestListFieldArrayListTestObject() { 233 TestObject custom = new TestObject(); 234 Integer [] array = { new Integer (1) }; 235 custom.setArrayForLists(array); 236 return custom; 237 } 238 239 public static TestObject getInputTestListUsingDestHintTestObject() { 240 TestObject custom = new TestObject(); 241 List list = new ArrayList (); 242 list.add(new TheFirstSubClass()); 243 custom.setHintList(list); 244 return custom; 245 } 246 247 public static TestObject getInputGeneralMappingTestObject() { 248 TestObject custom = new TestObject(); 249 custom.setOne("one"); 250 custom.setTwo(new Integer (2)); 251 252 int[] pa = { 0 , 1, 2, 3,4}; 253 custom.setPrimArray( pa ); 254 255 InsideTestObject ito = new InsideTestObject(); 256 ito.setLabel("label"); 257 ito.setWrapper(new Integer (1)); 258 ito.setToWrapper(1); 259 260 custom.setThree(ito); 261 262 InsideTestObject ito2 = new InsideTestObject(); 264 ito2.setLabel("label"); 265 custom.setInsideTestObject(ito2); 266 267 List list1 = new ArrayList (); 268 list1.add("1value"); 269 list1.add("2value"); 270 List list2 = new ArrayList (); 271 list2.add("1value"); 272 list2.add("2value"); 273 custom.setEqualNamedList(list1); 274 custom.setUnequalNamedList(list2); 275 276 custom.setThePrimitive(3); 277 custom.setTheMappedPrimitive(4); 278 279 int[] intArray = { 1, 1 }; 280 Integer [] integerArray = { new Integer (1), new Integer (1) }; 281 custom.setAnArray(intArray); 282 custom.setArrayForLists(integerArray); 283 custom.setBigDecimalToInt(new BigDecimal (1)); 284 custom.setIntToBigDecimal(1); 285 Date date = new Date (); 286 custom.setDate(date); 287 GregorianCalendar calendar = new GregorianCalendar (); 288 calendar.setTime(date); 289 custom.setCalendar(calendar); 290 Van van = new Van(); 291 van.setName("van"); 292 van.setTestValue("testValue"); 293 custom.setVan(van); 294 custom.setExcludeMe("takemeout"); 295 296 MetalThingyIF car = new Car(); 298 car.setName("metalthingy"); 299 custom.setCarMetalThingy(car); 300 301 List hintList = new ArrayList (); 302 TheFirstSubClass fsc = new TheFirstSubClass(); 303 TheFirstSubClass fsc2 = new TheFirstSubClass(); 304 fsc.setS("s"); 305 fsc2.setS("s"); 306 hintList.add(fsc); 307 hintList.add(fsc2); 308 309 custom.setHintList(hintList); 310 311 custom.setBlankDate(""); 312 custom.setBlankStringToLong(""); 313 NoExtendBaseObject nebo = new NoExtendBaseObject(); 314 custom.setCopyByReference(nebo); 315 NoExtendBaseObject nebo2 = new NoExtendBaseObject(); 316 custom.setCopyByReferenceDeep(nebo2); 317 NoExtendBaseObjectGlobalCopyByReference globalNebo = new NoExtendBaseObjectGlobalCopyByReference(); 318 custom.setGlobalCopyByReference(globalNebo); 319 320 String [] stringArray = new String [] { null, "one", "two" }; 321 custom.setStringArrayWithNullValue(stringArray); 322 return custom; 323 } 324 325 public static FurtherTestObject getInputTestNoWildcardsFurtherTestObject() { 326 FurtherTestObject custom = new FurtherTestObject(); 327 custom.setOne("label"); 328 custom.setTwo("another"); 329 return custom; 330 } 331 332 public static DehydrateTestObject getInputTestHydrateAndMoreDehydrateTestObject() { 333 DehydrateTestObject custom = new DehydrateTestObject(); 334 Car car = new Car(); 335 car.setName("name"); 336 List carList = new ArrayList (); 337 carList.add(car); 338 custom.setCars(carList); 339 340 Apple apple = new Apple(); 341 apple.setName("name"); 342 Orange orange = new Orange(); 343 orange.setName("name"); 344 List fruitList = new ArrayList (); 345 fruitList.add(apple); 346 fruitList.add(orange); 347 custom.setFruit(fruitList); 348 349 Van van = new Van(); 350 van.setName("name"); 351 List vanList = new ArrayList (); 352 vanList.add(van); 353 custom.setVans(vanList); 354 355 AppleComputer apple1 = new AppleComputer(); 356 apple1.setName("name"); 357 AppleComputer apple2 = new AppleComputer(); 358 apple2.setName("name"); 359 List compList = new ArrayList (); 360 compList.add(apple1); 361 compList.add(apple2); 362 custom.setAppleComputers(compList); 363 364 Car iterateCar = new Car(); 365 iterateCar.setName("name"); 366 List iterateCarList = new ArrayList (); 367 iterateCarList.add(car); 368 custom.setIterateCars(iterateCarList); 369 370 Car iterateMoreCar = new Car(); 371 iterateCar.setName("name"); 372 List iterateMoreCarList = new ArrayList (); 373 iterateMoreCarList.add(car); 374 custom.setIterateMoreCars(iterateMoreCarList); 375 376 return custom; 377 } 378 379 public static HydrateTestObject getExpectedTestHydrateAndMoreHydrateTestObject() { 380 HydrateTestObject hto = new HydrateTestObject(); 381 Car car = new Car(); 382 car.setName("name"); 383 Car buildByCar = new Car(); 384 buildByCar.setName("Build by buildCar"); 385 Van van = new Van(); 386 van.setName("name"); 387 388 AppleComputer apple1 = new AppleComputer(); 389 apple1.setName("name"); 390 AppleComputer apple2 = new AppleComputer(); 391 apple2.setName("name"); 392 List compList = new ArrayList (); 393 compList.add(apple1); 394 compList.add(apple2); 395 hto.setComputers(compList); 396 List iterateCars = new ArrayList (); 397 iterateCars.add(car); 398 hto.setIterateCars(iterateCars); 399 Car[] carArray = { car }; 400 hto.setCarArray(carArray); 401 return hto; 402 } 403 404 405 406 public static HydrateTestObject getInputTestHydrateAndMoreHydrateTestObject() { 407 HydrateTestObject hto = new HydrateTestObject(); 408 Car car = new Car(); 409 car.setName("name"); 410 Van van = new Van(); 411 van.setName("name"); 412 List vehicles = new ArrayList (); 413 vehicles.add(car); 414 vehicles.add(van); 415 hto.setVehicles(vehicles); 416 417 Apple apple = new Apple(); 418 apple.setName("name"); 419 Orange orange = new Orange(); 420 orange.setName("name"); 421 List apples = new ArrayList (); 422 apples.add(apple); 423 List oranges = new ArrayList (); 424 oranges.add(orange); 425 426 hto.setApples(apples); 427 hto.setOranges(oranges); 428 429 AppleComputer apple1 = new AppleComputer(); 430 apple1.setName("name"); 431 AppleComputer apple2 = new AppleComputer(); 432 apple2.setName("name"); 433 List compList = new ArrayList (); 434 compList.add(apple1); 435 compList.add(apple2); 436 hto.setComputers(compList); 437 438 List iterateCars = new ArrayList (); 439 iterateCars.add(car); 440 hto.setIterateCars(iterateCars); 441 return hto; 442 443 } 444 445 public static DehydrateTestObject getExpectedTestHydrateAndMoreDehydrateTestObject() { 446 DehydrateTestObject custom = new DehydrateTestObject(); 447 Car car = new Car(); 448 car.setName("name"); 449 450 AppleComputer apple1 = new AppleComputer(); 451 apple1.setName("name"); 452 AppleComputer apple2 = new AppleComputer(); 453 apple2.setName("name"); 454 List compList = new ArrayList (); 455 compList.add(apple1); 456 compList.add(apple2); 457 custom.setAppleComputers(compList); 458 List iterateCars = new ArrayList (); 459 iterateCars.add(car); 460 custom.setIterateCars(iterateCars); 461 return custom; 462 } 463 464 public static SimpleObj getSimpleObj() { 465 SimpleObj result = new SimpleObj(); 466 result.setField1("one"); 467 result.setField2(Integer.valueOf("2")); 468 result.setField3(BigDecimal.valueOf(3)); 469 result.setField4(new Double (44.44)); 470 result.setField5(Calendar.getInstance()); 471 result.setField6("66"); 472 473 return result; 474 } 475 476 public static AnotherSubClass getAnotherSubClass() { 477 AnotherSubClass asub = new AnotherSubClass(); 478 asub.setBaseAttribute("base"); 479 asub.setSubAttribute("sub"); 480 List list = new ArrayList (); 481 SClass s = new SClass(); 482 s.setBaseSubAttribute("sBase"); 483 s.setSubAttribute("s"); 484 S2Class s2 = new S2Class(); 485 s2.setBaseSubAttribute("s2Base"); 486 s2.setSub2Attribute("s2"); 487 list.add(s2); 488 list.add(s); 489 asub.setSubList(list); 490 491 List list2 = new ArrayList (); 492 SClass sclass = new SClass(); 493 sclass.setBaseSubAttribute("sBase"); 494 sclass.setSubAttribute("s"); 495 S2Class s2class = new S2Class(); 496 s2class.setBaseSubAttribute("s2Base"); 497 s2class.setSub2Attribute("s2"); 498 SClass sclass2 = new SClass(); 499 sclass2.setBaseSubAttribute("sclass2"); 500 sclass2.setSubAttribute("sclass2"); 501 list2.add(s2class); 502 list2.add(sclass); 503 list2.add(sclass2); 504 asub.setListToArray(list2); 505 506 SClass sclassA = new SClass(); 507 SClass sclassB = new SClass(); 508 sclassA.setBaseSubAttribute("sBase"); 509 sclassA.setSubAttribute("s"); 510 sclassB.setBaseSubAttribute("sBase"); 511 sclassB.setSubAttribute("s"); 512 asub.setSClass(sclassA); 513 asub.setSClass2(sclassB); 514 515 return asub; 516 } 517 518 public static MyClassA getRandomMyClassA() { 519 final Date today = new Date (); 520 final Random rand = new Random (today.getTime()); 521 Calendar cal = Calendar.getInstance(); 522 cal.set(RandomUtils.nextInt(rand, 3000), RandomUtils.nextInt(rand, 12), 523 RandomUtils.nextInt(rand, 31)); 524 525 MyClassA myClassAObj = new MyClassA(); 526 myClassAObj.setAStringList(getRandomStringList(500)); 527 528 return myClassAObj; 529 } 530 531 private static List getRandomStringList(int listSize) { 532 List stringList = new ArrayList (listSize); 533 534 for (int count = 0; count < listSize; count = count + 1) { 535 stringList.add(RandomStringUtils.randomAlphabetic(255)); 536 } 537 538 return stringList; 539 } 540 541 } 542 | Popular Tags |