@Test
  public void shouldMapMapElements() {
    // given
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();

    mapperFactory
        .classMap(BasicPerson.class, BasicPersonDto.class)
        .field("namePartsMap[\"first\"]", "firstName")
        .field("namePartsMap['second']", "lastName")
        .register();

    BasicPerson bp = new BasicPerson();
    Map<String, String> nameParamsMap = new HashMap<String, String>();
    nameParamsMap.put("first", "Jan");
    nameParamsMap.put("second", "Kowalski");
    bp.setNamePartsMap(nameParamsMap);

    // when
    MapperFacade mapperFacade = mapperFactory.getMapperFacade();
    BasicPersonDto result = mapperFacade.map(bp, BasicPersonDto.class);

    // then
    assertThat(result.getFirstName()).isEqualTo("Jan");
    assertThat(result.getLastName()).isEqualTo("Kowalski");
    assertThat(result.getBirthDate()).isNull();
    assertThat(result.getCurrentAge()).isEqualTo(0);
    assertThat(result.getFullName()).isNull();
  }
  @Test
  public void testMapElementProperties() {

    MapperFactory factory = MappingUtil.getMapperFactory();

    factory
        .classMap(Person.class, PersonDto.class)
        .field("name.first", "names['first']")
        .field("name.last", "names[\"last\"]")
        .register();

    MapperFacade mapper = factory.getMapperFacade();

    Person person = new Person();
    person.name = new Name();
    person.name.first = "Chuck";
    person.name.last = "Testa";

    PersonDto result = mapper.map(person, PersonDto.class);

    Assert.assertNotNull(result.names);
    Assert.assertEquals(person.name.first, result.names.get("first"));
    Assert.assertEquals(person.name.last, result.names.get("last"));

    Person mapBack = mapper.map(result, Person.class);

    Assert.assertNotNull(mapBack.name.first);
    Assert.assertEquals(person.name.first, mapBack.name.first);
    Assert.assertEquals(person.name.last, mapBack.name.last);
  }
  @Test
  public void shouldMapNestedElement() {
    // given
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();

    mapperFactory
        .classMap(BasicPerson.class, BasicPersonDto.class)
        .field("nestedElement.nip", "nip")
        .register();

    BasicPerson bp = new BasicPerson();
    NestedElement nestedElement = new NestedElement();
    nestedElement.setNip(NIP);
    bp.setNestedElement(nestedElement);

    // when
    MapperFacade mapperFacade = mapperFactory.getMapperFacade();
    BasicPersonDto result = mapperFacade.map(bp, BasicPersonDto.class);

    // then
    assertThat(result.getNip()).isNotNull();
    assertThat(result.getNip()).isEqualTo(NIP);
    assertThat(result.getFirstName()).isNull();
    assertThat(result.getLastName()).isNull();
    assertThat(result.getBirthDate()).isNull();
    assertThat(result.getCurrentAge()).isEqualTo(0);
    assertThat(result.getFullName()).isNull();
  }
  @Test
  public void shouldMapWithCustomizedClassMapBuilder() {
    // given
    MapperFactory mapperFactory =
        new DefaultMapperFactory.Builder()
            .classMapBuilderFactory(new ScoringClassMapBuilder.Factory())
            .build();

    mapperFactory.classMap(Source.class, Destination.class).byDefault().register();

    MapperFacade mapperFacade = mapperFactory.getMapperFacade();

    Source src = new Source();
    src.firstName = "Jan";
    src.postalAddress = new PostalAddress();
    src.postalAddress.country = new Country();
    src.postalAddress.country.alphaCode = "PL";

    // when
    Destination result = mapperFacade.map(src, Destination.class);

    // then
    assertThat(result.name.first).isEqualTo("Jan");
    assertThat(result.countryCode).isEqualTo("PL");
  }
  @Test
  public void shouldNotMapNulls_ClassLevel() {
    // given
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().mapNulls(true).build();

    mapperFactory.classMap(Container.class, Container.class).mapNulls(false).byDefault().register();

    Container a = new Container();
    Container b = new Container();

    b.longValue = 1L;
    b.stringValue = "TEST A";
    b.arrayOfString = new String[] {"a", "b", "c"};
    b.arrayOfInt = new int[] {1, 2, 3};
    b.listOfString = Arrays.asList("l1", "l2");
    b.map = Collections.singletonMap("key", (Object) "value");
    b.enumValue = Position.FIRST;

    // when
    mapperFactory.getMapperFacade().map(a, b);

    // then
    assertThat(b.stringValue).isNotNull();
    assertThat(b.arrayOfString).isNotNull();
    assertThat(b.arrayOfInt).isNotNull();
    assertThat(b.listOfString).isNotNull();
    assertThat(b.map).isNotNull();
    assertThat(b.enumValue).isNotNull();
  }
  @Test
  public void shouldExplicitlySpecifyConstructor() {
    // given
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();

    mapperFactory
        .classMap(BasicPerson.class, BasicPersonDtoWithConstructor.class)
        .constructorB("birthDate")
        .fieldAToB("name", "fullName")
        //                .field("age", "currentAge")
        .byDefault()
        .register();

    BasicPerson bp = createBasicPerson("Jan", 20, Calendar.getInstance().getTime());

    // when
    MapperFacade mapperFacade = mapperFactory.getMapperFacade();
    BasicPersonDtoWithConstructor result =
        mapperFacade.map(bp, BasicPersonDtoWithConstructor.class);

    // then
    assertThat(result.getFullName()).isEqualTo(bp.getName());
    assertThat(result.getCurrentAge()).isEqualTo(0); // !!
    assertThat(result.getBirthDate()).isNotNull();
  }
  @Test
  public void shouldMapListElements() {
    // given
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();

    mapperFactory
        .classMap(BasicPerson.class, BasicPersonDto.class)
        .field("nameParts[0]", "firstName")
        .field("nameParts[1]", "lastName")
        .register();

    BasicPerson bp = new BasicPerson();
    bp.setNameParts(Lists.asList("Jan", new String[] {"Kowalski"}));

    // when
    MapperFacade mapperFacade = mapperFactory.getMapperFacade();
    BasicPersonDto result = mapperFacade.map(bp, BasicPersonDto.class);

    // then
    assertThat(result.getFirstName()).isEqualTo("Jan");
    assertThat(result.getLastName()).isEqualTo("Kowalski");
    assertThat(result.getBirthDate()).isNull();
    assertThat(result.getCurrentAge()).isEqualTo(0);
    assertThat(result.getFullName()).isNull();
  }
  @Test
  public void testFail() {
    MapperFactory factory = new DefaultMapperFactory.Builder().build();

    factory.registerClassMap(
        factory
            .classMap(Base.class, BaseDto.class)
            .customize(
                new CustomMapper<Base, BaseDto>() {
                  @Override
                  public void mapAtoB(Base base, BaseDto baseDto, MappingContext context) {
                    baseDto.setBaseField(base.getBaseTrickField());
                  }
                })
            .toClassMap());
    factory.registerClassMap(
        factory.classMap(Child.class, ChildDto.class).byDefault().toClassMap());

    Child child = new Child();
    child.setChildField("CHILD FIELD");
    child.setBaseTrickField("BASE FIELD");

    ChildDto dto = factory.getMapperFacade(Child.class, ChildDto.class).map(child);

    Assert.assertNotNull(dto);
    Assert.assertEquals(child.getChildField(), dto.getChildField());
    Assert.assertEquals(child.getBaseTrickField(), dto.getBaseField());
  }
