Examples of Mapper


Examples of org.dozer.Mapper

    if (mappingFiles != null) {
      for (int i = 0; i < mappingFiles.length; i++) {
        list.add(mappingFiles[i]);
      }
    }
    Mapper mapper = new DozerBeanMapper();
    ((DozerBeanMapper) mapper).setMappingFiles(list);
    return mapper;
  }
View Full Code Here

Examples of org.dozer.Mapper

  }

  @Test
  public void testNoClassMappings() throws Exception {
    Mapper mapper = new DozerBeanMapper();
    // Should attempt mapping even though it is not in the beanmapping.xml file
    NoCustomMappingsObjectPrime dest1 = mapper.map(testDataFactory.getInputTestNoClassMappingsNoCustomMappingsObject(),
        NoCustomMappingsObjectPrime.class);
    NoCustomMappingsObject source = mapper.map(dest1, NoCustomMappingsObject.class);
    NoCustomMappingsObjectPrime dest3 = mapper.map(source, NoCustomMappingsObjectPrime.class);
    assertEquals(dest1, dest3);
  }
View Full Code Here

Examples of org.dozer.Mapper

    assertNotNull("field1 should have been mapped", dest.getField1());
  }

  @Test
  public void testBidirectionalWithCustomMapping() throws Exception {
    Mapper mapper = getMapper(new String[] { "infiniteLoopMapping.xml" });
    LoopObjectParent loopObjectParent = newInstance(LoopObjectParent.class);
    LoopObjectChild loopObjectChild = newInstance(LoopObjectChild.class);
    loopObjectChild.setParent(loopObjectParent);
    loopObjectParent.setChild(loopObjectChild);

    LoopObjectParentPrime loopObjectParentPrime = mapper.map(loopObjectParent, LoopObjectParentPrime.class);
    assertNotNull(loopObjectParentPrime);
    assertNotNull(loopObjectParentPrime.getChildPrime());
  }
View Full Code Here

Examples of org.dozer.Mapper

      org.dozer.vo.C c = newInstance(org.dozer.vo.C.class);
      c.setValue(Integer.toString(i));
      a.getCs()[i] = c;
    }

    Mapper mapper = DozerBeanMapperSingletonWrapper.getInstance();
    mapper.map(a, b);

    // Check if C object nr i holds value i after the mapping
    for (int i = 0; i < b.getCs().length; i++) {
      assertEquals("Wrong value ", b.getCs()[i].getValue(), Integer.toString(i));
    }
View Full Code Here

Examples of org.dozer.Mapper

  protected Mapper getMapper(String ... mappingFiles) {
    List<String> list = new ArrayList<String>();
    if (mappingFiles != null) {
      list.addAll(Arrays.asList(mappingFiles));
    }
    Mapper result = new DozerBeanMapper();
    ((DozerBeanMapper) result).setMappingFiles(list);
    return result;
  }
View Full Code Here

Examples of org.dozer.Mapper

    }

    // get mapper
    List<String> mappingFiles = new ArrayList<String>();
    mappingFiles.add("interface-recursion-mappings.xml");
    Mapper mapper = new DozerBeanMapper(mappingFiles);

    // do mapping
    UserGroupPrime userGroupPrime = null;
    try {
      userGroupPrime = mapper.map(userGroup, UserGroupPrime.class);
    } catch (StackOverflowError e) {
      fail("Recursive mapping caused a stack overflow.");
    }

    // check mapped group
View Full Code Here

Examples of org.dozer.Mapper

    assertNull(house2.getOwner().getYourName());
  }

  @Test
  public void testDeepInterfaceWithHint() throws Exception {
    Mapper mapper = getMapper(new String[] { "fieldAttributeMapping.xml" });
    InsideTestObject ito = newInstance(InsideTestObject.class);
    House house = newInstance(House.class);
    MetalThingyIF thingy = newInstance(Car.class);
    thingy.setName("name");
    house.setThingy(thingy);
    ito.setHouse(house);
    InsideTestObjectPrime itop = mapper.map(ito, InsideTestObjectPrime.class);
    assertEquals("name", itop.getDeepInterfaceString());

    mapper.map(itop, InsideTestObject.class);
    assertEquals("name", ito.getHouse().getThingy().getName());
  }
