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.avcsubscription
23 import com.fasterxml.jackson.databind.ObjectMapper
24 import org.mapstruct.factory.Mappers
25 import org.onap.cps.ncmp.api.models.SubscriptionEventResponse
26 import org.onap.cps.ncmp.events.avc.subscription.v1.SubscriptionEventOutcome
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 SubscriptionOutcomeMapperSpec extends Specification {
37 SubscriptionOutcomeMapper objectUnderTest = Mappers.getMapper(SubscriptionOutcomeMapper)
40 JsonObjectMapper jsonObjectMapper
42 def 'Map subscription event response to subscription event outcome'() {
43 given: 'a Subscription Response Event'
44 def subscriptionResponseJsonData = TestUtils.getResourceFileContent('avcSubscriptionEventResponse.json')
45 def subscriptionResponseEvent = jsonObjectMapper.convertJsonString(subscriptionResponseJsonData, SubscriptionEventResponse.class)
46 and: 'a Subscription Outcome Event'
47 def jsonDataOutcome = TestUtils.getResourceFileContent('avcSubscriptionOutcomeEvent.json')
48 def expectedEventOutcome = jsonObjectMapper.convertJsonString(jsonDataOutcome, SubscriptionEventOutcome.class)
49 expectedEventOutcome.setEventType(expectedEventType)
50 when: 'the subscription response event is mapped to a subscription event outcome'
51 def result = objectUnderTest.toSubscriptionEventOutcome(subscriptionResponseEvent)
52 result.setEventType(expectedEventType)
53 then: 'the resulting subscription event outcome contains the correct clientId'
54 assert result == expectedEventOutcome
55 where: 'the following values are used'
56 scenario || expectedEventType
57 'is full outcome' || SubscriptionEventOutcome.EventType.COMPLETE_OUTCOME
58 'is partial outcome' || SubscriptionEventOutcome.EventType.PARTIAL_OUTCOME