Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoprow committed Sep 20, 2024
1 parent 8a690da commit e9a7578
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class BusinessPartnerMappings {
externalId = entity.sharingState.externalId,
nameParts = entity.nameParts,
identifiers = entity.identifiers.map(::toIdentifierDto),
states = entity.states.map(::toStateDto),
states = entity.states.filter { it.businessPartnerTyp == BusinessPartnerType.GENERIC }.map(::toStateDto),
roles = entity.roles,
isOwnCompanyData = entity.isOwnCompanyData,
legalEntity = toLegalEntityComponentInputDto(entity),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@

package org.eclipse.tractusx.bpdm.test.system.config

import org.eclipse.tractusx.bpdm.gate.api.client.GateClient
import org.eclipse.tractusx.bpdm.pool.api.client.PoolApiClient
import org.eclipse.tractusx.bpdm.pool.api.model.IdentifierBusinessPartnerType
import org.eclipse.tractusx.bpdm.pool.api.model.IdentifierTypeDto
import org.eclipse.tractusx.bpdm.pool.api.model.request.LegalFormRequest
import org.eclipse.tractusx.bpdm.test.system.utils.GateInputFactory
import org.eclipse.tractusx.bpdm.test.system.utils.GateOutputFactory
import org.eclipse.tractusx.bpdm.test.system.utils.StepUtils
import org.eclipse.tractusx.bpdm.test.system.utils.TestMetadata
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
Expand Down Expand Up @@ -94,4 +96,9 @@ class TestDataConfiguration {
fun testRunData(): TestRunData {
return TestRunData(Instant.now())
}

@Bean
fun stepUtils(testRunData: TestRunData, gateClient: GateClient): StepUtils{
return StepUtils(gateClient)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ import java.time.Instant

data class TestRunData (
val testTime: Instant
)
){
fun toExternalId(seed: String): String = "${seed}_$testTime"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*******************************************************************************
* Copyright (c) 2021,2024 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.test.system.stepdefinations

import io.cucumber.java.en.Given
import io.cucumber.java.en.Then
import io.cucumber.java.en.When
import org.eclipse.tractusx.bpdm.common.dto.AddressType
import org.eclipse.tractusx.bpdm.common.dto.PaginationRequest
import org.eclipse.tractusx.bpdm.gate.api.client.GateClient
import org.eclipse.tractusx.bpdm.test.system.SpringTestRunConfiguration
import org.eclipse.tractusx.bpdm.test.system.config.TestRunData
import org.eclipse.tractusx.bpdm.test.system.utils.*

class ShareGenericNoBpnStepDefs(
private val gateInputDataFactory: GateInputFactory,
private val gateOutputFactory: GateOutputFactory,
private val gateClient: GateClient,
private val stepUtils: StepUtils,
private val testRunData: TestRunData
): SpringTestRunConfiguration() {

@Given("^output \"([^\"]*)\" with external-ID \"([^\"]*)\"$")
fun `given output seed with externalId`(seed: String, externalId: String) {
uploadInput(seed, externalId, null)
stepUtils.waitForResult(testRunData.toExternalId(externalId))
}

@When("^the sharing member uploads full valid input \"([^\"]*)\" with external-ID \"([^\"]*)\" with address type \"([^\"]*)\"$")
fun `when the sharing member uploads input seed with address type`(seed: String, externalId: String, addressType: String) {
uploadInput(seed, externalId, AddressType.valueOf(addressType))
}

@When("^the sharing member uploads full valid input \"([^\"]*)\" with external-ID \"([^\"]*)\" without address type")
fun `when the sharing member uploads input seed without address type`(seed: String, externalId: String) {
uploadInput(seed, externalId, null)
}

@Then("^the sharing member receives output \"([^\"]*)\" with external-ID \"([^\"]*)\" with address type \"([^\"]*)\"$")
fun `then the sharing member receives output seed with modifier`(seed: String, externalId: String, addressType: String) {
val expectedOutput = gateOutputFactory.createOutput(seed, externalId)
.withAddressType(AddressType.valueOf(addressType))
// On no auth config we can't get own company data to true
.copy(isOwnCompanyData = false)

stepUtils.waitForResult(expectedOutput.externalId)

val actualOutput = gateClient.businessParters.getBusinessPartnersOutput(listOf(expectedOutput.externalId), PaginationRequest()).content.single()

stepUtils.assertEqualIgnoreBpns(actualOutput, expectedOutput)
}


private fun uploadInput(seed: String, externalId: String, addressType: AddressType?){
val inputRequest = gateInputDataFactory.createFullValid(seed, externalId).withAddressType(addressType).withoutAnyBpn()
gateClient.businessParters.upsertBusinessPartnersInput(listOf(inputRequest))
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ class GateInputFactory(
private val testMetadata: TestMetadata,
private val testRunData: TestRunData
) {

val genericFullValidWithSiteWithoutAnyBpn = createAllFieldsFilled("genericFullValidWithSiteWithoutAnyBpn")
{ it.withoutAnyBpn().withAddressType(null) }

fun createAllFieldsFilled(seed: String, transform: (BusinessPartnerInputRequest) -> BusinessPartnerInputRequest = {it}): InputTestData {
return InputTestData(seed, transform(SeededTestDataCreator(seed).createAllFieldsFilled()))
}

fun createFullValid(seed: String, externalId: String = seed): BusinessPartnerInputRequest {
return SeededTestDataCreator(seed).createAllFieldsFilled().copy(externalId = testRunData.toExternalId(externalId))
}

inner class SeededTestDataCreator(
private val seed: String,
){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class GateOutputFactory(
confidenceLevel = 0
)

fun createOutput(fromSeed: String, externalId: String = fromSeed): BusinessPartnerOutputDto{
return createOutput(gateInputTestDataFactory.createFullValid(fromSeed, externalId))
}

fun createOutput(
fromInput: BusinessPartnerInputRequest
): BusinessPartnerOutputDto{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*******************************************************************************
* Copyright (c) 2021,2024 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.test.system.utils

import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.time.delay
import kotlinx.coroutines.time.withTimeout
import org.assertj.core.api.Assertions.assertThat
import org.eclipse.tractusx.bpdm.common.dto.PaginationRequest
import org.eclipse.tractusx.bpdm.gate.api.client.GateClient
import org.eclipse.tractusx.bpdm.gate.api.model.ConfidenceCriteriaDto
import org.eclipse.tractusx.bpdm.gate.api.model.SharingStateType
import org.eclipse.tractusx.bpdm.gate.api.model.response.AddressComponentOutputDto
import org.eclipse.tractusx.bpdm.gate.api.model.response.BusinessPartnerOutputDto
import org.eclipse.tractusx.bpdm.gate.api.model.response.LegalEntityRepresentationOutputDto
import org.eclipse.tractusx.bpdm.gate.api.model.response.SiteRepresentationOutputDto
import java.time.Duration

class StepUtils(
private val gateClient: GateClient
) {

fun waitForResult(externalId: String): SharingStateType = runBlocking {
println("Waiting for result for $externalId ...")
withTimeout(Duration.ofMinutes(3)) {
while (true) {
val sharingState = gateClient.sharingState.getSharingStates(PaginationRequest(), listOf(externalId)).content.single()
if (sharingState.sharingStateType == SharingStateType.Success || sharingState.sharingStateType == SharingStateType.Error) {
return@withTimeout sharingState.sharingStateType
}
delay(Duration.ofSeconds(10))
}
} as SharingStateType
}

fun assertEqualIgnoreBpns(actualOutput: BusinessPartnerOutputDto, expectedOutput: BusinessPartnerOutputDto){
assertThat(actualOutput)
.usingRecursiveComparison()
.ignoringCollectionOrder()
.ignoringFields(*ignoredFields)
.isEqualTo(expectedOutput)
}

val ignoredFields = arrayOf(
BusinessPartnerOutputDto::createdAt.name,
BusinessPartnerOutputDto::updatedAt.name,
"${BusinessPartnerOutputDto::legalEntity.name}.${LegalEntityRepresentationOutputDto::legalEntityBpn.name}",
"${BusinessPartnerOutputDto::site.name}.${SiteRepresentationOutputDto::siteBpn.name}",
"${BusinessPartnerOutputDto::address.name}.${AddressComponentOutputDto::addressBpn.name}",
// ToDo: Cleaning service dummy should have fixed confidence criteria dummy times otherwise we need to keep ignoring these fields
"${BusinessPartnerOutputDto::legalEntity.name}.${AddressComponentOutputDto::confidenceCriteria.name}.${ConfidenceCriteriaDto::lastConfidenceCheckAt.name}",
"${BusinessPartnerOutputDto::legalEntity.name}.${AddressComponentOutputDto::confidenceCriteria.name}.${ConfidenceCriteriaDto::nextConfidenceCheckAt.name}",
"${BusinessPartnerOutputDto::site.name}.${AddressComponentOutputDto::confidenceCriteria.name}.${ConfidenceCriteriaDto::lastConfidenceCheckAt.name}",
"${BusinessPartnerOutputDto::site.name}.${AddressComponentOutputDto::confidenceCriteria.name}.${ConfidenceCriteriaDto::nextConfidenceCheckAt.name}",
"${BusinessPartnerOutputDto::address.name}.${AddressComponentOutputDto::confidenceCriteria.name}.${ConfidenceCriteriaDto::lastConfidenceCheckAt.name}",
"${BusinessPartnerOutputDto::address.name}.${AddressComponentOutputDto::confidenceCriteria.name}.${ConfidenceCriteriaDto::nextConfidenceCheckAt.name}",
)


}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Feature: Share Valid Generic Business Partner without BPNs
Scenario: Update Without Address Type
Given output "CC_SHG_UWAT_1" with external-ID "CC_SHG_UWAT"
When the sharing member uploads full valid input "CC_SHG_UWAT_2" with external-ID "CC_SHG_UWAT" without address type
Then the sharing member receives output "CC_SHG_UWAT_2" with external-ID "CC_SHG_UWAT" with address type "LegalAndSiteMainAddress"

Scenario: Share Without Address Type
When the sharing member uploads full valid input "CC_SHG_WAT" with external-ID "CC_SHG_WAT" without address type
Then the sharing member receives output "CC_SHG_WAT" with external-ID "CC_SHG_WAT" with address type "LegalAndSiteMainAddress"

Scenario: Share With Address Type
When the sharing member uploads full valid input "CC_SHG_WAT" with external-ID "CC_SHG_WAT" with address type "<inputAddressType>"
Then the sharing member receives output "CC_SHG_WAT" with external-ID "CC_SHG_WAT" with address type "<outputAddressType>"

Examples:
| inputAddressType | outputAddressType |
| LegalAndSiteMainAddress | LegalAndSiteMainAddress |
| LegalAddress | LegalAndSiteMainAddress |
| SiteMainAddress | SiteMainAddress |
| AdditionalAddress | AdditionalAddress |

This file was deleted.

This file was deleted.

0 comments on commit e9a7578

Please sign in to comment.