View Full Code Here

Examples of org.dozer.Mapper

*/
public class GenericCollectionMappingTest extends AbstractFunctionalTest {

  @Test
  public void testGenericCollectionMapping() throws Exception {
    Mapper mapper = getMapper(new String[] { "genericCollectionMapping.xml" });

    // prepare beans
    User user1 = newInstance(User.class);
    user1.setFirstName("first name 1");
    user1.setLastName("last name 1");

    User user2 = newInstance(User.class);
    user2.setFirstName("first name 2");
    user2.setLastName("last name 2");

    Set<User> users = newInstance(HashSet.class);
    users.add(user1);
    users.add(user2);

    UserGroup userGroup = newInstance(UserGroup.class);
    userGroup.setName("usergroup name");
    userGroup.setUsers(users);
    userGroup.setStatus(Status.SUCCESS);

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

    // prove access to generic type information
    Method setter = UserGroupPrime.class.getMethod("setUsers", List.class);
    Type[] parameterTypes = setter.getGenericParameterTypes();
    assertEquals(1, parameterTypes.length);
    ParameterizedType parameterType = (ParameterizedType) parameterTypes[0];
    assertEquals(List.class, parameterType.getRawType());
    assertEquals(UserPrime.class, parameterType.getActualTypeArguments()[0]);

    // check group
    assertNotNull(userGroupPrime);
    assertEquals(userGroup.getName(), userGroupPrime.getName());

    // check resulting collection
    List<?> usersPrime = userGroupPrime.getUsers();
    assertNotNull(usersPrime);
    assertEquals(2, usersPrime.size());
    assertTrue("Expecting instance of UserPrime.", usersPrime.get(0) instanceof UserPrime);
    assertTrue("Expecting instance of UserPrime.", usersPrime.get(1) instanceof UserPrime);
    assertEquals("SUCCESS", userGroupPrime.getStatusPrime().name());

    // Map the other way
    UserGroup userGroupMapBack = mapper.map(userGroupPrime, UserGroup.class);
    Set<?> usersGroupPrime = userGroupMapBack.getUsers();
    assertNotNull(usersGroupPrime);
    assertEquals(2, usersGroupPrime.size());
    assertTrue("Expecting instance of UserPrime.", usersGroupPrime.iterator().next() instanceof User);
  }
View Full Code Here

Examples of org.dozer.Mapper

    assertTrue("Expecting instance of UserPrime.", usersGroupPrime.iterator().next() instanceof User);
  }

  @Test
  public void testDeepMappingWithIndexOnSrcField() {
    Mapper mapper = getMapper(new String[] { "genericCollectionMapping.xml" });

    AnotherTestObject anotherTestObject = newInstance(AnotherTestObject.class);
    anotherTestObject.setField3("another test object field 3 value");
    anotherTestObject.setField4("6453");

    TestObject testObject1 = newInstance(TestObject.class);
    TestObject testObject2 = newInstance(TestObject.class);
    testObject2.setEqualNamedList(Arrays.asList(new AnotherTestObject[] { anotherTestObject }));

    SrcDeepObj src = newInstance(SrcDeepObj.class);
    src.setSomeList(Arrays.asList(new TestObject[] { testObject1, testObject2 }));

    DestDeepObj dest = mapper.map(src, DestDeepObj.class);
    assertEquals("another test object field 3 value", dest.getDest5());
    assertEquals(Integer.valueOf("6453"), (dest.getHintList().get(0)).getTwoPrime());
  }
View Full Code Here

Examples of org.dozer.Mapper

    assertEquals(Integer.valueOf("6453"), (dest.getHintList().get(0)).getTwoPrime());
  }

  @Test
  public void testDeepMappingWithIndexOnDestField() {
    Mapper mapper = getMapper(new String[] { "genericCollectionMapping.xml" });
    DestDeepObj src = newInstance(DestDeepObj.class);
    src.setDest5("some string value for field");

    SrcDeepObj dest = mapper.map(src, SrcDeepObj.class);
    assertEquals("some string value for field", dest.getSomeList().get(1).getEqualNamedList().get(0).getField3());
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.