From 00245eeb7a41f434565b2f0102d86f2900113017 Mon Sep 17 00:00:00 2001 From: "halil.cakal" Date: Fri, 22 Mar 2024 11:46:03 +0000 Subject: Code review cleanup for: Add kafka messaging support to integration test module - Address code review on commit which already merged https://gerrit.onap.org/r/c/cps/+/137496 Issue-ID: CPS-2152 Change-Id: I7a46dd08c919227c37fdeacf4763d0ab364c88c1 Signed-off-by: halil.cakal --- .../cps/integration/base/CpsIntegrationSpecBase.groovy | 15 +++++++++------ .../integration/functional/NcmpCmHandleCreateSpec.groovy | 12 ++++++------ 2 files changed, 15 insertions(+), 12 deletions(-) (limited to 'integration-test/src/test/groovy/org/onap') diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy index 5020dceef6..2603c48edf 100644 --- a/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy +++ b/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy @@ -21,6 +21,7 @@ package org.onap.cps.integration.base import java.time.OffsetDateTime +import java.time.format.DateTimeFormatter import org.onap.cps.api.CpsAnchorService import org.onap.cps.api.CpsDataService import org.onap.cps.api.CpsDataspaceService @@ -39,6 +40,7 @@ import org.onap.cps.spi.exceptions.DataspaceNotFoundException import org.onap.cps.spi.model.DataNode import org.onap.cps.spi.repository.DataspaceRepository import org.onap.cps.spi.utils.SessionManager +import org.onap.cps.utils.JsonObjectMapper import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.boot.autoconfigure.domain.EntityScan @@ -56,13 +58,11 @@ import spock.lang.Shared import spock.lang.Specification import spock.util.concurrent.PollingConditions -import java.time.format.DateTimeFormatter - -import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo -import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT +import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo +import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK, classes = [CpsDataspaceService]) @Testcontainers @@ -77,10 +77,10 @@ abstract class CpsIntegrationSpecBase extends Specification { DatabaseTestContainer databaseTestContainer = DatabaseTestContainer.getInstance() @Shared - KafkaTestContainer kafkaTestContainer = KafkaTestContainer.getInstance(); + KafkaTestContainer kafkaTestContainer = KafkaTestContainer.getInstance() @Autowired - MockMvc mvc; + MockMvc mvc @Autowired CpsDataspaceService cpsDataspaceService @@ -115,6 +115,9 @@ abstract class CpsIntegrationSpecBase extends Specification { @Autowired ModuleSyncWatchdog moduleSyncWatchdog + @Autowired + JsonObjectMapper jsonObjectMapper + MockRestServiceServer mockDmiServer = null static final DMI_URL = 'http://mock-dmi-server' diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpCmHandleCreateSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpCmHandleCreateSpec.groovy index d20ac337bf..f03872d56b 100644 --- a/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpCmHandleCreateSpec.groovy +++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpCmHandleCreateSpec.groovy @@ -20,7 +20,8 @@ package org.onap.cps.integration.functional - +import java.time.Duration +import java.time.OffsetDateTime import org.apache.kafka.common.TopicPartition import org.apache.kafka.common.serialization.StringDeserializer import org.onap.cps.integration.KafkaTestContainer @@ -31,16 +32,14 @@ import org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse import org.onap.cps.ncmp.api.models.DmiPluginRegistration import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle +import org.onap.cps.ncmp.events.lcm.v1.LcmEvent import spock.util.concurrent.PollingConditions -import java.time.Duration -import java.time.OffsetDateTime - class NcmpCmHandleCreateSpec extends CpsIntegrationSpecBase { NetworkCmProxyDataService objectUnderTest - def kafkaConsumer = KafkaTestContainer.getConsumer("ncmp-group", StringDeserializer.class); + def kafkaConsumer = KafkaTestContainer.getConsumer('ncmp-group', StringDeserializer.class) static final MODULE_REFERENCES_RESPONSE_A = readResourceDataFile('mock-dmi-responses/bookStoreAWithModules_M1_M2_Response.json') static final MODULE_RESOURCES_RESPONSE_A = readResourceDataFile('mock-dmi-responses/bookStoreAWithModules_M1_M2_ResourcesResponse.json') @@ -82,7 +81,8 @@ class NcmpCmHandleCreateSpec extends CpsIntegrationSpecBase { def records = message.records(new TopicPartition('ncmp-events', 0)) and: 'the newest lcm event notification is received with READY state' - assert records.last().value().toString().contains('"cmHandleState":"READY"') + def notificationMessage = jsonObjectMapper.convertJsonString(records.last().value().toString(), LcmEvent) + assert notificationMessage.event.newValues.cmHandleState.value() == 'READY' and: 'the CM-handle has expected modules' assert ['M1', 'M2'] == objectUnderTest.getYangResourcesModuleReferences('ch-1').moduleName.sort() -- cgit 1.2.3-korg