예제 #9
0
/** Created by User on 9/21/2015. */
public class ShowTransformer {

  static final MapperFactory MAPPER_FACTORY = new DefaultMapperFactory.Builder().build();

  private static final BoundMapperFacade<RESTShow, Show> SHOW_MAPPER_FACADE =
      MAPPER_FACTORY.getMapperFacade(RESTShow.class, Show.class);

  private static final BoundMapperFacade<Show, RESTShow> REST_SHOW_MAPPER_FACADE =
      MAPPER_FACTORY.getMapperFacade(Show.class, RESTShow.class);

  public static Show transformShow(final RESTShow input) {
    return SHOW_MAPPER_FACADE.map(input);
  }

  public static RESTShow transformRESTShow(final Show input) {
    return REST_SHOW_MAPPER_FACADE.map(input);
  }
}
예제 #10
0
 public MapperFacade getClientMapperFacade() {
   MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
   ClassMapBuilder<Client, ClientDetailsEntity> clientClassMap =
       mapperFactory.classMap(Client.class, ClientDetailsEntity.class);
   clientClassMap.field("name", "clientName");
   clientClassMap.field("description", "clientDescription");
   clientClassMap.byDefault();
   clientClassMap.register();
   return mapperFactory.getMapperFacade();
 }
예제 #11
0
 @Test
 public void testMapOfEnum() {
   DefaultMapperFactory.Builder builder = new DefaultMapperFactory.Builder();
   MapperFactory factory = builder.build();
   MapperFacade mapperFacade = factory.getMapperFacade();
   Entity entity = new Entity();
   entity.setState(State.B);
   final Dto dto = mapperFacade.map(entity, Dto.class);
   Assert.assertEquals(dto.getState(), entity.getState());
 }
