@Test public void test_contract_to_domain_conversion() { UserRequest userRequest = buildUserRequest(); final long loggedInUserId = 345L; User userForCreate = userRequest.toDomain(loggedInUserId, true); Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT")); c.set(2017, 1, 1, 1, 1, 1); String expectedDate = c.getTime().toString(); assertEquals("Kroorveer", userForCreate.getName()); assertEquals("yakku", userForCreate.getUsername()); assertEquals("Dr.", userForCreate.getSalutation()); assertEquals("8967452310", userForCreate.getMobileNumber()); assertEquals("kroorkool@maildrop.cc", userForCreate.getEmailId()); assertEquals("0987654321", userForCreate.getAltContactNumber()); assertEquals("KR12345J", userForCreate.getPan()); assertEquals("qwerty-1234567", userForCreate.getAadhaarNumber()); assertEquals(Long.valueOf(loggedInUserId), userForCreate.getLoggedInUserId()); assertTrue(userForCreate.getActive()); assertEquals(expectedDate, userForCreate.getDob().toString()); assertEquals(expectedDate, userForCreate.getPasswordExpiryDate().toString()); assertEquals("en_IN", userForCreate.getLocale()); assertEquals(UserType.CITIZEN, userForCreate.getType()); assertFalse(userForCreate.getAccountLocked()); assertEquals("signature", userForCreate.getSignature()); assertEquals("myPhoto", userForCreate.getPhoto()); assertEquals("hole in the mole", userForCreate.getIdentificationMark()); assertEquals(Gender.MALE, userForCreate.getGender()); assertEquals(BloodGroup.O_POSITIVE, userForCreate.getBloodGroup()); assertNotNull(userForCreate.getLastModifiedDate()); assertNotNull(userForCreate.getCreatedDate()); assertNotEquals(expectedDate, userForCreate.getLastModifiedDate().toString()); assertNotEquals(expectedDate, userForCreate.getCreatedDate().toString()); final Set<Role> roles = userForCreate.getRoles(); assertEquals(1, roles.size()); assertEquals("CITIZEN", roles.iterator().next().getCode()); assertEquals("ap.public", userForCreate.getTenantId()); assertEquals("otpreference1", userForCreate.getOtpReference()); assertEquals("!abcd1234", userForCreate.getPassword()); }
@JsonIgnore public User toDomain(Long loggedInUserId, boolean isCreate) { BloodGroup bloodGroup = null; try { if (this.bloodGroup != null) bloodGroup = BloodGroup.valueOf(this.bloodGroup.toUpperCase()); } catch (Exception e) { bloodGroup = BloodGroup.fromValue(this.bloodGroup); } return User.builder() .uuid(this.uuid) .id(this.id) .name(this.name) .username(this.userName) .salutation(this.salutation) .mobileNumber(this.mobileNumber) .emailId(this.emailId) .altContactNumber(this.altContactNumber) .pan(this.pan) .aadhaarNumber(this.aadhaarNumber) .active(isActive(isCreate)) .dob(this.dob) .passwordExpiryDate(this.pwdExpiryDate) .locale(this.locale) .type(this.type) .accountLocked(isAccountLocked(isCreate)) .accountLockedDate(this.accountLockedDate) .signature(this.signature) .photo(this.photo) .identificationMark(this.identificationMark) .gender(this.gender != null ? Gender.valueOf(this.gender.toUpperCase()) : null) .bloodGroup(bloodGroup) .lastModifiedDate(new Date()) .createdDate(new Date()) .otpReference(this.otpReference) .tenantId(this.tenantId) .password(this.password) .roles(toDomainRoles()) .loggedInUserId(loggedInUserId) .permanentAddress(toDomainPermanentAddress()) .correspondenceAddress(toDomainCorrespondenceAddress()) .guardian(fatherOrHusbandName) .build(); }
UserRequest { @JsonIgnore public User toDomain(Long loggedInUserId, boolean isCreate) { BloodGroup bloodGroup = null; try { if (this.bloodGroup != null) bloodGroup = BloodGroup.valueOf(this.bloodGroup.toUpperCase()); } catch (Exception e) { bloodGroup = BloodGroup.fromValue(this.bloodGroup); } return User.builder() .uuid(this.uuid) .id(this.id) .name(this.name) .username(this.userName) .salutation(this.salutation) .mobileNumber(this.mobileNumber) .emailId(this.emailId) .altContactNumber(this.altContactNumber) .pan(this.pan) .aadhaarNumber(this.aadhaarNumber) .active(isActive(isCreate)) .dob(this.dob) .passwordExpiryDate(this.pwdExpiryDate) .locale(this.locale) .type(this.type) .accountLocked(isAccountLocked(isCreate)) .accountLockedDate(this.accountLockedDate) .signature(this.signature) .photo(this.photo) .identificationMark(this.identificationMark) .gender(this.gender != null ? Gender.valueOf(this.gender.toUpperCase()) : null) .bloodGroup(bloodGroup) .lastModifiedDate(new Date()) .createdDate(new Date()) .otpReference(this.otpReference) .tenantId(this.tenantId) .password(this.password) .roles(toDomainRoles()) .loggedInUserId(loggedInUserId) .permanentAddress(toDomainPermanentAddress()) .correspondenceAddress(toDomainCorrespondenceAddress()) .guardian(fatherOrHusbandName) .build(); } }
UserRequest { @JsonIgnore public User toDomain(Long loggedInUserId, boolean isCreate) { BloodGroup bloodGroup = null; try { if (this.bloodGroup != null) bloodGroup = BloodGroup.valueOf(this.bloodGroup.toUpperCase()); } catch (Exception e) { bloodGroup = BloodGroup.fromValue(this.bloodGroup); } return User.builder() .uuid(this.uuid) .id(this.id) .name(this.name) .username(this.userName) .salutation(this.salutation) .mobileNumber(this.mobileNumber) .emailId(this.emailId) .altContactNumber(this.altContactNumber) .pan(this.pan) .aadhaarNumber(this.aadhaarNumber) .active(isActive(isCreate)) .dob(this.dob) .passwordExpiryDate(this.pwdExpiryDate) .locale(this.locale) .type(this.type) .accountLocked(isAccountLocked(isCreate)) .accountLockedDate(this.accountLockedDate) .signature(this.signature) .photo(this.photo) .identificationMark(this.identificationMark) .gender(this.gender != null ? Gender.valueOf(this.gender.toUpperCase()) : null) .bloodGroup(bloodGroup) .lastModifiedDate(new Date()) .createdDate(new Date()) .otpReference(this.otpReference) .tenantId(this.tenantId) .password(this.password) .roles(toDomainRoles()) .loggedInUserId(loggedInUserId) .permanentAddress(toDomainPermanentAddress()) .correspondenceAddress(toDomainCorrespondenceAddress()) .guardian(fatherOrHusbandName) .build(); } UserRequest(User user); }
UserRequest { @JsonIgnore public User toDomain(Long loggedInUserId, boolean isCreate) { BloodGroup bloodGroup = null; try { if (this.bloodGroup != null) bloodGroup = BloodGroup.valueOf(this.bloodGroup.toUpperCase()); } catch (Exception e) { bloodGroup = BloodGroup.fromValue(this.bloodGroup); } return User.builder() .uuid(this.uuid) .id(this.id) .name(this.name) .username(this.userName) .salutation(this.salutation) .mobileNumber(this.mobileNumber) .emailId(this.emailId) .altContactNumber(this.altContactNumber) .pan(this.pan) .aadhaarNumber(this.aadhaarNumber) .active(isActive(isCreate)) .dob(this.dob) .passwordExpiryDate(this.pwdExpiryDate) .locale(this.locale) .type(this.type) .accountLocked(isAccountLocked(isCreate)) .accountLockedDate(this.accountLockedDate) .signature(this.signature) .photo(this.photo) .identificationMark(this.identificationMark) .gender(this.gender != null ? Gender.valueOf(this.gender.toUpperCase()) : null) .bloodGroup(bloodGroup) .lastModifiedDate(new Date()) .createdDate(new Date()) .otpReference(this.otpReference) .tenantId(this.tenantId) .password(this.password) .roles(toDomainRoles()) .loggedInUserId(loggedInUserId) .permanentAddress(toDomainPermanentAddress()) .correspondenceAddress(toDomainCorrespondenceAddress()) .guardian(fatherOrHusbandName) .build(); } UserRequest(User user); @JsonIgnore User toDomain(Long loggedInUserId, boolean isCreate); }
UserRequest { @JsonIgnore public User toDomain(Long loggedInUserId, boolean isCreate) { BloodGroup bloodGroup = null; try { if (this.bloodGroup != null) bloodGroup = BloodGroup.valueOf(this.bloodGroup.toUpperCase()); } catch (Exception e) { bloodGroup = BloodGroup.fromValue(this.bloodGroup); } return User.builder() .uuid(this.uuid) .id(this.id) .name(this.name) .username(this.userName) .salutation(this.salutation) .mobileNumber(this.mobileNumber) .emailId(this.emailId) .altContactNumber(this.altContactNumber) .pan(this.pan) .aadhaarNumber(this.aadhaarNumber) .active(isActive(isCreate)) .dob(this.dob) .passwordExpiryDate(this.pwdExpiryDate) .locale(this.locale) .type(this.type) .accountLocked(isAccountLocked(isCreate)) .accountLockedDate(this.accountLockedDate) .signature(this.signature) .photo(this.photo) .identificationMark(this.identificationMark) .gender(this.gender != null ? Gender.valueOf(this.gender.toUpperCase()) : null) .bloodGroup(bloodGroup) .lastModifiedDate(new Date()) .createdDate(new Date()) .otpReference(this.otpReference) .tenantId(this.tenantId) .password(this.password) .roles(toDomainRoles()) .loggedInUserId(loggedInUserId) .permanentAddress(toDomainPermanentAddress()) .correspondenceAddress(toDomainCorrespondenceAddress()) .guardian(fatherOrHusbandName) .build(); } UserRequest(User user); @JsonIgnore User toDomain(Long loggedInUserId, boolean isCreate);  }