aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test/groovy/org
diff options
context:
space:
mode:
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/client/DmiRestClientSpec.groovy42
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/trustlevel/dmiavailability/DMiPluginWatchDogSpec.groovy51
2 files changed, 91 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 0d03fd9ac..80c0a27bf 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 000000000..af546b7f5
--- /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
+ }
+
+}