Skip to content

Commit

Permalink
fix(leaning-service-dummy) - Changed hasChanged variable to be vased …
Browse files Browse the repository at this point in the history
…on Address Type
  • Loading branch information
alexsilva-CGI committed Nov 30, 2023
1 parent 700af9a commit 6471787
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.eclipse.tractusx.bpdm.cleaning.service


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

Expand All @@ -28,7 +29,7 @@ fun BusinessPartnerGenericDto.toLegalEntityDto(bpnReferenceDto: BpnReferenceDto,

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 @@ -67,9 +68,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 @@ -83,7 +85,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

0 comments on commit 6471787

Please sign in to comment.