From 216bb177ef825c33899dbecd8c75b24e0524c178 Mon Sep 17 00:00:00 2001 From: "fabio.d.mota" Date: Fri, 26 May 2023 11:50:39 +0100 Subject: [PATCH] feat(Gate-Pool): Removing_SaaS_Import_Logic --- .../resources/application-saas.properties | 34 --------------- .../opensearch/InvalidIndexStartupIT.kt | 18 +++++--- .../opensearch/ValidIndexStartupIT.kt | 17 +++++++- .../controller/OpenSearchControllerIT.kt | 28 ++++++++++--- .../tractusx/bpdm/pool/util/TestHelpers.kt | 41 ------------------- 5 files changed, 49 insertions(+), 89 deletions(-) delete mode 100644 bpdm-pool/src/main/resources/application-saas.properties diff --git a/bpdm-pool/src/main/resources/application-saas.properties b/bpdm-pool/src/main/resources/application-saas.properties deleted file mode 100644 index 3cd9a7018..000000000 --- a/bpdm-pool/src/main/resources/application-saas.properties +++ /dev/null @@ -1,34 +0,0 @@ -################################################################################ -# Copyright (c) 2021,2023 Contributors to the Eclipse Foundation -# -# See the NOTICE file(s) distributed with this work for additional -# information regarding copyright ownership. -# -# This program and the accompanying materials are made available under the -# terms of the Apache License, Version 2.0 which is available at -# https://www.apache.org/licenses/LICENSE-2.0. -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# SPDX-License-Identifier: Apache-2.0 -################################################################################ -bpdm.saas.enabled=true -bpdm.saas.host=${BPDM_SAAS_HOST} -bpdm.saas.api=data-exchange/rest/v4 -#Storage ID to import from -bpdm.saas.storage=${BPDM_SAAS_STORAGE} -#Datasource ID for records to import -bpdm.saas.datasource=${BPDM_SAAS_DATASOURCE} -bpdm.saas.api-key=${BPDM_SAAS_KEY} -bpdm.saas.import-limit=100 -# Special value "-" disables scheduling. See javadoc of org.springframework.scheduling.support.CronExpression.parse for format. -bpdm.saas.import-scheduler-cron-expr=- -bpdm.saas.export-page-size=100 -# Whether to import records that have a BPN in SaaS (but not in the Pool) as new records -# Otherwise those records are ignored with a warning -bpdm.saas.treat-invalid-bpn-as-new=false -bpdm.saas.request-size-limit=500 diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/InvalidIndexStartupIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/InvalidIndexStartupIT.kt index 2003ef552..afb00029e 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/InvalidIndexStartupIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/InvalidIndexStartupIT.kt @@ -120,16 +120,22 @@ class InvalidIndexStartupIT @Autowired constructor( assertThat(getResponse.found()).isFalse //import a business partner to DB - testHelpers.importAndGetResponse(listOf(SaasValues.legalEntity1), webTestClient, wireMockServer) - + testHelpers.createTestMetadata() + testHelpers.createBusinessPartnerStructure( + listOf( + LegalEntityStructureRequest( + legalEntity = RequestValues.legalEntityCreate1, + ) + ) + ) //export to index and check whether the imported business partner can be found as normal testHelpers.startSyncAndAwaitSuccess(webTestClient, EndpointValues.OPENSEARCH_SYNC_PATH) val searchResult = poolClient.legalEntities().getLegalEntities( - LegalEntityPropertiesSearchRequest.EmptySearchRequest - , AddressPropertiesSearchRequest.EmptySearchRequest - , SitePropertiesSearchRequest.EmptySearchRequest - , PaginationRequest() + LegalEntityPropertiesSearchRequest.EmptySearchRequest, + AddressPropertiesSearchRequest.EmptySearchRequest, + SitePropertiesSearchRequest.EmptySearchRequest, + PaginationRequest() ) assertThat(searchResult.content).isNotEmpty diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/ValidIndexStartupIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/ValidIndexStartupIT.kt index 64f16e9cf..4deae832e 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/ValidIndexStartupIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/ValidIndexStartupIT.kt @@ -77,13 +77,26 @@ class ValidIndexStartupIT @Autowired constructor( @DirtiesContext fun setupIndexForNextTest() { testHelpers.truncateDbTables() + testHelpers.createTestMetadata() //Clear and set up a fresh valid OpenSearch context // webTestClient.invokeDeleteEndpointWithoutResponse(EndpointValues.OPENSEARCH_SYNC_PATH) poolClient.opensearch().clear() //Import values to DB - val partnersToImport = listOf(SaasValues.legalEntity1, SaasValues.legalEntity2, SaasValues.legalEntity3) - testHelpers.importAndGetResponse(partnersToImport, webTestClient, wireMockServer) + testHelpers.createBusinessPartnerStructure( + listOf( + LegalEntityStructureRequest( + legalEntity = RequestValues.legalEntityCreate1, + ), + LegalEntityStructureRequest( + legalEntity = RequestValues.legalEntityCreate2, + ), + LegalEntityStructureRequest( + legalEntity = RequestValues.legalEntityCreate3, + ) + ) + ) + //Export to OpenSearch index testHelpers.startSyncAndAwaitSuccess(webTestClient, EndpointValues.OPENSEARCH_SYNC_PATH) //Make sure entries are indeed there diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/controller/OpenSearchControllerIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/controller/OpenSearchControllerIT.kt index 488ea0b95..e72cda537 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/controller/OpenSearchControllerIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/controller/OpenSearchControllerIT.kt @@ -34,8 +34,8 @@ import org.eclipse.tractusx.bpdm.pool.api.model.request.LegalEntityPropertiesSea import org.eclipse.tractusx.bpdm.pool.api.model.request.SitePropertiesSearchRequest import org.eclipse.tractusx.bpdm.pool.api.model.response.LegalEntityMatchResponse import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.service.OpenSearchSyncStarterService -import org.eclipse.tractusx.bpdm.pool.component.saas.config.SaasAdapterConfigProperties -import org.eclipse.tractusx.bpdm.pool.component.saas.service.ImportStarterService + + import org.eclipse.tractusx.bpdm.pool.util.* import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -59,15 +59,18 @@ import org.springframework.test.web.reactive.server.WebTestClient @ContextConfiguration(initializers = [PostgreSQLContextInitializer::class, OpenSearchContextInitializer::class]) class OpenSearchControllerIT @Autowired constructor( private val webTestClient: WebTestClient, - private val importService: ImportStarterService, private val openSearchSyncService: OpenSearchSyncStarterService, - private val saasAdapterConfigProperties: SaasAdapterConfigProperties, private val objectMapper: ObjectMapper, private val testHelpers: TestHelpers, private val poolClient: PoolClientImpl ) { companion object { + // Configuration properties of Saas mock + private val exchangeApiUrl: String = "data-exchange/rest/v4" + private val storage: String = "storage_id" + val readBusinessPartnerUrl = "/${exchangeApiUrl}/storages/${storage}/businesspartners" + @RegisterExtension var wireMockServer: WireMockExtension = WireMockExtension.newInstance() .options(WireMockConfiguration.wireMockConfig().dynamicPort()) @@ -101,15 +104,28 @@ class OpenSearchControllerIT @Autowired constructor( ) wireMockServer.stubFor( - WireMock.get(WireMock.urlPathMatching(saasAdapterConfigProperties.readBusinessPartnerUrl)) + WireMock.get(WireMock.urlPathMatching(readBusinessPartnerUrl)) .willReturn( WireMock.aResponse() .withHeader("Content-Type", "application/json") .withBody(objectMapper.writeValueAsString(importCollection)) ) ) + testHelpers.createTestMetadata() + testHelpers.createBusinessPartnerStructure( + listOf( + LegalEntityStructureRequest( + legalEntity = RequestValues.legalEntityCreate1, + ), + LegalEntityStructureRequest( + legalEntity = RequestValues.legalEntityCreate2, + ), + LegalEntityStructureRequest( + legalEntity = RequestValues.legalEntityCreate3, + ) + ) + ) - importService.import() } diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/TestHelpers.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/TestHelpers.kt index f55a2d54c..0c57f0340 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/TestHelpers.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/TestHelpers.kt @@ -19,28 +19,16 @@ package org.eclipse.tractusx.bpdm.pool.util -import com.fasterxml.jackson.databind.ObjectMapper -import com.github.tomakehurst.wiremock.client.WireMock -import com.github.tomakehurst.wiremock.junit5.WireMockExtension import jakarta.persistence.EntityManager import jakarta.persistence.EntityManagerFactory import org.assertj.core.api.Assertions import org.assertj.core.api.RecursiveComparisonAssert -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.BusinessPartnerSaas -import org.eclipse.tractusx.bpdm.common.dto.saas.PagedResponseSaas import org.eclipse.tractusx.bpdm.pool.api.client.PoolClientImpl import org.eclipse.tractusx.bpdm.pool.api.model.SyncStatus -import org.eclipse.tractusx.bpdm.pool.api.model.request.AddressPropertiesSearchRequest import org.eclipse.tractusx.bpdm.pool.api.model.request.IdentifiersSearchRequest -import org.eclipse.tractusx.bpdm.pool.api.model.request.LegalEntityPropertiesSearchRequest -import org.eclipse.tractusx.bpdm.pool.api.model.request.SitePropertiesSearchRequest import org.eclipse.tractusx.bpdm.pool.api.model.response.ErrorCode import org.eclipse.tractusx.bpdm.pool.api.model.response.ErrorInfo -import org.eclipse.tractusx.bpdm.pool.api.model.response.LegalEntityMatchResponse import org.eclipse.tractusx.bpdm.pool.api.model.response.SyncResponse -import org.eclipse.tractusx.bpdm.pool.component.saas.config.SaasAdapterConfigProperties import org.eclipse.tractusx.bpdm.pool.config.BpnConfigProperties import org.junit.Assert import org.junit.jupiter.api.assertThrows @@ -58,8 +46,6 @@ private const val BPDM_DB_SCHEMA_NAME: String = "bpdm" @Component class TestHelpers( entityManagerFactory: EntityManagerFactory, - private val objectMapper: ObjectMapper, - private val saasAdapterConfigProperties: SaasAdapterConfigProperties, private val bpnConfigProperties: BpnConfigProperties, private val poolClient: PoolClientImpl ) { @@ -237,34 +223,7 @@ class TestHelpers( return syncResponse } - fun importAndGetResponse( - partnersToImport: Collection, - client: WebTestClient, - wireMockServer: WireMockExtension - ): PageResponse { - val importCollection = PagedResponseSaas( - partnersToImport.size, - null, - null, - partnersToImport.size, - partnersToImport - ) - - wireMockServer.stubFor( - WireMock.get(WireMock.urlPathMatching(saasAdapterConfigProperties.readBusinessPartnerUrl)).willReturn( - WireMock.aResponse() - .withHeader("Content-Type", "application/json") - .withBody(objectMapper.writeValueAsString(importCollection)) - ) - ) - - startSyncAndAwaitSuccess(client, EndpointValues.SAAS_SYNCH_PATH) - return poolClient.legalEntities().getLegalEntities( - LegalEntityPropertiesSearchRequest.EmptySearchRequest, AddressPropertiesSearchRequest.EmptySearchRequest, - SitePropertiesSearchRequest.EmptySearchRequest, PaginationRequest() - ) - } fun assertRecursively(actual: T): RecursiveComparisonAssert<*> { return Assertions.assertThat(actual)