aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhalil.cakal <halil.cakal@est.tech>2024-03-22 11:46:03 +0000
committerhalil.cakal <halil.cakal@est.tech>2024-03-25 16:02:07 +0000
commit00245eeb7a41f434565b2f0102d86f2900113017 (patch)
treea67845b63ac8c636f290cb556e7bec9b50f5d9ca
parent712c644ad08b98bb27d186389f39a5b2e9f8a519 (diff)
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 <halil.cakal@est.tech>
-rw-r--r--integration-test/pom.xml20
-rw-r--r--integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy15
-rw-r--r--integration-test/src/test/groovy/org/onap/cps/integration/functional/NcmpCmHandleCreateSpec.groovy12
3 files changed, 25 insertions, 22 deletions
diff --git a/integration-test/pom.xml b/integration-test/pom.xml
index c84513291..ca2b26d1c 100644
--- a/integration-test/pom.xml
+++ b/integration-test/pom.xml
@@ -68,6 +68,11 @@
<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>
@@ -78,18 +83,18 @@
<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>
@@ -97,11 +102,6 @@
<artifactId>kafka</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-web</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
<profiles>
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 5020dceef..2603c48ed 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 d20ac337b..f03872d56 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()