2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022 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.event
23 import org.onap.cps.ncmp.api.inventory.CmHandleState
24 import org.onap.cps.ncmp.api.inventory.CompositeStateBuilder
25 import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
26 import spock.lang.Specification
28 import static org.onap.ncmp.cmhandle.lcm.event.Event.Operation.CREATE
29 import static org.onap.ncmp.cmhandle.lcm.event.Event.Operation.DELETE
30 import static org.onap.ncmp.cmhandle.lcm.event.Event.Operation.UPDATE
32 class NcmpEventsCreatorSpec extends Specification {
34 def objectUnderTest = new NcmpEventsCreator()
35 def cmHandleId = 'test-cm-handle'
37 def 'Map the NcmpEvent for operation #operation'() {
38 given: 'NCMP cm handle details'
39 def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, compositeState: new CompositeStateBuilder().withCmHandleState(CmHandleState.READY).build(),
40 publicProperties: ['publicProperty1': 'value1', 'publicProperty2': 'value2'])
41 when: 'the event is populated'
42 def result = objectUnderTest.populateNcmpEvent(cmHandleId, operation, ncmpServiceCmHandle)
43 then: 'event header is mapped correctly'
44 assert result.eventSource == 'org.onap.ncmp'
45 assert result.eventCorrelationId == cmHandleId
46 and: 'event payload is mapped correctly'
47 assert result.event.operation == operation
48 assert (result.event.cmhandleProperties != null) ? result.event.cmhandleProperties.size() : 0 == cmHandlePropertiesListSize
49 assert (result.event.cmhandleProperties != null) ? result.event.cmhandleProperties[0] : null == cmHandleProperties
50 where: 'the following operations are used'
51 operation | cmHandlePropertiesListSize | cmHandleProperties
52 CREATE | 1 | ['publicProperty1': 'value1', 'publicProperty2': 'value2']
53 UPDATE | 1 | ['publicProperty1': 'value1', 'publicProperty2': 'value2']