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