예제 #12
0
  @BeforeClass
  public static void init() {

    DefaultMapperFactory.Builder factoryBuilder = new DefaultMapperFactory.Builder();
    factoryBuilder.compilerStrategy(new EclipseJdtCompilerStrategy());
    MapperFactory factory = factoryBuilder.build();

    factory.getConverterFactory().registerConverter(new Converter.Object2String());
    factory.getConverterFactory().registerConverter(new Converter.String2Object());

    mapper = factory.getMapperFacade();
  }
예제 #13
0
  public MapperFacade getEmploymentMapperFacade() {
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
    ClassMapBuilder<Employment, OrgAffiliationRelationEntity> classMap =
        mapperFactory.classMap(Employment.class, OrgAffiliationRelationEntity.class);
    addV2CommonFields(classMap);
    registerSourceConverters(mapperFactory, classMap);
    classMap.field("organization.name", "org.name");
    classMap.field("organization.address.city", "org.city");
    classMap.field("organization.address.region", "org.region");
    classMap.field("organization.address.country", "org.country");
    classMap.field(
        "organization.disambiguatedOrganization.disambiguatedOrganizationIdentifier",
        "org.orgDisambiguated.sourceId");
    classMap.field(
        "organization.disambiguatedOrganization.disambiguationSource",
        "org.orgDisambiguated.sourceType");
    classMap.field("departmentName", "department");
    classMap.field("roleTitle", "title");
    classMap.register();

    ClassMapBuilder<EmploymentSummary, OrgAffiliationRelationEntity> employmentSummaryClassMap =
        mapperFactory.classMap(EmploymentSummary.class, OrgAffiliationRelationEntity.class);
    addV2CommonFields(employmentSummaryClassMap);
    registerSourceConverters(mapperFactory, employmentSummaryClassMap);
    employmentSummaryClassMap.field("organization.name", "org.name");
    employmentSummaryClassMap.field("organization.address.city", "org.city");
    employmentSummaryClassMap.field("organization.address.region", "org.region");
    employmentSummaryClassMap.field("organization.address.country", "org.country");
    employmentSummaryClassMap.field(
        "organization.disambiguatedOrganization.disambiguatedOrganizationIdentifier",
        "org.orgDisambiguated.sourceId");
    employmentSummaryClassMap.field(
        "organization.disambiguatedOrganization.disambiguationSource",
        "org.orgDisambiguated.sourceType");
    employmentSummaryClassMap.field("departmentName", "department");
    employmentSummaryClassMap.field("roleTitle", "title");
    employmentSummaryClassMap.register();

    mapperFactory
        .classMap(FuzzyDate.class, StartDateEntity.class)
        .field("year.value", "year")
        .field("month.value", "month")
        .field("day.value", "day")
        .register();
    mapperFactory
        .classMap(FuzzyDate.class, EndDateEntity.class)
        .field("year.value", "year")
        .field("month.value", "month")
        .field("day.value", "day")
        .register();
    return mapperFactory.getMapperFacade();
  }
