Skip to content

Commit

Permalink
Merge pull request #378 from catenax-ng/fix/Pool_Refactor_Remove_Open…
Browse files Browse the repository at this point in the history
…Search

feat(Pool): Remove Pool Mock for Opeansearch
  • Loading branch information
nicoprow authored Aug 9, 2023
2 parents 1ad609a + 21c5746 commit d676e6a
Show file tree
Hide file tree
Showing 23 changed files with 14 additions and 305 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class OpenSearchContextInitializer : ApplicationContextInitializer<ConfigurableA
"bpdm.opensearch.host=${openSearchContainer.host}",
"bpdm.opensearch.port=${openSearchContainer.getMappedPort(OPENSEARCH_PORT)}",
"bpdm.opensearch.scheme=http",
"bpdm.opensearch.enabled=true",
).applyTo(applicationContext.environment)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#
# SPDX-License-Identifier: Apache-2.0
################################################################################
bpdm.opensearch.enabled=false
bpdm.opensearch.refresh-on-write=true
bpdm.opensearch.alias=bpdm-opensearch
bpdm.datasource.alias=bpdm-postgres
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties

@ConfigurationProperties(prefix = "bpdm.opensearch")
class OpenSearchConfigProperties(
val enabled: Boolean = false,
val host: String = "localhost",
val port: Int = 9200,
val scheme: String = "http",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
class OpenSearchEnabledConfig
2 changes: 1 addition & 1 deletion bpdm-pool/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ management.health.readinessState.enabled=true
#Disable Security on default
bpdm.security.enabled=false
#Opensearch configuration
bpdm.opensearch.enabled=true

bpdm.opensearch.host=localhost
bpdm.opensearch.port=9200
bpdm.opensearch.scheme=http
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand All @@ -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(
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit d676e6a

Please sign in to comment.