summaryrefslogtreecommitdiffstats
path: root/src/test/groovy/org/onap
diff options
context:
space:
mode:
authormpriyank <priyank.maheshwari@est.tech>2022-04-08 15:12:22 +0530
committermpriyank <priyank.maheshwari@est.tech>2022-04-11 19:31:37 +0530
commit78e1d0616474d50d1b3d156e588c6cea9cba783d (patch)
tree8f3c1d9c02be33194207966b0e56a87aeab0181c /src/test/groovy/org/onap
parent08b499572102640cd6d298fec2abf443413803cb (diff)
NCMP Kafka Producer Infrastructure
- Producer configuration and Topic related information. - Accepted topicParameter and request id from NCMP to process async - Replacing Springfox and using Springdoc instead Issue-ID: CPS-829 Change-Id: I369b5ec6c16318220bb218701006918a0bf21419 Signed-off-by: mpriyank <priyank.maheshwari@est.tech>
Diffstat (limited to 'src/test/groovy/org/onap')
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/config/DmiPluginConfigSpec.groovy12
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy4
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/service/NcmpKafkaPublisherServiceSpec.groovy39
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/service/NcmpKafkaPublisherSpec.groovy69
4 files changed, 118 insertions, 6 deletions
diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/config/DmiPluginConfigSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/config/DmiPluginConfigSpec.groovy
index 64b82329..b391f8c0 100644
--- a/src/test/groovy/org/onap/cps/ncmp/dmi/config/DmiPluginConfigSpec.groovy
+++ b/src/test/groovy/org/onap/cps/ncmp/dmi/config/DmiPluginConfigSpec.groovy
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
+ * Copyright (C) 2021-2022 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,11 +20,11 @@
package org.onap.cps.ncmp.dmi.config
+import org.springdoc.core.GroupedOpenApi
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ContextConfiguration
import spock.lang.Specification
-import springfox.documentation.spring.web.plugins.Docket
@SpringBootTest
@ContextConfiguration(classes = [DmiPluginConfig.DmiPluginProperties])
@@ -38,15 +38,15 @@ class DmiPluginConfigSpec extends Specification {
dmiPluginProperties.dmiServiceUrl == 'some url for the dmi service'
}
- def 'DMI plugin docket creation.'() {
+ def 'DMI plugin api creation.'() {
given: 'a DMI plugin configuration'
DmiPluginConfig objectUnderTest = new DmiPluginConfig()
when: 'the api method is invoked'
def result = objectUnderTest.api()
then: 'a spring web plugin docket is returned'
- result instanceof Docket
- and: 'it is named "dmi-plugin-docket"'
- result.groupName == 'dmi-plugin-docket'
+ result instanceof GroupedOpenApi
+ and: 'it is named "dmi-plugin-api"'
+ result.group == 'dmi-plugin-api'
}
}
diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy
index 2f200cfa..1541f8ca 100644
--- a/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy
+++ b/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy
@@ -25,6 +25,7 @@ import org.onap.cps.ncmp.dmi.TestUtils
import org.onap.cps.ncmp.dmi.exception.DmiException
import org.onap.cps.ncmp.dmi.exception.ModuleResourceNotFoundException
import org.onap.cps.ncmp.dmi.exception.ModulesNotFoundException
+import org.onap.cps.ncmp.dmi.service.NcmpKafkaPublisherService
import org.onap.cps.ncmp.dmi.service.model.ModuleReference
import org.onap.cps.ncmp.dmi.model.ModuleSet
import org.onap.cps.ncmp.dmi.model.ModuleSetSchemas
@@ -62,6 +63,9 @@ class DmiRestControllerSpec extends Specification {
@SpringBean
DmiService mockDmiService = Mock()
+ @SpringBean
+ NcmpKafkaPublisherService mockNcmpKafkaPublisherService = Mock()
+
@Value('${rest.api.dmi-base-path}/v1')
def basePathV1
diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/service/NcmpKafkaPublisherServiceSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/service/NcmpKafkaPublisherServiceSpec.groovy
new file mode 100644
index 00000000..4fc697ed
--- /dev/null
+++ b/src/test/groovy/org/onap/cps/ncmp/dmi/service/NcmpKafkaPublisherServiceSpec.groovy
@@ -0,0 +1,39 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://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
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.dmi.service
+
+import spock.lang.Specification
+
+class NcmpKafkaPublisherServiceSpec extends Specification {
+
+ def mockNcmpKafkaPublisher = Mock(NcmpKafkaPublisher)
+ def objectUnderTest = new NcmpKafkaPublisherService(mockNcmpKafkaPublisher)
+
+ def 'Message publishing'() {
+ given: 'a sample message with key'
+ def message = 'sample message'
+ def messageKey = 'sample-key'
+ when: 'published'
+ objectUnderTest.publishToNcmp(messageKey, message)
+ then: 'no exception is thrown'
+ noExceptionThrown()
+ }
+}
diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/service/NcmpKafkaPublisherSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/service/NcmpKafkaPublisherSpec.groovy
new file mode 100644
index 00000000..54f3502c
--- /dev/null
+++ b/src/test/groovy/org/onap/cps/ncmp/dmi/service/NcmpKafkaPublisherSpec.groovy
@@ -0,0 +1,69 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://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
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.dmi.service
+
+
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.beans.factory.annotation.Value
+import org.springframework.boot.test.context.SpringBootTest
+import org.springframework.kafka.core.KafkaTemplate
+import org.springframework.test.context.DynamicPropertyRegistry
+import org.springframework.test.context.DynamicPropertySource
+import org.testcontainers.containers.KafkaContainer
+import org.testcontainers.spock.Testcontainers
+import spock.lang.Specification
+
+@SpringBootTest
+@Testcontainers
+class NcmpKafkaPublisherSpec extends Specification {
+
+ static kafkaTestContainer = new KafkaContainer()
+ static {
+ Runtime.getRuntime().addShutdownHook(new Thread(kafkaTestContainer::stop))
+ }
+
+ def setupSpec() {
+ kafkaTestContainer.start()
+ }
+
+ @Autowired
+ KafkaTemplate<String, Object> kafkaTemplate
+
+ @Value('${app.ncmp.async-m2m.topic}')
+ String topic
+
+ def 'Publish message'() {
+ given: 'a sample messsage and key'
+ def message = 'sample message'
+ def messageKey = 'message-key'
+ def objectUnderTest = new NcmpKafkaPublisher(kafkaTemplate, topic)
+ when: 'a message is published'
+ objectUnderTest.sendMessage(messageKey, message)
+ then: 'no exception is thrown'
+ noExceptionThrown()
+
+ }
+
+ @DynamicPropertySource
+ static void registerKafkaProperties(DynamicPropertyRegistry registry) {
+ registry.add('spring.kafka.bootstrap-servers', kafkaTestContainer::getBootstrapServers)
+ }
+}