Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (cleaning-service-dummy) - Adjust the value 'HasChanged' Based on Address Type #660

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
package org.eclipse.tractusx.bpdm.cleaning.service


import org.eclipse.tractusx.bpdm.common.dto.AddressType
import org.eclipse.tractusx.orchestrator.api.model.*


fun BusinessPartnerGenericDto.toLegalEntityDto(bpnReferenceDto: BpnReferenceDto, legalAddress: LogisticAddressDto): LegalEntityDto {

return LegalEntityDto(
bpnLReference = bpnReferenceDto,
hasChanged = true,
hasChanged = postalAddress.addressType in setOf(AddressType.LegalAddress, AddressType.LegalAndSiteMainAddress),
legalName = nameParts.joinToString(" "),
legalShortName = shortName,
identifiers = identifiers.mapNotNull { it.toLegalEntityIdentifierDto() },
Expand Down Expand Up @@ -66,9 +67,10 @@ fun BusinessPartnerStateDto.toSiteState(): SiteStateDto? {

fun BusinessPartnerGenericDto.toLogisticAddressDto(bpnReferenceDto: BpnReferenceDto):
LogisticAddressDto {

return LogisticAddressDto(
bpnAReference = bpnReferenceDto,
hasChanged = true,
hasChanged = postalAddress.addressType == AddressType.AdditionalAddress,
name = nameParts.joinToString(" "),
states = emptyList(),
identifiers = emptyList(),
Expand All @@ -82,7 +84,7 @@ fun BusinessPartnerGenericDto.toSiteDto(bpnReferenceDto: BpnReferenceDto, legalN

return SiteDto(
bpnSReference = bpnReferenceDto,
hasChanged = true,
hasChanged = postalAddress.addressType in setOf(AddressType.SiteMainAddress, AddressType.LegalAndSiteMainAddress),
name = legalName,
states = states.mapNotNull { it.toSiteState() },
mainAddress = siteAddressReference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class CleaningServiceDummyTest @Autowired constructor(

val expectedAddress = expectedLogisticAddressDto.copy(bpnAReference = BpnReferenceDto(expectedBpnA.toString(), BpnReferenceType.Bpn))

val expectedLegalEntity = expectedLegalEntityDto.copy(legalAddress = expectedLogisticAddressDto)
val expectedLegalEntity = expectedLegalEntityDto.copy(legalAddress = expectedLogisticAddressDto, hasChanged = false)

assertRecursively(resultedAddress).isEqualTo(expectedAddress)

Expand Down Expand Up @@ -97,7 +97,7 @@ class CleaningServiceDummyTest @Autowired constructor(

val expectedAddress = expectedLogisticAddressDto.copy()

val expectedLegalEntity = expectedLegalEntityDto.copy(legalAddress = expectedLogisticAddressDto)
val expectedLegalEntity = expectedLegalEntityDto.copy(legalAddress = expectedLogisticAddressDto, hasChanged = false)

// bpnAReference since they are generated
assertRecursively(resultedAddress).ignoringFields("bpnAReference").isEqualTo(expectedAddress)
Expand Down Expand Up @@ -130,6 +130,7 @@ class CleaningServiceDummyTest @Autowired constructor(

val expectedLegalEntity = expectedLegalEntityDto.copy(
legalAddress = expectedLogisticAddressDto.copy(
hasChanged = false,
bpnAReference = BpnReferenceDto(
expectedBpnA.toString(),
BpnReferenceType.Bpn
Expand Down Expand Up @@ -174,7 +175,9 @@ class CleaningServiceDummyTest @Autowired constructor(


val expectedLegalEntity = expectedLegalEntityDto.copy(
hasChanged = true,
legalAddress = expectedLogisticAddressDto.copy(
hasChanged = false,
bpnAReference = BpnReferenceDto(
expectedBpnA.toString(),
BpnReferenceType.Bpn
Expand All @@ -183,7 +186,8 @@ class CleaningServiceDummyTest @Autowired constructor(
)

val expectedSite = expectedSiteDto.copy(
mainAddress = expectedLogisticAddressDto.copy(bpnAReference = BpnReferenceDto(expectedBpnA.toString(), BpnReferenceType.Bpn)),
hasChanged = true,
mainAddress = expectedLogisticAddressDto.copy(bpnAReference = BpnReferenceDto(expectedBpnA.toString(), BpnReferenceType.Bpn), hasChanged = false),
bpnSReference = BpnReferenceDto(expectedBpnS.toString(), BpnReferenceType.Bpn)
)

Expand Down Expand Up @@ -222,9 +226,9 @@ class CleaningServiceDummyTest @Autowired constructor(
assertNotEquals(resultedAddress?.bpnAReference?.referenceValue, resultedLegalEntity?.legalAddress?.bpnAReference?.referenceValue)
assertNotEquals(resultedAddress?.bpnAReference?.referenceValue, resultedSite?.mainAddress?.bpnAReference?.referenceValue)

val expectedLegalEntity = expectedLegalEntityDto.copy(legalAddress = expectedLogisticAddressDto.copy())
val expectedLegalEntity = expectedLegalEntityDto.copy(legalAddress = expectedLogisticAddressDto.copy(hasChanged = false), hasChanged = false)

val expectedSite = expectedSiteDto.copy(mainAddress = expectedLogisticAddressDto.copy())
val expectedSite = expectedSiteDto.copy(mainAddress = expectedLogisticAddressDto.copy(hasChanged = false), hasChanged = true)


// ignoring bpnLReference and legalAddress.bpnAReference since they are generated
Expand Down
Loading