From 3ca87d0c2f6a4b849d375853babf7baef33c4867 Mon Sep 17 00:00:00 2001 From: rschneider <97682836+rainer-exxcellent@users.noreply.github.com> Date: Thu, 6 Jul 2023 04:14:12 +0200 Subject: [PATCH] feat(bridge-tests): Tests for syncing new legal entities, site & addresses #210 - ignore legal and main addresses on sync --- .../bridge/dummy/service/PoolUpdateService.kt | 73 ++++++++++++------- .../catenax/bpdm/bridge/dummy/BridgeSyncIT.kt | 12 +-- 2 files changed, 51 insertions(+), 34 deletions(-) diff --git a/bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/service/PoolUpdateService.kt b/bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/service/PoolUpdateService.kt index 1083b1036..1c8620967 100644 --- a/bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/service/PoolUpdateService.kt +++ b/bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/service/PoolUpdateService.kt @@ -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), ), @@ -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), ), @@ -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) { @@ -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): AddressPartnerUpdateResponseWrapper { val updateRequests = entriesToUpdate.map { AddressPartnerUpdateRequest( diff --git a/bpdm-bridge-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/BridgeSyncIT.kt b/bpdm-bridge-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/BridgeSyncIT.kt index fbdcc877d..ca206a531 100644 --- a/bpdm-bridge-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/BridgeSyncIT.kt +++ b/bpdm-bridge-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/BridgeSyncIT.kt @@ -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]!! } @@ -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]!! } @@ -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]!! }