summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test
diff options
context:
space:
mode:
authorhalil.cakal <halil.cakal@est.tech>2023-08-31 11:45:47 +0100
committerhalil.cakal <halil.cakal@est.tech>2023-09-04 11:54:40 +0100
commitc4485f7218fb9b2b4b7c113294ae2902979f5b5e (patch)
tree242038cf5386e75b9a6bd19aac20d1d56a011827 /cps-ncmp-service/src/test
parent17d14293823ec280e646071988be211184d1f7ce (diff)
Dmi plugin watchdog cheking aliveness
- Add capability of GET request into DmiRestClient - Add watchdog job to check aliveness of dmi plugins - DmiPluginStatus enum as UP or DOWN - Add unit tests for the new function in dmi rest client - Add unit tests for dmi watchdog Issue-ID: CPS-1856 Change-Id: Ic38a96f0485a0bfe1b6af5bb2f57f6119d8fa563 Signed-off-by: halil.cakal <halil.cakal@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/test')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/client/DmiRestClientSpec.groovy42
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DMiPluginWatchDogSpec.groovy51
-rw-r--r--cps-ncmp-service/src/test/resources/application.yml3
-rw-r--r--cps-ncmp-service/src/test/resources/dmiPluginHealthCheckResponse.json27
4 files changed, 121 insertions, 2 deletions
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 0d03fd9acf..80c0a27bf7 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
@@ -21,8 +21,13 @@
package org.onap.cps.ncmp.api.impl.client
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.fasterxml.jackson.databind.node.ObjectNode
import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration
import org.onap.cps.ncmp.api.impl.exception.HttpClientRequestException
+import org.onap.cps.ncmp.api.impl.trustlevel.dmiavailability.DmiPluginStatus
+import org.onap.cps.ncmp.utils.TestUtils
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
@@ -40,7 +45,7 @@ import static org.onap.cps.ncmp.api.impl.operations.OperationType.PATCH
import static org.onap.cps.ncmp.api.impl.operations.OperationType.CREATE
@SpringBootTest
-@ContextConfiguration(classes = [NcmpConfiguration.DmiProperties, DmiRestClient])
+@ContextConfiguration(classes = [NcmpConfiguration.DmiProperties, DmiRestClient, ObjectMapper])
class DmiRestClientSpec extends Specification {
@SpringBean
@@ -48,8 +53,11 @@ class DmiRestClientSpec extends Specification {
@Autowired
DmiRestClient objectUnderTest
- def resourceUrl = 'some url'
+ @Autowired
+ ObjectMapper objectMapper
+
+ def resourceUrl = 'some url'
def mockResponseEntity = Mock(ResponseEntity)
def dmiProperties = new NcmpConfiguration.DmiProperties()
@@ -85,6 +93,36 @@ class DmiRestClientSpec extends Specification {
operation << [CREATE, READ, PATCH]
}
+ def 'Get dmi plugin health status #scenario'() {
+ given: 'a health check response data as jsonNode'
+ def dmiPluginHealthCheckResponseJsonData = TestUtils.getResourceFileContent('dmiPluginHealthCheckResponse.json')
+ def jsonNode = objectMapper.readValue(dmiPluginHealthCheckResponseJsonData, JsonNode.class)
+ ((ObjectNode) jsonNode).put('status', dmiAliveness);
+ and: 'the rest template return a valid json node'
+ mockRestTemplate.getForObject(*_) >> {jsonNode}
+ when: 'get aliveness of the dmi plugin'
+ def result = objectUnderTest.getDmiPluginStatus(resourceUrl)
+ then: 'return value is equal to result of rest template call'
+ result == expectedResult
+ where: 'the following dmi aliveness are being used'
+ scenario | dmiAliveness || expectedResult
+ 'dmi plugin is UP' | 'UP' || DmiPluginStatus.UP
+ 'dmi plugin is DOWN' | 'DOWN' || DmiPluginStatus.DOWN
+ }
+
+ def 'Failing to get dmi plugin health status #scenario'() {
+ given: 'the rest template return null'
+ mockRestTemplate.getForObject(*_) >> {getResponse}
+ when: 'get aliveness of the dmi plugin'
+ def result = objectUnderTest.getDmiPluginStatus(resourceUrl)
+ then: 'return value is equal to result of rest template call'
+ result == expectedResult
+ where: 'the following dmi responses are being used'
+ scenario | getResponse || expectedResult
+ 'get response is null' | null || DmiPluginStatus.DOWN
+ 'get response throws exception' | {throw new Exception()} || DmiPluginStatus.DOWN
+ }
+
def 'Basic auth header #scenario'() {
when: 'Specific dmi properties are provided'
dmiProperties.dmiBasicAuthEnabled = authEnabled
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
new file mode 100644
index 0000000000..af546b7f5e
--- /dev/null
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DMiPluginWatchDogSpec.groovy
@@ -0,0 +1,51 @@
+/*
+ * ============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.dmiavailability
+
+import com.hazelcast.map.IMap
+import org.onap.cps.ncmp.api.impl.client.DmiRestClient
+import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel
+import spock.lang.Specification
+
+class DMiPluginWatchDogSpec extends Specification {
+
+
+ def mockTrustLevelPerDmiPlugin = Mock(IMap<String, TrustLevel>)
+ def mockDmiRestClient = Mock(DmiRestClient)
+ def objectUnderTest = new DMiPluginWatchDog(mockTrustLevelPerDmiPlugin, mockDmiRestClient)
+
+
+ def 'watch dmi plugin aliveness'() {
+ given: 'the dmi client returns aliveness for #dmi1Status'
+ mockDmiRestClient.getDmiPluginStatus('dmi1') >> dmi1Status
+ and: 'trust level cache returns dmi1'
+ mockTrustLevelPerDmiPlugin.keySet() >> {['dmi1'] as Set}
+ when: 'watch dog started'
+ objectUnderTest.watchDmiPluginAliveness()
+ then: 'trust level cache has been populated with #dmi1TrustLevel for dmi1'
+ 1 * mockTrustLevelPerDmiPlugin.put('dmi1', dmi1TrustLevel)
+ where: 'the following parameter are used'
+ scenario | dmi1Status || dmi1TrustLevel
+ 'dmi1 is UP' | DmiPluginStatus.UP || TrustLevel.COMPLETE
+ 'dmi1 is DOWN' | DmiPluginStatus.DOWN || TrustLevel.NONE
+ }
+
+}
diff --git a/cps-ncmp-service/src/test/resources/application.yml b/cps-ncmp-service/src/test/resources/application.yml
index 6e7577b1a8..a4bb4e8124 100644
--- a/cps-ncmp-service/src/test/resources/application.yml
+++ b/cps-ncmp-service/src/test/resources/application.yml
@@ -42,6 +42,9 @@ ncmp:
enabled: true
api:
base-path: dmi
+ timers:
+ trust-level:
+ dmi-availability-watchdog-ms: 30000
modules-sync-watchdog:
async-executor:
diff --git a/cps-ncmp-service/src/test/resources/dmiPluginHealthCheckResponse.json b/cps-ncmp-service/src/test/resources/dmiPluginHealthCheckResponse.json
new file mode 100644
index 0000000000..753222005e
--- /dev/null
+++ b/cps-ncmp-service/src/test/resources/dmiPluginHealthCheckResponse.json
@@ -0,0 +1,27 @@
+{
+ "status": "UP",
+ "components": {
+ "diskSpace": {
+ "status": "UP",
+ "details": {
+ "total": 269490393088,
+ "free": 228467286016,
+ "threshold": 10485760,
+ "exists": true
+ }
+ },
+ "livenessState": {
+ "status": "UP"
+ },
+ "ping": {
+ "status": "UP"
+ },
+ "readinessState": {
+ "status": "UP"
+ }
+ },
+ "groups": [
+ "liveness",
+ "readiness"
+ ]
+} \ No newline at end of file