diff --git a/bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/service/GateQueryService.kt b/bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/service/GateQueryService.kt index 1582160aa..31c6bb8c4 100644 --- a/bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/service/GateQueryService.kt +++ b/bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/service/GateQueryService.kt @@ -199,11 +199,11 @@ class GateQueryService( do { val pageResponse = gateClient.addresses().getAddressesByExternalIds( externalIds = externalIds, - paginationRequest = PaginationStartAfterRequest(pageStartAfter, bridgeConfigProperties.queryPageSize) + paginationRequest = PaginationRequest(0, bridgeConfigProperties.queryPageSize) ) - pageStartAfter = pageResponse.nextStartAfter + //pageStartAfter = pageResponse.nextStartAfter validContent.addAll(pageResponse.content) - invalidEntries += pageResponse.invalidEntries + invalidEntries += 0 //TODO Needs to be changed according to the removal of SaaS } while (pageStartAfter != null) logger.info { "Gate returned ${validContent.size} valid addresses, $invalidEntries were invalid" } diff --git a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/GateAddressApi.kt b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/GateAddressApi.kt index a5e8b42a2..fb3b31518 100644 --- a/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/GateAddressApi.kt +++ b/bpdm-gate-api/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/api/GateAddressApi.kt @@ -25,12 +25,13 @@ import io.swagger.v3.oas.annotations.media.Content import io.swagger.v3.oas.annotations.responses.ApiResponse import io.swagger.v3.oas.annotations.responses.ApiResponses import jakarta.validation.Valid +import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest +import org.eclipse.tractusx.bpdm.common.dto.response.PageResponse import org.eclipse.tractusx.bpdm.gate.api.model.AddressGateInputRequest import org.eclipse.tractusx.bpdm.gate.api.model.AddressGateInputResponse import org.eclipse.tractusx.bpdm.gate.api.model.AddressGateOutput import org.eclipse.tractusx.bpdm.gate.api.model.request.PaginationStartAfterRequest import org.eclipse.tractusx.bpdm.gate.api.model.response.PageOutputResponse -import org.eclipse.tractusx.bpdm.gate.api.model.response.PageStartAfterResponse import org.eclipse.tractusx.bpdm.gate.api.model.response.ValidationResponse import org.springdoc.core.annotations.ParameterObject import org.springframework.http.MediaType @@ -92,9 +93,9 @@ interface GateAddressApi { @PostMapping("/input/addresses/search") @PostExchange("/input/addresses/search") fun getAddressesByExternalIds( - @ParameterObject @Valid paginationRequest: PaginationStartAfterRequest, + @ParameterObject @Valid paginationRequest: PaginationRequest, @RequestBody externalIds: Collection - ): PageStartAfterResponse + ): PageResponse @Operation( @@ -109,7 +110,7 @@ interface GateAddressApi { ) @GetMapping("/input/addresses") @GetExchange("/input/addresses") - fun getAddresses(@ParameterObject @Valid paginationRequest: PaginationStartAfterRequest): PageStartAfterResponse + fun getAddresses(@ParameterObject @Valid paginationRequest: PaginationRequest): PageResponse @Operation( summary = "Get page of addresses", diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/controller/AddressController.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/controller/AddressController.kt index fdffe33ce..43275f165 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/controller/AddressController.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/controller/AddressController.kt @@ -19,13 +19,14 @@ package org.eclipse.tractusx.bpdm.gate.controller +import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest +import org.eclipse.tractusx.bpdm.common.dto.response.PageResponse import org.eclipse.tractusx.bpdm.gate.api.GateAddressApi import org.eclipse.tractusx.bpdm.gate.api.model.AddressGateInputRequest import org.eclipse.tractusx.bpdm.gate.api.model.AddressGateInputResponse import org.eclipse.tractusx.bpdm.gate.api.model.AddressGateOutput import org.eclipse.tractusx.bpdm.gate.api.model.request.PaginationStartAfterRequest import org.eclipse.tractusx.bpdm.gate.api.model.response.PageOutputResponse -import org.eclipse.tractusx.bpdm.gate.api.model.response.PageStartAfterResponse import org.eclipse.tractusx.bpdm.gate.api.model.response.ValidationResponse import org.eclipse.tractusx.bpdm.gate.config.ApiConfigProperties import org.eclipse.tractusx.bpdm.gate.containsDuplicates @@ -60,14 +61,14 @@ class AddressController( } override fun getAddressesByExternalIds( - paginationRequest: PaginationStartAfterRequest, + paginationRequest: PaginationRequest, externalIds: Collection - ): PageStartAfterResponse { - return addressService.getAddresses(limit = paginationRequest.limit, startAfter = paginationRequest.startAfter, externalIds = externalIds) + ): PageResponse { + return addressService.getAddresses(page = paginationRequest.page, size = paginationRequest.size, externalIds = externalIds) } - override fun getAddresses(paginationRequest: PaginationStartAfterRequest): PageStartAfterResponse { - return addressService.getAddresses(paginationRequest.limit, paginationRequest.startAfter) + override fun getAddresses(paginationRequest: PaginationRequest): PageResponse { + return addressService.getAddresses(page = paginationRequest.page, size = paginationRequest.size) } override fun getAddressesOutput( diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/repository/GateAddressRepository.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/repository/GateAddressRepository.kt index ed79eb77f..059a9bb6b 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/repository/GateAddressRepository.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/repository/GateAddressRepository.kt @@ -20,13 +20,17 @@ package org.eclipse.tractusx.bpdm.gate.repository import org.eclipse.tractusx.bpdm.gate.entity.LogisticAddress -import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.domain.Page +import org.springframework.data.domain.Pageable import org.springframework.data.repository.CrudRepository +import org.springframework.data.repository.PagingAndSortingRepository -interface GateAddressRepository : JpaRepository, CrudRepository { +interface GateAddressRepository : PagingAndSortingRepository, CrudRepository { fun findByExternalIdIn(externalId: Collection): Set fun findByExternalId(externalId: String): LogisticAddress? + fun findByExternalIdIn(externalId: Collection?, pageable: Pageable): Page + } \ No newline at end of file diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/repository/LegalEntityRepository.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/repository/LegalEntityRepository.kt index 3443d58fc..f76844083 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/repository/LegalEntityRepository.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/repository/LegalEntityRepository.kt @@ -26,6 +26,5 @@ import org.springframework.data.repository.CrudRepository interface LegalEntityRepository : JpaRepository, CrudRepository { fun findDistinctByExternalIdIn(externalId: Collection): Set - fun findByExternalId(externalId: String): LegalEntity? } \ No newline at end of file diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/AddressService.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/AddressService.kt index 02b3e1f26..c45ba5503 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/AddressService.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/AddressService.kt @@ -21,22 +21,22 @@ package org.eclipse.tractusx.bpdm.gate.service import mu.KotlinLogging import org.eclipse.tractusx.bpdm.common.dto.response.LogisticAddressResponse +import org.eclipse.tractusx.bpdm.common.dto.response.PageResponse import org.eclipse.tractusx.bpdm.common.dto.saas.BusinessPartnerSaas -import org.eclipse.tractusx.bpdm.common.dto.saas.FetchResponse -import org.eclipse.tractusx.bpdm.common.dto.saas.PagedResponseSaas import org.eclipse.tractusx.bpdm.common.exception.BpdmNotFoundException import org.eclipse.tractusx.bpdm.gate.api.model.AddressGateInputRequest import org.eclipse.tractusx.bpdm.gate.api.model.AddressGateInputResponse import org.eclipse.tractusx.bpdm.gate.api.model.AddressGateOutput import org.eclipse.tractusx.bpdm.gate.api.model.response.LsaType -import org.eclipse.tractusx.bpdm.gate.api.model.response.OptionalLsaType import org.eclipse.tractusx.bpdm.gate.api.model.response.PageOutputResponse -import org.eclipse.tractusx.bpdm.gate.api.model.response.PageStartAfterResponse import org.eclipse.tractusx.bpdm.gate.config.BpnConfigProperties import org.eclipse.tractusx.bpdm.gate.entity.ChangelogEntry -import org.eclipse.tractusx.bpdm.gate.exception.SaasInvalidRecordException +import org.eclipse.tractusx.bpdm.gate.entity.LogisticAddress import org.eclipse.tractusx.bpdm.gate.exception.SaasNonexistentParentException import org.eclipse.tractusx.bpdm.gate.repository.ChangelogRepository +import org.eclipse.tractusx.bpdm.gate.repository.GateAddressRepository +import org.springframework.data.domain.Page +import org.springframework.data.domain.PageRequest import org.springframework.stereotype.Service @Service @@ -49,71 +49,40 @@ class AddressService( private val bpnConfigProperties: BpnConfigProperties, private val typeMatchingService: TypeMatchingService, private val changelogRepository: ChangelogRepository, - private val addressPersistenceService: AddressPersistenceService + private val addressPersistenceService: AddressPersistenceService, + private val addressRepository: GateAddressRepository ) { private val logger = KotlinLogging.logger { } - fun getAddresses(limit: Int, startAfter: String?, externalIds: Collection? = null): PageStartAfterResponse { - val addressesPage = saasClient.getAddresses(limit, startAfter, externalIds) + fun getAddresses(page: Int, size: Int, externalIds: Collection? = null): PageResponse { - val addressGateInputResponse = toValidAddresses(addressesPage) + val logisticAddressPage = if (externalIds != null) { + addressRepository.findByExternalIdIn(externalIds, PageRequest.of(page, size)) + } else { + addressRepository.findAll(PageRequest.of(page, size)) + } - return PageStartAfterResponse( - total = addressesPage.total, - nextStartAfter = addressesPage.nextStartAfter, - content = addressGateInputResponse, - invalidEntries = addressesPage.values.size - addressGateInputResponse.size + return PageResponse( + page = page, + totalElements = logisticAddressPage.totalElements, + totalPages = logisticAddressPage.totalPages, + contentSize = logisticAddressPage.content.size, + content = toValidLogisticAddresses(logisticAddressPage), ) } - private fun toValidAddresses(addressesPage: PagedResponseSaas): List { - val validEntries = addressesPage.values - .filter { validateAddressBusinessPartner(it) } - - val addressesWithParent = validEntries.map { - Pair(it, inputSaasMappingService.toParentLegalEntityExternalId(it)!!) - } - - val parents = if (addressesWithParent.isNotEmpty()) - saasClient.getBusinessPartners( - externalIds = addressesWithParent.map { (_, parentId) -> parentId } - ).values - else - emptyList() - - val (legalEntityParents, siteParents) = typeMatchingService.partitionIntoParentTypes(parents) - val legalEntityParentIds = legalEntityParents.mapNotNull { it.externalId }.toHashSet() - val siteParentIds = siteParents.mapNotNull { it.externalId }.toHashSet() - - return addressesWithParent.mapNotNull { (address, parentId) -> - try { - when { - legalEntityParentIds.contains(parentId) -> - inputSaasMappingService.toInputAddress(address, parentId, null) - - siteParentIds.contains(parentId) -> - inputSaasMappingService.toInputAddress(address, null, parentId) - - else -> { - logger.warn { "Could not fetch parent for SaaS address record with ID ${address.id}" } - null - } - } - - } catch (e: RuntimeException) { - logger.warn { "SaaS address record with ID ${address.id} will be ignored: ${e.message}" } - null - } + private fun toValidLogisticAddresses(logisticAddressPage: Page): List { + return logisticAddressPage.content.map { logisticAddress -> + logisticAddress.toAddressGateInputResponse(logisticAddress) } } fun getAddressByExternalId(externalId: String): AddressGateInputResponse { - val fetchResponse = saasClient.getBusinessPartner(externalId) - when (fetchResponse.status) { - FetchResponse.Status.OK -> return toValidAddressInput(fetchResponse.businessPartner!!) - FetchResponse.Status.NOT_FOUND -> throw BpdmNotFoundException("Address", externalId) - } + val logisticAddress = addressRepository.findByExternalId(externalId) ?: throw BpdmNotFoundException("Logistic Address", externalId) + + return logisticAddress.toAddressGateInputResponse(logisticAddress) + } /** @@ -175,18 +144,11 @@ class AddressService( */ fun upsertAddresses(addresses: Collection) { - val addressesSaas = toSaasModels(addresses) - saasClient.upsertAddresses(addressesSaas) - // create changelog entry if all goes well from saasClient addresses.forEach { address -> changelogRepository.save(ChangelogEntry(address.externalId, LsaType.Address)) } - deleteParentRelationsOfAddresses(addresses) - - upsertParentRelations(addresses) - addressPersistenceService.persistAddressBP(addresses) } @@ -200,37 +162,6 @@ class AddressService( return addresses.map { toSaasModel(it, parentLegalEntitiesByExternalId[it.legalEntityExternalId], parentSitesByExternalId[it.siteExternalId]) } } - private fun upsertParentRelations(addresses: Collection) { - val legalEntityRelations = toLegalEntityParentRelations(addresses) - val siteRelations = toSiteParentRelations(addresses) - saasClient.upsertAddressRelations(legalEntityRelations, siteRelations) - } - - private fun deleteParentRelationsOfAddresses(addresses: Collection) { - val addressesPage = saasClient.getAddresses(externalIds = addresses.map { it.externalId }) - saasClient.deleteParentRelations(addressesPage.values) - } - - private fun toSiteParentRelations(addresses: Collection) = - addresses.filter { - it.siteExternalId != null - }.map { - SaasClient.AddressSiteRelation( - addressExternalId = it.externalId, - siteExternalId = it.siteExternalId!! - ) - }.toList() - - private fun toLegalEntityParentRelations(addresses: Collection) = - addresses.filter { - it.legalEntityExternalId != null - }.map { - SaasClient.AddressLegalEntityRelation( - addressExternalId = it.externalId, - legalEntityExternalId = it.legalEntityExternalId!! - ) - }.toList() - private fun getParentSites(addresses: Collection): Map { val parentSiteExternalIds = addresses.mapNotNull { it.siteExternalId }.distinct().toList() var parentSitesByExternalId: Map = HashMap() @@ -270,42 +201,4 @@ class AddressService( return addressSaas.copy(identifiers = addressSaas.identifiers.plus(parentIdentifiersWithoutBpn), names = parentNames) } - private fun toValidAddressInput(partner: BusinessPartnerSaas): AddressGateInputResponse { - if (!validateAddressBusinessPartner(partner)) { - throw SaasInvalidRecordException(partner.id) - } - - val parentId = inputSaasMappingService.toParentLegalEntityExternalId(partner) - val parentType = parentId?.let { saasClient.getBusinessPartner(it).businessPartner }?.let { typeMatchingService.determineType(it) } - - return when (parentType) { - OptionalLsaType.LegalEntity -> inputSaasMappingService.toInputAddress(partner, parentId, null) - OptionalLsaType.Site -> inputSaasMappingService.toInputAddress(partner, null, parentId) - else -> throw SaasInvalidRecordException(parentId) - } - } - - private fun validateAddressBusinessPartner(partner: BusinessPartnerSaas): Boolean { - val logMessageStart = "SaaS business partner for address with ${if (partner.id != null) "ID " + partner.id else "external id " + partner.externalId}" - - if (partner.addresses.size > 1) { - logger.warn { "$logMessageStart has multiple addresses" } - } - if (partner.addresses.isEmpty()) { - logger.warn { "$logMessageStart does not have an address" } - return false - } - - val numParents = inputSaasMappingService.toParentLegalEntityExternalIds(partner).size - if (numParents > 1) { - logger.warn { "$logMessageStart has multiple parents." } - } - - if (numParents == 0) { - logger.warn { "$logMessageStart does not have a parent legal entity or site." } - return false - } - - return true - } } \ No newline at end of file diff --git a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/ResponseMappings.kt b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/ResponseMappings.kt index 4aa792962..d442be874 100644 --- a/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/ResponseMappings.kt +++ b/bpdm-gate/src/main/kotlin/org/eclipse/tractusx/bpdm/gate/service/ResponseMappings.kt @@ -22,6 +22,7 @@ package org.eclipse.tractusx.bpdm.gate.service import org.eclipse.tractusx.bpdm.common.dto.* import org.eclipse.tractusx.bpdm.common.dto.response.PageResponse import org.eclipse.tractusx.bpdm.gate.api.model.AddressGateInputRequest +import org.eclipse.tractusx.bpdm.gate.api.model.AddressGateInputResponse import org.eclipse.tractusx.bpdm.gate.api.model.LegalEntityGateInputRequest import org.eclipse.tractusx.bpdm.gate.api.model.SiteGateInputRequest import org.eclipse.tractusx.bpdm.gate.api.model.response.ChangelogResponse @@ -176,7 +177,6 @@ fun toEntityIdentifier(dto: LegalEntityIdentifierDto, legalEntity: LegalEntity): fun toEntityState(dto: LegalEntityStateDto, legalEntity: LegalEntity): LegalEntityState { return LegalEntityState(dto.officialDenotation, dto.validFrom, dto.validTo, dto.type, legalEntity) } - fun toEntityClassification(dto: ClassificationDto, legalEntity: LegalEntity): Classification { return Classification(dto.value, dto.code, dto.type, legalEntity) } @@ -195,4 +195,105 @@ fun getMainAddressForSiteExternalId(siteExternalId: String): String { fun getMainAddressForLegalEntityExternalId(siteExternalId: String): String { return siteExternalId + "_legalAddress" +} + +//Logistic Address mapping to AddressGateInputResponse +fun LogisticAddress.toAddressGateInputResponse(logisticAddressPage: LogisticAddress): AddressGateInputResponse { + + val addressGateInputResponse = AddressGateInputResponse( + address = logisticAddressPage.toLogisticAddressDto(), + externalId = externalId, + legalEntityExternalId = legalEntity?.externalId, + siteExternalId = site?.externalId, + bpn = bpn, + processStartedAt = null //TODO Remove ? + ) + + return addressGateInputResponse +} + +//Logistic Address mapping to LogisticAddressDto +fun LogisticAddress.toLogisticAddressDto(): LogisticAddressDto { + + val logisticAddress = LogisticAddressDto( + name = name, + states = mapToDtoStates(states), + identifiers = mapToDtoIdentifiers(identifiers), + physicalPostalAddress = physicalPostalAddress.toPhysicalPostalAddress(), + alternativePostalAddress = alternativePostalAddress?.toAlternativePostalAddressDto(), + ) + + return logisticAddress +} + +fun mapToDtoStates(states: MutableSet): Collection { + return states.map { AddressStateDto(it.description, it.validFrom, it.validTo, it.type) } +} + +fun mapToDtoIdentifiers(identifier: MutableSet): Collection { + return identifier.map { AddressIdentifierDto(it.value, it.type) } +} + +fun AlternativePostalAddress.toAlternativePostalAddressDto(): AlternativePostalAddressDto { + + val basePostalAddressDto = BasePostalAddressDto( + geographicCoordinates = geographicCoordinates?.toGeographicCoordinateDto(), + country = country, + postalCode = postCode, + city = city + ) + + val areaDistrictAlternativDto = AreaDistrictAlternativDto( + administrativeAreaLevel1 = null // TODO Add region mapping Logic + ) + + return AlternativePostalAddressDto( + deliveryServiceType = deliveryServiceType, + deliveryServiceNumber = deliveryServiceNumber, + areaPart = areaDistrictAlternativDto, + baseAddress = basePostalAddressDto + ) + +} + +fun PhysicalPostalAddress.toPhysicalPostalAddress(): PhysicalPostalAddressDto { + + val basePostalAddressDto = BasePostalAddressDto( + geographicCoordinates = geographicCoordinates?.toGeographicCoordinateDto(), + country = country, + postalCode = postCode, + city = city + ) + + val areaDistrictDto = AreaDistrictDto( + administrativeAreaLevel1 = null, // TODO Add region mapping Logic + administrativeAreaLevel2 = administrativeAreaLevel2, + administrativeAreaLevel3 = administrativeAreaLevel3, + district = districtLevel1 + ) + + return PhysicalPostalAddressDto( + baseAddress = basePostalAddressDto, + companyPostalCode = companyPostCode, + industrialZone = industrialZone, + building = building, + street = street?.toStreetDto(), + floor = floor, + door = door, + areaPart = areaDistrictDto + ) + +} + +fun GeographicCoordinate.toGeographicCoordinateDto(): GeoCoordinateDto { + return GeoCoordinateDto(longitude, latitude, altitude) +} + +private fun Street.toStreetDto(): StreetDto { + return StreetDto( + name = name, + houseNumber = houseNumber, + milestone = milestone, + direction = direction + ) } \ No newline at end of file diff --git a/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/controller/AddressControllerInputIT.kt b/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/controller/AddressControllerInputIT.kt index c3aaafae7..cf9450238 100644 --- a/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/controller/AddressControllerInputIT.kt +++ b/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/controller/AddressControllerInputIT.kt @@ -43,19 +43,15 @@ import com.github.tomakehurst.wiremock.client.WireMock.* import com.github.tomakehurst.wiremock.core.WireMockConfiguration import com.github.tomakehurst.wiremock.junit5.WireMockExtension import org.assertj.core.api.Assertions.assertThat +import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest +import org.eclipse.tractusx.bpdm.common.dto.response.PageResponse import org.eclipse.tractusx.bpdm.common.dto.saas.* import org.eclipse.tractusx.bpdm.gate.api.client.GateClient -import org.eclipse.tractusx.bpdm.gate.api.model.request.PaginationStartAfterRequest -import org.eclipse.tractusx.bpdm.gate.api.model.response.PageStartAfterResponse import org.eclipse.tractusx.bpdm.gate.api.model.response.ValidationResponse import org.eclipse.tractusx.bpdm.gate.api.model.response.ValidationStatus -import org.eclipse.tractusx.bpdm.gate.config.SaasConfigProperties import org.eclipse.tractusx.bpdm.gate.repository.GateAddressRepository - import org.eclipse.tractusx.bpdm.gate.util.* import org.eclipse.tractusx.bpdm.gate.util.EndpointValues.SAAS_MOCK_BUSINESS_PARTNER_PATH -import org.eclipse.tractusx.bpdm.gate.util.EndpointValues.SAAS_MOCK_RELATIONS_PATH -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotEquals import org.junit.jupiter.api.BeforeEach @@ -64,7 +60,6 @@ import org.junit.jupiter.api.extension.RegisterExtension import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest import org.springframework.http.HttpStatus -import org.springframework.http.HttpStatusCode import org.springframework.test.context.ActiveProfiles import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.DynamicPropertyRegistry @@ -76,9 +71,9 @@ import org.springframework.web.reactive.function.client.WebClientResponseExcepti @ContextConfiguration(initializers = [PostgreSQLContextInitializer::class]) internal class AddressControllerInputIT @Autowired constructor( private val objectMapper: ObjectMapper, - private val saasConfigProperties: SaasConfigProperties, val gateClient: GateClient, - private val gateAddressRepository: GateAddressRepository + private val gateAddressRepository: GateAddressRepository, + val testHelpers: DbTestHelpers, ) { companion object { @RegisterExtension @@ -96,62 +91,25 @@ internal class AddressControllerInputIT @Autowired constructor( @BeforeEach fun beforeEach() { wireMockServer.resetAll() + testHelpers.truncateDbTables() } /** - * Given address exists in SaaS + * Given address exists in the persistence database * When getting address by external id * Then address mapped to the catena data model should be returned */ @Test fun `get address by external id`() { - val externalIdToQuery = SaasValues.addressBusinessPartnerWithRelations1.externalId!! - val expectedAddress = ResponseValues.addressGateInputResponse1 - val addressRequest = FetchRequest( - dataSource = saasConfigProperties.datasource, - externalId = externalIdToQuery, - featuresOn = listOf(FetchRequest.SaasFeatures.FETCH_RELATIONS) - ) - wireMockServer.stubFor( - post(urlPathMatching(EndpointValues.SAAS_MOCK_FETCH_BUSINESS_PARTNER_PATH)) - .withRequestBody(equalToJson(objectMapper.writeValueAsString(addressRequest))) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBody( - objectMapper.writeValueAsString( - FetchResponse( - businessPartner = SaasValues.addressBusinessPartnerWithRelations1, - status = FetchResponse.Status.OK - ) - ) - ) - ) - ) + val externalIdToQuery = CommonValues.externalIdAddress2 + val expectedAddress = ResponseValues.logisticAddressGateInputResponse2 - val parentRequest = FetchRequest( - dataSource = saasConfigProperties.datasource, - externalId = SaasValues.legalEntityRequest1.externalId!!, - featuresOn = listOf(FetchRequest.SaasFeatures.FETCH_RELATIONS) - ) - wireMockServer.stubFor( - post(urlPathMatching(EndpointValues.SAAS_MOCK_FETCH_BUSINESS_PARTNER_PATH)) - .withRequestBody(equalToJson(objectMapper.writeValueAsString(parentRequest))) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBody( - objectMapper.writeValueAsString( - FetchResponse( - businessPartner = SaasValues.legalEntityResponse1, - status = FetchResponse.Status.OK - ) - ) - ) - ) + val addresses = listOf( + RequestValues.addressGateInputRequest2 ) + gateClient.addresses().upsertAddresses(addresses) val valueResponse = gateClient.addresses().getAddressByExternalId(externalIdToQuery) @@ -159,27 +117,12 @@ internal class AddressControllerInputIT @Autowired constructor( } /** - * Given address does not exist in SaaS + * Given address does not exist in the persistence database * When getting address by external id * Then "not found" response is sent */ @Test fun `get address by external id, not found`() { - wireMockServer.stubFor( - post(urlPathMatching(EndpointValues.SAAS_MOCK_FETCH_BUSINESS_PARTNER_PATH)) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBody( - objectMapper.writeValueAsString( - FetchResponse( - businessPartner = null, - status = FetchResponse.Status.NOT_FOUND - ) - ) - ) - ) - ) try { gateClient.addresses().getAddressByExternalId("NONEXISTENT_BPN") @@ -189,335 +132,92 @@ internal class AddressControllerInputIT @Autowired constructor( } /** - * When SaaS api responds with an error status code while fetching address by external id - * Then an internal server error response should be sent - */ - @Test - fun `get address by external id, SaaS error`() { - wireMockServer.stubFor( - post(urlPathMatching(EndpointValues.SAAS_MOCK_FETCH_BUSINESS_PARTNER_PATH)) - .willReturn(badRequest()) - ) - - try { - gateClient.addresses().getAddressByExternalId(SaasValues.legalEntityRequest1.externalId.toString()) - } catch (e: WebClientResponseException) { - val statusCode: HttpStatusCode = e.statusCode - val statusCodeValue: Int = statusCode.value() - Assertions.assertTrue(statusCodeValue in 500..599) - } - } - - /** - * Given address business partner without address data in SaaS - * When query by its external ID - * Then server error is returned - */ - @Test - fun `get address for which SaaS data is invalid, expect error`() { - - val invalidPartner = SaasValues.addressBusinessPartnerWithRelations1.copy(addresses = emptyList()) - - wireMockServer.stubFor( - post(urlPathMatching(EndpointValues.SAAS_MOCK_FETCH_BUSINESS_PARTNER_PATH)) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBody( - objectMapper.writeValueAsString( - FetchResponse( - businessPartner = invalidPartner, - status = FetchResponse.Status.OK - ) - ) - ) - ) - ) - - try { - gateClient.addresses().getAddressByExternalId(SaasValues.addressBusinessPartnerWithRelations1.externalId.toString()) - } catch (e: WebClientResponseException) { - val statusCode: HttpStatusCode = e.statusCode - val statusCodeValue: Int = statusCode.value() - Assertions.assertTrue(statusCodeValue in 500..599) - } - - } - - /** - * Given addresses exists in SaaS + * Given addresses exists in the persistence database * When getting addresses page * Then addresses page mapped to the catena data model should be returned */ - @Test fun `get addresses`() { - val addressesSaas = listOf( - SaasValues.addressBusinessPartnerWithRelations1, - SaasValues.addressBusinessPartnerWithRelations2 - ) - val parentsSaas = listOf( - SaasValues.legalEntityResponse1, - SaasValues.siteBusinessPartner1 + val expectedAddresses = listOf( + ResponseValues.logisticAddressGateInputResponse1, + ResponseValues.logisticAddressGateInputResponse2, ) - val expectedAddresses = listOf( - ResponseValues.addressGateInputResponse1, - ResponseValues.addressGateInputResponse2, + val addresses = listOf( + RequestValues.addressGateInputRequest1, + RequestValues.addressGateInputRequest2 ) - val limit = 2 - val startAfter = "Aaa111" - val nextStartAfter = "Aaa222" - val total = 10 - val invalidEntries = 0 + val page = 0 + val size = 10 - wireMockServer.stubFor( - get(urlPathMatching(SAAS_MOCK_BUSINESS_PARTNER_PATH)) - .withQueryParam("externalId", absent()) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBody( - objectMapper.writeValueAsString( - PagedResponseSaas( - limit = limit, - startAfter = startAfter, - nextStartAfter = nextStartAfter, - total = total, - values = addressesSaas - ) - ) - ) - ) - ) + val totalElements = 2L + val totalPages = 1 + val pageValue = 0 + val contentSize = 2 - wireMockServer.stubFor( - get(urlPathMatching(SAAS_MOCK_BUSINESS_PARTNER_PATH)) - .withQueryParam("externalId", matching(".*")) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBody( - objectMapper.writeValueAsString( - PagedResponseSaas( - limit = parentsSaas.size, - startAfter = null, - nextStartAfter = null, - total = parentsSaas.size, - values = parentsSaas - ) - ) - ) - ) - ) + gateClient.addresses().upsertAddresses(addresses) - val paginationValue = PaginationStartAfterRequest(startAfter, limit) + val paginationValue = PaginationRequest(page, size) val pageResponse = gateClient.addresses().getAddresses(paginationValue) assertThat(pageResponse).isEqualTo( - PageStartAfterResponse( - total = total, - nextStartAfter = nextStartAfter, - content = expectedAddresses, - invalidEntries = invalidEntries + PageResponse( + totalElements = totalElements, + totalPages = totalPages, + page = pageValue, + contentSize = contentSize, + content = expectedAddresses ) ) } /** - * Given addresses exists in SaaS + * Given addresses exists in the Persistence Database * When getting addresses page based on external id list - * Then addresses page mapped to the catena data model should be returned + * Then addresses should be returned */ @Test fun `get addresses filter by external ids`() { - val addressesSaas = listOf( - SaasValues.addressBusinessPartnerWithRelations1, - SaasValues.addressBusinessPartnerWithRelations2 - ) - - val parentsSaas = listOf( - SaasValues.legalEntityResponse1, - SaasValues.siteBusinessPartner1 + val addresses = listOf( + RequestValues.addressGateInputRequest1, + RequestValues.addressGateInputRequest2 ) val expectedAddresses = listOf( - ResponseValues.addressGateInputResponse1, - ResponseValues.addressGateInputResponse2, + ResponseValues.logisticAddressGateInputResponse1, + ResponseValues.logisticAddressGateInputResponse2, ) - val limit = 2 - val startAfter = "Aaa111" - val nextStartAfter = "Aaa222" - val total = 10 - val invalidEntries = 0 + val page = 0 + val size = 10 + val totalElements = 2L + val totalPages = 1 + val pageValue = 0 + val contentSize = 2 + val listExternalIds = addresses.map { it.externalId } - wireMockServer.stubFor( - get(urlPathMatching(SAAS_MOCK_BUSINESS_PARTNER_PATH)) - .withQueryParam("externalId", matching(".*")) - .withQueryParam("typeTechnicalKeys", matching(".*")) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBody( - objectMapper.writeValueAsString( - PagedResponseSaas( - limit = limit, - startAfter = startAfter, - nextStartAfter = nextStartAfter, - total = total, - values = addressesSaas - ) - ) - ) - ) - ) - - wireMockServer.stubFor( - get(urlPathMatching(SAAS_MOCK_BUSINESS_PARTNER_PATH)) - .withQueryParam("externalId", matching(".*")) - .withQueryParam("typeTechnicalKeys", absent()) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBody( - objectMapper.writeValueAsString( - PagedResponseSaas( - limit = parentsSaas.size, - startAfter = null, - nextStartAfter = null, - total = parentsSaas.size, - values = parentsSaas - ) - ) - ) - ) - ) - - val listExternalIds = addressesSaas.mapNotNull { it.externalId } + gateClient.addresses().upsertAddresses(addresses) - val paginationValue = PaginationStartAfterRequest(startAfter, limit) - val pageResponse = gateClient.addresses().getAddressesByExternalIds(paginationValue, listExternalIds) + val pagination = PaginationRequest(page, size) + val pageResponse = gateClient.addresses().getAddressesByExternalIds(pagination, listExternalIds) assertThat(pageResponse).isEqualTo( - PageStartAfterResponse( - total = total, - nextStartAfter = nextStartAfter, - content = expectedAddresses, - invalidEntries = invalidEntries + PageResponse( + totalElements = totalElements, + totalPages = totalPages, + page = pageValue, + contentSize = contentSize, + content = expectedAddresses ) ) } - /** - * Given invalid addresses in SaaS - * When getting addresses page - * Then only valid addresses on page returned - */ - @Test - fun `filter invalid addresses`() { - val addressesSaas = listOf( - SaasValues.addressBusinessPartnerWithRelations1, - SaasValues.addressBusinessPartnerWithRelations2, - SaasValues.addressBusinessPartnerWithRelations1.copy(addresses = emptyList()), // address without address data - ) - - val parentsSaas = listOf( - SaasValues.legalEntityResponse1, - SaasValues.siteBusinessPartner1 - ) - - val expectedAddresses = listOf( - ResponseValues.addressGateInputResponse1, - ResponseValues.addressGateInputResponse2, - ) - - val limit = 3 - val startAfter = "Aaa111" - val nextStartAfter = "Aaa222" - val total = 10 - val invalidEntries = 1 - - wireMockServer.stubFor( - get(urlPathMatching(SAAS_MOCK_BUSINESS_PARTNER_PATH)) - .withQueryParam("externalId", absent()) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBody( - objectMapper.writeValueAsString( - PagedResponseSaas( - limit = limit, - startAfter = startAfter, - nextStartAfter = nextStartAfter, - total = total, - values = addressesSaas - ) - ) - ) - ) - ) - - wireMockServer.stubFor( - get(urlPathMatching(SAAS_MOCK_BUSINESS_PARTNER_PATH)) - .withQueryParam("externalId", matching(".*")) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBody( - objectMapper.writeValueAsString( - PagedResponseSaas( - limit = parentsSaas.size, - startAfter = null, - nextStartAfter = null, - total = parentsSaas.size, - values = parentsSaas - ) - ) - ) - ) - ) - - val paginationValues = PaginationStartAfterRequest(startAfter, limit) - val pageResponse = gateClient.addresses().getAddresses(paginationValues) - - assertThat(pageResponse).isEqualTo( - PageStartAfterResponse( - total = total, - nextStartAfter = nextStartAfter, - content = expectedAddresses, - invalidEntries = invalidEntries - ) - ) - } - - /** - * When SaaS api responds with an error status code while getting addresses - * Then an internal server error response should be sent - */ - @Test - fun `get addresses, SaaS error`() { - wireMockServer.stubFor( - get(urlPathMatching(SAAS_MOCK_BUSINESS_PARTNER_PATH)) - .willReturn(badRequest()) - ) - - try { - gateClient.addresses().getAddresses(PaginationStartAfterRequest("")) - } catch (e: WebClientResponseException) { - val statusCode: HttpStatusCode = e.statusCode - val statusCodeValue: Int = statusCode.value() - Assertions.assertTrue(statusCodeValue in 500..599) - } - - } - /** * When requesting too many addresses * Then a bad request response should be sent @@ -525,7 +225,10 @@ internal class AddressControllerInputIT @Autowired constructor( @Test fun `get addresses, pagination limit exceeded`() { - val paginationRequest = PaginationStartAfterRequest("", limit = 999999) + val page = 0 + val size = 999999 + + val paginationRequest = PaginationRequest(page, size) try { gateClient.addresses().getAddresses(paginationRequest) @@ -536,9 +239,9 @@ internal class AddressControllerInputIT @Autowired constructor( } /** - * Given legal entities and sites in SaaS - * When upserting addresses of legal entities and sites - * Then upsert addresses and relations in SaaS api should be called with the address data mapped to the SaaS data model + * Given legal entities and sites + * When upserting addresses of legal entities and sites or a new one + * Then upsert addresses should be persisted on the database */ @Test fun `upsert addresses`() { @@ -547,166 +250,6 @@ internal class AddressControllerInputIT @Autowired constructor( RequestValues.addressGateInputRequest2 ) - val legalEntity = listOf( - RequestValues.legalEntityGateInputRequest1, - ) - - val sites = listOf( - RequestValues.siteGateInputRequest1, - ) - - val parentLegalEntitiesSaas = listOf( - SaasValues.legalEntityResponse1 - ) - - val parentSitesSaas = listOf( - SaasValues.siteBusinessPartner1 - ) - - val expectedAddresses = listOf( - SaasValues.addressBusinessPartnerRequest1, - SaasValues.addressBusinessPartnerRequest2, - ) - - val expectedRelations = listOf( - SaasValues.relationAddress1ToLegalEntity, - SaasValues.relationAddress2ToSite - ) - - val expectedDeletedRelations = listOf( - DeleteRelationsRequestSaas.RelationToDeleteSaas( - startNode = DeleteRelationsRequestSaas.RelationNodeToDeleteSaas( - dataSourceId = saasConfigProperties.datasource, - externalId = SaasValues.addressBusinessPartnerWithRelations1.relations.first().startNode - ), - endNode = DeleteRelationsRequestSaas.RelationNodeToDeleteSaas( - dataSourceId = saasConfigProperties.datasource, - externalId = SaasValues.addressBusinessPartnerWithRelations1.relations.first().endNode - ), - ), - DeleteRelationsRequestSaas.RelationToDeleteSaas( - startNode = DeleteRelationsRequestSaas.RelationNodeToDeleteSaas( - dataSourceId = saasConfigProperties.datasource, - externalId = SaasValues.addressBusinessPartnerWithRelations2.relations.first().startNode - ), - endNode = DeleteRelationsRequestSaas.RelationNodeToDeleteSaas( - dataSourceId = saasConfigProperties.datasource, - externalId = SaasValues.addressBusinessPartnerWithRelations2.relations.first().endNode - ), - ), - ) - - // mock "get parent legal entities" - wireMockServer.stubFor( - get(urlPathMatching(SAAS_MOCK_BUSINESS_PARTNER_PATH)) - .withQueryParam("externalId", equalTo(addresses.mapNotNull { it.legalEntityExternalId }.joinToString(","))) - .withQueryParam("dataSource", equalTo(saasConfigProperties.datasource)) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBody( - objectMapper.writeValueAsString( - PagedResponseSaas( - limit = 50, - total = 1, - values = parentLegalEntitiesSaas - ) - ) - ) - ) - ) - // mock "get parent sites" - wireMockServer.stubFor( - get(urlPathMatching(SAAS_MOCK_BUSINESS_PARTNER_PATH)) - .withQueryParam("externalId", equalTo(addresses.mapNotNull { it.siteExternalId }.joinToString(","))) - .withQueryParam("dataSource", equalTo(saasConfigProperties.datasource)) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBody( - objectMapper.writeValueAsString( - PagedResponseSaas( - limit = 50, - total = 1, - values = parentSitesSaas - ) - ) - ) - ) - ) - val stubMappingUpsertAddresses = wireMockServer.stubFor( - put(urlPathMatching(SAAS_MOCK_BUSINESS_PARTNER_PATH)) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBody( - objectMapper.writeValueAsString( - UpsertResponse( - emptyList(), - emptyList(), - 2, - 0 - ) - ) - ) - ) - ) - // mock "get addresses with relations" - // this simulates the case that the address already had some relations - wireMockServer.stubFor( - get(urlPathMatching(SAAS_MOCK_BUSINESS_PARTNER_PATH)) - .withQueryParam("externalId", equalTo(addresses.map { it.externalId }.joinToString(","))) - .withQueryParam("dataSource", equalTo(saasConfigProperties.datasource)) - .withQueryParam("featuresOn", containing("FETCH_RELATIONS")) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBody( - objectMapper.writeValueAsString( - PagedResponseSaas( - limit = 50, - total = 2, - values = listOf( - SaasValues.addressBusinessPartnerWithRelations1, - SaasValues.addressBusinessPartnerWithRelations2 - ) - ) - ) - ) - ) - ) - val stubMappingDeleteRelations = wireMockServer.stubFor( - post(urlPathMatching(EndpointValues.SAAS_MOCK_DELETE_RELATIONS_PATH)) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBody( - objectMapper.writeValueAsString( - DeleteRelationsResponseSaas(2) - ) - ) - ) - ) - val stubMappingUpsertRelations = wireMockServer.stubFor( - put(urlPathMatching(SAAS_MOCK_RELATIONS_PATH)) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBody( - objectMapper.writeValueAsString( - UpsertRelationsResponseSaas( - failures = emptyList(), - numberOfFailed = 0, - numberOfInserts = 2, - numberOfProvidedRelations = 2, - numberOfUpdates = 0 - ) - ) - ) - ) - ) - - try { gateClient.addresses().upsertAddresses(addresses) } catch (e: WebClientResponseException) { @@ -720,17 +263,25 @@ internal class AddressControllerInputIT @Autowired constructor( val addressExternal2 = gateAddressRepository.findByExternalId("address-external-2") assertNotEquals(addressExternal2, null) - // TODO -// val upsertAddressesRequest = wireMockServer.deserializeMatchedRequests(stubMappingUpsertAddresses, objectMapper).single() -// assertThat(upsertAddressesRequest.businessPartners).containsExactlyInAnyOrderElementsOf(expectedAddresses) + } + + /** + * When upserting addresses + * if both have both have the same externalId, "bad request" should show + */ + @Test + fun `upsert addresses, same externalid`() { + val addresses = listOf( + RequestValues.addressGateInputRequest1, + RequestValues.addressGateInputRequest1 + ) - // check that "delete relations" was called in SaaS as expected - val deleteRelationsRequestSaas = - wireMockServer.deserializeMatchedRequests(stubMappingDeleteRelations, objectMapper).single() - assertThat(deleteRelationsRequestSaas.relations).containsExactlyInAnyOrderElementsOf(expectedDeletedRelations) + try { + gateClient.addresses().upsertAddresses(addresses) + } catch (e: WebClientResponseException) { + assertEquals(HttpStatus.BAD_REQUEST, e.statusCode) + } - val upsertRelationsRequest = wireMockServer.deserializeMatchedRequests(stubMappingUpsertRelations, objectMapper).single() - assertThat(upsertRelationsRequest.relations).containsExactlyInAnyOrderElementsOf(expectedRelations) } /** @@ -743,26 +294,6 @@ internal class AddressControllerInputIT @Autowired constructor( RequestValues.addressGateInputRequest1 ) - // mock "get parent legal entities" - wireMockServer.stubFor( - get(urlPathMatching(SAAS_MOCK_BUSINESS_PARTNER_PATH)) - .withQueryParam("externalId", equalTo(addresses.mapNotNull { it.legalEntityExternalId }.joinToString(","))) - .withQueryParam("dataSource", equalTo(saasConfigProperties.datasource)) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBody( - objectMapper.writeValueAsString( - PagedResponseSaas( - limit = 50, - total = 0, - values = emptyList() - ) - ) - ) - ) - ) - try { gateClient.addresses().upsertAddresses(addresses) } catch (e: WebClientResponseException) { @@ -781,26 +312,6 @@ internal class AddressControllerInputIT @Autowired constructor( RequestValues.addressGateInputRequest2 ) - // mock "get parent sites" - wireMockServer.stubFor( - get(urlPathMatching(SAAS_MOCK_BUSINESS_PARTNER_PATH)) - .withQueryParam("externalId", equalTo(addresses.mapNotNull { it.siteExternalId }.joinToString(","))) - .withQueryParam("dataSource", equalTo(saasConfigProperties.datasource)) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBody( - objectMapper.writeValueAsString( - PagedResponseSaas( - limit = 50, - total = 0, - values = emptyList() - ) - ) - ) - ) - ) - try{ gateClient.addresses().upsertAddresses(addresses) }catch (e: WebClientResponseException){ diff --git a/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/util/RequestValues.kt b/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/util/RequestValues.kt index 11f9f67f5..f267dea81 100644 --- a/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/util/RequestValues.kt +++ b/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/util/RequestValues.kt @@ -155,6 +155,45 @@ object RequestValues { ) ) + //New Values for Logistic Addresses Tests + val postalAddressLogisticAddress1 = PhysicalPostalAddressDto( + industrialZone = CommonValues.industrialZone1, + building = CommonValues.building1, + floor = CommonValues.floor1, + door = CommonValues.door1, + areaPart = AreaDistrictDto( + administrativeAreaLevel1 = null, + administrativeAreaLevel2 = CommonValues.county1, + district = CommonValues.district1, + ), + street = StreetDto(name = CommonValues.street1, houseNumber = CommonValues.houseNumber1, direction = CommonValues.direction1), + baseAddress = BasePostalAddressDto( + geographicCoordinates = geoCoordinate1, + country = CommonValues.country1, + postalCode = CommonValues.postCode1, + city = CommonValues.city1, + ) + ) + + val postalAddressLogisticAddress2 = PhysicalPostalAddressDto( + industrialZone = CommonValues.industrialZone2, + building = CommonValues.building2, + floor = CommonValues.floor2, + door = CommonValues.door2, + areaPart = AreaDistrictDto( + administrativeAreaLevel1 = null, + administrativeAreaLevel2 = CommonValues.county2, + district = CommonValues.district2, + ), + street = StreetDto(name = CommonValues.street2, houseNumber = CommonValues.houseNumber2, direction = CommonValues.direction2), + baseAddress = BasePostalAddressDto( + geographicCoordinates = geoCoordinate2, + country = CommonValues.country2, + postalCode = CommonValues.postCode2, + city = CommonValues.city2, + ) + ) + val address1 = LogisticAddressDto( physicalPostalAddress = postalAddress1, ) @@ -163,6 +202,15 @@ object RequestValues { physicalPostalAddress = postalAddress2, ) + //New Values for Logistic Address Tests + val logisticAddress1 = LogisticAddressDto( + physicalPostalAddress = postalAddressLogisticAddress1, + ) + + val logisticAddress2 = LogisticAddressDto( + physicalPostalAddress = postalAddressLogisticAddress2, + ) + val legalEntity1 = LegalEntityDto( identifiers = listOf(identifier1, identifier2), @@ -221,13 +269,24 @@ object RequestValues { ) val addressGateInputRequest1 = AddressGateInputRequest( - address = address1, + address = address1.copy( + name = CommonValues.name1, + identifiers = listOf( + AddressIdentifierDto(SaasValues.identifier1.value!!, SaasValues.identifier1.type?.technicalKey!!) + ) + ), externalId = CommonValues.externalIdAddress1, legalEntityExternalId = CommonValues.externalId1, bpn = CommonValues.bpnAddress1 ) + val addressGateInputRequest2 = AddressGateInputRequest( - address = address2, + address = address2.copy( + name = CommonValues.name2, + identifiers = listOf( + AddressIdentifierDto(SaasValues.identifier1.value!!, SaasValues.identifier1.type?.technicalKey!!) + ) + ), externalId = CommonValues.externalIdAddress2, siteExternalId = CommonValues.externalIdSite1, bpn = CommonValues.bpnAddress2 diff --git a/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/util/ResponseValues.kt b/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/util/ResponseValues.kt index dbe45c5bc..0ee0f251e 100644 --- a/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/util/ResponseValues.kt +++ b/bpdm-gate/src/test/kotlin/org/eclipse/tractusx/bpdm/gate/util/ResponseValues.kt @@ -329,8 +329,8 @@ object ResponseValues { bpn = CommonValues.bpnAddress1, processStartedAt = SaasValues.modificationTime1, ) - val addressGateInputResponse2 = AddressGateInputResponse( + val addressGateInputResponse2 = AddressGateInputResponse( address = RequestValues.address2 .copy( name = CommonValues.nameSite1, @@ -353,4 +353,30 @@ object ResponseValues { address = logisticAddress2, externalId = CommonValues.externalIdAddress2, ) + + val logisticAddressGateInputResponse1 = AddressGateInputResponse( + address = RequestValues.logisticAddress1.copy( + name = CommonValues.name1, + identifiers = listOf( + AddressIdentifierDto(SaasValues.identifier1.value!!, SaasValues.identifier1.type?.technicalKey!!) + ) + ), + externalId = CommonValues.externalIdAddress1, + legalEntityExternalId = null, + bpn = CommonValues.bpnAddress1, + processStartedAt = null, + ) + + val logisticAddressGateInputResponse2 = AddressGateInputResponse( + address = RequestValues.logisticAddress2.copy( + name = CommonValues.name2, + identifiers = listOf( + AddressIdentifierDto(SaasValues.identifier1.value!!, SaasValues.identifier1.type?.technicalKey!!) + ) + ), + externalId = CommonValues.externalIdAddress2, + bpn = CommonValues.bpnAddress2, + siteExternalId = null, + processStartedAt = null, + ) } \ No newline at end of file