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 a75a39401..36709cea5 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 @@ -20,7 +20,9 @@ package com.catenax.bpdm.bridge.dummy import com.catenax.bpdm.bridge.dummy.client.BridgeClient +import com.catenax.bpdm.bridge.dummy.testdata.CommonValues import com.catenax.bpdm.bridge.dummy.testdata.GateRequestValues +import com.catenax.bpdm.bridge.dummy.testdata.GateRequestValues.addressGateInputRequest1 import com.catenax.bpdm.bridge.dummy.util.* import org.assertj.core.api.Assertions.assertThat import org.eclipse.tractusx.bpdm.common.dto.request.AddressPartnerBpnSearchRequest @@ -28,22 +30,23 @@ import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest import org.eclipse.tractusx.bpdm.common.dto.request.SiteBpnSearchRequest import org.eclipse.tractusx.bpdm.common.dto.response.LogisticAddressVerboseDto import org.eclipse.tractusx.bpdm.gate.api.client.GateClient -import org.eclipse.tractusx.bpdm.gate.api.model.* +import org.eclipse.tractusx.bpdm.gate.api.model.SharingStateType +import org.eclipse.tractusx.bpdm.gate.api.model.StreetGateDto import org.eclipse.tractusx.bpdm.gate.api.model.request.AddressGateInputRequest import org.eclipse.tractusx.bpdm.gate.api.model.request.LegalEntityGateInputRequest import org.eclipse.tractusx.bpdm.gate.api.model.request.SiteGateInputRequest import org.eclipse.tractusx.bpdm.gate.api.model.response.SharingStateDto import org.eclipse.tractusx.bpdm.pool.api.client.PoolApiClient +import org.eclipse.tractusx.bpdm.pool.api.model.request.ChangelogSearchRequest import org.eclipse.tractusx.bpdm.pool.api.model.request.LegalEntityPropertiesSearchRequest import org.eclipse.tractusx.bpdm.pool.api.model.response.LegalEntityMatchVerboseDto import org.eclipse.tractusx.bpdm.pool.api.model.response.SitePoolVerboseDto -import org.junit.jupiter.api.* +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest import org.springframework.test.context.ActiveProfiles import org.springframework.test.context.ContextConfiguration -import org.eclipse.tractusx.bpdm.gate.api.model.request.ChangelogSearchRequest as GateChangelogSearchRequest -import org.eclipse.tractusx.bpdm.pool.api.model.request.ChangelogSearchRequest as PoolChangelogSearchRequest private val DEFAULT_PAGINATION_REQUEST = PaginationRequest(0, 100) @@ -67,7 +70,7 @@ class BridgeSyncIT @Autowired constructor( fun `just use API clients`() { assertGateChangelogHasCount(0) val poolChangelogResponses = poolClient.changelogs().getChangelogEntries( - paginationRequest = DEFAULT_PAGINATION_REQUEST, changelogSearchRequest = PoolChangelogSearchRequest(timestampAfter = null, bpns = null) + paginationRequest = DEFAULT_PAGINATION_REQUEST, changelogSearchRequest = ChangelogSearchRequest(timestampAfter = null, bpns = null) ) assertThat(poolChangelogResponses.contentSize).isZero() bridgeClient.bridge().triggerSync() @@ -83,7 +86,7 @@ class BridgeSyncIT @Autowired constructor( gateClient.legalEntities().upsertLegalEntities(gateLegalEntityRequests) assertGateChangelogHasCount(3 + 3) // 3 LEs + 3 addresses - assertSharingStatesSuccessful(0) + assertThat(readSuccessfulSharingStatesWithBpn().size).isEqualTo(0) // Action: Sync from Gate to Pool and BPN back to Gate bridgeClient.bridge().triggerSync() @@ -92,7 +95,8 @@ class BridgeSyncIT @Autowired constructor( assertPoolChangelogHasCount(3 + 3) // 3 legal entities - val sharingStatesOkay = assertSharingStatesSuccessful(3) + val sharingStatesOkay = readSuccessfulSharingStatesWithBpn() + assertThat(sharingStatesOkay.size).isEqualTo(3) val bpnByExternalId = buildBpnByExternalIdMap(sharingStatesOkay) val gateLegalEntityRequestByBpn = gateLegalEntityRequests.associateBy { bpnByExternalId[it.externalId]!! } @@ -131,7 +135,7 @@ class BridgeSyncIT @Autowired constructor( gateClient.sites().upsertSites(gateSiteRequests) assertGateChangelogHasCount(3 + 2 + 3 + 2) // 3 LEs + 2 sites + 3 le addresses + 2 site main addresses - assertSharingStatesSuccessful(0) + assertThat(readSuccessfulSharingStatesWithBpn().size).isEqualTo(0) // Action: Sync from Gate to Pool and BPN back to Gate bridgeClient.bridge().triggerSync() @@ -140,7 +144,8 @@ class BridgeSyncIT @Autowired constructor( assertPoolChangelogHasCount(3 + 3 + 2 + 2) // 3 LEs + 2 sites - val sharingStatesOkay = assertSharingStatesSuccessful(3 + 2) + val sharingStatesOkay = readSuccessfulSharingStatesWithBpn() + assertThat(sharingStatesOkay.size).isEqualTo(3 + 2) val bpnByExternalId = buildBpnByExternalIdMap(sharingStatesOkay) val gateSiteRequestsByBpn = gateSiteRequests.associateBy { bpnByExternalId[it.externalId]!! } @@ -175,13 +180,13 @@ class BridgeSyncIT @Autowired constructor( gateClient.sites().upsertSites(gateSiteRequests) val gateAddressRequests = listOf( - GateRequestValues.addressGateInputRequest1, + addressGateInputRequest1, GateRequestValues.addressGateInputRequest2 ) gateClient.addresses().upsertAddresses(gateAddressRequests) assertGateChangelogHasCount(1 + 1 + 2 + 2) // 1 LE + 1 site + 2 addresses - assertSharingStatesSuccessful(0) + assertThat(readSuccessfulSharingStatesWithBpn().size).isEqualTo(0) // Action: Sync from Gate to Pool and BPN back to Gate bridgeClient.bridge().triggerSync() @@ -190,7 +195,8 @@ class BridgeSyncIT @Autowired constructor( assertPoolChangelogHasCount(1 + 1 + 1 + 1 + 2) // 1 LE + 1 site + 2 addresses - val sharingStatesOkay = assertSharingStatesSuccessful(1 + 1 + 2) + val sharingStatesOkay = readSuccessfulSharingStatesWithBpn() + assertThat(sharingStatesOkay.size).isEqualTo(1 + 1 + 2) val bpnByExternalId = buildBpnByExternalIdMap(sharingStatesOkay) val gateAddressRequestsByBpn = gateAddressRequests.associateBy { bpnByExternalId[it.externalId]!! } @@ -212,6 +218,198 @@ class BridgeSyncIT @Autowired constructor( } } + @Test + fun `sync updated legal entities`() { + val gateLegalEntityRequests = listOf( + GateRequestValues.legalEntityGateInputRequest1, + GateRequestValues.legalEntityGateInputRequest2, + GateRequestValues.legalEntityGateInputRequest3 + ) + gateClient.legalEntities().upsertLegalEntities(gateLegalEntityRequests) + assertGateChangelogHasCount(3 + 3) + // Action: Sync from Gate to Pool and BPN back to Gate + bridgeClient.bridge().triggerSync() + assertPoolChangelogHasCount(3 + 3) + + val legalEntitiesFromPool = allLegalEntitiesFromPool() + assertThat(legalEntitiesFromPool.size).isEqualTo(3) + + val bpnByExternalId = buildBpnByExternalIdMap(readSuccessfulSharingStatesWithBpn()) + val gateLegalEntityRequestByBpn = gateLegalEntityRequests.associateBy { bpnByExternalId[it.externalId]!! } + legalEntitiesFromPool.forEach { poolLe -> + assertEqualLegalEntity(gateLegalEntityRequestByBpn[poolLe.legalEntity.bpnl]!!, poolLe) + } + + // update legal entity and le address and trigger sync + val leRquestUpdate = GateRequestValues.legalEntityGateInputRequest1.copy( + legalEntity = GateRequestValues.legalEntity1.copy(legalShortName = "ChangedShortNam"), + legalAddress = GateRequestValues.address1.copy( + physicalPostalAddress = GateRequestValues.postalAddress1.copy( + street = StreetGateDto(name = "Changed Street Entiy", houseNumber = CommonValues.houseNumber1, direction = CommonValues.direction1), + ), + ), + ) + gateClient.legalEntities().upsertLegalEntities(listOf(leRquestUpdate)) + assertGateChangelogHasCount(4 + 4) // 3 insert + 1 update + bridgeClient.bridge().triggerSync() + assertPoolChangelogHasCount(4 + 4) + + val entitiesFromPoolAFterUpdate = allLegalEntitiesFromPool() + assertThat(legalEntitiesFromPool.size).isEqualTo(3) + val gateLegalEntityUpdateRequestsByBpn = listOf( + leRquestUpdate, + GateRequestValues.legalEntityGateInputRequest2, + GateRequestValues.legalEntityGateInputRequest3 + ).associateBy { bpnByExternalId[it.externalId]!! } + + entitiesFromPoolAFterUpdate.forEach { poolLe -> + assertEqualLegalEntity(gateLegalEntityUpdateRequestsByBpn[poolLe.legalEntity.bpnl]!!, poolLe) + } + } + + @Test + fun `sync update sites`() { + // site needs parent legal entity! + val gateLegalEntityRequests = listOf( + GateRequestValues.legalEntityGateInputRequest1, + GateRequestValues.legalEntityGateInputRequest2, + GateRequestValues.legalEntityGateInputRequest3 + ) + gateClient.legalEntities().upsertLegalEntities(gateLegalEntityRequests) + + val gateSiteRequests = listOf( + GateRequestValues.siteGateInputRequest1, + GateRequestValues.siteGateInputRequest2 + ) + gateClient.sites().upsertSites(gateSiteRequests) + + assertGateChangelogHasCount(3 + 2 + 3 + 2) // 3 LEs + 2 sites + 3 le addresses + 2 site main addresses + assertThat(readSuccessfulSharingStatesWithBpn().size).isEqualTo(0) + + // Action: Sync from Gate to Pool and BPN back to Gate + bridgeClient.bridge().triggerSync() + + // 3 legal entities + 3 legal addresses & 2 sites + 2 main addresses + assertPoolChangelogHasCount(3 + 3 + 2 + 2) + + // 3 LEs + 2 sites + val sharingStatesOkay = readSuccessfulSharingStatesWithBpn() + assertThat(sharingStatesOkay.size).isEqualTo(3 + 2) + val bpnByExternalId = buildBpnByExternalIdMap(sharingStatesOkay) + val gateSiteRequestsByBpn = gateSiteRequests.associateBy { bpnByExternalId[it.externalId]!! } + + val poolSiteResponses = poolClient.sites().searchSites( + siteSearchRequest = SiteBpnSearchRequest(sites = gateSiteRequestsByBpn.keys), + paginationRequest = DEFAULT_PAGINATION_REQUEST + ) + assertThat(poolSiteResponses.contentSize).isEqualTo(2) + poolSiteResponses.content.forEach { poolSite -> + assertEqualSite(gateSiteRequestsByBpn[poolSite.site.bpns]!!, poolSite) + } + + // update site and main address and trigger sync + val siteRquestUpdate = GateRequestValues.siteGateInputRequest1.copy( + site = GateRequestValues.site1.copy(nameParts = listOf("ChangedNamePart1")), + mainAddress = GateRequestValues.address1.copy( + physicalPostalAddress = GateRequestValues.postalAddress1.copy( + street = StreetGateDto(name = "Changed Street Site", houseNumber = CommonValues.houseNumber1, direction = CommonValues.direction1), + ), + ) + ) + gateClient.sites().upsertSites(listOf(siteRquestUpdate)) + bridgeClient.bridge().triggerSync() + val poolSiteUpdateResponses = poolClient.sites().searchSites( + siteSearchRequest = SiteBpnSearchRequest(sites = gateSiteRequestsByBpn.keys), + paginationRequest = DEFAULT_PAGINATION_REQUEST + ) + + val gateSiteUpdateRequestsByBpn = listOf( + siteRquestUpdate, + GateRequestValues.siteGateInputRequest2 + ).associateBy { bpnByExternalId[it.externalId]!! } + + poolSiteUpdateResponses.content.forEach { poolSite -> + assertEqualSite(gateSiteUpdateRequestsByBpn[poolSite.site.bpns]!!, poolSite) + } + + } + + @Test + fun `sync update addresses`() { + // insert le, sites and addresses + val gateLegalEntityRequests = listOf( + GateRequestValues.legalEntityGateInputRequest1, + ) + gateClient.legalEntities().upsertLegalEntities(gateLegalEntityRequests) + val gateSiteRequests = listOf( + GateRequestValues.siteGateInputRequest1, + ) + gateClient.sites().upsertSites(gateSiteRequests) + + val gateAddressRequests = listOf( + addressGateInputRequest1, + GateRequestValues.addressGateInputRequest2 + ) + gateClient.addresses().upsertAddresses(gateAddressRequests) + + assertGateChangelogHasCount(1 + 1 + 2 + 2) // 1 LE + le address + 1 site + main address + 2 addresses + assertThat(readSuccessfulSharingStatesWithBpn().size).isEqualTo(0) + + // Action: Sync from Gate to Pool and BPN back to Gate + bridgeClient.bridge().triggerSync() + + // 1 legal entity + 1 le address & 1 site + 1 main address & 2 addresses + assertPoolChangelogHasCount(1 + 1 + 1 + 1 + 2) + + val bpnByExternalId = buildBpnByExternalIdMap(readSuccessfulSharingStatesWithBpn()) + val gateAddressRequestsByBpn = gateAddressRequests.associateBy { bpnByExternalId[it.externalId]!! } + + val poolAddressResponses = poolClient.addresses().searchAddresses( + addressSearchRequest = AddressPartnerBpnSearchRequest(addresses = gateAddressRequestsByBpn.keys), + paginationRequest = DEFAULT_PAGINATION_REQUEST + ).content + assertThat(poolAddressResponses.size).isEqualTo(2) + + poolAddressResponses.forEach { poolVersion -> + assertEqualAddress(gateAddressRequestsByBpn[poolVersion.bpna]!!, poolVersion) + } + + // update address nad trigger sync + val addressRequestUpdate = addressGateInputRequest1.copy( + address = GateRequestValues.address1.copy( + nameParts = listOf("Changed Address Name"), + physicalPostalAddress = GateRequestValues.postalAddress1 + .copy(street = StreetGateDto(name = "UpdateSteet", houseNumber = CommonValues.houseNumber1, direction = CommonValues.direction1)) + ), + + ) + gateClient.addresses().upsertAddresses(listOf(addressRequestUpdate)) + bridgeClient.bridge().triggerSync() + val poolAddressUpdateResponses = poolClient.addresses().searchAddresses( + addressSearchRequest = AddressPartnerBpnSearchRequest(addresses = gateAddressRequestsByBpn.keys), + paginationRequest = DEFAULT_PAGINATION_REQUEST + ).content + + val gateAddressUpdateRequestsByBpn = listOf( + addressRequestUpdate, + GateRequestValues.addressGateInputRequest2 + ).associateBy { bpnByExternalId[it.externalId]!! } + + poolAddressUpdateResponses.forEach { poolVersion -> + assertEqualAddress(gateAddressUpdateRequestsByBpn[poolVersion.bpna]!!, poolVersion) + } + + } + + private fun allLegalEntitiesFromPool(): Collection { + val poolLegalEntityResponses = poolClient.legalEntities().getLegalEntities( + bpSearchRequest = LegalEntityPropertiesSearchRequest.EmptySearchRequest, + paginationRequest = DEFAULT_PAGINATION_REQUEST + ) + return poolLegalEntityResponses.content + + } + private fun buildBpnByExternalIdMap(sharingStatesOkay: List) = sharingStatesOkay .associateBy { it.externalId } @@ -220,7 +418,7 @@ class BridgeSyncIT @Autowired constructor( private fun assertGateChangelogHasCount(changelogCount: Int) { val gateChangelogResponses = gateClient.changelog().getInputChangelog( paginationRequest = DEFAULT_PAGINATION_REQUEST, - searchRequest = GateChangelogSearchRequest(timestampAfter = null, businessPartnerTypes = emptySet()) + searchRequest = org.eclipse.tractusx.bpdm.gate.api.model.request.ChangelogSearchRequest(timestampAfter = null, businessPartnerTypes = emptySet()) ) assertThat(gateChangelogResponses.contentSize).isEqualTo(changelogCount) } @@ -228,14 +426,14 @@ class BridgeSyncIT @Autowired constructor( private fun assertPoolChangelogHasCount(changelogCount: Int) { val poolChangelogResponses = poolClient.changelogs().getChangelogEntries( paginationRequest = DEFAULT_PAGINATION_REQUEST, - changelogSearchRequest = PoolChangelogSearchRequest(timestampAfter = null, bpns = null) + changelogSearchRequest = ChangelogSearchRequest(timestampAfter = null, bpns = null) ) assertThat(poolChangelogResponses.contentSize).isEqualTo(changelogCount) } - private fun assertSharingStatesSuccessful(successfulStatesCount: Int): List { + private fun readSuccessfulSharingStatesWithBpn(): List { val sharingStates = gateClient.sharingState().getSharingStates( paginationRequest = DEFAULT_PAGINATION_REQUEST, businessPartnerType = null, @@ -243,7 +441,6 @@ class BridgeSyncIT @Autowired constructor( ) val sharingStatesOkay = sharingStates.content .filter { it.sharingStateType == SharingStateType.Success && it.bpn != null } - assertThat(sharingStatesOkay.size).isEqualTo(successfulStatesCount) return sharingStatesOkay } @@ -260,6 +457,7 @@ class BridgeSyncIT @Autowired constructor( private fun assertEqualSite(gateVersion: SiteGateInputRequest, poolVersion: SitePoolVerboseDto) { assertThat(poolVersion.site.name).isEqualTo(gateVersion.site.nameParts.first()) assertThat(poolVersion.site.states.map { it.description }).isEqualTo(gateVersion.site.states.map { it.description }) + assertThat(poolVersion.mainAddress.physicalPostalAddress.street?.name).isEqualTo(gateVersion.mainAddress.physicalPostalAddress.street?.name) } private fun assertEqualAddress(gateVersion: AddressGateInputRequest, poolVersion: LogisticAddressVerboseDto) { diff --git a/bpdm-bridge-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/testdata/CommonValues.kt b/bpdm-bridge-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/testdata/CommonValues.kt index 2c2bbf963..569ea8fd4 100644 --- a/bpdm-bridge-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/testdata/CommonValues.kt +++ b/bpdm-bridge-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/testdata/CommonValues.kt @@ -21,7 +21,6 @@ package com.catenax.bpdm.bridge.dummy.testdata import com.neovisionaries.i18n.CountryCode import com.neovisionaries.i18n.LanguageCode -import org.eclipse.tractusx.bpdm.common.dto.NameRegioncodeVerboseDto import org.eclipse.tractusx.bpdm.common.model.BusinessStateType import org.eclipse.tractusx.bpdm.common.model.CharacterSet import org.eclipse.tractusx.bpdm.common.model.ClassificationType @@ -81,6 +80,7 @@ object CommonValues { const val identifierValue2 = "US123456789" const val identifierValue3 = "FR123456789" const val identifierValue4 = "NL123456789" + const val identifierValue5 = "US777882222" const val identifierIssuingBodyTechnicalKey1 = "issuing body 1" const val identifierIssuingBodyTechnicalKey2 = "issuing body 2" @@ -91,6 +91,7 @@ object CommonValues { const val identifierIssuingBodyName2 = "Body Y" const val identifierIssuingBodyName3 = "Official Z" const val identifierIssuingBodyName4 = "Gov A" + const val identifierIssuingBodyName5 = "Gov B" const val identifierIssuingBody1 = "Agency X" const val identifierIssuingBody2 = "Body Y" @@ -126,6 +127,7 @@ object CommonValues { const val identifierTypeTechnicalKey2 = "VAT_US" const val identifierTypeTechnicalKey3 = "VAT_FR" const val identifierTypeTechnicalKey4 = "VAT_NL" + const val identifierTypeTechnicalKey5 = "VAT_US" val nameType1 = NameType.OTHER @@ -174,16 +176,8 @@ object CommonValues { const val context1 = "Context1" const val context2 = "Context2" - // TODO enable regionCodes later -// val adminAreaLevel1RegionCode_1 = "BW" -// val adminAreaLevel1Region1 = NameRegioncodeDto(adminAreaLevel1RegionCode_1, "Baden-Württemberg") -// val adminAreaLevel1RegionCode_2 = "GA" -// val adminAreaLevel1Region2 = NameRegioncodeDto(adminAreaLevel1RegionCode_2, "Georgia") - - val adminAreaLevel1RegionCode_1: String? = null - val adminAreaLevel1Region1: NameRegioncodeVerboseDto? = null - val adminAreaLevel1RegionCode_2: String? = null - val adminAreaLevel1Region2: NameRegioncodeVerboseDto? = null + val adminAreaLevel1RegionCode_1: String = "adminAreaLevel1RegionCode_1" + val adminAreaLevel1RegionCode_2: String = "adminAreaLevel1RegionCode_2" const val county1 = "Stuttgart" const val county2 = " Fulton County" diff --git a/bpdm-bridge-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/testdata/GateRequestValues.kt b/bpdm-bridge-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/testdata/GateRequestValues.kt index 815188440..c108b531e 100644 --- a/bpdm-bridge-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/testdata/GateRequestValues.kt +++ b/bpdm-bridge-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/testdata/GateRequestValues.kt @@ -50,11 +50,18 @@ object GateRequestValues { ) val identifier4 = LegalEntityIdentifierDto( - value = CommonValues.identifierValue4, + value = CommonValues.identifierValue5, type = CommonValues.identifierTypeTechnicalKey4, issuingBody = CommonValues.identifierIssuingBodyName4, ) + val identifier5 = + LegalEntityIdentifierDto( + value = CommonValues.identifierValue5, + type = CommonValues.identifierTypeTechnicalKey5, + issuingBody = CommonValues.identifierIssuingBodyName5, + ) + val genericIdentifier = GenericIdentifierDto( CommonValues.identifierValue1, @@ -262,7 +269,7 @@ object GateRequestValues { ) val legalEntity3 = LegalEntityDto( - identifiers = listOf(identifier1, identifier2), + identifiers = listOf(identifier5), legalShortName = CommonValues.shortName1, legalForm = CommonValues.legalFormTechnicalKey1, states = listOf(leBusinessStatus1), diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/LegalEntityControllerIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/LegalEntityControllerIT.kt index 1a17d0dd8..5a578189f 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/LegalEntityControllerIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/LegalEntityControllerIT.kt @@ -31,6 +31,7 @@ import org.eclipse.tractusx.bpdm.pool.api.model.response.LegalEntityPartnerCreat import org.eclipse.tractusx.bpdm.pool.api.model.response.LegalEntityUpdateError import org.eclipse.tractusx.bpdm.pool.util.* import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest @@ -44,7 +45,7 @@ import java.time.Instant webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = [Application::class, TestHelpers::class] ) @ActiveProfiles("test") -@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class,OpenSearchContextInitializer::class]) +@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class, OpenSearchContextInitializer::class]) class LegalEntityControllerIT @Autowired constructor( val testHelpers: TestHelpers, val webTestClient: WebTestClient, @@ -158,6 +159,34 @@ class LegalEntityControllerIT @Autowired constructor( assertThat(response.errorCount).isEqualTo(0) } + /** + * Given several legal entity with multiple identifiers + * When updating values of legal entity via BPN + * Then legal entity updated with the values + */ + @Disabled("Fix insert with same identifiers") + @Test + fun `update existing legal entities multiple identifier`() { + val given = listOf(RequestValues.legalEntityCreateMultipleIdentifier, RequestValues.legalEntityCreate2, RequestValues.legalEntityCreate3) + + val createResponses = poolClient.legalEntities().createBusinessPartners(given) + .entities + + val createResponse = createResponses.filter { response -> + response.index.equals(RequestValues.legalEntityCreateMultipleIdentifier.index) + }[0] + + val givenBpnL = createResponse.legalEntity.bpnl + + val toUpdate = RequestValues.legalEntityUpdateMultipleIdentifier.copy( + bpnl = givenBpnL, + legalEntity = RequestValues.legalEntityCreateMultipleIdentifier.legalEntity.copy(legalShortName = "ChangedShortNam"), + ) + val response = poolClient.legalEntities().updateBusinessPartners(listOf(toUpdate)) + + assertThat(response.errorCount).isEqualTo(0) + } + /** * Given legal entities * When trying to update via non-existent BPN diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/RequestValues.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/RequestValues.kt index 8fb7864cb..f1aca16ab 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/RequestValues.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/RequestValues.kt @@ -204,6 +204,20 @@ object RequestValues { index = CommonValues.index3 ) + val legalEntityCreateMultipleIdentifier = LegalEntityPartnerCreateRequest( + legalEntity = LegalEntityDto( + legalShortName = null, + identifiers = listOf(identifier1, identifier2), + legalForm = CommonValues.legalFormTechnicalKey1, + states = listOf(leStatus1), + classifications = listOf(classification1, classification2), + ), + legalAddress = logisticAddress1, + legalName = CommonValues.name1, + index = CommonValues.index1 + ) + + val legalEntityUpdate1 = LegalEntityPartnerUpdateRequest( bpnl = CommonValues.bpnL1, legalName = legalEntityCreate1.legalName, @@ -225,6 +239,13 @@ object RequestValues { legalAddress = legalEntityCreate3.legalAddress, ) + val legalEntityUpdateMultipleIdentifier = LegalEntityPartnerUpdateRequest( + bpnl = CommonValues.bpnL1, + legalName = legalEntityCreateMultipleIdentifier.legalName, + legalEntity = legalEntityCreateMultipleIdentifier.legalEntity, + legalAddress = legalEntityCreateMultipleIdentifier.legalAddress, + ) + val siteCreate1 = SitePartnerCreateRequest( site = SiteDto( name = CommonValues.siteName1, diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/ResponseValues.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/ResponseValues.kt index 03026caf6..807137b96 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/ResponseValues.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/ResponseValues.kt @@ -434,5 +434,27 @@ object ResponseValues { index = CommonValues.index3 ) + val legalEntityUpsertMultipleIdentifier = LegalEntityPartnerCreateVerboseDto( + legalName = CommonValues.name1, + legalEntity = LegalEntityVerboseDto( + bpnl = CommonValues.bpnL1, + identifiers = listOf( + LegalEntityIdentifierVerboseDto(CommonValues.identifierValue1, RequestValues.identifierType1, CommonValues.issuingBody1), + LegalEntityIdentifierVerboseDto(CommonValues.identifierValue2, RequestValues.identifierType2, CommonValues.issuingBody2) + ), + legalForm = legalForm1, + states = listOf(leStatus1), + classifications = listOf(classification1, classification2), + currentness = createdTime1.toInstant(ZoneOffset.UTC), + createdAt = CommonValues.now, + updatedAt = CommonValues.now, + + ), + legalAddress = addressPartner1.copy( + bpnLegalEntity = legalEntity1.legalEntity.bpnl, + isLegalAddress = true + ), + index = CommonValues.index1 + ) } \ No newline at end of file