Package org.dozer

Examples of org.dozer.Mapper


    // assert 2 users in collection
    assertEquals("Two users in source usergroup expected.", 2, userGroup.getUsers().size());

    // get mapper
    Mapper mapper = getMapper(new String[] { "mapping-interface.xml" });

    // do mapping
    UserGroupPrime userGroupPrime = mapper.map(userGroup, UserGroupPrime.class);

    // check mapped group
    assertNotNull(userGroupPrime);
    assertEquals(userGroup.getName(), userGroupPrime.getName());
View Full Code Here


    // assert 2 users in collection
    assertEquals("Two users in source usergroup expected.", 2, userGroup.getUsers().size());

    // get mapper
    Mapper mapper = getMapper(new String[] { "mapping-concrete.xml" });

    // do mapping
    UserGroupPrime userGroupPrime = mapper.map(userGroup, UserGroupPrime.class);

    // check mapped group
    assertNotNull(userGroupPrime);
    assertEquals(userGroup.getName(), userGroupPrime.getName());
View Full Code Here

  public void testRecursiveSelfMapping_Iterate() {
    testMapping(c1, "selfreference_recursive_iterate.xml");
  }

  private void testMapping(ContainerBean c1, String mappingFile) {
    Mapper mapper = getMapper(mappingFile);

    try {
      ContainerBean2 c2 = mapper.map(c1, ContainerBean2.class);
      SelfReferencingBean mb1 = c2.getBeans().get(0);
      SelfReferencingBean mb2 = c2.getBeans().get(1);
      assertEquals(mb1.getId().longValue(), 1L);
      assertEquals(mb2.getId().longValue(), 2L);
      assertEquals(mb1.getOneToOne(), mb2);
View Full Code Here

   * test mapping of a generic field
   */
  @Test
  public void testSimpleGenerics() {

    Mapper mapper = new DozerBeanMapper();

    A a = new A();
    a.setId(15L);

    B b = mapper.map(a, B.class);
    Assert.assertEquals((Integer) a.getId().intValue(), b.getId());

    A a2 = mapper.map(a, A.class);
    Assert.assertEquals(a.getId(), a2.getId());

  }
View Full Code Here

  /**
   * test mapping of a generic field with inheritance
   */
  @Test
  public void testSimpleGenericsInheritance() {
    Mapper mapper = new DozerBeanMapper();

    B b = new B();
    b.setId(15);

    AA aa = mapper.map(b, AA.class);
    Assert.assertEquals((Long) b.getId().longValue(), aa.getId());

    AA aa2 = mapper.map(b, AA.class);
    Assert.assertEquals((Long) b.getId().longValue(), aa2.getId());

  }
View Full Code Here

   * Test mapping for deepn generic inheritance
   * @throws Exception
   */
  @Test
  public void testDeepGenericInheritanceTest() throws Exception {
    Mapper mapper = new DozerBeanMapper();

    B b = new B();
    b.setId(12345);
    C c1 = mapper.map(b, C.class);
    Assert.assertEquals(c1.getId().longValue(), 12345L);
  }
View Full Code Here

  /**
   * test mapping of an object with three type parameters
   */
  @Test
  public void testGenericsWithSeveralTypes() {
    Mapper mapper = new DozerBeanMapper();

    GenericTestType testType = new GenericTestType();
    testType.setA(15L);
    testType.setB("test");
    testType.setC(7);

    GenericTestType testType2 = mapper.map(testType, GenericTestType.class);
    Assert.assertEquals(testType.getA(), testType2.getA());
    Assert.assertEquals(testType.getB(), testType2.getB());
    Assert.assertEquals(testType.getC(), testType2.getC());
  }
View Full Code Here

    assertEquals(src, mappedSrc);
  }

  @Test
  public void testMapToMap() throws Exception {
    Mapper mapper = getMapper(new String[] { "mapInterfaceMapping.xml", "dozerBeanMapping.xml" });
    TestObject to = newInstance(TestObject.class);
    to.setOne("one");
    TestObject to2 = newInstance(TestObject.class);
    to2.setTwo(new Integer(2));
    Map<String, TestObject> map = newInstance(HashMap.class);
    map.put("to", to);
    map.put("to2", to2);

    Map<String, TestObject> map2 = newInstance(HashMap.class);
    map2.put("to", to);
    map2.put("to2", to2);

    MapToMap mtm = new MapToMap(map, map2);

    MapToMapPrime mtmp = mapper.map(mtm, MapToMapPrime.class);
    assertEquals("one", ((TestObject) mtmp.getStandardMap().get("to")).getOne());
    assertEquals(2, ((TestObject) mtmp.getStandardMap().get("to2")).getTwo().intValue());
    // verify that we transformed from object to object prime
    assertEquals("one", ((TestObjectPrime) mtmp.getStandardMapWithHint().get("to")).getOnePrime());
    assertEquals(2, ((TestObjectPrime) mtmp.getStandardMapWithHint().get("to2")).getTwoPrime().intValue());
View Full Code Here

    assertEquals(2, ((TestObjectPrime) mtmp.getStandardMapWithHint().get("to2")).getTwoPrime().intValue());
  }

  @Test
  public void testMapToMapExistingDestination() throws Exception {
    Mapper mapper = getMapper(new String[] { "mapInterfaceMapping.xml", "dozerBeanMapping.xml" });
    TestObject to = newInstance(TestObject.class);
    to.setOne("one");
    TestObject to2 = newInstance(TestObject.class);
    to2.setTwo(new Integer(2));
    Map<String, TestObject> map = newInstance(HashMap.class);
    map.put("to", to);
    map.put("to2", to2);
    MapToMap mtm = newInstance(MapToMap.class);
    mtm.setStandardMap(map);

    // create an existing map and set a value so we can test if it exists after
    // mapping
    MapToMapPrime mtmp = newInstance(MapToMapPrime.class);
    Map<String, Serializable> map2 = newInstance(Hashtable.class);
    map2.put("toDest", to);
    mtmp.setStandardMap(map2);

    mapper.map(mtm, mtmp);
    assertEquals("one", ((TestObject) mtmp.getStandardMap().get("to")).getOne());
    assertEquals(2, ((TestObject) mtmp.getStandardMap().get("to2")).getTwo().intValue());
    assertEquals("one", ((TestObject) mtmp.getStandardMap().get("toDest")).getOne());
  }
View Full Code Here

  @Test
  public void testNoMappingFilesSpecified() throws Exception {
    // Mapper can be used without specifying any mapping files. Fields that have the same name will be mapped
    // automatically.
    Mapper mapper = new DozerBeanMapper();

    assertCommon(mapper);
  }
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.