import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
+import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NO_TIMESTAMP
import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
@Shared
def childDataNodesForCmHandleWithState = [new DataNode(xpath: "/dmi-registry/cm-handles[@id='some-cm-handle']/state", leaves: ['cm-handle-state': 'ADVISED'])]
- @Shared
- def static sampleDataNodes = [new DataNode()]
-
def "Retrieve CmHandle using datanode with #scenario."() {
given: 'the cps data service returns a data node from the DMI registry'
def dataNode = new DataNode(childDataNodes:childDataNodes, leaves: leaves)
- mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', xpath, INCLUDE_ALL_DESCENDANTS) >> dataNode
+ mockCpsDataPersistenceService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', xpath, INCLUDE_ALL_DESCENDANTS) >> dataNode
when: 'retrieving the yang modelled cm handle'
def result = objectUnderTest.getYangModelCmHandle(cmHandleId)
then: 'the result has the correct id and service names'
def "Handling missing service names as null CPS-1043."() {
given: 'the cps data service returns a data node from the DMI registry with empty child and leaf attributes'
def dataNode = new DataNode(childDataNodes:[], leaves: [:])
- mockCpsDataService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', xpath, INCLUDE_ALL_DESCENDANTS) >> dataNode
+ mockCpsDataPersistenceService.getDataNode('NCMP-Admin', 'ncmp-dmi-registry', xpath, INCLUDE_ALL_DESCENDANTS) >> dataNode
when: 'retrieving the yang modelled cm handle'
def result = objectUnderTest.getYangModelCmHandle(cmHandleId)
then: 'the service names ae returned as null'
'DELETING' | CmHandleState.DELETING || '{"state":{"cm-handle-state":"DELETING","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'
- mockCpsDataPersistenceService.queryDataNodes('NCMP-Admin', 'ncmp-dmi-registry',
- '//state[@cm-handle-state="ADVISED"]/ancestor::cm-handles', OMIT_DESCENDANTS) >> sampleDataNodes
- 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 == sampleDataNodes
- }
-
- def 'Get Cm Handles By State and Cm-Handle Id'() {
- given: 'a cm handle state to query'
- def cmHandleState = CmHandleState.READY
- and: 'cps data service returns a list of data nodes'
- mockCpsDataPersistenceService.queryDataNodes('NCMP-Admin', 'ncmp-dmi-registry',
- '//cm-handles[@id=\'some-cm-handle\']/state[@cm-handle-state="'+ 'READY'+'"]/ancestor::cm-handles', OMIT_DESCENDANTS) >> sampleDataNodes
- when: 'get cm handles by state and id is invoked'
- def result = objectUnderTest.getCmHandlesByIdAndState(cmHandleId, cmHandleState)
- then: 'the returned result is a list of data nodes returned by cps data service'
- assert result == sampleDataNodes
- }
-
- def 'Get Cm Handles By Operational Sync State : UNSYNCHRONIZED'() {
- given: 'a cm handle state to query'
- def cmHandleState = CmHandleState.READY
- and: 'cps data service returns a list of data nodes'
- mockCpsDataPersistenceService.queryDataNodes('NCMP-Admin', 'ncmp-dmi-registry',
- '//state/datastores/operational[@sync-state="'+'UNSYNCHRONIZED'+'"]/ancestor::cm-handles', OMIT_DESCENDANTS) >> sampleDataNodes
- when: 'get cm handles by operational sync state as UNSYNCHRONIZED is invoked'
- def result = objectUnderTest.getCmHandlesByOperationalSyncState(DataStoreSyncState.UNSYNCHRONIZED)
- then: 'the returned result is a list of data nodes returned by cps data service'
- assert result == sampleDataNodes
- }
-
- def 'Retrieve cm handle by cps path '() {
- given: 'a cm handle state to query based on the cps path'
- def cmHandleDataNode = new DataNode(xpath: 'xpath', leaves: ['cm-handle-state': 'LOCKED'])
- def cpsPath = '//cps-path'
- and: 'cps data service returns a valid data node'
- mockCpsDataPersistenceService.queryDataNodes('NCMP-Admin', 'ncmp-dmi-registry',
- cpsPath, INCLUDE_ALL_DESCENDANTS)
- >> Arrays.asList(cmHandleDataNode)
- when: 'get cm handles by cps path is invoked'
- def result = objectUnderTest.getCmHandleDataNodesByCpsPath(cpsPath, INCLUDE_ALL_DESCENDANTS)
- then: 'the returned result is a list of data nodes returned by cps data service'
- assert result.contains(cmHandleDataNode)
- }
-
def 'Get module definitions'() {
given: 'cps module service returns a collection of module definitions'
def moduleDefinitions = [new ModuleDefinition('moduleName','revision','content')]
assert result == moduleReferences
}
- def 'Save list elements'() {
- when: 'the method to save list elements is called'
- objectUnderTest.saveListElements('sample Json data')
+ def 'Save Cmhandle'() {
+ given: 'cmHandle represented as Yang Model'
+ def yangModelCmHandle = new YangModelCmHandle(id: 'cmhandle', dmiProperties: [], publicProperties: [])
+ when: 'the method to save cmhandle is called'
+ objectUnderTest.saveCmHandle(yangModelCmHandle)
then: 'the data service method to save list elements is called once'
- 1 * mockCpsDataService.saveListElements('NCMP-Admin','ncmp-dmi-registry','/dmi-registry','sample Json data',null)
+ 1 * mockCpsDataService.saveListElements('NCMP-Admin','ncmp-dmi-registry','/dmi-registry',_,null) >> {
+ args -> {
+ assert args[3].startsWith('{"cm-handles":[{"id":"cmhandle","additional-properties":[],"public-properties":[]}]}')
+ }
+ }
}
def 'Delete list or list elements'() {
0 * mockCpsModuleService.deleteSchemaSet('NFP-Operational', 'sampleSchemaSetName', CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED)
}
- def 'Query data nodes via cpsPath'() {
- when: 'the method to query data nodes is called'
- objectUnderTest.queryDataNodes('sample cpsPath')
- then: 'the data persistence service method to query data nodes is invoked once'
- 1 * mockCpsDataPersistenceService.queryDataNodes('NCMP-Admin','ncmp-dmi-registry','sample cpsPath', INCLUDE_ALL_DESCENDANTS)
- }
-
def 'Get data node via xPath'() {
when: 'the method to get data nodes is called'
objectUnderTest.getDataNode('sample xPath')
1 * mockCpsDataPersistenceService.getDataNode('NCMP-Admin','ncmp-dmi-registry','sample xPath', INCLUDE_ALL_DESCENDANTS)
}
+ def 'Get cmHandle data node'() {
+ given: 'expected xPath to get cmHandle data node'
+ def expectedXPath = '/dmi-registry/cm-handles[@id=\'sample cmHandleId\']';
+ when: 'the method to get data nodes is called'
+ objectUnderTest.getCmHandleDataNode('sample cmHandleId')
+ then: 'the data persistence service method to get cmHandle data node is invoked once with expected xPath'
+ 1 * mockCpsDataPersistenceService.getDataNode('NCMP-Admin','ncmp-dmi-registry',expectedXPath, INCLUDE_ALL_DESCENDANTS)
+ }
+
def 'Query anchors'() {
when: 'the method to query anchors is called'
objectUnderTest.queryAnchors(['sample-module-name'])
def 'Get anchors'() {
when: 'the method to get anchors with no parameters is called'
- objectUnderTest.getAnchors()
+ objectUnderTest.getAnchors()
then: 'the admin persistence service method to query anchors is invoked once with a specific dataspace name'
1 * mockCpsAdminPersistenceService.getAnchors('NFP-Operational')
}
+
+ def 'Replace list content'() {
+ when: 'replace list content method is called with xpath and data nodes collection'
+ objectUnderTest.replaceListContent('sample xpath', [new DataNode()])
+ then: 'the cps data service method to replace list content is invoked once with same parameters'
+ 1 * mockCpsDataService.replaceListContent('NCMP-Admin', 'ncmp-dmi-registry',
+ 'sample xpath', [new DataNode()], NO_TIMESTAMP);
+ }
+
+ def 'Delete data node via xPath'() {
+ when: 'Delete data node method is called with xpath as parameter'
+ objectUnderTest.deleteDataNode('sample dataNode xpath')
+ then: 'the cps data service method to delete data node is invoked once with the same xPath'
+ 1 * mockCpsDataService.deleteDataNode('NCMP-Admin', 'ncmp-dmi-registry',
+ 'sample dataNode xpath', NO_TIMESTAMP);
+ }
+
}