+ def 'upgrade model for a existing cm handle'() {
+ given: 'a cm handle that is ready but locked for upgrade'
+ def ncmpServiceCmHandle = new NcmpServiceCmHandle()
+ ncmpServiceCmHandle.setCompositeState(new CompositeStateBuilder()
+ .withLockReason(MODULE_UPGRADE, 'new moduleSetTag: targetModuleSetTag').build())
+ ncmpServiceCmHandle.setCmHandleId('cmHandleId-1')
+ def yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle('some service name', '', '', ncmpServiceCmHandle, 'targetModuleSetTag')
+ mockCmHandleQueries.cmHandleHasState('cmHandleId-1', CmHandleState.READY) >> true
+ and: 'the module service returns some module references'
+ def moduleReferences = [new ModuleReference('module1', '1'), new ModuleReference('module2', '2')]
+ mockCpsModuleService.getYangResourcesModuleReferences(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR) >> moduleReferences
+ and: 'a cm handle with the same moduleSetTag can be found in the registry'
+ mockCmHandleQueries.queryNcmpRegistryByCpsPath("//cm-handles[@module-set-tag='targetModuleSetTag']",
+ FetchDescendantsOption.OMIT_DESCENDANTS) >> [new DataNode(xpath: '/dmi-registry/cm-handles[@id=\'cmHandleId-1\']', leaves: ['id': 'cmHandleId-1', 'cm-handle-state': 'READY'])]
+ when: 'module upgrade is triggered'
+ objectUnderTest.syncAndCreateOrUpgradeSchemaSetAndAnchor(yangModelCmHandle)
+ then: 'the upgrade is delegated to the module service (with the correct parameters)'
+ 1 * mockCpsModuleService.createOrUpgradeSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, 'cmHandleId-1', Collections.emptyMap(), moduleReferences)
+ }
+
+ def 'Delete Schema Set for CmHandle'() {