예제 #14
0
 public MapperFacade getEmailMapperFacade() {
   MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
   ClassMapBuilder<Email, EmailEntity> emailClassMap =
       mapperFactory.classMap(Email.class, EmailEntity.class);
   emailClassMap.byDefault();
   emailClassMap.field("email", "id");
   emailClassMap.field("primary", "primary");
   emailClassMap.field("verified", "verified");
   addV2DateFields(emailClassMap);
   registerSourceConverters(mapperFactory, emailClassMap);
   emailClassMap.register();
   return mapperFactory.getMapperFacade();
 }
예제 #15
0
 public MapperFacade getKeywordMapperFacade() {
   MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
   ClassMapBuilder<Keyword, ProfileKeywordEntity> keywordClassMap =
       mapperFactory.classMap(Keyword.class, ProfileKeywordEntity.class);
   addV2DateFields(keywordClassMap);
   registerSourceConverters(mapperFactory, keywordClassMap);
   keywordClassMap.field("putCode", "id");
   keywordClassMap.field("content", "keywordName");
   keywordClassMap.fieldBToA("displayIndex", "displayIndex");
   keywordClassMap.byDefault();
   keywordClassMap.register();
   return mapperFactory.getMapperFacade();
 }
예제 #16
0
 public MapperFacade getNameMapperFacade() {
   MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
   ClassMapBuilder<Name, RecordNameEntity> nameClassMap =
       mapperFactory.classMap(Name.class, RecordNameEntity.class);
   addV2DateFields(nameClassMap);
   nameClassMap.field("creditName.content", "creditName");
   nameClassMap.field("givenNames.content", "givenNames");
   nameClassMap.field("familyName.content", "familyName");
   nameClassMap.field("path", "profile.id");
   nameClassMap.byDefault();
   nameClassMap.register();
   return mapperFactory.getMapperFacade();
 }
  @Test
  public void testBeanToCustomMapGeneration() throws Exception {

    MapperFactory factory = MappingUtil.getMapperFactory();

    Type<Map<String, String>> mapType = new TypeBuilder<Map<String, String>>() {}.build();
    Type<Student> studentType = TypeFactory.valueOf(Student.class);

    factory
        .classMap(Student.class, mapType)
        .field("grade.letter", "letterGrade")
        .field("grade.point", "GPA")
        .field("grade.percentage", "gradePercentage")
        .field("name.first", "firstName")
        .field("name.last", "lastName")
        .byDefault()
        .register();

    MapperFacade mapper = factory.getMapperFacade();

    Student student = new Student();
    student.id = "1";
    student.email = "*****@*****.**";
    student.name = new Name();
    student.name.first = "Chuck";
    student.name.last = "Testa";
    student.grade = new Grade();
    student.grade.letter = "B-";
    student.grade.percentage = 81.5;
    student.grade.point = 2.7;

    Map<String, String> result = mapper.map(student, studentType, mapType);

    Assert.assertEquals(student.id, result.get("id"));
    Assert.assertEquals(student.email, result.get("email"));
    Assert.assertEquals(student.name.first, result.get("firstName"));
    Assert.assertEquals(student.name.last, result.get("lastName"));
    Assert.assertEquals(student.grade.letter, result.get("letterGrade"));
    Assert.assertEquals("" + student.grade.percentage, result.get("gradePercentage"));
    Assert.assertEquals("" + student.grade.point, result.get("GPA"));

    Student mapBack = mapper.map(result, mapType, studentType);

    Assert.assertEquals(student.id, mapBack.id);
    Assert.assertEquals(student.email, mapBack.email);
    Assert.assertEquals(student.name.first, mapBack.name.first);
    Assert.assertEquals(student.name.last, mapBack.name.last);
    Assert.assertEquals(student.grade.letter, mapBack.grade.letter);
    Assert.assertEquals(student.grade.percentage, mapBack.grade.percentage);
    Assert.assertEquals(student.grade.point, mapBack.grade.point);
  }
