summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test/groovy/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-service/src/test/groovy/org/onap')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy69
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandleSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/YangModelCmHandleSpec.groovy)32
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy2
3 files changed, 100 insertions, 3 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 3d2e9950af..ddede66393 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
@@ -139,4 +139,73 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification {
and: 'the method to publish Lcm event is called once'
1 * mockLcmEventsService.publishLcmEvent(cmHandleId, _)
}
+
+ def 'No state change and no event to be published'() {
+ given: 'Cm Handle batch with same state transition as before'
+ def cmHandleStateMap = setupBatch('NO_CHANGE')
+ when: 'updating a batch of changes'
+ objectUnderTest.updateCmHandleStateBatch(cmHandleStateMap)
+ then: 'batch is empty and nothing to update'
+ 1 * mockInventoryPersistence.saveCmHandleBatch(_) >> {
+ args -> {
+ assert (args[0] as Collection<YangModelCmHandle>).size() == 0
+ }
+ }
+ and: 'no event will be published'
+ 0 * mockLcmEventsService.publishLcmEvent(*_)
+ }
+
+ def 'Batch of new cm handles provided'() {
+ given: 'A batch of new cm handles'
+ def cmHandleStateMap = setupBatch('NEW')
+ when: 'updating a batch of changes'
+ objectUnderTest.updateCmHandleStateBatch(cmHandleStateMap)
+ then: 'new cm handles are saved using inventory persistence'
+ 1 * mockInventoryPersistence.saveCmHandleBatch(_) >> {
+ args -> {
+ assert (args[0] as Collection<YangModelCmHandle>).id.containsAll('cmhandle1', 'cmhandle2')
+ }
+ }
+ and: 'event service is called to publish event'
+ 2 * mockLcmEventsService.publishLcmEvent(_, _)
+
+ }
+
+ def 'Batch of existing cm handles is updated'() {
+ given: 'A batch of updated cm handles'
+ def cmHandleStateMap = setupBatch('UPDATE')
+ when: 'updating a batch of changes'
+ objectUnderTest.updateCmHandleStateBatch(cmHandleStateMap)
+ then : 'existing cm handles composite state is persisted'
+ 1 * mockInventoryPersistence.saveCmHandleStateBatch(_) >> {
+ args -> {
+ assert (args[0] as Map<String, CompositeState>).keySet().containsAll(['cmhandle1','cmhandle2'])
+ }
+ }
+ and: 'event service is called to publish event'
+ 2 * mockLcmEventsService.publishLcmEvent(_, _)
+
+ }
+
+ def setupBatch(type) {
+
+ def yangModelCmHandle1 = new YangModelCmHandle(id: 'cmhandle1', dmiProperties: [], publicProperties: [])
+ def yangModelCmHandle2 = new YangModelCmHandle(id: 'cmhandle2', dmiProperties: [], publicProperties: [])
+
+ if ('NEW' == type) {
+ return [(yangModelCmHandle1): ADVISED, (yangModelCmHandle2): ADVISED]
+ }
+
+ if ('UPDATE' == type) {
+ yangModelCmHandle1.compositeState = new CompositeState(cmHandleState: ADVISED)
+ yangModelCmHandle2.compositeState = new CompositeState(cmHandleState: READY)
+ return [(yangModelCmHandle1): READY, (yangModelCmHandle2): DELETING]
+ }
+
+ if ('NO_CHANGE' == type) {
+ yangModelCmHandle1.compositeState = new CompositeState(cmHandleState: ADVISED)
+ yangModelCmHandle2.compositeState = new CompositeState(cmHandleState: READY)
+ return [(yangModelCmHandle1): ADVISED, (yangModelCmHandle2): READY]
+ }
+ }
} \ No newline at end of file
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/YangModelCmHandleSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandleSpec.groovy
index 09f42e4b9f..5fe2660249 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/models/YangModelCmHandleSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandleSpec.groovy
@@ -18,13 +18,14 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.models
+package org.onap.cps.ncmp.api.impl.yangmodels
-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
import org.onap.cps.ncmp.api.inventory.CompositeStateBuilder
import org.onap.cps.ncmp.api.inventory.LockReasonCategory
import org.onap.cps.ncmp.api.inventory.DataStoreSyncState
+import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle
import spock.lang.Specification
import static org.onap.cps.ncmp.api.impl.operations.RequiredDmiService.DATA
@@ -79,4 +80,31 @@ class YangModelCmHandleSpec extends Specification {
'only data service registered' | null | 'does not matter' | null | MODEL || null
}
+ def 'Yang Model Cm Handle Deep Copy'() {
+ given: 'a yang model cm handle'
+ def currentYangModelCmHandle = new YangModelCmHandle(id: 'cmhandle',
+ publicProperties: [new YangModelCmHandle.Property('publicProperty1', 'value1')],
+ dmiProperties: [new YangModelCmHandle.Property('dmiProperty1', 'value1')],
+ compositeState: new CompositeState(cmHandleState: CmHandleState.ADVISED, dataSyncEnabled: false))
+ when: 'a deep copy is created'
+ def yangModelCmhandleDeepCopy = YangModelCmHandle.deepCopyOf(currentYangModelCmHandle)
+ and: 'we try to mutate current yang model cm handle'
+ currentYangModelCmHandle.id = 'cmhandle-changed'
+ currentYangModelCmHandle.dmiProperties = [new YangModelCmHandle.Property('updatedPublicProperty1', 'value1')]
+ currentYangModelCmHandle.publicProperties = [new YangModelCmHandle.Property('updatedDmiProperty1', 'value1')]
+ currentYangModelCmHandle.compositeState.cmHandleState = CmHandleState.READY
+ currentYangModelCmHandle.compositeState.dataSyncEnabled = true
+ then: 'there is no change in the deep copied object'
+ assert yangModelCmhandleDeepCopy.id == 'cmhandle'
+ assert yangModelCmhandleDeepCopy.dmiProperties == [new YangModelCmHandle.Property('dmiProperty1', 'value1')]
+ assert yangModelCmhandleDeepCopy.publicProperties == [new YangModelCmHandle.Property('publicProperty1', 'value1')]
+ assert yangModelCmhandleDeepCopy.compositeState.cmHandleState == CmHandleState.ADVISED
+ assert yangModelCmhandleDeepCopy.compositeState.dataSyncEnabled == false
+ and: 'equality on reference and hashcode behave as expected'
+ assert currentYangModelCmHandle.hashCode() != yangModelCmhandleDeepCopy.hashCode()
+ assert currentYangModelCmHandle != yangModelCmhandleDeepCopy
+
+ }
+
+
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy
index 76f10de831..19c8ae81ce 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy
@@ -159,7 +159,7 @@ class InventoryPersistenceSpec extends Specification {
def compositeState2 = new CompositeState(cmHandleState: cmHandleState, lastUpdateTime: formattedDateAndTime)
when: 'update cm handle state is invoked with the #scenario state'
def cmHandleStateMap = ['Some-Cm-Handle1' : compositeState1, 'Some-Cm-Handle2' : compositeState2]
- objectUnderTest.saveCmHandleStates(cmHandleStateMap)
+ objectUnderTest.saveCmHandleStateBatch(cmHandleStateMap)
then: 'update node leaves is invoked with the correct params'
1 * mockCpsDataService.updateDataNodesAndDescendants('NCMP-Admin', 'ncmp-dmi-registry', cmHandlesJsonDataMap, _ as OffsetDateTime)
where: 'the following states are used'