2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023-2024 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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.ncmp.impl.inventory.trustlevel
23 import org.onap.cps.ncmp.api.inventory.models.TrustLevel
24 import org.onap.cps.ncmp.impl.dmi.DmiRestClient
25 import org.onap.cps.ncmp.impl.dmi.UrlTemplateParameters
26 import org.onap.cps.ncmp.impl.inventory.CmHandleQueryService
27 import reactor.core.publisher.Mono
28 import spock.lang.Specification
30 class DmiPluginTrustLevelWatchDogSpec extends Specification {
32 def mockDmiRestClient = Mock(DmiRestClient)
33 def mockCmHandleQueryService = Mock(CmHandleQueryService)
34 def mockTrustLevelManager = Mock(TrustLevelManager)
35 def trustLevelPerDmiPlugin = [:]
38 def objectUnderTest = new DmiPluginTrustLevelWatchDog(mockDmiRestClient, mockCmHandleQueryService, mockTrustLevelManager, trustLevelPerDmiPlugin)
40 def 'watch dmi plugin health status for #dmiHealhStatus'() {
41 given: 'the cache has been initialised and "knows" about dmi-1'
42 trustLevelPerDmiPlugin.put('dmi-1', dmiOldTrustLevel)
43 and: 'dmi client returns health status #dmiHealhStatus'
44 def urlTemplateParameters = new UrlTemplateParameters('dmi-1/actuator/health', [:])
45 mockDmiRestClient.getDmiHealthStatus(urlTemplateParameters) >> Mono.just(dmiHealhStatus)
46 when: 'dmi watch dog method runs'
47 objectUnderTest.checkDmiAvailability()
48 then: 'the update delegated to manager'
49 numberOfCalls * mockTrustLevelManager.handleUpdateOfDmiTrustLevel('dmi-1', _, newDmiTrustLevel)
50 where: 'the following parameters are used'
51 dmiHealhStatus | dmiOldTrustLevel | newDmiTrustLevel || numberOfCalls
52 'UP' | TrustLevel.COMPLETE | TrustLevel.COMPLETE || 0
53 'DOWN' | TrustLevel.COMPLETE | TrustLevel.NONE || 1
54 'DOWN' | TrustLevel.NONE | TrustLevel.NONE || 0
55 'UP' | TrustLevel.NONE | TrustLevel.COMPLETE || 1
56 '' | TrustLevel.COMPLETE | TrustLevel.NONE || 1