+
+ def 'Get a Cm Handle Composite State'() {
+ given: 'a valid cm handle id'
+ def cmHandleId = 'Some-Cm-Handle'
+ def dataNode = new DataNode(leaves: ['cm-handle-state': 'ADVISED'])
+ and: 'cps data service returns a valid data node'
+ mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry',
+ '/dmi-registry/cm-handles[@id=\'Some-Cm-Handle\']/state', FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
+ when: 'get cm handle state is invoked'
+ def result = objectUnderTest.getCmHandleState(cmHandleId)
+ then: 'result has returned the correct cm handle state'
+ result.cmHandleState == CmHandleState.ADVISED
+ }
+
+ def 'Update Cm Handle with #scenario State'() {
+ given: 'a cm handle and a composite state'
+ def cmHandleId = 'Some-Cm-Handle'
+ def compositeState = new CompositeState(cmHandleState: cmHandleState, lastUpdateTime: formattedDateAndTime)
+ when: 'update cm handle state is invoked with the #scenario state'
+ objectUnderTest.saveCmHandleState(cmHandleId, compositeState)
+ then: 'update node leaves is invoked with the correct params'
+ 1 * mockCpsDataService.replaceNodeTree('NCMP-Admin', 'ncmp-dmi-registry', '/dmi-registry/cm-handles[@id=\'Some-Cm-Handle\']', expectedJsonData, _ as OffsetDateTime)
+ where: 'the following states are used'
+ scenario | cmHandleState || expectedJsonData
+ 'READY' | CmHandleState.READY || '{"state":{"cm-handle-state":"READY","last-update-time":"2022-12-31T20:30:40.000+0000"}}'
+ 'LOCKED' | CmHandleState.LOCKED || '{"state":{"cm-handle-state":"LOCKED","last-update-time":"2022-12-31T20:30:40.000+0000"}}'
+ }
+
+ def 'Get Cm Handles By State'() {
+ given: 'a cm handle state to query'
+ def cmHandleState = CmHandleState.ADVISED
+ and: 'cps data service returns a list of data nodes'
+ def dataNodes = [new DataNode()]
+ mockCpsDataPersistenceService.queryDataNodes('NCMP-Admin', 'ncmp-dmi-registry',
+ '//state[@cm-handle-state="ADVISED"]/ancestor::cm-handles', OMIT_DESCENDANTS) >> dataNodes
+ when: 'get cm handles by state is invoked'
+ def result = objectUnderTest.getCmHandlesByState(cmHandleState)
+ then: 'the returned result is a list of data nodes returned by cps data service'
+ assert result == dataNodes
+ }
+