PersonResourceConverter extends AbstractConverter<PersonResource, Person> { @Override public Person convert(final PersonResource source, final Person target) { target.setBegDate(source.getBegDate()); target.setBirthPlace(source.getBirthPlace()); target.setDocNum(source.getDocNum()); target.setDocSeries(source.getDocSeries()); target.setEndDate(source.getEndDate()); target.setFatherName(source.getFatherName()); target.setFirstName(source.getFirstName()); target.setIdentifier(source.getIdentifier()); target.setIsHostel(source.getIsHostel()); target.setIsMilitary(source.getIsMilitary()); target.setName(source.getName()); target.setPhoto(source.getPhoto()); target.setResident(source.getResident()); target.setSurname(source.getSurname()); if (source.getPersonTypeId() != null) { PersonType personType = new PersonType(); personType.setId(source.getPersonTypeId()); target.setPersonType(personType); } if (source.getGenderTypeId() != null) { GenderType genderType = new GenderType(); genderType.setId(source.getGenderTypeId()); target.setGenderType(genderType); } if (source.getMarriedTypeId() != null) { MarriedType marriedType = new MarriedType(); marriedType.setId(source.getMarriedTypeId()); target.setMarriedType(marriedType); } if (source.getParentId() != null) { Person parent = new Person(); parent.setId(source.getParentId()); target.setParent(parent); } if (source.getCitizenCountryId() != null) { AdminUnit citizenCountry = new AdminUnit(); citizenCountry.setId(source.getCitizenCountryId()); target.setCitizenCountry(citizenCountry); } return target; }  @Override Person convert(final PersonResource source, final Person target); @Override Person convert(final PersonResource source);  }
@Test public void testConvert() throws Exception { Date begDate = new Date(); String birthPlace = "fsd"; String docNum = "gfdsf"; String docSeries = "fdafdsfs"; Date endDate = new Date(); String fatherName = " fdsfsdfsd"; String firstName = " gfdsgsd"; Long id = 1L; String identifier = "fdsfds"; Integer isHostel = 1; Integer isMilitary = 0; String name = "fdsfds"; String photo = "fdsdfsdfsd"; Integer resident = 1; String surname = "fdfds"; Long personTypeId = 2L; PersonType personType = new PersonType(); personType.setId(personTypeId); Long marriedTypeId = 4L; MarriedType marriedType = new MarriedType(); marriedType.setId(marriedTypeId); Long parentId = 5L; Person parent = new Person(); parent.setId(parentId); Long citizenCountryId = 6L; AdminUnit citizenCountry = new AdminUnit(); citizenCountry.setId(citizenCountryId); Long genderTypeId = 7L; GenderType genderType = new GenderType(); genderType.setId(genderTypeId); Person expected = new Person(); expected.setBegDate(begDate); expected.setBirthPlace(birthPlace); expected.setDocNum(docNum); expected.setDocSeries(docSeries); expected.setEndDate(endDate); expected.setFatherName(fatherName); expected.setFirstName(firstName); expected.setId(id); expected.setIdentifier(identifier); expected.setIsHostel(isHostel); expected.setIsMilitary(isMilitary); expected.setName(name); expected.setPhoto(photo); expected.setResident(resident); expected.setSurname(surname); expected.setPersonType(personType); expected.setGenderType(genderType); expected.setMarriedType(marriedType); expected.setParent(parent); expected.setCitizenCountry(citizenCountry); PersonResource source = new PersonResource(); source.setBegDate(begDate); source.setBirthPlace(birthPlace); source.setDocNum(docNum); source.setDocSeries(docSeries); source.setEndDate(endDate); source.setFatherName(fatherName); source.setFirstName(firstName); source.setId(id); source.setIdentifier(identifier); source.setIsHostel(isHostel); source.setIsMilitary(isMilitary); source.setName(name); source.setPhoto(photo); source.setResident(resident); source.setSurname(surname); source.setPersonTypeId(personTypeId); source.setGenderTypeId(genderTypeId); source.setMarriedTypeId(marriedTypeId); source.setParentId(parentId); source.setCitizenCountryId(citizenCountryId); Person actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { Date begDate = new Date(); String birthPlace = "fsd"; String docNum = "gfdsf"; String docSeries = "fdafdsfs"; Date endDate = new Date(); String fatherName = " fdsfsdfsd"; String firstName = " gfdsgsd"; Long id = 1L; String identifier = "fdsfds"; Integer isHostel = 1; Integer isMilitary = 0; String name = "fdsfds"; String photo = "fdsdfsdfsd"; Integer resident = 1; String surname = "fdfds"; Person expected = new Person(); expected.setBegDate(begDate); expected.setBirthPlace(birthPlace); expected.setDocNum(docNum); expected.setDocSeries(docSeries); expected.setEndDate(endDate); expected.setFatherName(fatherName); expected.setFirstName(firstName); expected.setId(id); expected.setIdentifier(identifier); expected.setIsHostel(isHostel); expected.setIsMilitary(isMilitary); expected.setName(name); expected.setPhoto(photo); expected.setResident(resident); expected.setSurname(surname); PersonResource source = new PersonResource(); source.setBegDate(begDate); source.setBirthPlace(birthPlace); source.setDocNum(docNum); source.setDocSeries(docSeries); source.setEndDate(endDate); source.setFatherName(fatherName); source.setFirstName(firstName); source.setId(id); source.setIdentifier(identifier); source.setIsHostel(isHostel); source.setIsMilitary(isMilitary); source.setName(name); source.setPhoto(photo); source.setResident(resident); source.setSurname(surname); Person actual = unit.convert(source); assertEquals(expected, actual); }