Skip to content

Commit

Permalink
feat(Gate-Pool): Removing_SaaS_Import_Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiodmota committed May 26, 2023
1 parent fca655a commit 216bb17
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 89 deletions.
34 changes: 0 additions & 34 deletions bpdm-pool/src/main/resources/application-saas.properties

This file was deleted.

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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
) {
Expand Down Expand Up @@ -237,34 +223,7 @@ class TestHelpers(
return syncResponse
}

fun importAndGetResponse(
partnersToImport: Collection<BusinessPartnerSaas>,
client: WebTestClient,
wireMockServer: WireMockExtension
): PageResponse<LegalEntityMatchResponse> {
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 <T> assertRecursively(actual: T): RecursiveComparisonAssert<*> {
return Assertions.assertThat(actual)
Expand Down

0 comments on commit 216bb17

Please sign in to comment.