BAEL-6572: Added mapping for id and test, based on review comment
This commit is contained in:
parent
c3141107b9
commit
f0f66ceba9
@ -4,6 +4,7 @@ import java.time.Duration;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.time.ZoneOffset;
|
import java.time.ZoneOffset;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.mapstruct.AfterMapping;
|
import org.mapstruct.AfterMapping;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
@ -20,6 +21,7 @@ public interface LicenseMapper {
|
|||||||
@Mapping(target = "endDate", ignore = true)
|
@Mapping(target = "endDate", ignore = true)
|
||||||
@Mapping(target = "active", constant = "true")
|
@Mapping(target = "active", constant = "true")
|
||||||
@Mapping(target = "renewalRequired", conditionExpression = "java(isEndDateInTwoWeeks(licenseDto))", source = ".")
|
@Mapping(target = "renewalRequired", conditionExpression = "java(isEndDateInTwoWeeks(licenseDto))", source = ".")
|
||||||
|
@Mapping(target = "id", expression = "java(setId())")
|
||||||
License toLicense(LicenseDto licenseDto);
|
License toLicense(LicenseDto licenseDto);
|
||||||
|
|
||||||
@AfterMapping
|
@AfterMapping
|
||||||
@ -40,4 +42,8 @@ public interface LicenseMapper {
|
|||||||
.toDays() <= 14;
|
.toDays() <= 14;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default UUID setId() {
|
||||||
|
return UUID.randomUUID();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ class LicenseMapperUnitTest {
|
|||||||
licenseDto.setStartDate(LocalDateTime.now());
|
licenseDto.setStartDate(LocalDateTime.now());
|
||||||
License license = licenseMapper.toLicense(licenseDto);
|
License license = licenseMapper.toLicense(licenseDto);
|
||||||
assertThat(license).isNotNull();
|
assertThat(license).isNotNull();
|
||||||
|
assertThat(license.getId()).isNotNull();
|
||||||
assertThat(license.getEndDate()
|
assertThat(license.getEndDate()
|
||||||
.toLocalDate()).isEqualTo(LocalDate.now()
|
.toLocalDate()).isEqualTo(LocalDate.now()
|
||||||
.plusYears(1));
|
.plusYears(1));
|
||||||
@ -33,6 +34,7 @@ class LicenseMapperUnitTest {
|
|||||||
.plusYears(2));
|
.plusYears(2));
|
||||||
License license = licenseMapper.toLicense(licenseDto);
|
License license = licenseMapper.toLicense(licenseDto);
|
||||||
assertThat(license).isNotNull();
|
assertThat(license).isNotNull();
|
||||||
|
assertThat(license.getId()).isNotNull();
|
||||||
assertThat(license.getStartDate()
|
assertThat(license.getStartDate()
|
||||||
.toLocalDate()).isEqualTo(LocalDate.now());
|
.toLocalDate()).isEqualTo(LocalDate.now());
|
||||||
}
|
}
|
||||||
@ -42,6 +44,7 @@ class LicenseMapperUnitTest {
|
|||||||
LicenseDto licenseDto = new LicenseDto();
|
LicenseDto licenseDto = new LicenseDto();
|
||||||
License license = licenseMapper.toLicense(licenseDto);
|
License license = licenseMapper.toLicense(licenseDto);
|
||||||
assertThat(license).isNotNull();
|
assertThat(license).isNotNull();
|
||||||
|
assertThat(license.getId()).isNotNull();
|
||||||
assertThat(license.getStartDate()
|
assertThat(license.getStartDate()
|
||||||
.toLocalDate()).isEqualTo(LocalDate.now());
|
.toLocalDate()).isEqualTo(LocalDate.now());
|
||||||
assertThat(license.getEndDate()
|
assertThat(license.getEndDate()
|
||||||
@ -58,6 +61,7 @@ class LicenseMapperUnitTest {
|
|||||||
.plusDays(10));
|
.plusDays(10));
|
||||||
License license = licenseMapper.toLicense(licenseDto);
|
License license = licenseMapper.toLicense(licenseDto);
|
||||||
assertThat(license).isNotNull();
|
assertThat(license).isNotNull();
|
||||||
|
assertThat(license.getId()).isNotNull();
|
||||||
assertThat(license.isRenewalRequired()).isTrue();
|
assertThat(license.isRenewalRequired()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user