From c9d7f88db4cb8146dc9a0770ff6fca75150ab5d8 Mon Sep 17 00:00:00 2001 From: "fabio.d.mota" Date: Mon, 7 Aug 2023 17:09:18 +0100 Subject: [PATCH 1/2] feat(Pool): Remove Pool Mock for Opeansearch --- .../eclipse/tractusx/bpdm/pool/Application.kt | 9 +- .../opensearch/mock/OpenSearchMockConfig.kt | 36 -------- .../mock/service/SearchServiceMock.kt | 87 ------------------- .../pool/config/OpenSearchEnabledConfig.kt | 18 +--- .../opensearch/InvalidIndexStartupIT.kt | 9 -- .../opensearch/ValidIndexStartupIT.kt | 10 --- .../controller/OpenSearchControllerIT.kt | 32 +------ .../pool/controller/AddressControllerIT.kt | 2 +- .../bpdm/pool/controller/BpnControllerIT.kt | 17 +--- .../pool/controller/ChangelogControllerIT.kt | 2 +- .../controller/LegalEntityControllerIT.kt | 2 +- .../LegalEntityControllerSearchIT.kt | 2 +- .../pool/controller/MetadataControllerIT.kt | 2 +- .../bpdm/pool/controller/SiteControllerIT.kt | 2 +- .../tractusx/bpdm/pool/util/EndpointValues.kt | 5 -- .../tractusx/bpdm/pool/util/TestHelpers.kt | 4 +- .../bpdm/pool/util/WebTestClientExtensions.kt | 71 --------------- 17 files changed, 12 insertions(+), 298 deletions(-) delete mode 100644 bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/mock/OpenSearchMockConfig.kt delete mode 100644 bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/mock/service/SearchServiceMock.kt diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/Application.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/Application.kt index 0f8e8e78c..2f4eef6b8 100644 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/Application.kt +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/Application.kt @@ -25,14 +25,7 @@ import org.springframework.boot.runApplication import org.springframework.scheduling.annotation.EnableScheduling -@SpringBootApplication( - scanBasePackages = [ - "org.eclipse.tractusx.bpdm.pool.config", - "org.eclipse.tractusx.bpdm.pool.controller", - "org.eclipse.tractusx.bpdm.pool.repository", - "org.eclipse.tractusx.bpdm.pool.service" - ] -) +@SpringBootApplication @ConfigurationPropertiesScan @EnableScheduling class Application diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/mock/OpenSearchMockConfig.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/mock/OpenSearchMockConfig.kt deleted file mode 100644 index 99940ab7c..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/mock/OpenSearchMockConfig.kt +++ /dev/null @@ -1,36 +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 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.component.opensearch.mock - -import jakarta.annotation.PostConstruct -import mu.KotlinLogging -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration - -@Configuration -@ComponentScan -class OpenSearchMockConfig { - private val logger = KotlinLogging.logger { } - - @PostConstruct - fun logCreation() { - logger.info { "OpenSearch not enabled, mock connection" } - } -} \ No newline at end of file diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/mock/service/SearchServiceMock.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/mock/service/SearchServiceMock.kt deleted file mode 100644 index 3d1e06773..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/mock/service/SearchServiceMock.kt +++ /dev/null @@ -1,87 +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 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.component.opensearch.mock.service - -import mu.KotlinLogging -import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest -import org.eclipse.tractusx.bpdm.common.dto.response.PageDto -import org.eclipse.tractusx.bpdm.pool.api.model.request.AddressPartnerSearchRequest -import org.eclipse.tractusx.bpdm.pool.api.model.request.BusinessPartnerSearchRequest -import org.eclipse.tractusx.bpdm.pool.api.model.response.AddressMatchVerboseDto -import org.eclipse.tractusx.bpdm.pool.api.model.response.LegalEntityMatchVerboseDto -import org.eclipse.tractusx.bpdm.pool.api.model.response.SiteMatchVerboseDto -import org.eclipse.tractusx.bpdm.pool.component.opensearch.SearchService -import org.eclipse.tractusx.bpdm.pool.repository.LegalEntityRepository -import org.eclipse.tractusx.bpdm.pool.repository.LogisticAddressRepository -import org.eclipse.tractusx.bpdm.pool.repository.SiteRepository -import org.eclipse.tractusx.bpdm.pool.service.toDto -import org.eclipse.tractusx.bpdm.pool.service.toMatchDto -import org.springframework.data.domain.PageRequest -import org.springframework.stereotype.Service - -/** - * Mock implementation of the [SearchService] in case the system is configured to run without OpenSearch - */ -@Service -class SearchServiceMock( - val legalEntityRepository: LegalEntityRepository, - val logisticAddressRepository: LogisticAddressRepository, - val siteRepository: SiteRepository -) : SearchService { - - private val logger = KotlinLogging.logger { } - - /** - * Ignores [searchRequest] and returns an unfiltered result of legal entities in the database, - * adding a default relevancy score to each entry - */ - override fun searchLegalEntities( - searchRequest: BusinessPartnerSearchRequest, - paginationRequest: PaginationRequest - ): PageDto { - val resultPage = - legalEntityRepository.findAll(PageRequest.of(paginationRequest.page, paginationRequest.size)) - - logger.info { "Mock search: Returning ${resultPage.size} business partners from database" } - - return resultPage.toDto(resultPage.content.map { it.toMatchDto(1f) }) - } - - /** - * Ignores [searchRequest] and returns an unfiltered result of addresses in the database, - * adding a default relevancy score to each entry - */ - override fun searchAddresses(searchRequest: AddressPartnerSearchRequest, paginationRequest: PaginationRequest): PageDto { - val resultPage = logisticAddressRepository.findAll(PageRequest.of(paginationRequest.page, paginationRequest.size)) - - logger.info { "Mock search: Returning ${resultPage.size} addresses from database" } - - return resultPage.toDto(resultPage.content.map { it.toMatchDto(1f) }) - } - - override fun searchSites(paginationRequest: PaginationRequest): PageDto { - val resultPage = siteRepository.findAll(PageRequest.of(paginationRequest.page, paginationRequest.size)) - - logger.info { "Mock search: Returning ${resultPage.size} sites from database" } - - return resultPage.toDto(resultPage.content.map { it.toMatchDto() }) - } - -} \ No newline at end of file diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/OpenSearchEnabledConfig.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/OpenSearchEnabledConfig.kt index 6d388f4fd..df88d21bc 100644 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/OpenSearchEnabledConfig.kt +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/OpenSearchEnabledConfig.kt @@ -20,26 +20,10 @@ package org.eclipse.tractusx.bpdm.pool.config import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.OpenSearchImplConfig -import org.eclipse.tractusx.bpdm.pool.component.opensearch.mock.OpenSearchMockConfig -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty import org.springframework.context.annotation.Configuration import org.springframework.context.annotation.Import @Configuration @Import(value = [OpenSearchImplConfig::class]) -@ConditionalOnProperty( - value = ["bpdm.opensearch.enabled"], - havingValue = "true", - matchIfMissing = false -) -class OpenSearchEnabledConfig - -@Configuration -@Import(OpenSearchMockConfig::class) -@ConditionalOnProperty( - value = ["bpdm.opensearch.enabled"], - havingValue = "false", - matchIfMissing = true -) -class OpenSearchDisabledConfig \ No newline at end of file +class OpenSearchEnabledConfig \ No newline at end of file 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 044c2b69b..4b56f364d 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 @@ -19,8 +19,6 @@ package org.eclipse.tractusx.bpdm.pool.component.opensearch -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.pool.Application @@ -32,7 +30,6 @@ import org.junit.jupiter.api.MethodOrderer.OrderAnnotation import org.junit.jupiter.api.Order import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestMethodOrder -import org.junit.jupiter.api.extension.RegisterExtension import org.opensearch.client.opensearch.OpenSearchClient import org.opensearch.client.opensearch._types.Refresh import org.springframework.beans.factory.annotation.Autowired @@ -55,13 +52,7 @@ class InvalidIndexStartupIT @Autowired constructor( private val poolClient: PoolClientImpl ) { - companion object { - @RegisterExtension - var wireMockServer: WireMockExtension = WireMockExtension.newInstance() - .options(WireMockConfiguration.wireMockConfig().dynamicPort()) - .build() - } val bpnBogusDocument = "BPN_FAKE" 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 96fcaae49..c97cc41e7 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 @@ -19,8 +19,6 @@ package org.eclipse.tractusx.bpdm.pool.component.opensearch -import com.github.tomakehurst.wiremock.core.WireMockConfiguration -import com.github.tomakehurst.wiremock.junit5.WireMockExtension import org.assertj.core.api.Assertions import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest import org.eclipse.tractusx.bpdm.pool.Application @@ -31,7 +29,6 @@ import org.junit.jupiter.api.MethodOrderer import org.junit.jupiter.api.Order import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestMethodOrder -import org.junit.jupiter.api.extension.RegisterExtension import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest import org.springframework.test.annotation.DirtiesContext @@ -51,13 +48,6 @@ class ValidIndexStartupIT @Autowired constructor( val poolClient: PoolClientImpl ) { - companion object { - @RegisterExtension - var wireMockServer: WireMockExtension = WireMockExtension.newInstance() - .options(WireMockConfiguration.wireMockConfig().dynamicPort()) - .build() - - } /** * Not a real test but prepares the OpenSearch container for the next test that will be run in a fresh Spring-Boot context 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 949a31919..d7cfb75d9 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 @@ -21,9 +21,6 @@ package org.eclipse.tractusx.bpdm.pool.component.opensearch.controller import com.fasterxml.jackson.databind.ObjectMapper -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.PageDto @@ -35,13 +32,10 @@ import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.service.OpenSear import org.eclipse.tractusx.bpdm.pool.util.* import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.RegisterExtension 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.springframework.test.context.DynamicPropertyRegistry -import org.springframework.test.context.DynamicPropertySource import org.springframework.test.web.reactive.server.WebTestClient @@ -61,23 +55,7 @@ class OpenSearchControllerIT @Autowired constructor( 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()) - .build() - - @JvmStatic - @DynamicPropertySource - fun properties(registry: DynamicPropertyRegistry) { - registry.add("bpdm.saas.host") { wireMockServer.baseUrl() } - } - } + // We import 3 legal entities which result in 6 OpenSearch records: 3 for the LEs itself and 3 for the corresponding legal addresses. val partnerDocs = listOf( @@ -99,14 +77,6 @@ class OpenSearchControllerIT @Autowired constructor( partnerDocs ) - wireMockServer.stubFor( - WireMock.get(WireMock.urlPathMatching(readBusinessPartnerUrl)) - .willReturn( - WireMock.aResponse() - .withHeader("Content-Type", "application/json") - .withBody(objectMapper.writeValueAsString(importCollection)) - ) - ) testHelpers.createTestMetadata() testHelpers.createBusinessPartnerStructure( listOf( diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/AddressControllerIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/AddressControllerIT.kt index 2cb172778..169ebbdb2 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/AddressControllerIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/AddressControllerIT.kt @@ -36,7 +36,7 @@ import org.springframework.test.context.ContextConfiguration @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = [Application::class, TestHelpers::class]) @ActiveProfiles("test") -@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class]) +@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class,OpenSearchContextInitializer::class]) class AddressControllerIT @Autowired constructor( val testHelpers: TestHelpers, val poolClient: PoolApiClient diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/BpnControllerIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/BpnControllerIT.kt index 59c7f3761..fbd5bbbfe 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/BpnControllerIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/BpnControllerIT.kt @@ -19,21 +19,15 @@ package org.eclipse.tractusx.bpdm.pool.controller -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.IdentifierBusinessPartnerType import org.eclipse.tractusx.bpdm.common.dto.LegalEntityIdentifierDto import org.eclipse.tractusx.bpdm.pool.Application import org.eclipse.tractusx.bpdm.pool.api.client.PoolClientImpl import org.eclipse.tractusx.bpdm.pool.api.model.request.IdentifiersSearchRequest -import org.eclipse.tractusx.bpdm.pool.util.LegalEntityStructureRequest -import org.eclipse.tractusx.bpdm.pool.util.PostgreSQLContextInitializer -import org.eclipse.tractusx.bpdm.pool.util.RequestValues -import org.eclipse.tractusx.bpdm.pool.util.TestHelpers +import org.eclipse.tractusx.bpdm.pool.util.* import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test -import org.junit.jupiter.api.extension.RegisterExtension import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest import org.springframework.test.context.ActiveProfiles @@ -44,18 +38,11 @@ import org.springframework.test.context.ContextConfiguration properties = ["bpdm.controller.search-request-limit=2"] ) @ActiveProfiles("test") -@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class]) +@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class, OpenSearchContextInitializer::class]) class BpnControllerIT @Autowired constructor( val testHelpers: TestHelpers, val poolClient: PoolClientImpl ) { - companion object { - @RegisterExtension - val wireMockServer: WireMockExtension = WireMockExtension.newInstance() - .options(WireMockConfiguration.wireMockConfig().dynamicPort()) - .build() - - } val identifierType = RequestValues.legalEntityCreate1.legalEntity.identifiers.first().type val identifierValue1 = RequestValues.legalEntityCreate1.legalEntity.identifiers.first().value diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/ChangelogControllerIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/ChangelogControllerIT.kt index f9bdba41f..f31796da6 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/ChangelogControllerIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/ChangelogControllerIT.kt @@ -43,7 +43,7 @@ import java.util.* properties = ["bpdm.controller.search-request-limit=2"] ) @ActiveProfiles("test") -@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class]) +@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class,OpenSearchContextInitializer::class]) class ChangelogControllerIT @Autowired constructor( val testHelpers: TestHelpers, val poolClient: PoolClientImpl 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 32daae925..1a17d0dd8 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 @@ -44,7 +44,7 @@ import java.time.Instant webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = [Application::class, TestHelpers::class] ) @ActiveProfiles("test") -@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class]) +@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class,OpenSearchContextInitializer::class]) class LegalEntityControllerIT @Autowired constructor( val testHelpers: TestHelpers, val webTestClient: WebTestClient, diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/LegalEntityControllerSearchIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/LegalEntityControllerSearchIT.kt index fa3f93950..9364fbb76 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/LegalEntityControllerSearchIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/LegalEntityControllerSearchIT.kt @@ -75,7 +75,7 @@ class LegalEntityControllerSearchIT @Autowired constructor( @BeforeEach fun beforeEach() { testHelpers.truncateDbTables() - //webTestClient.invokeDeleteEndpointWithoutResponse(EndpointValues.OPENSEARCH_SYNC_PATH) + poolClient.opensearch().clear() testHelpers.createTestMetadata() val givenStructure = testHelpers.createBusinessPartnerStructure(listOf(partnerStructure1, partnerStructure2)) diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/MetadataControllerIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/MetadataControllerIT.kt index d9b50add6..6ec2448cd 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/MetadataControllerIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/MetadataControllerIT.kt @@ -61,7 +61,7 @@ private typealias GetFunction = (client: WebTestClient, page: Int, size: Int) -> webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = [Application::class, TestHelpers::class] ) @ActiveProfiles("test") -@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class]) +@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class,OpenSearchContextInitializer::class]) class MetadataControllerIT @Autowired constructor( private val testHelpers: TestHelpers, private val webTestClient: WebTestClient, diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/SiteControllerIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/SiteControllerIT.kt index 68f29b4ff..0d96a59dc 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/SiteControllerIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/SiteControllerIT.kt @@ -37,7 +37,7 @@ import java.time.Instant @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = [Application::class, TestHelpers::class]) @ActiveProfiles("test") -@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class]) +@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class,OpenSearchContextInitializer::class]) class SiteControllerIT @Autowired constructor( val testHelpers: TestHelpers, val poolClient: PoolClientImpl diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/EndpointValues.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/EndpointValues.kt index a4739dcca..8701c62ee 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/EndpointValues.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/EndpointValues.kt @@ -21,13 +21,8 @@ package org.eclipse.tractusx.bpdm.pool.util object EndpointValues { - const val TEXT_PARAM_NAME = "text" - const val CATENA_PATH = "/api/catena" - const val CATENA_BUSINESS_PARTNERS_PATH = "$CATENA_PATH/business-partners" - const val CATENA_BUSINESS_PARTNER_LEGACY_PATH = "$CATENA_PATH/business-partner" - const val CATENA_CHANGELOG_PATH_POSTFIX = "/changelog" const val CATENA_LEGAL_ENTITY_PATH = "$CATENA_PATH/legal-entities" 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 27d9763ea..5c7d6b83e 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 @@ -198,9 +198,7 @@ class TestHelpers( return startSyncAndAwaitResult(client, syncPath, SyncStatus.SUCCESS) } - fun startSyncAndAwaitError(client: WebTestClient, syncPath: String): SyncDto { - return startSyncAndAwaitResult(client, syncPath, SyncStatus.ERROR) - } + private fun startSyncAndAwaitResult(client: WebTestClient, syncPath: String, status: SyncStatus): SyncDto { diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/WebTestClientExtensions.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/WebTestClientExtensions.kt index 308cad977..dc48f7411 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/WebTestClientExtensions.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/WebTestClientExtensions.kt @@ -38,18 +38,6 @@ inline fun WebTestClient.invokePostEndpoint(path: String, body .blockFirst()!! } -/** - * Helper method for invoking a post endpoint on [path] with a request [body] and an expected array response body - */ -inline fun WebTestClient.invokePostWithArrayResponse(path: String, body: Any): Collection { - return post().uri(path) - .body(BodyInserters.fromValue(body)) - .exchange() - .expectStatus().is2xxSuccessful - .expectBodyList(T::class.java) - .returnResult() - .responseBody!! -} fun WebTestClient.invokePostEndpointWithoutResponse(path: String, body: Any? = null) { val bodyInserter = body?.let { BodyInserters.fromValue(it) } ?: BodyInserters.empty() @@ -64,53 +52,6 @@ fun WebTestClient.invokePostEndpointWithoutResponse(path: String, body: Any? = n */ } -/** - * Helper method for invoking a put endpoint on [path] with a request [body] and an expected response body - * Only works for response bodies that are serialized as Json Objects - */ -inline fun WebTestClient.invokePutEndpoint(path: String, body: Any): T { - return put().uri(path) - .body(BodyInserters.fromValue(body)) - .exchange() - .expectStatus().is2xxSuccessful - .returnResult() - .responseBody - .blockFirst()!! -} - -inline fun WebTestClient.invokePutWithArrayResponse(path: String, body: Any): Collection { - return put().uri(path) - .body(BodyInserters.fromValue(body)) - .exchange() - .expectStatus().is2xxSuccessful - .expectBodyList(T::class.java) - .returnResult() - .responseBody!! -} - -fun WebTestClient.invokePutWithoutResponse(path: String, body: Any) { - put().uri(path) - .body(BodyInserters.fromValue(body)) - .exchange() - .expectStatus().is2xxSuccessful - .expectBody() - .returnResult() - /* - Mitigates Timeout issue when WebTestClient gets executed too many times without result returned - */ -} - -fun WebTestClient.invokeDeleteEndpointWithoutResponse(path: String) { - delete().uri(path) - .exchange() - .expectStatus().is2xxSuccessful - .expectBody() - .returnResult() - /* - Mitigates Timeout issue when WebTestClient gets executed too many times without result returned - */ -} - inline fun WebTestClient.invokeGetEndpoint(path: String, vararg params: Pair): T { return get().uri { builder -> @@ -125,15 +66,3 @@ inline fun WebTestClient.invokeGetEndpoint(path: String, varar .blockFirst()!! } -inline fun WebTestClient.invokeGetEndpointWithArrayResponse(path: String, vararg params: Pair): Collection { - return get().uri { builder -> - var b = builder.path(path) - params.forEach { p -> b = b.queryParam(p.first, p.second) } - b.build() - } - .exchange() - .expectStatus().is2xxSuccessful - .expectBodyList(T::class.java) - .returnResult() - .responseBody!! -} From 21c5746cf24b45f22ca4ac895d8cb781a9daf3de Mon Sep 17 00:00:00 2001 From: "fabio.d.mota" Date: Wed, 9 Aug 2023 15:53:34 +0100 Subject: [PATCH 2/2] feat(Pool): Remove opensearch.enabled flag that is unused --- .../bpdm/bridge/dummy/util/OpenSearchContextInitializer.kt | 1 - .../src/test/resources/application-test.properties | 1 - .../tractusx/bpdm/pool/config/OpenSearchConfigProperties.kt | 1 - bpdm-pool/src/main/resources/application.properties | 2 +- .../tractusx/bpdm/pool/util/OpenSearchContextInitializer.kt | 3 +-- bpdm-pool/src/test/resources/application-test.properties | 1 - 6 files changed, 2 insertions(+), 7 deletions(-) diff --git a/bpdm-bridge-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/util/OpenSearchContextInitializer.kt b/bpdm-bridge-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/util/OpenSearchContextInitializer.kt index 8b7771b83..d94315fcd 100644 --- a/bpdm-bridge-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/util/OpenSearchContextInitializer.kt +++ b/bpdm-bridge-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/util/OpenSearchContextInitializer.kt @@ -66,7 +66,6 @@ class OpenSearchContextInitializer : ApplicationContextInitializer