summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test
diff options
context:
space:
mode:
authorsourabh_sourabh <sourabh.sourabh@est.tech>2023-10-23 14:40:25 +0100
committersourabh_sourabh <sourabh.sourabh@est.tech>2023-10-23 16:19:50 +0100
commit4266fbbaad4ab3741accf1b3911278835ca19795 (patch)
tree8bef45b9fd2c3e15a40e455d1ef586eaee2c339c /cps-ncmp-service/src/test
parent3ccd62ed40e96dbe2970de1433b2ebdbe014d4aa (diff)
Introduce and use new Hazelcast map pt. 2
- modified ModuleSyncService - created ModuleSetTagCacheConfig and tests - ensure both Create and Upgrade cm Handle use cases work - Moved inventory pkg to its right patha as production code. Issue-ID: CPS-1859 Signed-off-by: leventecsanyi <levente.csanyi@est.tech> Change-Id: I173dcd81fe2e74d86d85365b2ead461302cad974 Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/test')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/ModuleSetTagCacheConfigSpec.groovy76
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfigSpec.groovy32
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueriesImplSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImplSpec.groovy)2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/CompositeStateBuilderSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateBuilderSpec.groovy)2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/CompositeStateSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateSpec.groovy)2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImplSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImplSpec.groovy)2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/DataSyncWatchdogSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdogSpec.groovy)2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncServiceSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncServiceSpec.groovy)88
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncTasksSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasksSpec.groovy)2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncWatchdogSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy)6
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/SyncUtilsSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy)2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/config/WatchdogSchedulingConfigurerSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/config/WatchdogSchedulingConfigurerSpec.groovy)2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/executor/AsyncTaskExecutorSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/executor/AsyncTaskExecutorSpec.groovy)2
13 files changed, 150 insertions, 70 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/ModuleSetTagCacheConfigSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/ModuleSetTagCacheConfigSpec.groovy
new file mode 100644
index 0000000000..8a6a32bd8d
--- /dev/null
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/ModuleSetTagCacheConfigSpec.groovy
@@ -0,0 +1,76 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.api.impl.config.embeddedcache
+
+import com.hazelcast.config.Config
+import com.hazelcast.core.Hazelcast
+import org.onap.cps.spi.model.ModuleReference
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.test.context.SpringBootTest
+import spock.lang.Specification
+
+@SpringBootTest(classes = [ModuleSetTagCacheConfig])
+class ModuleSetTagCacheConfigSpec extends Specification {
+
+ @Autowired
+ private Map<String, Collection<ModuleReference>> moduleSetTagCache
+
+ def 'Embedded (hazelcast) caches for module set tag.'() {
+ expect: 'system is able to create an instance of a map to hold module set tags'
+ assert null != moduleSetTagCache
+ and: 'there is at least 1 instance'
+ assert Hazelcast.allHazelcastInstances.size() > 0
+ and: 'hazelcast instance name of module set tag is correct'
+ assert Hazelcast.allHazelcastInstances.name.contains('moduleSetTags')
+ }
+
+ def 'Verify configs of module set tag distributed object.'(){
+ when: 'retrieving the map config of module set tag'
+ def cacheConfig = Hazelcast.getHazelcastInstanceByName('moduleSetTags').config
+ def moduleSetTagMapConfig = cacheConfig.mapConfigs.get('moduleSetTagCacheMapConfig')
+ then: 'the module set tag map config has correct backup counts'
+ assert moduleSetTagMapConfig.backupCount == 3
+ assert moduleSetTagMapConfig.asyncBackupCount == 3
+ }
+
+ def 'Verify deployment network configs of distributed cache of module set tag object.'() {
+ given: 'network config of module set tag cache'
+ def moduleSetTagNetworkConfig = Hazelcast.getHazelcastInstanceByName('moduleSetTags').config.networkConfig
+ expect: 'module set tag cache has the correct settings'
+ assert moduleSetTagNetworkConfig.join.autoDetectionConfig.enabled
+ assert !moduleSetTagNetworkConfig.join.kubernetesConfig.enabled
+ }
+
+ def 'Verify network of module set tag cache'() {
+ given: 'Synchronization config object and test configuration'
+ def objectUnderTest = new ModuleSetTagCacheConfig()
+ def testConfig = new Config()
+ when: 'kubernetes properties are enabled'
+ objectUnderTest.cacheKubernetesEnabled = true
+ objectUnderTest.cacheKubernetesServiceName = 'test-service-name'
+ and: 'method called to update the discovery mode'
+ objectUnderTest.updateDiscoveryMode(testConfig)
+ then: 'applied properties are reflected'
+ assert testConfig.networkConfig.join.kubernetesConfig.enabled
+ assert testConfig.networkConfig.join.kubernetesConfig.properties.get('service-name') == 'test-service-name'
+
+ }
+}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfigSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfigSpec.groovy
index 2fa9606923..501714a2be 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfigSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/SynchronizationCacheConfigSpec.groovy
@@ -44,9 +44,6 @@ class SynchronizationCacheConfigSpec extends Specification {
@Autowired
private IMap<String, Boolean> dataSyncSemaphores
- @Autowired
- private IMap<String, Set<String>> moduleSetTagCache
-
def 'Embedded (hazelcast) Caches for Module and Data Sync.'() {
expect: 'system is able to create an instance of the Module Sync Work Queue'
assert null != moduleSyncWorkQueue
@@ -54,12 +51,10 @@ class SynchronizationCacheConfigSpec extends Specification {
assert null != moduleSyncStartedOnCmHandles
and: 'system is able to create an instance of a map to hold data sync semaphores'
assert null != dataSyncSemaphores
- and: 'system is able to create an instance of a map to hold module set tags'
- assert null != moduleSetTagCache
- and: 'there are at least 4 instances'
- assert Hazelcast.allHazelcastInstances.size() > 3
+ and: 'there are at least 3 instances'
+ assert Hazelcast.allHazelcastInstances.size() > 2
and: 'they have the correct names (in any order)'
- assert Hazelcast.allHazelcastInstances.name.containsAll('moduleSyncWorkQueue', 'moduleSyncStartedOnCmHandles', 'dataSyncSemaphores', 'moduleSetTags')
+ assert Hazelcast.allHazelcastInstances.name.containsAll('moduleSyncWorkQueue', 'moduleSyncStartedOnCmHandles', 'dataSyncSemaphores')
}
def 'Verify configs for Distributed objects'(){
@@ -72,9 +67,6 @@ class SynchronizationCacheConfigSpec extends Specification {
and: 'the Data Sync Semaphores Map config'
def dataSyncSemaphoresConfig = Hazelcast.getHazelcastInstanceByName('dataSyncSemaphores').config
def dataSyncSemaphoresMapConfig = dataSyncSemaphoresConfig.mapConfigs.get('dataSyncSemaphoresConfig')
- and: 'the Module Set Tag Map config'
- def moduleSetTagCacheConfig = Hazelcast.getHazelcastInstanceByName('moduleSetTags').config
- def moduleSetTagMapConfig = moduleSetTagCacheConfig.mapConfigs.get('moduleSetTagCacheMapConfig')
expect: 'system created instance with correct config of Module Sync Work Queue'
assert moduleSyncDefaultWorkQueueConfig.backupCount == 3
assert moduleSyncDefaultWorkQueueConfig.asyncBackupCount == 3
@@ -84,15 +76,11 @@ class SynchronizationCacheConfigSpec extends Specification {
and: 'Data Sync Semaphore Map has the correct settings'
assert dataSyncSemaphoresMapConfig.backupCount == 3
assert dataSyncSemaphoresMapConfig.asyncBackupCount == 3
- and: 'Module Set Tag Map has the correct settings'
- assert moduleSetTagMapConfig.backupCount == 3
- assert moduleSetTagMapConfig.asyncBackupCount == 3
and: 'all instances are part of same cluster'
def testClusterName = 'cps-and-ncmp-test-caches'
assert moduleSyncWorkQueueConfig.clusterName == testClusterName
assert moduleSyncStartedOnCmHandlesConfig.clusterName == testClusterName
assert dataSyncSemaphoresConfig.clusterName == testClusterName
- assert moduleSetTagCacheConfig.clusterName == testClusterName
}
def 'Verify deployment network configs for Distributed objects'() {
@@ -102,8 +90,6 @@ class SynchronizationCacheConfigSpec extends Specification {
def moduleSyncStartedOnCmHandlesNetworkConfig = Hazelcast.getHazelcastInstanceByName('moduleSyncStartedOnCmHandles').config.networkConfig
and: 'the Data Sync Semaphores Map config'
def dataSyncSemaphoresNetworkConfig = Hazelcast.getHazelcastInstanceByName('dataSyncSemaphores').config.networkConfig
- and: 'the Module Set Tag Map config'
- def moduleSetTagNetworkConfig = Hazelcast.getHazelcastInstanceByName('moduleSetTags').config.networkConfig
expect: 'system created instance with correct config of Module Sync Work Queue'
assert queueNetworkConfig.join.autoDetectionConfig.enabled
assert !queueNetworkConfig.join.kubernetesConfig.enabled
@@ -113,9 +99,6 @@ class SynchronizationCacheConfigSpec extends Specification {
and: 'Data Sync Semaphore Map has the correct settings'
assert dataSyncSemaphoresNetworkConfig.join.autoDetectionConfig.enabled
assert !dataSyncSemaphoresNetworkConfig.join.kubernetesConfig.enabled
- and: 'Module Set Tag Map has the correct settings'
- assert moduleSetTagNetworkConfig.join.autoDetectionConfig.enabled
- assert !moduleSetTagNetworkConfig.join.kubernetesConfig.enabled
}
def 'Verify network config'() {
@@ -151,15 +134,6 @@ class SynchronizationCacheConfigSpec extends Specification {
waitMax2SecondsForKeyExpiration(dataSyncSemaphores, 'testKeyDataSync')
}
- def 'Time to Live Verify for Module Set Tag'() {
- when: 'the key is inserted with a TTL of 1 second'
- moduleSetTagCache.put('testKeyModuleSetTag', ['module-set-tag'] as Set, 1, TimeUnit.SECONDS)
- then: 'the entry is present in the map'
- assert moduleSetTagCache.get('testKeyModuleSetTag') != null
- and: 'the entry expires in less then 2 seconds'
- waitMax2SecondsForKeyExpiration(moduleSetTagCache, 'testKeyModuleSetTag')
- }
-
def waitMax2SecondsForKeyExpiration(map, key) {
def count = 0
while ( map.get(key)!=null && ++count <= 20 ) {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueriesImplSpec.groovy
index a3a5efc748..78b09e6a15 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/CmHandleQueriesImplSpec.groovy
@@ -19,7 +19,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.inventory
+package org.onap.cps.ncmp.api.impl.inventory
import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateBuilderSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/CompositeStateBuilderSpec.groovy
index c2cdd9bc2e..777b505b46 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateBuilderSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/CompositeStateBuilderSpec.groovy
@@ -19,7 +19,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.inventory
+package org.onap.cps.ncmp.api.impl.inventory
import org.onap.cps.ncmp.api.impl.inventory.CmHandleState
import org.onap.cps.ncmp.api.impl.inventory.CompositeState
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/CompositeStateSpec.groovy
index 985bdc5cd4..d8beba8de0 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/CompositeStateSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/CompositeStateSpec.groovy
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.inventory
+package org.onap.cps.ncmp.api.impl.inventory
import com.fasterxml.jackson.databind.ObjectMapper
import org.onap.cps.ncmp.api.impl.inventory.CmHandleState
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImplSpec.groovy
index 724f05b1b8..bb4eebd40e 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImplSpec.groovy
@@ -20,7 +20,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.inventory
+package org.onap.cps.ncmp.api.impl.inventory
import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME
import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdogSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/DataSyncWatchdogSpec.groovy
index ed313a0ad8..65dfc05791 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/DataSyncWatchdogSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/DataSyncWatchdogSpec.groovy
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.inventory.sync
+package org.onap.cps.ncmp.api.impl.inventory.sync
import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncServiceSpec.groovy
index a13f595200..18b87af9a1 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncServiceSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncServiceSpec.groovy
@@ -18,11 +18,9 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.inventory.sync
+package org.onap.cps.ncmp.api.impl.inventory.sync
import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.LOCKED_MISBEHAVING
-import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DATASPACE_NAME
-import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR
import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME
import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.MODULE_UPGRADE
@@ -32,6 +30,7 @@ import org.onap.cps.spi.model.DataNode
import org.onap.cps.api.CpsAdminService
import org.onap.cps.api.CpsDataService
import org.onap.cps.api.CpsModuleService
+import org.onap.cps.spi.model.DataNodeBuilder
import org.onap.cps.ncmp.api.impl.inventory.sync.ModuleSyncService
import org.onap.cps.ncmp.api.impl.operations.DmiModelOperations
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
@@ -52,38 +51,76 @@ class ModuleSyncServiceSpec extends Specification {
def mockCmHandleQueries = Mock(CmHandleQueries)
def mockCpsDataService = Mock(CpsDataService)
def mockJsonObjectMapper = Mock(JsonObjectMapper)
+ def mockModuleSetTagCache = [:]
def objectUnderTest = new ModuleSyncService(mockDmiModelOperations, mockCpsModuleService, mockCpsAdminService,
- mockCmHandleQueries, mockCpsDataService, mockJsonObjectMapper)
+ mockCmHandleQueries, mockCpsDataService, mockJsonObjectMapper, mockModuleSetTagCache)
def expectedDataspaceName = NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME
+ def static cmHandleWithModuleSetTag = new DataNodeBuilder().withXpath("//cm-handles[@module-set-tag='tag-1'][@id='otherId']").withAnchor('otherId').build()
- def 'Sync model for a (new) cm handle with #scenario'() {
- given: 'a cm handle'
+ def 'Sync model for a NEW cm handle without cache with #scenario'() {
+ given: 'a cm handle having some state'
def ncmpServiceCmHandle = new NcmpServiceCmHandle()
- ncmpServiceCmHandle.setCompositeState(new CompositeStateBuilder().build())
- def dmiServiceName = 'some service name'
- ncmpServiceCmHandle.cmHandleId = 'cmHandleId-1'
- def yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(dmiServiceName, '', '', ncmpServiceCmHandle,'')
+ ncmpServiceCmHandle.setCompositeState(new CompositeStateBuilder().withCmHandleState(CmHandleState.ADVISED).build())
+ ncmpServiceCmHandle.cmHandleId = 'ch-1'
+ def yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle('some service name', '', '', ncmpServiceCmHandle, moduleSetTag)
and: 'DMI operations returns some module references'
def moduleReferences = [ new ModuleReference('module1','1'), new ModuleReference('module2','2') ]
mockDmiModelOperations.getModuleReferences(yangModelCmHandle) >> moduleReferences
- and: 'CPS-Core returns list of existing module resources'
- mockCpsModuleService.getYangResourceModuleReferences(expectedDataspaceName) >> toModuleReference(existingModuleResourcesInCps)
and: 'DMI-Plugin returns resource(s) for "new" module(s)'
mockDmiModelOperations.getNewYangResourcesFromDmi(yangModelCmHandle, [new ModuleReference('module1', '1')]) >> newModuleNameContentToMap
+ and: 'the module service identifies #identifiedNewModuleReferences.size() new modules'
+ mockCpsModuleService.identifyNewModuleReferences(moduleReferences) >> toModuleReferences(identifiedNewModuleReferences)
+ and: 'system contains #existingCmHandlesWithSameTag.size() cm handles with same tag'
+ mockCmHandleQueries.queryNcmpRegistryByCpsPath("//cm-handles[@module-set-tag='new-tag-1']",
+ FetchDescendantsOption.OMIT_DESCENDANTS) >> []
when: 'module sync is triggered'
- mockCpsModuleService.identifyNewModuleReferences(moduleReferences) >> toModuleReference(identifiedNewModuleReferences)
objectUnderTest.syncAndCreateOrUpgradeSchemaSetAndAnchor(yangModelCmHandle)
then: 'create schema set from module is invoked with correct parameters'
- 1 * mockCpsModuleService.createOrUpgradeSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, 'cmHandleId-1', newModuleNameContentToMap, moduleReferences)
+ 1 * mockCpsModuleService.createOrUpgradeSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, 'ch-1', newModuleNameContentToMap, moduleReferences)
and: 'anchor is created with the correct parameters'
- 1 * mockCpsAdminService.createAnchor(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, 'cmHandleId-1', 'cmHandleId-1')
+ 1 * mockCpsAdminService.createAnchor(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, 'ch-1', 'ch-1')
where: 'the following parameters are used'
- scenario | existingModuleResourcesInCps | identifiedNewModuleReferences | newModuleNameContentToMap
- 'one new module' | [['module2' : '2'], ['module3' : '3']] | [['module1' : '1']] | [module1: 'some yang source']
- 'no add. properties' | [['module2' : '2'], ['module3' : '3']] | [['module1' : '1']] | [module1: 'some yang source']
- 'no new module' | [['module1' : '1'], ['module2' : '2']] | [] | [:]
+ scenario | existingModuleResourcesInCps | identifiedNewModuleReferences | newModuleNameContentToMap | moduleSetTag
+ 'one new module' | [['module2': '2'], ['module3': '3']] | [['module1': '1']] | [module1: 'some yang source'] | ''
+ 'no new module' | [['module1': '1'], ['module2': '2']] | [] | [:] | 'new-tag-1'
+ }
+
+ def 'Upgrade model for an existing cm handle with Module Set Tag where the modules are #scenario'() {
+ given: 'a cm handle being upgraded to module set tag: tag-1'
+ def ncmpServiceCmHandle = new NcmpServiceCmHandle()
+ ncmpServiceCmHandle.setCompositeState(new CompositeStateBuilder().withLockReason(MODULE_UPGRADE, 'new moduleSetTag: tag-1').build())
+ def dmiServiceName = 'some service name'
+ ncmpServiceCmHandle.cmHandleId = 'upgraded-ch'
+ def yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(dmiServiceName, '', '', ncmpServiceCmHandle,'tag-1')
+ and: 'some module references'
+ def moduleReferences = [ new ModuleReference('module1','1') ]
+ and: 'cache or DMI operations returns some module references for upgraded cm handle'
+ if (populateCache) {
+ mockModuleSetTagCache.put('tag-1',moduleReferences)
+ } else {
+ mockDmiModelOperations.getModuleReferences(yangModelCmHandle) >> moduleReferences
+ }
+ and: 'none of these module references are new (unknown to the system)'
+ mockCpsModuleService.identifyNewModuleReferences(moduleReferences) >> []
+ and: 'CPS-Core returns list of existing module resources for TBD'
+ mockCpsModuleService.getYangResourcesModuleReferences(*_) >> [ new ModuleReference('module1','1') ]
+ and: 'system contains #existingCmHandlesWithSameTag.size() cm handles with same tag'
+ mockCmHandleQueries.queryNcmpRegistryByCpsPath("//cm-handles[@module-set-tag='tag-1']", FetchDescendantsOption.OMIT_DESCENDANTS) >> existingCmHandlesWithSameTag
+ and: 'the other cm handle is a state ready'
+ mockCmHandleQueries.cmHandleHasState('otherId', CmHandleState.READY) >> true
+ when: 'module sync is triggered'
+ objectUnderTest.syncAndCreateOrUpgradeSchemaSetAndAnchor(yangModelCmHandle)
+ then: 'create schema set from module is invoked for the upgraded cm handle'
+ 1 * mockCpsModuleService.createOrUpgradeSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, 'upgraded-ch', [:], moduleReferences)
+ and: 'No anchor is created for the upgraded cm handle'
+ 0 * mockCpsAdminService.createAnchor(*_)
+ where: 'the following parameters are used'
+ scenario | populateCache | existingCmHandlesWithSameTag
+ 'new' | false | []
+ 'in cache' | true | []
+ 'in database' | false | [cmHandleWithModuleSetTag]
}
def 'upgrade model for a existing cm handle'() {
@@ -96,7 +133,7 @@ class ModuleSyncServiceSpec extends Specification {
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
+ mockCpsModuleService.getYangResourcesModuleReferences(*_)>> 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'])]
@@ -133,17 +170,12 @@ class ModuleSyncServiceSpec extends Specification {
result == unsupportedOperationException
}
- def 'Extract module set tag with #scenario'() {
+ def 'Extract module set tag'() {
expect: 'the module set tag is extracted correctly'
- assert expectedModuleSetTag == objectUnderTest.extractModuleSetTag(new CompositeStateBuilder().withLockReason(lockReason, 'new moduleSetTag: targetModuleSetTag').build())
- where: 'the following parameters are used'
- scenario | lockReason || expectedModuleSetTag
- 'locked reason is null' | null || ''
- 'locked for other reason' | LOCKED_MISBEHAVING || ''
- 'locked for module upgrade' | MODULE_UPGRADE || 'targetModuleSetTag'
+ assert 'targetModuleSetTag' == objectUnderTest.extractModuleSetTag(new CompositeStateBuilder().withLockReason(MODULE_UPGRADE, 'new moduleSetTag: targetModuleSetTag').build())
}
- def toModuleReference(moduleReferenceAsMap) {
+ def toModuleReferences(moduleReferenceAsMap) {
def moduleReferences = [].withDefault { [:] }
moduleReferenceAsMap.forEach(property ->
property.forEach((moduleName, revision) -> {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasksSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncTasksSpec.groovy
index 8698136d65..0d927551d0 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncTasksSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncTasksSpec.groovy
@@ -19,7 +19,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.inventory.sync
+package org.onap.cps.ncmp.api.impl.inventory.sync
import ch.qos.logback.classic.Level
import ch.qos.logback.classic.Logger
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncWatchdogSpec.groovy
index 390e88b3d4..7425a52ff1 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncWatchdogSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/ModuleSyncWatchdogSpec.groovy
@@ -19,7 +19,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.inventory.sync
+package org.onap.cps.ncmp.api.impl.inventory.sync
import com.hazelcast.map.IMap
import org.onap.cps.ncmp.api.impl.inventory.sync.ModuleSyncTasks
@@ -45,9 +45,7 @@ class ModuleSyncWatchdogSpec extends Specification {
def spiedAsyncTaskExecutor = Spy(AsyncTaskExecutor)
- def moduleSetTagCache = Mock(IMap<String, Set<String>>)
-
- def objectUnderTest = new ModuleSyncWatchdog(mockSyncUtils, moduleSyncWorkQueue , mockModuleSyncStartedOnCmHandles, mockModuleSyncTasks, spiedAsyncTaskExecutor, moduleSetTagCache)
+ def objectUnderTest = new ModuleSyncWatchdog(mockSyncUtils, moduleSyncWorkQueue , mockModuleSyncStartedOnCmHandles, mockModuleSyncTasks, spiedAsyncTaskExecutor)
void setup() {
spiedAsyncTaskExecutor.setupThreadPool()
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/SyncUtilsSpec.groovy
index df2ad711ed..025d9482d6 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/SyncUtilsSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/SyncUtilsSpec.groovy
@@ -19,7 +19,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.inventory.sync
+package org.onap.cps.ncmp.api.impl.inventory.sync
import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.LOCKED_MISBEHAVING
import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_OPERATIONAL
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/config/WatchdogSchedulingConfigurerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/config/WatchdogSchedulingConfigurerSpec.groovy
index 7361948bc6..7760b39cb3 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/config/WatchdogSchedulingConfigurerSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/config/WatchdogSchedulingConfigurerSpec.groovy
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.inventory.sync.config
+package org.onap.cps.ncmp.api.impl.inventory.sync.config
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/executor/AsyncTaskExecutorSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/executor/AsyncTaskExecutorSpec.groovy
index b3ed94520a..64ecafefc7 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/executor/AsyncTaskExecutorSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/sync/executor/AsyncTaskExecutorSpec.groovy
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.inventory.sync.executor
+package org.onap.cps.ncmp.api.impl.inventory.sync.executor
import org.onap.cps.ncmp.api.impl.inventory.sync.executor.AsyncTaskExecutor
import org.springframework.beans.factory.annotation.Autowired