예제 #18
0
 public MapperFacade getAddressMapperFacade() {
   MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
   ClassMapBuilder<Address, AddressEntity> addressClassMap =
       mapperFactory.classMap(Address.class, AddressEntity.class);
   addV2DateFields(addressClassMap);
   registerSourceConverters(mapperFactory, addressClassMap);
   addressClassMap.field("putCode", "id");
   addressClassMap.field("country.value", "iso2Country");
   addressClassMap.field("visibility", "visibility");
   addressClassMap.fieldBToA("displayIndex", "displayIndex");
   addressClassMap.byDefault();
   addressClassMap.register();
   return mapperFactory.getMapperFacade();
 }
예제 #19
0
 public MapperFacade getResearcherUrlMapperFacade() {
   MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
   ClassMapBuilder<ResearcherUrl, ResearcherUrlEntity> researcherUrlClassMap =
       mapperFactory.classMap(ResearcherUrl.class, ResearcherUrlEntity.class);
   addV2DateFields(researcherUrlClassMap);
   registerSourceConverters(mapperFactory, researcherUrlClassMap);
   researcherUrlClassMap.field("putCode", "id");
   researcherUrlClassMap.field("url.value", "url");
   researcherUrlClassMap.field("urlName", "urlName");
   researcherUrlClassMap.fieldBToA("displayIndex", "displayIndex");
   researcherUrlClassMap.byDefault();
   researcherUrlClassMap.register();
   return mapperFactory.getMapperFacade();
 }
예제 #20
0
 public MapperFacade getOtherNameMapperFacade() {
   MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
   ClassMapBuilder<OtherName, OtherNameEntity> otherNameClassMap =
       mapperFactory.classMap(OtherName.class, OtherNameEntity.class);
   addV2DateFields(otherNameClassMap);
   registerSourceConverters(mapperFactory, otherNameClassMap);
   otherNameClassMap.field("putCode", "id");
   otherNameClassMap.field("content", "displayName");
   otherNameClassMap.field("path", "profile.orcid");
   otherNameClassMap.fieldBToA("displayIndex", "displayIndex");
   otherNameClassMap.byDefault();
   otherNameClassMap.register();
   return mapperFactory.getMapperFacade();
 }
  @Test
  public void testBeanToMapGeneration() throws Exception {

    MapperFactory factory = MappingUtil.getMapperFactory();

    factory
        .classMap(Student.class, Map.class)
        .field("grade.letter", "letterGrade")
        .field("grade.point", "GPA")
        .field("grade.percentage", "gradePercentage")
        .field("name.first", "firstName")
        .field("name.last", "lastName")
        .byDefault()
        .register();

    MapperFacade mapper = factory.getMapperFacade();

    Student student = new Student();
    student.id = "1";
    student.email = "*****@*****.**";
    student.name = new Name();
    student.name.first = "Chuck";
    student.name.last = "Testa";
    student.grade = new Grade();
    student.grade.letter = "B-";
    student.grade.percentage = 81.5;
    student.grade.point = 2.7;

    @SuppressWarnings("unchecked")
    Map<String, Object> result = mapper.map(student, Map.class);

    Assert.assertEquals(student.id, result.get("id"));
    Assert.assertEquals(student.email, result.get("email"));
    Assert.assertEquals(student.name.first, result.get("firstName"));
    Assert.assertEquals(student.name.last, result.get("lastName"));
    Assert.assertEquals(student.grade.letter, result.get("letterGrade"));
    Assert.assertEquals(student.grade.percentage, result.get("gradePercentage"));
    Assert.assertEquals(student.grade.point, result.get("GPA"));

    Student mapBack = mapper.map(result, Student.class);

    Assert.assertEquals(student.id, mapBack.id);
    Assert.assertEquals(student.email, mapBack.email);
    Assert.assertEquals(student.name.first, mapBack.name.first);
    Assert.assertEquals(student.name.last, mapBack.name.last);
    Assert.assertEquals(student.grade.letter, mapBack.grade.letter);
    Assert.assertEquals(student.grade.percentage, mapBack.grade.percentage);
    Assert.assertEquals(student.grade.point, mapBack.grade.point);
  }
