Package org.dozer

Examples of org.dozer.Mapper


    assertEquals("two", toDest.getFieldAccessibleArrayToList()[1]);
  }

  @Test
  public void testOverloadGetSetMethods() throws Exception {
    Mapper mapper = getMapper("fieldAttributeMapping.xml");
    TestObject to = newInstance(TestObject.class);
    Date date = new Date();
    to.setOverloadGetField(new Date());
    TestObjectPrime top = mapper.map(to, TestObjectPrime.class);
    assertEquals(date, top.getOverloadSetField());

    // Map Back
    TestObject toDest = (TestObject) mapper.map(top, TestObject.class);
    assertEquals(date, toDest.getOverloadGetField());
  }
View Full Code Here


    assertEquals(date, toDest.getOverloadGetField());
  }

  @Test
  public void testFieldCreateMethod() throws Exception {
    Mapper mapper = getMapper("fieldAttributeMapping.xml");
    TestObject to = newInstance(TestObject.class);
    InsideTestObject ito = newInstance(InsideTestObject.class);
    // we did not set any values. this will be set in the 'createMethod'
    to.setCreateMethodType(ito);
    TestObjectPrime top = mapper.map(to, TestObjectPrime.class);
    assertEquals("myField", top.getCreateMethodType().getMyField());

    // Map Back
    TestObject toDest = mapper.map(top, TestObject.class);
    assertEquals("testCreateMethod", toDest.getCreateMethodType().getTestCreateMethod());
  }
View Full Code Here

    assertEquals("testCreateMethod", toDest.getCreateMethodType().getTestCreateMethod());
  }

  @Test
  public void testIntegerToString() throws Exception {
    Mapper mapper = getMapper("fieldAttributeMapping.xml");
    TestObject to = newInstance(TestObject.class);
    Integer[] array = new Integer[] { new Integer(1), new Integer(2) };
    to.setArrayForLists(array);
    TestObjectPrime top = mapper.map(to, TestObjectPrime.class);
    assertEquals("1", top.getListForArray().get(0));
  }
View Full Code Here

    assertEquals("1", top.getListForArray().get(0));
  }

  @Test
  public void testMapNull_MappingLevel() throws Exception {
    Mapper mapper = getMapper("nullFieldMapping.xml");
    // check that null does not override an existing value when map-null="false"
    AnotherTestObject src = newInstance(AnotherTestObject.class);
    src.setField3(null);
    src.setField4(null);
    AnotherTestObjectPrime dest = newInstance(AnotherTestObjectPrime.class);
    dest.setTo(newInstance(TestObject.class));
    dest.setField3("555");
    dest.getTo().setOne("4641");

    // dest field should remain unchanged
    mapper.map(src, dest);
    assertEquals("invalid dest field value", "555", dest.getField3());
    assertEquals("invalid dest field value2", "4641", dest.getTo().getOne());
  }
View Full Code Here

    assertEquals("invalid dest field value2", "4641", dest.getTo().getOne());
  }

  @Test
  public void testMapNull_MappingLevel2() throws Exception {
    Mapper mapper = getMapper("nullFieldMapping.xml");
    // Reverse mapping
    AnotherTestObjectPrime src = newInstance(AnotherTestObjectPrime.class);
    src.setTo(newInstance(TestObject.class));
    src.setField3(null);
    src.getTo().setOne(null);
    AnotherTestObject dest = newInstance(AnotherTestObject.class);
    dest.setField3("555");
    dest.setField4("4641");

    // dest field should remain unchanged
    mapper.map(src, dest);
    assertEquals("invalid dest field value", "555", dest.getField3());
    assertEquals("invalid dest field value2", "4641", dest.getField4());
  }
View Full Code Here

    assertEquals("invalid dest field value2", "4641", dest.getField4());
  }

  @Test
  public void testMapEmptyString_MappingLevel() throws Exception {
    Mapper mapper = getMapper("nullFieldMapping.xml");
    // check that "" does not override an existing value when
    // map-empty-string="false"
    AnotherTestObject src = newInstance(AnotherTestObject.class);
    src.setField3("");
    src.setField4("");
    AnotherTestObjectPrime dest = newInstance(AnotherTestObjectPrime.class);
    dest.setTo(newInstance(TestObject.class));
    dest.setField3("555");
    dest.getTo().setOne("4641");

    // dest field should remain unchanged
    mapper.map(src, dest);
    assertEquals("invalid dest field value", "555", dest.getField3());
    assertEquals("invalid dest field value2", "4641", dest.getTo().getOne());
  }
