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.deprecated.cmsubscription
23 import com.fasterxml.jackson.databind.ObjectMapper
24 import org.mapstruct.factory.Mappers
25 import org.onap.cps.ncmp.api.models.CmSubscriptionEvent
26 import org.onap.cps.ncmp.api.models.CmSubscriptionStatus
27 import org.onap.cps.ncmp.utils.TestUtils
28 import org.onap.cps.spi.exceptions.DataValidationException
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 CmSubscriptionEventToCmSubscriptionNcmpOutEventMapperSpec extends Specification {
38 CmSubscriptionEventToCmSubscriptionNcmpOutEventMapper objectUnderTest = Mappers.getMapper(CmSubscriptionEventToCmSubscriptionNcmpOutEventMapper)
41 JsonObjectMapper jsonObjectMapper
43 def 'Map cm subscription event to ncmp out event'() {
44 given: 'a cm subscription event'
45 def cmSubscriptionEventJsonData = TestUtils.getResourceFileContent('deprecatedCmSubscription/cmSubscriptionEvent.json')
46 def cmSubscriptionEvent = jsonObjectMapper.convertJsonString(cmSubscriptionEventJsonData, CmSubscriptionEvent.class)
47 when: 'cm subscription event is mapped to ncmp out event'
48 def result = objectUnderTest.toCmSubscriptionNcmpOutEvent(cmSubscriptionEvent)
49 then: 'the resulting ncmp out event contains expected pending targets per details grouping'
50 def pendingCmHandleTargetsPerDetails = result.getData().getAdditionalInfo().getPending()
51 assert pendingCmHandleTargetsPerDetails.get(0).getDetails() == 'Some other error happened'
52 assert pendingCmHandleTargetsPerDetails.get(0).getTargets() == ['CMHandle4','CMHandle5']
53 assert pendingCmHandleTargetsPerDetails.get(1).getDetails() == 'Some error causes pending'
54 assert pendingCmHandleTargetsPerDetails.get(1).getTargets() == ['CMHandle3']
55 and: 'the resulting ncmp out event contains expected rejected targets per details grouping'
56 def rejectedCmHandleTargetsPerDetails = result.getData().getAdditionalInfo().getRejected()
57 assert rejectedCmHandleTargetsPerDetails.get(0).getDetails() == 'Some other error message from the DMI'
58 assert rejectedCmHandleTargetsPerDetails.get(0).getTargets() == ['CMHandle2']
59 assert rejectedCmHandleTargetsPerDetails.get(1).getDetails() == 'Some error message from the DMI'
60 assert rejectedCmHandleTargetsPerDetails.get(1).getTargets() == ['CMHandle1']
63 def 'Map cm subscription event to ncmp out event with the given scenarios causes an exception'() {
64 given: 'a cm subscription event'
65 def cmSubscriptionEventJsonData = TestUtils.getResourceFileContent('deprecatedCmSubscription/cmSubscriptionEvent.json')
66 def cmSubscriptionEvent = jsonObjectMapper.convertJsonString(cmSubscriptionEventJsonData, CmSubscriptionEvent.class)
67 and: 'set cm subscription status with given scenarios'
68 cmSubscriptionEvent.setCmSubscriptionStatus(subscriptionStatusList)
69 when: 'cm subscription event is mapped to ncmp out event'
70 objectUnderTest.toCmSubscriptionNcmpOutEvent(cmSubscriptionEvent)
71 then: 'a DataValidationException is thrown with an expected exception details'
72 def exception = thrown(DataValidationException)
73 exception.details == 'CmSubscriptionStatus list cannot be null or empty'
74 where: 'the following values are used'
75 scenario || subscriptionStatusList
76 'A null subscription status list' || null
77 'An empty subscription status list' || new ArrayList<CmSubscriptionStatus>()
80 def 'Map cm subscription event to ncmp out event without any exception'() {
81 given: 'a cm subscription Event'
82 def subscriptionResponseJsonData = TestUtils.getResourceFileContent('deprecatedCmSubscription/cmSubscriptionEvent.json')
83 def subscriptionResponseEvent = jsonObjectMapper.convertJsonString(subscriptionResponseJsonData, CmSubscriptionEvent.class)
84 when: 'cm subscription event is mapped to ncmp out event'
85 objectUnderTest.toCmSubscriptionNcmpOutEvent(subscriptionResponseEvent)
86 then: 'no exception thrown'