Merge "Expose hazelcast cluster info"
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / impl / events / avc / ncmptoclient / AvcEventPublisherSpec.groovy
1 /*
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
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20
21 package org.onap.cps.ncmp.api.impl.events.avc.ncmptoclient
22
23 import com.fasterxml.jackson.databind.ObjectMapper
24 import io.cloudevents.CloudEvent
25 import org.onap.cps.ncmp.api.impl.events.EventsPublisher
26 import org.onap.cps.ncmp.api.impl.utils.context.CpsApplicationContext
27 import org.onap.cps.ncmp.api.kafka.MessagingBaseSpec
28 import org.onap.cps.ncmp.events.avc.ncmp_to_client.Avc
29 import org.onap.cps.ncmp.events.avc.ncmp_to_client.AvcEvent
30 import org.onap.cps.utils.JsonObjectMapper
31 import org.springframework.test.context.ContextConfiguration
32
33 import static org.onap.cps.ncmp.api.impl.events.mapper.CloudEventMapper.toTargetEvent
34
35 @ContextConfiguration(classes = [CpsApplicationContext, ObjectMapper, JsonObjectMapper])
36 class AvcEventPublisherSpec extends MessagingBaseSpec {
37
38     def mockEventsPublisher = Mock(EventsPublisher<CloudEvent>)
39     def objectUnderTest = new AvcEventPublisher(mockEventsPublisher)
40
41     def 'Publish an attribute value change event'() {
42         given: 'the event key'
43             def someEventKey = 'someEventKey'
44         and: 'the name of the attribute being changed'
45             def someAttributeName = 'someAttributeName'
46         and: 'the old value of the attribute'
47             def someOldAttributeValue = 'someOldAttributeValue'
48         and: 'the new value of the attribute'
49             def someNewAttributeValue = 'someNewAttributeValue'
50         when: 'an attribute value change event is published'
51             objectUnderTest.publishAvcEvent(someEventKey, someAttributeName, someOldAttributeValue, someNewAttributeValue)
52         then: 'the cloud event publisher is invoked with the correct data'
53             1 * mockEventsPublisher.publishCloudEvent(_, someEventKey,
54                 cloudEvent -> {
55                     def actualAvcs = toTargetEvent(cloudEvent, AvcEvent.class).data.attributeValueChange
56                     def expectedAvc = new Avc(attributeName: someAttributeName,
57                         oldAttributeValue: someOldAttributeValue,
58                         newAttributeValue: someNewAttributeValue)
59                     assert actualAvcs == [expectedAvc]
60                 })
61     }
62
63 }