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
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.api.impl.trustlevel
23 import org.onap.cps.ncmp.api.impl.events.avc.ncmptoclient.AvcEventPublisher
24 import spock.lang.Specification
26 class TrustLevelManagerSpec extends Specification {
28 def trustLevelPerCmHandle = [:]
29 def mockAttributeValueChangeEventPublisher = Mock(AvcEventPublisher)
30 def objectUnderTest = new TrustLevelManager(trustLevelPerCmHandle, mockAttributeValueChangeEventPublisher)
32 def 'Initial cm handle registration'() {
33 given: 'two cm handles: one with no trust level and one trusted'
34 def cmHandleModelsToBeCreated = ['ch-1': null, 'ch-2': TrustLevel.COMPLETE]
35 when: 'the initial registration handled'
36 objectUnderTest.handleInitialRegistrationOfTrustLevels(cmHandleModelsToBeCreated)
37 then: 'no notification sent'
38 0 * mockAttributeValueChangeEventPublisher.publishAvcEvent(*_)
39 and: 'both cm handles are in the cache and are trusted'
40 assert trustLevelPerCmHandle.get('ch-1') == TrustLevel.COMPLETE
41 assert trustLevelPerCmHandle.get('ch-2') == TrustLevel.COMPLETE
44 def 'Initial cm handle registration with a cm handle that is not trusted'() {
45 given: 'a not trusted cm handle'
46 def cmHandleModelsToBeCreated = ['ch-2': TrustLevel.NONE]
47 when: 'the initial registration handled'
48 objectUnderTest.handleInitialRegistrationOfTrustLevels(cmHandleModelsToBeCreated)
49 then: 'notification is sent'
50 1 * mockAttributeValueChangeEventPublisher.publishAvcEvent(*_)
53 def 'Trust level updated'() {
54 given: 'a not trusted cm handle'
55 trustLevelPerCmHandle.put('ch-1', TrustLevel.NONE)
56 when: 'the update is handled'
57 objectUnderTest.handleUpdateOfTrustLevels('ch-1', 'COMPLETE')
58 then: 'notification is sent'
59 1 * mockAttributeValueChangeEventPublisher.publishAvcEvent('ch-1', 'trustLevel', 'NONE', 'COMPLETE')
60 and: 'the cm handle in the cache is trusted'
61 assert trustLevelPerCmHandle.get('ch-1') == TrustLevel.COMPLETE
64 def 'Trust level updated with same value'() {
65 given: 'a trusted cm handle'
66 trustLevelPerCmHandle.put('ch-1', TrustLevel.COMPLETE)
67 when: 'the update is handled'
68 objectUnderTest.handleUpdateOfTrustLevels('ch-1', 'COMPLETE')
69 then: 'no notification is sent'
70 0 * mockAttributeValueChangeEventPublisher.publishAvcEvent(*_)