Skip to content

Commit

Permalink
feat(bridge-tests): Tests for syncing new legal entities, site & addr…
Browse files Browse the repository at this point in the history
…esses eclipse-tractusx#210

- ignore legal and main addresses on sync
  • Loading branch information
rainer-exxcellent committed Jul 12, 2023
1 parent aaf8f20 commit 3ca87d0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class PoolUpdateService(
?.let { leParentBpn ->
SitePartnerCreateRequest(
site = SiteDto(
name = entry.site.nameParts.firstOrNull()?: "",
name = entry.site.nameParts.firstOrNull() ?: "",
states = entry.site.states,
mainAddress = gateToPoolLogisticAddress(entry.mainAddress),
),
Expand All @@ -131,7 +131,7 @@ class PoolUpdateService(
val updateRequests = entriesToUpdate.map {
SitePartnerUpdateRequest(
site = SiteDto(
name = it.site.nameParts.firstOrNull()?: "",
name = it.site.nameParts.firstOrNull() ?: "",
states = it.site.states,
mainAddress = gateToPoolLogisticAddress(it.mainAddress),
),
Expand All @@ -147,36 +147,40 @@ class PoolUpdateService(
val leParentBpnByExternalId = entriesToCreate
.mapNotNull { it.legalEntityExternalId }
.let { gateQueryService.getBpnByExternalId(LsaType.LEGAL_ENTITY, it.toSet()) }
val leParentsCreateRequests = entriesToCreate.mapNotNull { entry ->
leParentBpnByExternalId[entry.legalEntityExternalId]
?.let { leParentBpn ->
AddressPartnerCreateRequest(
address = gateToPoolLogisticAddress(entry.address),
index = entry.externalId,
bpnParent = leParentBpn
)
}
}
val leParentsCreateRequests = entriesToCreate
.filter { !isLegalAddress(it) }
.mapNotNull { entry ->
leParentBpnByExternalId[entry.legalEntityExternalId]
?.let { leParentBpn ->
AddressPartnerCreateRequest(
address = gateToPoolLogisticAddress(entry.address),
index = entry.externalId,
bpnParent = leParentBpn
)
}
}

val siteParentBpnByExternalId = entriesToCreate
.mapNotNull { it.siteExternalId }
.let { gateQueryService.getBpnByExternalId(LsaType.SITE, it.toSet()) }
val siteParentsCreateRequests = entriesToCreate.mapNotNull { entry ->
siteParentBpnByExternalId[entry.siteExternalId]
?.let { siteParentBpn ->
AddressPartnerCreateRequest(
address = LogisticAddressDto(
name = entry.address.nameParts.firstOrNull(),
states = entry.address.states,
identifiers = entry.address.identifiers,
physicalPostalAddress = gateToPoolPhysicalAddress(entry.address.physicalPostalAddress),
alternativePostalAddress = entry.address.alternativePostalAddress
),
index = entry.externalId,
bpnParent = siteParentBpn
)
}
}
val siteParentsCreateRequests = entriesToCreate
.filter { !isSiteMainAddress(it) }
.mapNotNull { entry ->
siteParentBpnByExternalId[entry.siteExternalId]
?.let { siteParentBpn ->
AddressPartnerCreateRequest(
address = LogisticAddressDto(
name = entry.address.nameParts.firstOrNull(),
states = entry.address.states,
identifiers = entry.address.identifiers,
physicalPostalAddress = gateToPoolPhysicalAddress(entry.address.physicalPostalAddress),
alternativePostalAddress = entry.address.alternativePostalAddress
),
index = entry.externalId,
bpnParent = siteParentBpn
)
}
}

val createRequests = leParentsCreateRequests.plus(siteParentsCreateRequests)
if (createRequests.size != entriesToCreate.size) {
Expand All @@ -189,6 +193,19 @@ class PoolUpdateService(
.also { logger.info { "Pool accepted ${it.entityCount} new addresses, ${it.errorCount} were refused" } }
}

private fun isSiteMainAddress(it: GateAddressInfo): Boolean {

val mainAdressExternalId = it.siteExternalId?.let { it1 -> gateQueryService.gateClient.sites().getSiteByExternalId(it1).mainAddress.externalId }
return it.externalId == mainAdressExternalId
}

private fun isLegalAddress(it: GateAddressInfo): Boolean {

val legalAdressExternalId =
it.legalEntityExternalId?.let { it1 -> gateQueryService.gateClient.legalEntities().getLegalEntityByExternalId(it1).legalAddress.externalId }
return it.externalId == legalAdressExternalId
}

fun updateAddressesInPool(entriesToUpdate: Collection<GateAddressInfo>): AddressPartnerUpdateResponseWrapper {
val updateRequests = entriesToUpdate.map {
AddressPartnerUpdateRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ class BridgeSyncIT @Autowired constructor(
bridgeClient.bridge().triggerSync()

// 3 legal entities + 3 legal addresses
assertPoolChangelogHasCount(3 + 3 + 3)
assertPoolChangelogHasCount(3 + 3)

// 3 legal entities
val sharingStatesOkay = assertSharingStatesSuccessful(6)
val sharingStatesOkay = assertSharingStatesSuccessful(3)
val bpnByExternalId = buildBpnByExternalIdMap(sharingStatesOkay)

val gateLegalEntityRequestByBpn = gateLegalEntityRequests.associateBy { bpnByExternalId[it.externalId]!! }
Expand Down Expand Up @@ -133,10 +133,10 @@ class BridgeSyncIT @Autowired constructor(
bridgeClient.bridge().triggerSync()

// 3 legal entities + 3 legal addresses & 2 sites + 2 main addresses
assertPoolChangelogHasCount(3 * 2 + 2 * 2 + 5)
assertPoolChangelogHasCount(3 + 3 + 2 + 2)

// 3 LEs + 2 sites
val sharingStatesOkay = assertSharingStatesSuccessful(3 + 2 + 5)
val sharingStatesOkay = assertSharingStatesSuccessful(3 + 2)
val bpnByExternalId = buildBpnByExternalIdMap(sharingStatesOkay)

val gateSiteRequestsByBpn = gateSiteRequests.associateBy { bpnByExternalId[it.externalId]!! }
Expand Down Expand Up @@ -183,10 +183,10 @@ class BridgeSyncIT @Autowired constructor(
bridgeClient.bridge().triggerSync()

// 1 legal entity + 1 legal address & 1 site + 1 main address & 2 addresses
assertPoolChangelogHasCount(1 * 2 + 1 * 2 + 2 + 2)
assertPoolChangelogHasCount(1 + 1 + 1 + 1 + 2)

// 1 LE + 1 site + 2 addresses
val sharingStatesOkay = assertSharingStatesSuccessful(1 + 1 + 2 + 2)
val sharingStatesOkay = assertSharingStatesSuccessful(1 + 1 + 2)
val bpnByExternalId = buildBpnByExternalIdMap(sharingStatesOkay)

val gateAddressRequestsByBpn = gateAddressRequests.associateBy { bpnByExternalId[it.externalId]!! }
Expand Down

0 comments on commit 3ca87d0

Please sign in to comment.