Package org.dozer.vo

Examples of org.dozer.vo.TestObject


  }

  @Test
  public void testImplicitInnerObject() {
    // This tests that we implicitly map an inner object to an inner object without defining it in the mapping file
    TestObject to = newInstance(TestObject.class);
    to.setNoMappingsObj(testDataFactory.getInputTestNoClassMappingsNoCustomMappingsObject());
    TestObjectPrime dest2 = mapper.map(to, TestObjectPrime.class);
    TestObject source2 = mapper.map(dest2, TestObject.class);
    TestObjectPrime dest4 = mapper.map(source2, TestObjectPrime.class);
    assertEquals(dest2, dest4);
  }
View Full Code Here


  @Test
  public void testListField() throws Exception {
    // test empty list --> empty list
    TestObjectPrime dest = mapper.map(testDataFactory.getInputTestListFieldEmptyListTestObject(), TestObjectPrime.class);
    TestObject source = mapper.map(dest, TestObject.class);
    TestObjectPrime dest2 = mapper.map(source, TestObjectPrime.class);
    assertEquals(dest2, dest);

    // test empty array --> empty list
    dest = mapper.map(testDataFactory.getInputTestListFieldArrayListTestObject(), TestObjectPrime.class);
View Full Code Here

  }

  @Test
  public void testListUsingDestHint() throws Exception {
    TestObjectPrime dest = mapper.map(testDataFactory.getInputTestListUsingDestHintTestObject(), TestObjectPrime.class);
    TestObject source = mapper.map(dest, TestObject.class);
    TestObjectPrime dest2 = mapper.map(source, TestObjectPrime.class);
    assertEquals(dest, dest2);
  }
View Full Code Here

    // Map
    TestObjectPrime prime = mapper.map(testDataFactory.getInputGeneralMappingTestObject(), TestObjectPrime.class);
    assertEquals("excludeMe", prime.getExcludeMe());
    assertEquals("excludeMeOneWay", prime.getExcludeMeOneWay());
    // map back
    TestObject to = mapper.map(prime, TestObject.class);
    assertNull(to.getExcludeMe());
    assertEquals("excludeMeOneWay", to.getExcludeMeOneWay());
  }
View Full Code Here

  }

  @Test
  public void testGeneralMapping() throws Exception {
    // Map
    TestObject to = testDataFactory.getInputGeneralMappingTestObject();
    TestObjectPrime prime = mapper.map(to, TestObjectPrime.class);
    // valdidate that we copied by object reference -
    TestObject source = mapper.map(prime, TestObject.class);
    TestObjectPrime prime2 = mapper.map(source, TestObjectPrime.class);
    assertEquals(prime2, prime);
  }
View Full Code Here

  }

  @Test
  public void testGeneralMappingPassByReference() throws Exception {
    // Map
    TestObject to = testDataFactory.getInputGeneralMappingTestObject();
    TestObject toClone = SerializationUtils.clone(to);
    TestObjectPrime prime = mapper.map(to, TestObjectPrime.class);
    mapper.map(prime, to);
    // more objects should be added to the clone from the ArrayList
    TheFirstSubClass fsc = new TheFirstSubClass();
    fsc.setS("s");
    toClone.getHintList().add(fsc);
    toClone.getHintList().add(fsc);
    toClone.getEqualNamedList().add("1value");
    toClone.getEqualNamedList().add("2value");
    int[] pa = { 0, 1, 2, 3, 4, 0, 1, 2, 3, 4 };
    int[] intArray = { 1, 1, 1, 1 };
    Integer[] integerArray = { new Integer(1), new Integer(1), new Integer(1), new Integer(1) };
    toClone.setAnArray(intArray);
    toClone.setArrayForLists(integerArray);
    toClone.setPrimArray(pa);
    toClone.setBlankDate(null);
    toClone.setBlankStringToLong(null);
    // since we copy by reference the attribute copyByReference we need to null it out. The clone method above creates
    // two versions of it...
    // which is incorrect
    to.setCopyByReference(null);
    toClone.setCopyByReference(null);
    to.setCopyByReferenceDeep(null);
    toClone.setCopyByReferenceDeep(null);
    to.setGlobalCopyByReference(null);
    toClone.setGlobalCopyByReference(null);
    // null out string array because we get NPE since a NULL value in the String []
    to.setStringArrayWithNullValue(null);
    toClone.setStringArrayWithNullValue(null);
    toClone.setExcludeMeOneWay("excludeMeOneWay");
    assertEquals(toClone, to);
  }
