ec1d8e8f3d9e5af4e815f49fc7d39f46fe678e26
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / impl / trustlevel / dmiavailability / DmiPluginWatchDogSpec.groovy
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2023 Nordix Foundation
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20
21 package org.onap.cps.ncmp.api.impl.trustlevel.dmiavailability
22
23 import org.onap.cps.ncmp.api.NetworkCmProxyDataService
24 import org.onap.cps.ncmp.api.impl.client.DmiRestClient
25 import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel
26 import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelManager
27 import spock.lang.Specification
28
29 class DmiPluginWatchDogSpec extends Specification {
30
31     def mockDmiRestClient = Mock(DmiRestClient)
32     def mockNetworkCmProxyDataService = Mock(NetworkCmProxyDataService)
33     def mockTrustLevelManager = Mock(TrustLevelManager)
34     def trustLevelPerDmiPlugin = [:]
35
36
37     def objectUnderTest = new DmiPluginWatchDog(mockDmiRestClient,
38         mockNetworkCmProxyDataService,
39         mockTrustLevelManager,
40         trustLevelPerDmiPlugin)
41
42     def 'watch dmi plugin health status for #dmiHealhStatus'() {
43         given: 'the cache has been initialised and "knows" about dmi-1'
44             trustLevelPerDmiPlugin.put('dmi-1', dmiOldTrustLevel)
45         and: 'dmi client returns health status #dmiHealhStatus'
46             mockDmiRestClient.getDmiHealthStatus('dmi-1') >> dmiHealhStatus
47         and: 'network cm proxy data returns a list of all cm handle ids belonging to a dmi'
48             mockNetworkCmProxyDataService.getAllCmHandleIdsByDmiPluginIdentifier('dmi-1') >> ['ch-1']
49         when: 'dmi watch dog method runs'
50             objectUnderTest.checkDmiAvailability()
51         then: 'the result is as expected'
52             assert trustLevelPerDmiPlugin.get('dmi-1') == newDmiTrustLevel
53         and: 'the update delegated to manager'
54             times * mockTrustLevelManager.handleUpdateOfTrustLevels(*_)
55         where: 'the following parameters are used'
56             dmiHealhStatus | dmiOldTrustLevel    || newDmiTrustLevel    || times
57             'UP'           | TrustLevel.COMPLETE || TrustLevel.COMPLETE || 0
58             'DOWN'         | TrustLevel.COMPLETE || TrustLevel.NONE     || 1
59             'DOWN'         | TrustLevel.NONE     || TrustLevel.NONE     || 0
60             'UP'           | TrustLevel.NONE     || TrustLevel.COMPLETE || 1
61             ''             | TrustLevel.COMPLETE || TrustLevel.NONE     || 1
62     }
63
64 }