Code review cleanup for: Add kafka messaging support to integration test module 48/137548/2
authorhalil.cakal <halil.cakal@est.tech>
Fri, 22 Mar 2024 11:46:03 +0000 (11:46 +0000)
committerhalil.cakal <halil.cakal@est.tech>
Mon, 25 Mar 2024 16:02:07 +0000 (16:02 +0000)
- 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 <halil.cakal@est.tech>
integration-test/pom.xml
integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy
integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpCmHandleCreateSpec.groovy

index c845132..ca2b26d 100644 (file)
             <artifactId>spock-core</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-web</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.spockframework</groupId>
             <artifactId>spock-spring</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.testcontainers</groupId>
-            <artifactId>postgresql</artifactId>
+            <groupId>org.springframework.kafka</groupId>
+            <artifactId>spring-kafka-test</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.testcontainers</groupId>
-            <artifactId>spock</artifactId>
+            <artifactId>postgresql</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.springframework.kafka</groupId>
-            <artifactId>spring-kafka-test</artifactId>
+            <groupId>org.testcontainers</groupId>
+            <artifactId>spock</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
             <artifactId>kafka</artifactId>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.springframework</groupId>
-            <artifactId>spring-web</artifactId>
-            <scope>test</scope>
-        </dependency>
     </dependencies>
 
     <profiles>
index 5020dce..2603c48 100644 (file)
@@ -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'
index d20ac33..f03872d 100644 (file)
@@ -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()