View Full Code Here

  }

  @Test
  public void testLongToLongMapping() throws Exception {
    // Map
    TestObject source = testDataFactory.getInputGeneralMappingTestObject();
    source.setAnotherLongValue(42);
    TestObjectPrime prime2 = mapper.map(source, TestObjectPrime.class);
    Long value = prime2.getTheLongValue();
    assertEquals(value.longValue(), 42);
  }
View Full Code Here

    set.add(orange1);
    set.add(orange2);
    Set<Orange> set2 = newInstance(HashSet.class);
    set2.add(orange3);
    set2.add(orange4);
    TestObject to = newInstance(TestObject.class);
    to.setSetToArray(set);
    to.setSetToObjectArray(set2);

    TestObjectPrime top = mapper.map(to, TestObjectPrime.class);

    Set<String> fruitNames = new HashSet<String>();
    fruitNames.add(top.getArrayToSet()[0].getName());
    fruitNames.add(top.getArrayToSet()[1].getName());
    assertTrue(fruitNames.remove("orange1"));
    assertTrue(fruitNames.remove("orange2"));

    fruitNames.add(((Apple) top.getObjectArrayToSet()[0]).getName());
    fruitNames.add(((Apple) top.getObjectArrayToSet()[1]).getName());
    assertTrue(fruitNames.remove("orange3"));
    assertTrue(fruitNames.remove("orange4"));

    Apple apple = newInstance(Apple.class);
    apple.setName("apple1");
    Apple[] appleArray = { apple };
    top.setSetToArrayWithValues(appleArray);
    // now map back
    Apple apple2 = newInstance(Apple.class);
    apple2.setName("apple2");
    TestObject toDest = newInstance(TestObject.class);
    Set<Apple> hashSet = newInstance(HashSet.class);
    hashSet.add(apple2);
    toDest.setSetToArrayWithValues(hashSet);
    mapper.map(top, toDest);
    assertTrue(toDest.getSetToArray().contains(top.getArrayToSet()[0]));
    assertTrue(toDest.getSetToArray().contains(top.getArrayToSet()[1]));
    assertTrue(toDest.getSetToObjectArray().contains(top.getObjectArrayToSet()[0]));
    assertTrue(toDest.getSetToObjectArray().contains(top.getObjectArrayToSet()[1]));
    assertTrue(toDest.getSetToArrayWithValues().contains(apple));
    assertTrue(toDest.getSetToArrayWithValues().contains(apple2));
    assertTrue(toDest.getSetToArrayWithValues() instanceof HashSet);
  }
View Full Code Here

    Orange orange2 = newInstance(Orange.class);
    orange2.setName("orange2");
    Set<Orange> set = newInstance(HashSet.class);
    set.add(orange1);
    set.add(orange2);
    TestObject to = newInstance(TestObject.class);
    to.setSetToList(set);
    TestObjectPrime top = mapper.map(to, TestObjectPrime.class);
    assertEquals("orange1", ((Orange) top.getListToSet().get(0)).getName());
    assertEquals("orange2", ((Orange) top.getListToSet().get(1)).getName());
    List<Orange> list = newInstance(ArrayList.class);
    Orange orange4 = newInstance(Orange.class);
    orange4.setName("orange4");
    list.add(orange4);
    top.setSetToListWithValues(list);
    // Map back
    Orange orange3 = newInstance(Orange.class);
    orange3.setName("orange3");
    Set<Orange> set2 = newInstance(HashSet.class);
    set2.add(orange3);
    set2.add(orange4);
    TestObject toDest = newInstance(TestObject.class);
    toDest.setSetToListWithValues(set2);
    mapper.map(top, toDest);
    assertTrue(toDest.getSetToList().contains(top.getListToSet().get(0)));
    assertTrue(toDest.getSetToList().contains(top.getListToSet().get(1)));
    assertTrue(toDest.getSetToListWithValues().contains(orange3));
    assertTrue(toDest.getSetToListWithValues().contains(orange4));
  }
View Full Code Here

    custom.setSetDataType(set);
    return custom;
  }

  public TestObject getInputTestListFieldEmptyListTestObject() {
    TestObject custom = newInstance(TestObject.class);
    custom.setEqualNamedList(newInstance(ArrayList.class));
    return custom;
  }
View Full Code Here

TOP

Related Classes of org.dozer.vo.TestObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.