예제 #22
0
  @Bean
  public Mapper mapper() {
    EditorMapper mapper = new EditorMapper();
    // http://stackoverflow.com/a/32309223/1203690
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();

    ConverterFactory converterFactory = mapperFactory.getConverterFactory();

    converterFactory.registerConverter(new PassThroughConverter(LocalDate.class));

    converterFactory.registerConverter(new PassThroughConverter(LocalDateTime.class));
    mapper.setMapperFacade(mapperFactory.getMapperFacade());

    return mapper;
  }
예제 #23
0
  public MapperFacade getGroupIdRecordMapperFacade() {
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();

    ClassMapBuilder<GroupIdRecord, GroupIdRecordEntity> classMap =
        mapperFactory.classMap(GroupIdRecord.class, GroupIdRecordEntity.class);
    addV2CommonFields(classMap);
    registerSourceConverters(mapperFactory, classMap);
    classMap.field("name", "groupName");
    classMap.field("groupId", "groupId");
    classMap.field("description", "groupDescription");
    classMap.field("type", "groupType");
    classMap.register();

    return mapperFactory.getMapperFacade();
  }
  static {
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();

    mapperFactory
        .classMap(Customer.class, com.intuit.ipp.data.Customer.class)
        .field("firstName", "givenName")
        .field("lastName", "familyName")
        .field("emailAddress", "primaryEmailAddr.address")
        .field("phoneNumber", "primaryPhone.freeFormNumber")
        .exclude("id")
        .byDefault()
        .register();

    domainToQBOMapper =
        mapperFactory.getMapperFacade(Customer.class, com.intuit.ipp.data.Customer.class);
  }
