Remove subscriptionModelLoader flag
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / impl / events / cmsubscription / CmNotificationSubscriptionNcmpInEventConsumerSpec.groovy
1 /*
2  * ============LICENSE_START=======================================================
3  * Copyright (c) 2024 Nordix Foundation.
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an 'AS IS' BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20
21 package org.onap.cps.ncmp.api.impl.events.cmsubscription
22
23 import ch.qos.logback.classic.Level
24 import ch.qos.logback.classic.Logger
25 import ch.qos.logback.classic.spi.ILoggingEvent
26 import ch.qos.logback.core.read.ListAppender
27 import com.fasterxml.jackson.databind.ObjectMapper
28 import io.cloudevents.CloudEvent
29 import io.cloudevents.core.builder.CloudEventBuilder
30 import org.apache.kafka.clients.consumer.ConsumerRecord
31 import org.onap.cps.ncmp.api.kafka.MessagingBaseSpec
32 import org.onap.cps.ncmp.events.cmnotificationsubscription_merge1_0_0.client_to_ncmp.CmNotificationSubscriptionNcmpInEvent
33 import org.onap.cps.ncmp.utils.TestUtils
34 import org.onap.cps.utils.JsonObjectMapper
35 import org.slf4j.LoggerFactory
36 import org.springframework.beans.factory.annotation.Autowired
37 import org.springframework.boot.test.context.SpringBootTest
38
39 @SpringBootTest(classes = [ObjectMapper, JsonObjectMapper])
40 class CmNotificationSubscriptionNcmpInEventConsumerSpec extends MessagingBaseSpec {
41
42     def objectUnderTest = new CmNotificationSubscriptionNcmpInEventConsumer()
43     def logger = Spy(ListAppender<ILoggingEvent>)
44
45     @Autowired
46     JsonObjectMapper jsonObjectMapper
47
48     @Autowired
49     ObjectMapper objectMapper
50
51     void setup() {
52         ((Logger) LoggerFactory.getLogger(CmNotificationSubscriptionNcmpInEventConsumer.class)).addAppender(logger)
53         logger.start()
54     }
55
56     void cleanup() {
57         ((Logger) LoggerFactory.getLogger(CmNotificationSubscriptionNcmpInEventConsumer.class)).detachAndStopAllAppenders()
58     }
59
60
61     def 'Consume valid CMSubscription create message'() {
62         given: 'a cmsubscription event'
63             def jsonData = TestUtils.getResourceFileContent('cmSubscription/cmSubscriptionNcmpInEvent.json')
64             def testEventSent = jsonObjectMapper.convertJsonString(jsonData, CmNotificationSubscriptionNcmpInEvent.class)
65             def testCloudEventSent = CloudEventBuilder.v1()
66                 .withData(objectMapper.writeValueAsBytes(testEventSent))
67                 .withId('subscriptionCreated')
68                 .withType('subscriptionCreated')
69                 .withSource(URI.create('some-resource'))
70                 .withExtension('correlationid', 'test-cmhandle1').build()
71             def consumerRecord = new ConsumerRecord<String, CloudEvent>('topic-name', 0, 0, 'event-key', testCloudEventSent)
72         and: 'notifications are enabled'
73             objectUnderTest.notificationFeatureEnabled = true
74         when: 'the valid event is consumed'
75             objectUnderTest.consumeSubscriptionEvent(consumerRecord)
76         then: 'an event is logged with level INFO'
77             def loggingEvent = getLoggingEvent()
78             assert loggingEvent.level == Level.INFO
79         and: 'the log indicates the task completed successfully'
80             assert loggingEvent.formattedMessage == 'Subscription with name cm-subscription-001 to be mapped to hazelcast object...'
81     }
82
83     def getLoggingEvent() {
84         return logger.list[0]
85     }
86
87 }