diff options
author | mpriyank <priyank.maheshwari@est.tech> | 2022-06-15 14:40:50 +0100 |
---|---|---|
committer | mpriyank <priyank.maheshwari@est.tech> | 2022-06-20 12:52:16 +0100 |
commit | 8a85791b8e38967b637445991caf16160721f4c8 (patch) | |
tree | 8561279e490cc9acba8af6c9b03e92b5c5eead89 /cps-ncmp-service/src/test/groovy/org | |
parent | 44d933db05217eac411eec4972a0d7c880cf5c4e (diff) |
Publish LCM Events
- Publish LCM Create Event when watchdog process moves the cmHandle state from
ADVISED to READY
- Publish LCM Update Event when public properties are updated, no event
when DMI propertis are updated
- Publish LCM Delete Event when a cmHandle is been removed
- Related test scenarios update
- See User Story CPS-1034 for related sub-tasks
Issue-ID: CPS-1090
Change-Id: I70d81fde7c80794ea13a10cd1f235a7012b20b3c
Signed-off-by: mpriyank <priyank.maheshwari@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/test/groovy/org')
4 files changed, 32 insertions, 5 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy index e9d02dfc72..8a45e66971 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy @@ -23,6 +23,7 @@ package org.onap.cps.ncmp.api.impl import com.fasterxml.jackson.databind.ObjectMapper import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService +import org.onap.cps.ncmp.api.impl.event.NcmpEventsService import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle import org.onap.cps.api.CpsAdminService import org.onap.cps.api.CpsDataService @@ -66,6 +67,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { def mockInventoryPersistence = Mock(InventoryPersistence) def mockModuleSyncService = Mock(ModuleSyncService) def stubbedNetworkCmProxyCmHandlerQueryService = Stub(NetworkCmProxyCmHandlerQueryService) + def mockNcmpEventsService = Mock(NcmpEventsService) def noTimestamp = null def objectUnderTest = getObjectUnderTest() @@ -350,6 +352,6 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification { def getObjectUnderTest() { return Spy(new NetworkCmProxyDataServiceImpl(mockCpsDataService, spiedJsonObjectMapper, mockDmiDataOperations, mockCpsModuleService, mockCpsAdminService, mockNetworkCmProxyDataServicePropertyHandler, mockInventoryPersistence, - mockModuleSyncService, stubbedNetworkCmProxyCmHandlerQueryService)) + mockModuleSyncService, stubbedNetworkCmProxyCmHandlerQueryService, mockNcmpEventsService)) } } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy index d58fe6a7cd..783fabb1d3 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy @@ -23,6 +23,7 @@ package org.onap.cps.ncmp.api.impl import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService +import org.onap.cps.ncmp.api.impl.event.NcmpEventsService import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle import org.onap.cps.ncmp.api.inventory.CmHandleState import org.onap.cps.ncmp.api.inventory.CompositeState @@ -66,6 +67,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def mockModuleSyncService = Mock(ModuleSyncService) def mockDmiPluginRegistration = Mock(DmiPluginRegistration) def mockCpsCmHandlerQueryService = Mock(NetworkCmProxyCmHandlerQueryService) + def mockNcmpEventsService = Mock(NcmpEventsService) def NO_TOPIC = null def NO_REQUEST_ID = null @@ -76,7 +78,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def objectUnderTest = new NetworkCmProxyDataServiceImpl(mockCpsDataService, spiedJsonObjectMapper, mockDmiDataOperations, mockCpsModuleService, mockCpsAdminService, nullNetworkCmProxyDataServicePropertyHandler, mockInventoryPersistence, - mockModuleSyncService, mockCpsCmHandlerQueryService) + mockModuleSyncService, mockCpsCmHandlerQueryService, mockNcmpEventsService) def cmHandleXPath = "/dmi-registry/cm-handles[@id='testCmHandle']" diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandlerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandlerSpec.groovy index 5eba5eecd2..0cf04a9ff3 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandlerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandlerSpec.groovy @@ -21,12 +21,14 @@ package org.onap.cps.ncmp.api.impl +import org.onap.cps.ncmp.api.impl.event.NcmpEventsService import org.onap.cps.spi.exceptions.DataValidationException import static org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.RegistrationError.CM_HANDLE_DOES_NOT_EXIST import static org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.RegistrationError.CM_HANDLE_INVALID_ID import static org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.RegistrationError.UNKNOWN_ERROR import static org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.Status +import static org.onap.ncmp.cmhandle.lcm.event.Event.Operation.UPDATE import org.onap.cps.api.CpsDataService import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle @@ -39,8 +41,9 @@ import spock.lang.Specification class NetworkCmProxyDataServicePropertyHandlerSpec extends Specification { def mockCpsDataService = Mock(CpsDataService) + def mockNcmpEventsService = Mock(NcmpEventsService) - def objectUnderTest = new NetworkCmProxyDataServicePropertyHandler(mockCpsDataService) + def objectUnderTest = new NetworkCmProxyDataServicePropertyHandler(mockCpsDataService, mockNcmpEventsService) def dataspaceName = 'NCMP-Admin' def anchorName = 'ncmp-dmi-registry' def static cmHandleId = 'myHandle1' @@ -67,6 +70,8 @@ class NetworkCmProxyDataServicePropertyHandlerSpec extends Specification { assert args[3].leaves.containsAll(convertToProperties(expectedPropertiesAfterUpdate)) } } + and: 'ncmp event is published' + 1 * mockNcmpEventsService.publishNcmpEvent(cmHandleId, UPDATE) where: 'following public properties updates are made' scenario | updatedPublicProperties || expectedPropertiesAfterUpdate 'property added' | ['newPubProp1': 'pub-val'] || [['publicProp3': 'publicValue3'], ['publicProp4': 'publicValue4'], ['newPubProp1': 'pub-val']] @@ -89,6 +94,8 @@ class NetworkCmProxyDataServicePropertyHandlerSpec extends Specification { assert args[3].leaves.containsAll(convertToProperties(expectedPropertiesAfterUpdate)) } } + and: 'ncmp event is not published on dmi properties update' + 0 * mockNcmpEventsService.publishNcmpEvent(_, _) where: 'following DMI properties updates are made' scenario | updatedDmiProperties || expectedPropertiesAfterUpdate | expectedCallsToReplaceMethod 'property added' | ['newAdditionalProp1': 'add-value'] || [['additionalProp1': 'additionalValue1'], ['additionalProp2': 'additionalValue2'], ['newAdditionalProp1': 'add-value']] | 1 @@ -114,6 +121,8 @@ class NetworkCmProxyDataServicePropertyHandlerSpec extends Specification { assert arg[2].contains("@name='publicProp") } } + and: 'ncmp event is published with updated public properties' + 1 * mockNcmpEventsService.publishNcmpEvent(cmHandleId, UPDATE) where: 'following public properties updates are made' scenario | originalPropertyDataNodes || expectedCallsToDeleteDataNode '2 original properties, both removed' | propertyDataNodes || 2 @@ -136,6 +145,8 @@ class NetworkCmProxyDataServicePropertyHandlerSpec extends Specification { assert it.registrationError == expectedError assert it.errorText == expectedErrorText } + and: 'ncmp event is not published' + 0 * mockNcmpEventsService.publishNcmpEvent(_, _) where: scenario | cmHandleId | exception || expectedError | expectedErrorText 'Cm Handle does not exist' | 'cmHandleId' | new DataNodeNotFoundException('NCMP-Admin', 'ncmp-dmi-registry') || CM_HANDLE_DOES_NOT_EXIST | 'cm-handle does not exist' @@ -171,7 +182,9 @@ class NetworkCmProxyDataServicePropertyHandlerSpec extends Specification { assert it.errorText == "cm-handle does not exist" } then: 'the replace list method is called twice' - 2 * mockCpsDataService.replaceListContent(*_) + 2 * mockCpsDataService.replaceListContent(dataspaceName, anchorName, cmHandleXpath, _, noTimeStamp) + and: 'the ncmp event is published' + 2 * mockNcmpEventsService.publishNcmpEvent(cmHandleId, UPDATE) } def convertToProperties(expectedPropertiesAfterUpdateAsMap) { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy index 544f739c06..802035c726 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy @@ -21,6 +21,9 @@ package org.onap.cps.ncmp.api.inventory.sync +import static org.onap.ncmp.cmhandle.lcm.event.Event.Operation.CREATE + +import org.onap.cps.ncmp.api.impl.event.NcmpEventsService import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle import org.onap.cps.ncmp.api.inventory.CmHandleState import org.onap.cps.ncmp.api.inventory.CompositeState @@ -37,9 +40,11 @@ class ModuleSyncSpec extends Specification { def mockModuleSyncService = Mock(ModuleSyncService) + def mockNcmpEventsService = Mock(NcmpEventsService) + def cmHandleState = CmHandleState.ADVISED - def objectUnderTest = new ModuleSyncWatchdog(mockInventoryPersistence, mockSyncUtils, mockModuleSyncService) + def objectUnderTest = new ModuleSyncWatchdog(mockInventoryPersistence, mockSyncUtils, mockModuleSyncService, mockNcmpEventsService) def 'Schedule a Cm-Handle Sync for ADVISED Cm-Handles'() { given: 'cm handles in an advised state' @@ -67,6 +72,9 @@ class ModuleSyncSpec extends Specification { assert compositeState2.getCmHandleState() == CmHandleState.READY and: 'the second cm handle state is updated' 1 * mockInventoryPersistence.saveCmHandleState('some-cm-handle-2', compositeState2) + and: 'the ncmp event will be published for both cmHandles' + 1 * mockNcmpEventsService.publishNcmpEvent('some-cm-handle', CREATE) + 1 * mockNcmpEventsService.publishNcmpEvent('some-cm-handle-2', CREATE) } def 'Schedule a Cm-Handle Sync for ADVISED Cm-Handle with failure'() { @@ -87,6 +95,8 @@ class ModuleSyncSpec extends Specification { 1 * mockSyncUtils.updateLockReasonDetailsAndAttempts(compositeState, LockReasonCategory.LOCKED_MISBEHAVING ,'some exception') and: 'the cm handle state is updated' 1 * mockInventoryPersistence.saveCmHandleState('some-cm-handle', compositeState) + and: 'the ncmp event is not published' + 0 * mockNcmpEventsService.publishNcmpEvent(_, _) } |