2 * ============LICENSE_START=======================================================
3 * Copyright (c) 2024-2025 OpenInfra Foundation Europe. All rights reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.ncmp.impl.cmnotificationsubscription.ncmp
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 org.onap.cps.ncmp.impl.cmnotificationsubscription_1_0_0.client_to_ncmp.DataJobSubscriptionOperationInEvent
29 import org.onap.cps.ncmp.utils.TestUtils
30 import org.onap.cps.utils.JsonObjectMapper
31 import org.slf4j.LoggerFactory
32 import org.springframework.beans.factory.annotation.Autowired
33 import org.springframework.boot.test.context.SpringBootTest
34 import spock.lang.Specification
36 @SpringBootTest(classes = [ObjectMapper, JsonObjectMapper])
37 class NcmpInEventConsumerSpec extends Specification {
39 def objectUnderTest = new NcmpInEventConsumer()
40 def logger = new ListAppender<ILoggingEvent>()
43 JsonObjectMapper jsonObjectMapper
46 ObjectMapper objectMapper
49 ((Logger) LoggerFactory.getLogger(NcmpInEventConsumer.class)).addAppender(logger)
54 ((Logger) LoggerFactory.getLogger(NcmpInEventConsumer.class)).detachAndStopAllAppenders()
57 def 'Consuming CM Data Notification #scenario data type id.'() {
58 given: 'a JSON file containing a subscription event'
59 def jsonData = TestUtils.getResourceFileContent('sample_dataJobSubscriptionInEvent.json')
60 jsonData = jsonData.replace('#dataTypeId', dataTypeId)
61 def event = objectMapper.readValue(jsonData, DataJobSubscriptionOperationInEvent)
62 when: 'the event is consumed'
63 objectUnderTest.consumeSubscriptionEvent(event)
64 then: 'event details are logged at level INFO'
65 def loggingEvent = logger.list.last()
66 assert loggingEvent.level == Level.INFO
67 assert loggingEvent.formattedMessage.contains('jobId=my job id')
68 assert loggingEvent.formattedMessage.contains('eventType=my event type')
69 assert loggingEvent.formattedMessage.contains("dataType=${dataTypeId}")
70 assert loggingEvent.formattedMessage.contains('fdns=[/SubNetwork=SN1]')
71 where: 'the following data type ids are used'
73 'with' | 'my data type'