2  *  ============LICENSE_START=======================================================
 
   3  *  Copyright (c) 2023 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
 
   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.api.impl.events.cmsubscription
 
  23 import com.fasterxml.jackson.databind.ObjectMapper
 
  24 import org.mapstruct.factory.Mappers
 
  25 import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionStatus
 
  26 import org.onap.cps.ncmp.events.cmsubscription1_0_0.client_to_ncmp.CmSubscriptionNcmpInEvent
 
  27 import org.onap.cps.ncmp.utils.TestUtils
 
  28 import org.onap.cps.utils.JsonObjectMapper
 
  29 import org.springframework.beans.factory.annotation.Autowired
 
  30 import org.springframework.boot.test.context.SpringBootTest
 
  31 import spock.lang.Specification
 
  34 @SpringBootTest(classes = [JsonObjectMapper, ObjectMapper])
 
  35 class CmSubscriptionNcmpInEventMapperSpec extends Specification {
 
  37     CmSubscriptionNcmpInEventMapper objectUnderTest = Mappers.getMapper(CmSubscriptionNcmpInEventMapper)
 
  40     JsonObjectMapper jsonObjectMapper
 
  42     def 'Map subscription event to yang model subscription event where #scenario'() {
 
  43         given: 'a Subscription Event'
 
  44             def jsonData = TestUtils.getResourceFileContent('cmSubscriptionNcmpInEvent.json')
 
  45             def testEventToMap = jsonObjectMapper.convertJsonString(jsonData, CmSubscriptionNcmpInEvent.class)
 
  46         when: 'the event is mapped to a yang model subscription'
 
  47             def result = objectUnderTest.toYangModelSubscriptionEvent(testEventToMap)
 
  48         then: 'the resulting yang model subscription event contains the correct clientId'
 
  49             assert result.clientId == "SCO-9989752"
 
  50         and: 'subscription name'
 
  51             assert result.subscriptionName == "cm-subscription-001"
 
  52         and: 'is tagged value is false'
 
  53             assert !result.isTagged
 
  54         and: 'predicate targets '
 
  55             assert result.predicates.targetCmHandles.cmHandleId == ["CMHandle1", "CMHandle2", "CMHandle3"]
 
  56         and: 'the status for these targets is set to pending'
 
  57             assert result.predicates.targetCmHandles.status == [SubscriptionStatus.PENDING, SubscriptionStatus.PENDING, SubscriptionStatus.PENDING]
 
  58         and: 'the topic is null'
 
  59             assert result.topic == null
 
  62     def 'Map empty subscription event to yang model subscription event'() {
 
  63         given: 'a new Subscription Event with no data'
 
  64             def testEventToMap = new CmSubscriptionNcmpInEvent()
 
  65         when: 'the event is mapped to a yang model subscription'
 
  66             def result = objectUnderTest.toYangModelSubscriptionEvent(testEventToMap)
 
  67         then: 'the resulting yang model subscription event contains null clientId'
 
  68             assert result.clientId == null
 
  69         and: 'subscription name is null'
 
  70             assert result.subscriptionName == null
 
  71         and: 'is tagged value is false'
 
  72             assert result.isTagged == false
 
  73         and: 'predicates is null'
 
  74             assert result.predicates == null
 
  75         and: 'the topic is null'
 
  76             assert result.topic == null