View Full Code Here

    assertEquals("invalid dest field value2", "4641", dest.getTo().getOne());
  }

  @Test
  public void testMapEmptyString_MappingLevel2() throws Exception {
    Mapper mapper = getMapper("nullFieldMapping.xml");
    // reverse mapping
    AnotherTestObjectPrime src = newInstance(AnotherTestObjectPrime.class);
    src.setTo(newInstance(TestObject.class));
    src.setField3("");
    src.getTo().setOne("");
    AnotherTestObject dest = newInstance(AnotherTestObject.class);
    dest.setField3("555");
    dest.setField4("4641");

    // dest field should remain unchanged
    mapper.map(src, dest);
    assertEquals("invalid dest field value", "555", dest.getField3());
    assertEquals("invalid dest field value2", "4641", dest.getField4());
  }
View Full Code Here

    assertEquals("invalid dest field value2", "4641", dest.getField4());
  }

  @Test
  public void testMapNull_ClassLevel() throws Exception {
    Mapper mapper = getMapper("nullFieldMapping.xml");
    // check that null does not override an existing value when map-null="false"
    TestObject src = newInstance(TestObject.class);
    src.setOne(null);
    TestObjectPrime2 dest = newInstance(TestObjectPrime2.class);
    dest.setOne("555");

    // dest field should remain unchanged
    mapper.map(src, dest);
    assertNotNull("dest should not be null", dest.getOne());
    assertEquals("invalid dest field value", "555", dest.getOne());

    // reverse mapping
    TestObjectPrime2 src2 = newInstance(TestObjectPrime2.class);
    src2.setOne(null);
    TestObject dest2 = newInstance(TestObject.class);
    dest2.setOne("555");

    // dest field should NOT remain unchanged
    mapper.map(src2, dest2);
    assertNull("dest should be null", dest2.getOne());
  }
View Full Code Here

    assertNull("dest should be null", dest2.getOne());
  }

  @Test
  public void testMapEmptyString_ClassLevel() throws Exception {
    Mapper mapper = getMapper("nullFieldMapping.xml");
    // check that "" does not override an existing value when
    // map-empty-string="false"
    TestObject src = newInstance(TestObject.class);
    src.setOne("");
    TestObjectPrime2 dest = newInstance(TestObjectPrime2.class);
    dest.setOne("555");

    // dest field should remain unchanged
    mapper.map(src, dest);
    assertNotNull("dest should not be null", dest.getOne());
    assertEquals("invalid dest field value", "555", dest.getOne());

    // reverse mapping
    TestObjectPrime2 src2 = newInstance(TestObjectPrime2.class);
    src2.setOne("");
    TestObject dest2 = newInstance(TestObject.class);
    dest2.setOne("555");

    // dest field should NOT remain unchanged
    mapper.map(src2, dest2);
    assertNotNull("dest should not be null", dest2.getOne());
    assertEquals("dest should be an empty string", "", dest2.getOne());

  }
View Full Code Here

  }

  @Test
  public void testContextMappingWithNestedContext() throws Exception {
    Mapper mapper = getMapper("contextMapping.xml");

    ContextMappingNested cmn = newInstance(ContextMappingNested.class);
    cmn.setLoanNo("loanNoNested");
    List<ContextMappingNested> list = newInstance(ArrayList.class);
    list.add(cmn);
    ContextMapping cm = newInstance(ContextMapping.class);
    cm.setLoanNo("loanNo");
    cm.setContextList(list);

    ContextMappingPrime cmpA = mapper.map(cm, ContextMappingPrime.class, "caseA");
    assertNull(cmpA.getLoanNo());
    assertNull(((ContextMappingNestedPrime) cmpA.getContextList().get(0)).getLoanNo());

    ContextMappingPrime cmpB = mapper.map(cm, ContextMappingPrime.class, "caseB");
    assertEquals("loanNo", cmpB.getLoanNo());
    assertEquals("loanNoNested", ((ContextMappingNested) cmpB.getContextList().get(0)).getLoanNo());

    ContextMappingNestedPrime cmn2 = newInstance(ContextMappingNestedPrime.class);
    cmn2.setLoanNo("loanNoNested");
    List<ContextMappingNestedPrime> list2 = newInstance(ArrayList.class);
    list2.add(cmn2);
    ContextMappingPrime prime = newInstance(ContextMappingPrime.class);
    prime.setLoanNo("loanNo");
    prime.setContextList(list2);

    ContextMapping cmDest = mapper.map(prime, ContextMapping.class, "caseA");
    assertNull(cmDest.getLoanNo());
    assertNull(((ContextMappingNested) cmDest.getContextList().get(0)).getLoanNo());

    ContextMapping cmpBDest = mapper.map(prime, ContextMapping.class, "caseB");
    assertEquals("loanNo", cmpBDest.getLoanNo());
    assertEquals("loanNoNested", ((ContextMappingNestedPrime) cmpBDest.getContextList().get(0)).getLoanNo());
  }
View Full Code Here

TOP

Related Classes of org.dozer.Mapper

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.