Package org.dozer

Examples of org.dozer.Mapper


    assertEquals("invalid value for dest object", src.getStringProperty(), ((FieldValue) entry).getValue("theKey"));
  }

  @Test(expected = TestException.class)
  public void testAllowedExceptionsThrowException() throws Exception {
    Mapper mapper = getMapper("allowedExceptionsMapping.xml");
    TestObject to = newInstance(TestObject.class);
    to.setThrowAllowedExceptionOnMap("throw me");
    mapper.map(to, TestObjectPrime.class);
    fail("We should have thrown TestException");

  }
View Full Code Here


    fail("We should have thrown TestException");

  }

  public void testAllowedExceptionsDoNotThrowException() throws Exception {
    Mapper mapper = getMapper("allowedExceptionsMapping.xml");
    TestObject to2 = newInstance(TestObject.class);
    to2.setThrowNonAllowedExceptionOnMap("do not throw me");
    try {
      mapper.map(to2, TestObjectPrime.class);
    } catch (RuntimeException e) {
      fail("This should not have been thrown");
    }
  }
View Full Code Here

    }
  }

  @Test(expected = TestException.class)
  public void testAllowedExceptions_Implicit() throws Exception {
    Mapper mapper = getMapper("implicitAllowedExceptionsMapping.xml");
    ThrowException to = newInstance(ThrowException.class);
    to.setThrowAllowedException("throw me");
    mapper.map(to, ThrowExceptionPrime.class);
    fail("We should have thrown TestException");

  }
View Full Code Here

    // For some reason the resulting SomeVO contains a Set with 4 objects. 2 SomeOtherDTO's and 2 SomeOtherVO's. I
    // believe it
    // should only contain 2 SomeOtherVO's. It has something to do with specifying the field name starting with cap in
    // the mapping file. If
    // you change the field mapping to start with lower case it seems to map correctly.
    Mapper mapper = getMapper("setMappingWithUpperCaseFieldName.xml");

    SomeDTO someDto = newInstance(SomeDTO.class);
    someDto.setField1(new Integer("1"));

    SomeOtherDTO someOtherDto = newInstance(SomeOtherDTO.class);
    someOtherDto.setOtherField2(someDto);
    someOtherDto.setOtherField3("value1");

    SomeDTO someDto2 = newInstance(SomeDTO.class);
    someDto2.setField1(new Integer("2"));

    SomeOtherDTO someOtherDto2 = newInstance(SomeOtherDTO.class);
    someOtherDto2.setOtherField2(someDto2);
    someOtherDto2.setOtherField3("value2");

    SomeDTO src = newInstance(SomeDTO.class);
    src.setField2(new SomeOtherDTO[] { someOtherDto2, someOtherDto });

    SomeVO dest = mapper.map(src, SomeVO.class);

    assertEquals("incorrect resulting set size", src.getField2().length, dest.getField2().size());
    // TODO: add more asserts
  }
View Full Code Here

*/
public class OneWayMappingTest extends AbstractFunctionalTest {

  @Test
  public void testOneWay() {
    Mapper mapper = getMapper("oneWayMapping.xml");

    SourceClass source = newInstance(SourceClass.class, new Object[] {"A"});

    Holder holder = mapper.map(source, Holder.class);
    DestClass dest = holder.getDest();

    assertNotNull(dest);
    assertEquals("A", dest.anonymousAccessor());
  }
View Full Code Here

  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

    }

    // 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

    // 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

   * 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

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.