diff options
author | Toine Siebelink <toine.siebelink@est.tech> | 2022-05-13 08:03:43 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2022-05-13 08:03:43 +0000 |
commit | 806d31aed57c798cba0ecc33d92e5b43fa1d957b (patch) | |
tree | 87e4b3ba1fc6cff6d9dc40805e8191faeddba82b /cps-ncmp-service/src/test/groovy | |
parent | ac57cca55024135a237a7d7f036f80b6b628b868 (diff) | |
parent | f16b9614298e7f0a820435f2dab2a856b487bf45 (diff) |
Merge "Watchdog-process that syncs 'ADVISED' CM Handles"
Diffstat (limited to 'cps-ncmp-service/src/test/groovy')
3 files changed, 66 insertions, 9 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/CmHandleStateSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/CmHandleStateSpec.groovy new file mode 100644 index 0000000000..923a9037d5 --- /dev/null +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/CmHandleStateSpec.groovy @@ -0,0 +1,46 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022 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.inventory.sync + +import org.onap.cps.ncmp.api.inventory.CmHandleState +import spock.lang.Specification + +class CmHandleStateSpec extends Specification{ + + def 'Transition to READY state from ADVISED state'() { + given: 'a cm handle with an ADVISED state' + def cmHandleState = CmHandleState.ADVISED + when: 'the state transitions to the READY state' + cmHandleState = cmHandleState.ready() + then: 'the cm handle state changes to READY' + assert CmHandleState.READY == cmHandleState + } + + def 'Transition to READY state from READY state'() { + given: 'a cm handle with a READY state' + def cmHandleState = CmHandleState.READY + when: 'the state transitions to READY state' + cmHandleState = cmHandleState.ready() + then: 'the cm handle state remains as READY' + assert CmHandleState.READY == cmHandleState + } + +} diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy index bcc6bb4676..0a06fbaa88 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/sync/ModuleSyncSpec.groovy @@ -22,25 +22,35 @@ package org.onap.cps.ncmp.api.inventory.sync import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle +import org.onap.cps.ncmp.api.inventory.CmHandleState import spock.lang.Specification class ModuleSyncSpec extends Specification { def mockSyncUtils = Mock(SyncUtils) - def objectUnderTest = new ModuleSyncWatchdog(mockSyncUtils) + def mockModuleSyncService = Mock(ModuleSyncService) + + def cmHandleState = CmHandleState.ADVISED + + def objectUnderTest = new ModuleSyncWatchdog(mockSyncUtils, mockModuleSyncService) def 'Schedule a Cm-Handle Sync for ADVISED Cm-Handles'() { - given: 'a cm handle' - def yangModelCmHandle1 = new YangModelCmHandle() - def yangModelCmHandle2 = new YangModelCmHandle() + given: 'cm handles in an advised state' + def yangModelCmHandle1 = new YangModelCmHandle(cmHandleState: cmHandleState) + def yangModelCmHandle2 = new YangModelCmHandle(cmHandleState: cmHandleState) and: 'sync utilities return a cm handle twice' mockSyncUtils.getAnAdvisedCmHandle() >>> [yangModelCmHandle1, yangModelCmHandle2, null] when: 'module sync poll is executed' objectUnderTest.executeAdvisedCmHandlePoll() - then: 'each cm handle is updated to state "READY"' - 1 * mockSyncUtils.updateCmHandleState(yangModelCmHandle1, 'READY') - 1 * mockSyncUtils.updateCmHandleState(yangModelCmHandle2, 'READY') + then: 'module sync service syncs the first cm handle and creates a schema set' + 1 * mockModuleSyncService.syncAndCreateSchemaSet(yangModelCmHandle1) + and: 'the first cm handle is updated to state "READY" from "ADVISED"' + 1 * mockSyncUtils.updateCmHandleState(yangModelCmHandle1, CmHandleState.READY) + then: 'module sync service syncs the second cm handle and creates a schema set' + 1 * mockModuleSyncService.syncAndCreateSchemaSet(yangModelCmHandle2) + then: 'the second cm handle is updated to state "READY" from "ADVISED"' + 1 * mockSyncUtils.updateCmHandleState(yangModelCmHandle2, CmHandleState.READY) } } 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/inventory/sync/SyncUtilsSpec.groovy index 04b2d55133..e5d3652d21 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/inventory/sync/SyncUtilsSpec.groovy @@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.ObjectMapper import org.onap.cps.api.CpsDataService import org.onap.cps.ncmp.api.impl.operations.YangModelCmHandleRetriever import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle +import org.onap.cps.ncmp.api.inventory.CmHandleState import org.onap.cps.spi.CpsDataPersistenceService import org.onap.cps.spi.FetchDescendantsOption import org.onap.cps.spi.model.DataNode @@ -67,10 +68,10 @@ class SyncUtilsSpec extends Specification{ def 'Update cm handle state from Advised to Ready'() { given: 'a yang model cm handle and the expected json data' - def yangModelCmHandle = new YangModelCmHandle('id': 'Some-Cm-Handle', 'cmHandleState': 'ADVISED') + def yangModelCmHandle = new YangModelCmHandle(id: 'Some-Cm-Handle', cmHandleState: CmHandleState.ADVISED) def expectedJsonData = '{"cm-handles":[{"id":"Some-Cm-Handle","state":"READY"}]}' when: 'update cm handle state is called' - objectUnderTest.updateCmHandleState(yangModelCmHandle, 'READY') + objectUnderTest.updateCmHandleState(yangModelCmHandle, CmHandleState.READY) then: 'update data note leaves is invoked with the correct params' 1 * mockCpsDataService.updateNodeLeaves('NCMP-Admin', 'ncmp-dmi-registry', '/dmi-registry', expectedJsonData, _ as OffsetDateTime) } |