예제 #25
0
  public MapperFacade getExternalIdentifierMapperFacade() {
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
    ClassMapBuilder<PersonExternalIdentifier, ExternalIdentifierEntity> externalIdentifierClassMap =
        mapperFactory.classMap(PersonExternalIdentifier.class, ExternalIdentifierEntity.class);
    addV2DateFields(externalIdentifierClassMap);
    externalIdentifierClassMap.field("putCode", "id");
    externalIdentifierClassMap.field("type", "externalIdCommonName");
    externalIdentifierClassMap.field("value", "externalIdReference");
    externalIdentifierClassMap.field("url.value", "externalIdUrl");
    externalIdentifierClassMap.fieldBToA("displayIndex", "displayIndex");
    externalIdentifierClassMap.byDefault();
    registerSourceConverters(mapperFactory, externalIdentifierClassMap);

    // TODO: add relationship to database schema for people.
    externalIdentifierClassMap.register();
    return mapperFactory.getMapperFacade();
  }
  @Test
  public void shouldMapBigDecimalToPrimtiveDouble() {

    MapperFactory factory = MappingUtil.getMapperFactory();
    factory
        .getConverterFactory()
        .registerConverter(
            new CustomConverter<BigDecimal, Double>() {

              public Double convert(BigDecimal source, Type<? extends Double> destinationType) {
                return new Double(source.doubleValue());
              }
            });

    A source = new A();
    source.setValue(BigDecimal.TEN);
    B dest = factory.getMapperFacade().map(source, B.class);

    Assert.assertEquals(new Double(10), (Double) dest.getValue());
  }
  @Test
  public void shouldCustomizeMapping() {
    // given
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();

    mapperFactory
        .classMap(BasicPerson.class, BasicPersonDto.class)
        .field("age", "currentAge")
        .byDefault()
        .customize(
            new CustomMapper<BasicPerson, BasicPersonDto>() {
              @Override
              public void mapAtoB(
                  BasicPerson basicPerson, BasicPersonDto basicPersonDto, MappingContext context) {
                Joiner joiner = Joiner.on(" ");
                String fullName =
                    joiner
                        .appendTo(
                            new StringBuilder(basicPerson.getName()).append(" "),
                            basicPerson.getNameParts())
                        .toString();

                basicPersonDto.setFullName(fullName);
              }
            })
        .register();

    BasicPerson bp = createBasicPerson("Jan", 20, Calendar.getInstance().getTime());
    bp.setNameParts(Lists.asList("von", new String[] {"Kowalski"}));

    // when
    MapperFacade mapperFacade = mapperFactory.getMapperFacade();
    BasicPersonDto result = mapperFacade.map(bp, BasicPersonDto.class);

    // then
    assertThat(result.getFullName()).isEqualTo("Jan von Kowalski");
    assertThat(result.getCurrentAge()).isEqualTo(bp.getAge());
    assertThat(result.getBirthDate()).isNotNull();
  }
  @Test
  public void shouldRegisterClassMap() {
    // given
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();

    mapperFactory
        .classMap(BasicPerson.class, BasicPersonDto.class)
        .field("name", "fullName")
        .field("age", "currentAge")
        .register();

    BasicPerson bp = createBasicPerson("Jan", 20, Calendar.getInstance().getTime());

    // when
    MapperFacade mapperFacade = mapperFactory.getMapperFacade();
    BasicPersonDto result = mapperFacade.map(bp, BasicPersonDto.class);

    // then
    assertThat(result.getFullName()).isEqualTo(bp.getName());
    assertThat(result.getCurrentAge()).isEqualTo(bp.getAge());
    assertThat(result.getBirthDate()).isNull();
  }
  @Test
  public void testNestedMapElement() {

    MapperFactory factory = MappingUtil.getMapperFactory();

    factory
        .classMap(Person.class, PersonDto2.class)
        .field("name.first", "names['self'].first")
        .field("name.last", "names['self'].last")
        .field("father.first", "names['father'].first")
        .field("father.last", "names['father'].last")
        .register();

    MapperFacade mapper = factory.getMapperFacade();

    Person person = new Person();
    person.name = new Name();
    person.name.first = "Chuck";
    person.name.last = "Testa";
    person.father = new Name();
    person.father.first = "Buck";
    person.father.last = "Testa";

    PersonDto2 result = mapper.map(person, PersonDto2.class);

    Assert.assertNotNull(result.names);
    Assert.assertEquals(person.name.first, result.names.get("self").first);
    Assert.assertEquals(person.name.last, result.names.get("self").last);
    Assert.assertEquals(person.father.first, result.names.get("father").first);
    Assert.assertEquals(person.father.last, result.names.get("father").last);

    Person mapBack = mapper.map(result, Person.class);

    Assert.assertNotNull(mapBack.name.first);
    Assert.assertEquals(person.name.first, mapBack.name.first);
    Assert.assertEquals(person.name.last, mapBack.name.last);
    Assert.assertEquals(person.father.first, mapBack.father.first);
    Assert.assertEquals(person.father.last, mapBack.father.last);
  }
  @Test
  public void shouldUseOnlyOneDirectionMapping() {
    // given
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();

    mapperFactory
        .classMap(BasicPerson.class, BasicPersonDto.class)
        .fieldAToB("name", "fullName")
        .field("age", "currentAge")
        .field("birthDate", "birthDate")
        .register();

    BasicPerson bpSrc = createBasicPerson("Jan", 20, Calendar.getInstance().getTime());

    BasicPersonDto bpDtoSrc = new BasicPersonDto();
    bpDtoSrc.setFullName("Jan");
    bpDtoSrc.setCurrentAge(20);
    bpDtoSrc.setBirthDate(Calendar.getInstance().getTime());

    // when
    BoundMapperFacade<BasicPerson, BasicPersonDto> boundMapper =
        mapperFactory.getMapperFacade(BasicPerson.class, BasicPersonDto.class);

    BasicPersonDto bpDtoDest = boundMapper.map(bpSrc);
    BasicPerson bpDest = boundMapper.mapReverse(bpDtoSrc);

    // then
    assertThat(bpDtoDest.getCurrentAge()).isEqualTo(bpSrc.getAge());
    assertThat(bpDtoDest.getFullName()).isEqualTo(bpSrc.getName());
    assertThat(bpDtoDest.getBirthDate()).isEqualTo(bpSrc.getBirthDate());

    assertThat(bpDest.getAge()).isEqualTo(bpDtoSrc.getCurrentAge());
    assertThat(bpDest.getName()).isNull();
    assertThat(bpDest.getBirthDate()).isEqualTo(bpDtoSrc.getBirthDate());
  }