diff options
author | 2022-07-21 16:38:55 +0100 | |
---|---|---|
committer | 2022-08-04 10:16:46 +0100 | |
commit | eaa94ffea1871c04b5db95e4619c2a8b4e6bc166 (patch) | |
tree | 08b7224992bbbd36a0de92cfbc4fe4bf23b89720 /cps-ncmp-service/src/test/groovy/org | |
parent | 7dfc3a01f327654d64451865ac05b819c5583b27 (diff) |
LcmEvent state handler refactoring
- State handler will now handle new structure of LcmEvent.
- We have 3 types of events i.e create, update and delete.
- Introduced the LcmEventCreatorHelper to delegate some of the
responsibility of event creation based on event type and the state.
- New tests and existing refactoring
- Code rebased
- Refactored name as per group code review
- Code rebase with other commits
- Used copy constructor for deep copy operation of NcmpServiceCmhandle
and CompositeState
- UPCOMING : Related user stories to trigger the event publishing using
state handler.
Issue-ID: CPS-1128
Change-Id: I94b5a87d37d6a174c017ee0aa37cd0f0f74ba084
Signed-off-by: mpriyank <priyank.maheshwari@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/test/groovy/org')
3 files changed, 124 insertions, 11 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy index b3436792d..3d2e9950a 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy @@ -66,9 +66,8 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification { } def 'Update and Publish Events on State Change from NO_EXISTING state to ADVISED'() { - given: 'Cm Handle represented as YangModelCmHandle in READY state' - compositeState = new CompositeState() - yangModelCmHandle = new YangModelCmHandle(id: cmHandleId, dmiProperties: [], publicProperties: [], compositeState: compositeState) + given: 'Cm Handle represented as YangModelCmHandle' + yangModelCmHandle = new YangModelCmHandle(id: cmHandleId, dmiProperties: [], publicProperties: []) when: 'update state is invoked' objectUnderTest.updateCmHandleState(yangModelCmHandle, ADVISED) then: 'state is saved using inventory persistence' @@ -87,8 +86,8 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification { then: 'state is saved using inventory persistence and old lock reason details are retained' 1 * mockInventoryPersistence.saveCmHandleState(cmHandleId, _) >> { args -> { - assert (args[1] as CompositeState).lockReason.details == 'some lock details' - } + assert (args[1] as CompositeState).lockReason.details == 'some lock details' + } } and: 'event service is called to publish event' 1 * mockLcmEventsService.publishLcmEvent(cmHandleId, _) @@ -140,4 +139,4 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification { and: 'the method to publish Lcm event is called once' 1 * mockLcmEventsService.publishLcmEvent(cmHandleId, _) } -} +}
\ No newline at end of file diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCreatorSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCreatorSpec.groovy index aa79d634f..ccf956fac 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCreatorSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCreatorSpec.groovy @@ -20,23 +20,87 @@ package org.onap.cps.ncmp.api.impl.event.lcm +import org.onap.cps.ncmp.api.inventory.CmHandleState +import org.onap.cps.ncmp.api.inventory.CompositeState +import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle +import org.onap.ncmp.cmhandle.event.lcm.Values import spock.lang.Specification +import static org.onap.cps.ncmp.api.inventory.CmHandleState.ADVISED +import static org.onap.cps.ncmp.api.inventory.CmHandleState.DELETING +import static org.onap.cps.ncmp.api.inventory.CmHandleState.READY + class LcmEventsCreatorSpec extends Specification { def objectUnderTest = new LcmEventsCreator() def cmHandleId = 'test-cm-handle' - def 'Map the LcmEvent'() { + def 'Map the LcmEvent for #operation'() { + given: 'NCMP cm handle details with current and old details' + def existingNcmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, compositeState: new CompositeState(dataSyncEnabled: true, cmHandleState: existingCmHandleState), + publicProperties: ['publicProperty1': 'value1', 'publicProperty2': 'value2', 'publicProperty3': 'value3']) + def targetNcmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, compositeState: new CompositeState(dataSyncEnabled: false, cmHandleState: targetCmHandleState), + publicProperties: ['publicProperty1': 'value1', 'publicProperty2': 'value22']) + when: 'the event is populated' + def result = objectUnderTest.populateLcmEvent(cmHandleId, targetNcmpServiceCmHandle, existingNcmpServiceCmHandle) + then: 'event header is mapped correctly' + assert result.eventSource == 'org.onap.ncmp' + assert result.eventCorrelationId == cmHandleId + assert result.eventType == LcmEventType.UPDATE.eventType + and: 'event payload is mapped correctly with correct cmhandle id' + assert result.event.cmHandleId == cmHandleId + and: 'it should have correct old values' + assert result.event.oldValues.cmHandleState == expectedExistingCmHandleState + assert result.event.oldValues.dataSyncEnabled == true + and: 'the correct new values' + assert result.event.newValues.cmHandleState == expectedTargetCmHandleState + assert result.event.newValues.dataSyncEnabled == false + and: 'cmhandle properties are just the one which are differing' + assert result.event.oldValues.cmHandleProperties == [['publicProperty2': 'value2', 'publicProperty3': 'value3']] + assert result.event.newValues.cmHandleProperties == [['publicProperty2': 'value22']] + where: 'following parameters are provided' + operation | existingCmHandleState | targetCmHandleState || expectedExistingCmHandleState | expectedTargetCmHandleState + 'UPDATE' | ADVISED | READY || Values.CmHandleState.ADVISED | Values.CmHandleState.READY + 'DELETING' | READY | DELETING || Values.CmHandleState.READY | Values.CmHandleState.DELETING + + + } + + def 'Map the LcmEvent for operation CREATE'() { + given: 'NCMP cm handle details' + def targetNcmpServiceCmhandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, compositeState: new CompositeState(dataSyncEnabled: false, cmHandleState: READY), + publicProperties: ['publicProperty1': 'value11', 'publicProperty2': 'value22']) + def existingNcmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, publicProperties: ['publicProperty1': 'value1', 'publicProperty2': 'value2']) + when: 'the event is populated' + def result = objectUnderTest.populateLcmEvent(cmHandleId, targetNcmpServiceCmhandle, existingNcmpServiceCmHandle) + then: 'event header is mapped correctly' + assert result.eventSource == 'org.onap.ncmp' + assert result.eventCorrelationId == cmHandleId + assert result.eventType == LcmEventType.CREATE.eventType + and: 'event payload is mapped correctly' + assert result.event.cmHandleId == cmHandleId + assert result.event.newValues.cmHandleState == Values.CmHandleState.READY + assert result.event.newValues.dataSyncEnabled == false + assert result.event.newValues.cmHandleProperties == [['publicProperty1': 'value11', 'publicProperty2': 'value22']] + and: 'it should not have any old values' + assert result.event.oldValues == null + } + + def 'Map the LcmEvent for DELETE operation'() { + given: 'NCMP cm handle details' + def targetNcmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, compositeState: new CompositeState(dataSyncEnabled: false, cmHandleState: CmHandleState.DELETED), + publicProperties: ['publicProperty1': 'value11', 'publicProperty2': 'value22']) + def existingNcmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, compositeState: new CompositeState(dataSyncEnabled: true, cmHandleState: DELETING), + publicProperties: ['publicProperty1': 'value1']) when: 'the event is populated' - def result = objectUnderTest.populateLcmEvent(cmHandleId) + def result = objectUnderTest.populateLcmEvent(cmHandleId, targetNcmpServiceCmHandle, existingNcmpServiceCmHandle) then: 'event header is mapped correctly' assert result.eventSource == 'org.onap.ncmp' assert result.eventCorrelationId == cmHandleId - and: 'the result has the correct cm handle id' + assert result.eventType == LcmEventType.DELETE.eventType + and: 'event payload is mapped correctly ' assert result.event.cmHandleId == cmHandleId - and: 'the old and new values are not set yet' assert result.event.oldValues == null assert result.event.newValues == null } -} +}
\ No newline at end of file diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/NcmpServiceCmHandleSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/NcmpServiceCmHandleSpec.groovy new file mode 100644 index 000000000..3569887e5 --- /dev/null +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/NcmpServiceCmHandleSpec.groovy @@ -0,0 +1,50 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.ncmp.api.models + +import org.onap.cps.ncmp.api.inventory.CmHandleState +import org.onap.cps.ncmp.api.inventory.CompositeState +import spock.lang.Specification + +class NcmpServiceCmHandleSpec extends Specification { + + + def 'NCMP Service CmHandle check for deep copy operation'() { + given: 'ncmp service cm handle' + def originalNcmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: 'cmhandleid', + dmiProperties: ['property1': 'value1', 'property2': 'value2'], + publicProperties: ['pubproperty1': 'value1', 'pubproperty2': 'value2'], + compositeState: new CompositeState(cmHandleState: CmHandleState.ADVISED, dataSyncEnabled: Boolean.FALSE)) + when: 'we create a deep copy' + def deepCopiedNcmpServiceCmHandle = new NcmpServiceCmHandle(originalNcmpServiceCmHandle) + and: 'we change the original ncmp service cmhandle' + originalNcmpServiceCmHandle.dmiProperties = ['newProperty1': 'newValue1'] + originalNcmpServiceCmHandle.publicProperties = ['newPublicProperty1': 'newPubValue1'] + originalNcmpServiceCmHandle.compositeState = new CompositeState(cmHandleState: CmHandleState.DELETED, dataSyncEnabled: Boolean.TRUE) + then: 'no change in the copied dmi and public properties of ncmp service cmhandle' + deepCopiedNcmpServiceCmHandle.dmiProperties == ['property1': 'value1', 'property2': 'value2'] + deepCopiedNcmpServiceCmHandle.publicProperties == ['pubproperty1': 'value1', 'pubproperty2': 'value2'] + and: 'no change in the composite state' + deepCopiedNcmpServiceCmHandle.compositeState.cmHandleState == CmHandleState.ADVISED + deepCopiedNcmpServiceCmHandle.compositeState.dataSyncEnabled == Boolean.FALSE + } + +} |