aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test/groovy/org
diff options
context:
space:
mode:
authorJvD_Ericsson <jeff.van.dam@est.tech>2023-11-27 15:58:54 +0000
committerJvD_Ericsson <jeff.van.dam@est.tech>2023-11-28 11:27:19 +0000
commit2e71615fa27cefd1aee3fb85d04907f3d95d5d14 (patch)
treea262419342396412c89d18a00635e7415fa01d50 /cps-ncmp-service/src/test/groovy/org
parente1f12d7e903c6bb3071f2848c939ccb4afb939ba (diff)
Publish trust level notification event
- Add mapper that maps attribute value change event to cloud event - Add publisher that publish the cloud event from ncmp to client - Handle notifications for the uses cases below - Initial registration case - Device heart beat consumer case - Dmi status changes within dmi watchdog case - Added tests for mapper, publisher, and trustLevelManager - Added test for dmi watchdog Issue-ID: CPS-1910 Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech> Change-Id: I7c0798346a221e703da58902b9d631115de8d91a Signed-off-by: halil.cakal <halil.cakal@est.tech> Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/test/groovy/org')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy25
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy14
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy6
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avc/ncmptoclient/AvcEventPublisherSpec.groovy63
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy9
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/DeviceHeartbeatConsumerSpec.groovy29
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelManagerSpec.groovy73
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelSpec.groovy (renamed from cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelTest.groovy)2
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginWatchDogSpec.groovy32
9 files changed, 189 insertions, 64 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy
index 9f15e1fa56..97693a4154 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy
@@ -21,6 +21,7 @@
package org.onap.cps.ncmp.api.impl
+import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelManager
import org.onap.cps.ncmp.api.models.UpgradedCmHandles
import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_FOUND
@@ -68,8 +69,8 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
def mockLcmEventsCmHandleStateHandler = Mock(LcmEventsCmHandleStateHandler)
def mockCpsDataService = Mock(CpsDataService)
def mockModuleSyncStartedOnCmHandles = Mock(IMap<String, Object>)
- def trustLevelPerCmHandle = [:]
def trustLevelPerDmiPlugin = [:]
+ def mockTrustLevelManager = Mock(TrustLevelManager)
def objectUnderTest = getObjectUnderTest()
def 'DMI Registration: Create, Update, Delete & Upgrade operations are processed in the right order'() {
@@ -208,14 +209,12 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
assert it.cmHandle == 'cmhandle'
}
and: 'state handler is invoked with the expected parameters'
- 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(_) >> {
+ 1 * mockLcmEventsCmHandleStateHandler.initiateStateAdvised(_) >> {
args ->
{
def cmHandleStatePerCmHandle = (args[0] as Map)
cmHandleStatePerCmHandle.each {
- assert (it.key.id == 'cmhandle'
- && it.key.dmiServiceName == 'my-server'
- && it.value == CmHandleState.ADVISED)
+ assert (it.id == 'cmhandle' && it.dmiServiceName == 'my-server')
}
}
}
@@ -237,12 +236,12 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
then: 'a successful response is received'
assert response.createdCmHandles.size() == expectedNumberOfCreatedCmHandles
and: 'trustLevel is set for the created cm-handle'
- assert trustLevelPerCmHandle.get(cmHandleId) == expectedTrustLevel
+ 1 * mockTrustLevelManager.handleInitialRegistrationOfTrustLevels(_)
where:
- scenario | cmHandleId | registrationTrustLevel || expectedNumberOfCreatedCmHandles | expectedTrustLevel
- 'new cmHandleId and trustLevel' | 'ch-new' | TrustLevel.COMPLETE || 2 | TrustLevel.COMPLETE
- 'existing cmHandleId with null trustLevel' | 'ch-1' | null || 1 | TrustLevel.NONE
- 'cmHandleId with null trustLevel' | 'ch-new' | null || 2 | TrustLevel.COMPLETE
+ scenario | cmHandleId | registrationTrustLevel || expectedNumberOfCreatedCmHandles
+ 'new trusted cm handle' | 'ch-new' | TrustLevel.COMPLETE || 2
+ 'existing cm handle without trust level' | 'ch-1' | null || 1
+ 'new cm handle without trust level' | 'ch-new' | null || 2
}
def 'Create CM-Handle Multiple Requests: All cm-handles creation requests are processed with some failures'() {
@@ -253,7 +252,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
new NcmpServiceCmHandle(cmHandleId: 'cmhandle3')])
and: 'cm-handle creation is successful for 1st and 3rd; failed for 2nd'
def xpath = "somePathWithId[@id='cmhandle2']"
- mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(*_) >> { throw AlreadyDefinedException.forDataNodes([xpath], 'some-context') }
+ mockLcmEventsCmHandleStateHandler.initiateStateAdvised(*_) >> { throw AlreadyDefinedException.forDataNodes([xpath], 'some-context') }
when: 'registration is updated to create cm-handles'
def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
then: 'a response is received for all cm-handles'
@@ -272,7 +271,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server')
dmiPluginRegistration.createdCmHandles = [new NcmpServiceCmHandle(cmHandleId: 'cmhandle')]
and: 'cm-handler registration fails: #scenario'
- mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(*_) >> { throw exception }
+ mockLcmEventsCmHandleStateHandler.initiateStateAdvised(*_) >> { throw exception }
when: 'registration is updated'
def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
then: 'a failure response is received'
@@ -439,7 +438,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
return Spy(new NetworkCmProxyDataServiceImpl(spiedJsonObjectMapper, mockDmiDataOperations,
mockNetworkCmProxyDataServicePropertyHandler, mockInventoryPersistence, mockCmHandleQueries,
stubbedNetworkCmProxyCmHandlerQueryService, mockLcmEventsCmHandleStateHandler, mockCpsDataService,
- mockModuleSyncStartedOnCmHandles, trustLevelPerCmHandle, trustLevelPerDmiPlugin))
+ mockModuleSyncStartedOnCmHandles, trustLevelPerDmiPlugin, mockTrustLevelManager))
}
def addPersistedYangModelCmHandles(ids) {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
index 71511cc161..4f7b726985 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
@@ -22,7 +22,6 @@
*/
package org.onap.cps.ncmp.api.impl
-
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
import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_ANCHOR
@@ -36,6 +35,7 @@ import com.hazelcast.map.IMap
import org.onap.cps.ncmp.api.NetworkCmProxyCmHandleQueryService
import org.onap.cps.ncmp.api.impl.events.lcm.LcmEventsCmHandleStateHandler
import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel
+import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelManager
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueries
import org.onap.cps.ncmp.api.impl.inventory.CmHandleState
@@ -76,8 +76,8 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
def mockCpsCmHandlerQueryService = Mock(NetworkCmProxyCmHandleQueryService)
def mockLcmEventsCmHandleStateHandler = Mock(LcmEventsCmHandleStateHandler)
def stubModuleSyncStartedOnCmHandles = Stub(IMap<String, Object>)
- def stubTrustLevelPerCmHandle = Stub(Map<String, TrustLevel>)
def stubTrustLevelPerDmiPlugin = Stub(Map<String, TrustLevel>)
+ def mockTrustLevelManager = Mock(TrustLevelManager)
def NO_TOPIC = null
def NO_REQUEST_ID = null
@@ -96,8 +96,8 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
mockLcmEventsCmHandleStateHandler,
mockCpsDataService,
stubModuleSyncStartedOnCmHandles,
- stubTrustLevelPerCmHandle,
- stubTrustLevelPerDmiPlugin)
+ stubTrustLevelPerDmiPlugin,
+ mockTrustLevelManager)
def cmHandleXPath = "/dmi-registry/cm-handles[@id='testCmHandle']"
@@ -265,11 +265,11 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
when: 'parse and create cm handle in dmi registration then sync module'
objectUnderTest.parseAndProcessCreatedCmHandlesInRegistration(mockDmiPluginRegistration)
then: 'system persists the cm handle state'
- 1 * mockLcmEventsCmHandleStateHandler.updateCmHandleStateBatch(_) >> {
+ 1 * mockLcmEventsCmHandleStateHandler.initiateStateAdvised(_) >> {
args -> {
- def cmHandleStatePerCmHandle = (args[0] as Map)
+ def cmHandleStatePerCmHandle = (args[0] as Collection)
cmHandleStatePerCmHandle.each {
- assert it.key.id == 'test-cm-handle-id' && it.value == CmHandleState.ADVISED
+ assert it.id == 'test-cm-handle-id'
}
}
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy
index c9ba5645fb..0176de7147 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy
@@ -96,7 +96,7 @@ class DmiRestClientSpec extends Specification {
mockRestTemplate.getForObject(*_) >> {jsonNode}
when: 'get trust level of the dmi plugin'
def result = objectUnderTest.getDmiHealthStatus('some url')
- then: 'the correct trust level is returned'
+ then: 'the status value from the json is return'
assert result == 'my status'
}
@@ -105,9 +105,9 @@ class DmiRestClientSpec extends Specification {
mockRestTemplate.getForObject(*_) >> healthStatusResponse
when: 'attempt to get health status of the dmi plugin'
def result = objectUnderTest.getDmiHealthStatus('some url')
- then: 'result will be EMPTY_STRING "" '
+ then: 'result will be empty'
assert result == ''
- where: 'the following values are used'
+ where: 'the following responses are used'
scenario | healthStatusResponse
'null' | null
'exception' | {throw new Exception()}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avc/ncmptoclient/AvcEventPublisherSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avc/ncmptoclient/AvcEventPublisherSpec.groovy
new file mode 100644
index 0000000000..a614fd2a1d
--- /dev/null
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avc/ncmptoclient/AvcEventPublisherSpec.groovy
@@ -0,0 +1,63 @@
+/*
+ * ============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.events.avc.ncmptoclient
+
+import com.fasterxml.jackson.databind.ObjectMapper
+import io.cloudevents.CloudEvent
+import org.onap.cps.ncmp.api.impl.events.EventsPublisher
+import org.onap.cps.ncmp.api.impl.utils.context.CpsApplicationContext
+import org.onap.cps.ncmp.api.kafka.MessagingBaseSpec
+import org.onap.cps.ncmp.events.avc.ncmp_to_client.Avc
+import org.onap.cps.ncmp.events.avc.ncmp_to_client.AvcEvent
+import org.onap.cps.utils.JsonObjectMapper
+import org.springframework.test.context.ContextConfiguration
+
+import static org.onap.cps.ncmp.api.impl.events.mapper.CloudEventMapper.toTargetEvent
+
+@ContextConfiguration(classes = [CpsApplicationContext, ObjectMapper, JsonObjectMapper])
+class AvcEventPublisherSpec extends MessagingBaseSpec {
+
+ def mockEventsPublisher = Mock(EventsPublisher<CloudEvent>)
+ def objectUnderTest = new AvcEventPublisher(mockEventsPublisher)
+
+ def 'Publish an attribute value change event'() {
+ given: 'the event key'
+ def someEventKey = 'someEventKey'
+ and: 'the name of the attribute being changed'
+ def someAttributeName = 'someAttributeName'
+ and: 'the old value of the attribute'
+ def someOldAttributeValue = 'someOldAttributeValue'
+ and: 'the new value of the attribute'
+ def someNewAttributeValue = 'someNewAttributeValue'
+ when: 'an attribute value change event is published'
+ objectUnderTest.publishAvcEvent(someEventKey, someAttributeName, someOldAttributeValue, someNewAttributeValue)
+ then: 'the cloud event publisher is invoked with the correct data'
+ 1 * mockEventsPublisher.publishCloudEvent(_, someEventKey,
+ cloudEvent -> {
+ def actualAvcs = toTargetEvent(cloudEvent, AvcEvent.class).data.attributeValueChange
+ def expectedAvc = new Avc(attributeName: someAttributeName,
+ oldAttributeValue: someOldAttributeValue,
+ newAttributeValue: someNewAttributeValue)
+ assert actualAvcs == [expectedAvc]
+ })
+ }
+
+}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy
index 0ec73a26a4..3ae95209f2 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerImplSpec.groovy
@@ -169,9 +169,9 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification {
def 'Batch of new cm handles provided'() {
given: 'A batch of new cm handles'
- def cmHandleStateMap = setupBatch('NEW')
- when: 'updating a batch of changes'
- objectUnderTest.updateCmHandleStateBatch(cmHandleStateMap)
+ def yangModelCmHandlesToBeCreated = setupBatch('NEW')
+ when: 'instantiating a batch of new cm handles'
+ objectUnderTest.initiateStateAdvised(yangModelCmHandlesToBeCreated)
then: 'new cm handles are saved using inventory persistence'
1 * mockInventoryPersistence.saveCmHandleBatch(_) >> {
args -> {
@@ -180,7 +180,6 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification {
}
and: 'event service is called to publish events'
2 * mockLcmEventsService.publishLcmEvent(_, _, _)
-
}
def 'Batch of existing cm handles is updated'() {
@@ -219,7 +218,7 @@ class LcmEventsCmHandleStateHandlerImplSpec extends Specification {
def yangModelCmHandle2 = new YangModelCmHandle(id: 'cmhandle2', dmiProperties: [], publicProperties: [])
if ('NEW' == type) {
- return [(yangModelCmHandle1): ADVISED, (yangModelCmHandle2): ADVISED]
+ return [yangModelCmHandle1, yangModelCmHandle2]
}
if ('DELETED' == type) {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/DeviceHeartbeatConsumerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/DeviceHeartbeatConsumerSpec.groovy
index 80778b9c71..8886fc189f 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/DeviceHeartbeatConsumerSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/DeviceHeartbeatConsumerSpec.groovy
@@ -21,7 +21,6 @@
package org.onap.cps.ncmp.api.impl.trustlevel
import com.fasterxml.jackson.databind.ObjectMapper
-import com.hazelcast.map.IMap
import io.cloudevents.CloudEvent
import io.cloudevents.core.builder.CloudEventBuilder
import org.apache.kafka.clients.consumer.ConsumerRecord
@@ -34,9 +33,9 @@ import spock.lang.Specification
@SpringBootTest(classes = [ObjectMapper, JsonObjectMapper])
class DeviceHeartbeatConsumerSpec extends Specification {
- def mockTrustLevelPerCmHandle = Mock(Map<String, TrustLevel>)
+ def mockTrustLevelManager = Mock(TrustLevelManager)
- def objectUnderTest = new DeviceHeartbeatConsumer(mockTrustLevelPerCmHandle)
+ def objectUnderTest = new DeviceHeartbeatConsumer(mockTrustLevelManager)
def objectMapper = new ObjectMapper()
@Autowired
@@ -54,29 +53,7 @@ class DeviceHeartbeatConsumerSpec extends Specification {
when: 'the event is consumed'
objectUnderTest.heartbeatListener(consumerRecord)
then: 'cm handles are stored with correct trust level'
- 1 * mockTrustLevelPerCmHandle.put('"cmhandle1"', TrustLevel.COMPLETE)
- }
-
- def 'Consume trustlevel event without cloud event id'() {
- given: 'an event from dmi'
- def payload = jsonObjectMapper.convertJsonString(trustLevelString, DeviceTrustLevel.class)
- def eventFromDmi = createTrustLevelEvent(payload)
- and: 'transformed to a consumer record WITHOUT Cloud event ID (ce_id)'
- def consumerRecord = new ConsumerRecord<String, CloudEvent>('test-device-heartbeat', 0, 0, 'sample-message-key', eventFromDmi)
- when: 'the event is consumed'
- objectUnderTest.heartbeatListener(consumerRecord)
- then: 'no cm handle has been stored in the map'
- 0 * mockTrustLevelPerCmHandle.put(*_)
- }
-
- def 'Consume a trust level event without payload'() {
- given: 'a consumer record with ce_id header but without payload'
- def consumerRecord = new ConsumerRecord<String, CloudEvent>('test-device-heartbeat', 0, 0, 'cmhandle1', createTrustLevelEvent(null))
- consumerRecord.headers().add('some_other_header_value', objectMapper.writeValueAsBytes('cmhandle1'))
- when: 'the event is consumed'
- objectUnderTest.heartbeatListener(consumerRecord)
- then: 'no cm handle has been stored in the map'
- 0 * mockTrustLevelPerCmHandle.put(*_)
+ 1 * mockTrustLevelManager.handleUpdateOfTrustLevels('"cmhandle1"', 'COMPLETE')
}
def createTrustLevelEvent(eventPayload) {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelManagerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelManagerSpec.groovy
new file mode 100644
index 0000000000..b3559e41ee
--- /dev/null
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelManagerSpec.groovy
@@ -0,0 +1,73 @@
+/*
+ * ============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.trustlevel
+
+import org.onap.cps.ncmp.api.impl.events.avc.ncmptoclient.AvcEventPublisher
+import spock.lang.Specification
+
+class TrustLevelManagerSpec extends Specification {
+
+ def trustLevelPerCmHandle = [:]
+ def mockAttributeValueChangeEventPublisher = Mock(AvcEventPublisher)
+ def objectUnderTest = new TrustLevelManager(trustLevelPerCmHandle, mockAttributeValueChangeEventPublisher)
+
+ def 'Initial cm handle registration'() {
+ given: 'two cm handles: one with no trust level and one trusted'
+ def cmHandleModelsToBeCreated = ['ch-1': null, 'ch-2': TrustLevel.COMPLETE]
+ when: 'the initial registration handled'
+ objectUnderTest.handleInitialRegistrationOfTrustLevels(cmHandleModelsToBeCreated)
+ then: 'no notification sent'
+ 0 * mockAttributeValueChangeEventPublisher.publishAvcEvent(*_)
+ and: 'both cm handles are in the cache and are trusted'
+ assert trustLevelPerCmHandle.get('ch-1') == TrustLevel.COMPLETE
+ assert trustLevelPerCmHandle.get('ch-2') == TrustLevel.COMPLETE
+ }
+
+ def 'Initial cm handle registration with a cm handle that is not trusted'() {
+ given: 'a not trusted cm handle'
+ def cmHandleModelsToBeCreated = ['ch-2': TrustLevel.NONE]
+ when: 'the initial registration handled'
+ objectUnderTest.handleInitialRegistrationOfTrustLevels(cmHandleModelsToBeCreated)
+ then: 'notification is sent'
+ 1 * mockAttributeValueChangeEventPublisher.publishAvcEvent(*_)
+ }
+
+ def 'Trust level updated'() {
+ given: 'a not trusted cm handle'
+ trustLevelPerCmHandle.put('ch-1', TrustLevel.NONE)
+ when: 'the update is handled'
+ objectUnderTest.handleUpdateOfTrustLevels('ch-1', 'COMPLETE')
+ then: 'notification is sent'
+ 1 * mockAttributeValueChangeEventPublisher.publishAvcEvent('ch-1', 'trustLevel', 'NONE', 'COMPLETE')
+ and: 'the cm handle in the cache is trusted'
+ assert trustLevelPerCmHandle.get('ch-1') == TrustLevel.COMPLETE
+ }
+
+ def 'Trust level updated with same value'() {
+ given: 'a trusted cm handle'
+ trustLevelPerCmHandle.put('ch-1', TrustLevel.COMPLETE)
+ when: 'the update is handled'
+ objectUnderTest.handleUpdateOfTrustLevels('ch-1', 'COMPLETE')
+ then: 'no notification is sent'
+ 0 * mockAttributeValueChangeEventPublisher.publishAvcEvent(*_)
+ }
+
+}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelTest.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelSpec.groovy
index 9971f6307c..f2521b560c 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelTest.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/TrustLevelSpec.groovy
@@ -22,7 +22,7 @@ package org.onap.cps.ncmp.api.impl.trustlevel
import spock.lang.Specification
-class TrustLevelTest extends Specification {
+class TrustLevelSpec extends Specification {
def 'Get effective trust level between this and other.'() {
expect: 'the lower of two is returned'
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginWatchDogSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginWatchDogSpec.groovy
index 2771c4df13..ec1d8e8f3d 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginWatchDogSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DmiPluginWatchDogSpec.groovy
@@ -20,31 +20,45 @@
package org.onap.cps.ncmp.api.impl.trustlevel.dmiavailability
+import org.onap.cps.ncmp.api.NetworkCmProxyDataService
import org.onap.cps.ncmp.api.impl.client.DmiRestClient
import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel
+import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevelManager
import spock.lang.Specification
class DmiPluginWatchDogSpec extends Specification {
def mockDmiRestClient = Mock(DmiRestClient)
+ def mockNetworkCmProxyDataService = Mock(NetworkCmProxyDataService)
+ def mockTrustLevelManager = Mock(TrustLevelManager)
def trustLevelPerDmiPlugin = [:]
- def objectUnderTest = new DmiPluginWatchDog(mockDmiRestClient, trustLevelPerDmiPlugin)
+
+ def objectUnderTest = new DmiPluginWatchDog(mockDmiRestClient,
+ mockNetworkCmProxyDataService,
+ mockTrustLevelManager,
+ trustLevelPerDmiPlugin)
def 'watch dmi plugin health status for #dmiHealhStatus'() {
given: 'the cache has been initialised and "knows" about dmi-1'
- trustLevelPerDmiPlugin.put('dmi-1',null)
+ trustLevelPerDmiPlugin.put('dmi-1', dmiOldTrustLevel)
and: 'dmi client returns health status #dmiHealhStatus'
mockDmiRestClient.getDmiHealthStatus('dmi-1') >> dmiHealhStatus
+ and: 'network cm proxy data returns a list of all cm handle ids belonging to a dmi'
+ mockNetworkCmProxyDataService.getAllCmHandleIdsByDmiPluginIdentifier('dmi-1') >> ['ch-1']
when: 'dmi watch dog method runs'
- objectUnderTest.watchDmiPluginTrustLevel()
+ objectUnderTest.checkDmiAvailability()
then: 'the result is as expected'
- assert trustLevelPerDmiPlugin.get('dmi-1') == expectedResult
- where: 'the following health status is used'
- dmiHealhStatus || expectedResult
- 'UP' || TrustLevel.COMPLETE
- 'Other' || TrustLevel.NONE
- null || TrustLevel.NONE
+ assert trustLevelPerDmiPlugin.get('dmi-1') == newDmiTrustLevel
+ and: 'the update delegated to manager'
+ times * mockTrustLevelManager.handleUpdateOfTrustLevels(*_)
+ where: 'the following parameters are used'
+ dmiHealhStatus | dmiOldTrustLevel || newDmiTrustLevel || times
+ 'UP' | TrustLevel.COMPLETE || TrustLevel.COMPLETE || 0
+ 'DOWN' | TrustLevel.COMPLETE || TrustLevel.NONE || 1
+ 'DOWN' | TrustLevel.NONE || TrustLevel.NONE || 0
+ 'UP' | TrustLevel.NONE || TrustLevel.COMPLETE || 1
+ '' | TrustLevel.COMPLETE || TrustLevel.NONE || 1
}
}