diff options
author | Shaaban Ebrahim <shaaban.eltanany.ext@orange.com> | 2019-10-24 12:37:21 +0200 |
---|---|---|
committer | Shaaban Ebrahim <shaaban.eltanany.ext@orange.com> | 2019-11-06 12:45:51 +0200 |
commit | 843d1f7ec7c45e3aad1d5198b776bb99a235448d (patch) | |
tree | 231c92a592b13e05eb670c2c27d47309a5143118 /ms/blueprintsprocessor/modules/inbounds/health-api-common/src/test/kotlin | |
parent | e967b59012d3aec0a5ad01d1ad508fc1e0a61a5f (diff) |
Update on Health-api
-add Combined health check
-add combined metrics check
Issue-ID: CCSDK-1669
Signed-off-by: Shaaban Ebrahim <shaaban.eltanany.ext@orange.com>
Change-Id: Idb3c7f67b3f22bd6069f75c193ae458c346fb2ac
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds/health-api-common/src/test/kotlin')
2 files changed, 201 insertions, 0 deletions
diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckServiceTest.kt b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckServiceTest.kt new file mode 100644 index 000000000..c4a8d1235 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckServiceTest.kt @@ -0,0 +1,167 @@ +/* + * Copyright © 2019-2020 Orange. + * + * 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. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.healthapi + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNotNull +import org.mockito.ArgumentMatchers.any +import org.mockito.ArgumentMatchers.eq +import org.mockito.Mockito.anyString +import org.mockito.Mockito.mock + +import java.util.Arrays +import org.junit.Assert +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.ArgumentMatchers +import org.mockito.InjectMocks +import org.mockito.Mock +import org.mockito.Mockito +import org.mockito.junit.MockitoJUnitRunner +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.configuration.HealthCheckProperties +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthApiResponse +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthCheckStatus +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.ServiceEndpoint +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.service.EndPointExecution +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.service.health.BluePrintProcessorHealthCheck +import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties +import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BasicAuthRestClientService +import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService +import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService.WebClientResponse +import org.springframework.http.HttpMethod + +@RunWith(MockitoJUnitRunner::class) +class HealthCheckServiceTest { + + @Mock + private val basicAuthRestClientService: BasicAuthRestClientService? = null + + @Mock + private val restClientProperties: BasicAuthRestClientProperties? = null + + @Mock + private val healthCheckProperties: HealthCheckProperties? = null + + @InjectMocks + private var endPointExecution: EndPointExecution? = null + + private var bluePrintProcessorHealthCheck: BluePrintProcessorHealthCheck? = null + + + @Before + fun setup() { + endPointExecution = Mockito.spy(endPointExecution!!) + Mockito.`when`(healthCheckProperties!!.getBluePrintServiceInformation()).thenReturn(Arrays.asList( + ServiceEndpoint("Execution service ", "http://cds-blueprints-processor-http:8080/api/v1/execution-service/health-check"), + ServiceEndpoint("Resources service", "http://cds-blueprints-processor-http:8080/api/v1/resources/health-check"), ServiceEndpoint("Template service", "http://cds-blueprints-processor-http:8080/api/v1/template/health-check") + )) + + bluePrintProcessorHealthCheck = BluePrintProcessorHealthCheck(endPointExecution!!, healthCheckProperties) + } + + @Test + fun testSystemIsCompletelyDown() { + + Mockito.`when`(basicAuthRestClientService!!.exchangeResource( + anyString(), + anyString(), + anyString())).thenThrow(RuntimeException()) + val healthApiResponse = bluePrintProcessorHealthCheck!!.retrieveEndpointExecutionStatus() + assertNotNull(healthApiResponse) + Assert.assertEquals(HealthCheckStatus.DOWN, healthApiResponse.status) + healthApiResponse.checks.forEach { serviceEndpoint -> + assertNotNull(serviceEndpoint) + assertEquals(HealthCheckStatus.DOWN, serviceEndpoint.status) + + } + + } + + @Test + fun testSystemIsUPAndRunning() { + + Mockito.`when`(basicAuthRestClientService!! + .exchangeResource( + anyString(), + anyString(), + anyString())).thenReturn(BlueprintWebClientService.WebClientResponse(200, "Success")) + val healthApiResponse = bluePrintProcessorHealthCheck!!.retrieveEndpointExecutionStatus() + assertNotNull(healthApiResponse) + assertEquals(HealthCheckStatus.UP, healthApiResponse.status) + healthApiResponse.checks.forEach { serviceEndpoint -> + assertNotNull(serviceEndpoint) + assertEquals(HealthCheckStatus.UP, serviceEndpoint.status) + + } + + } + + @Test + fun testServiceIsNotFound() { + Mockito.`when`(basicAuthRestClientService!!.exchangeResource( + anyString(), + anyString(), + anyString())).thenReturn(BlueprintWebClientService.WebClientResponse(404, "failure")) + val healthApiResponse = bluePrintProcessorHealthCheck!!.retrieveEndpointExecutionStatus() + assertNotNull(healthApiResponse) + assertEquals(HealthCheckStatus.DOWN, healthApiResponse.status) + healthApiResponse.checks.forEach { serviceEndpoint -> + assertNotNull(serviceEndpoint) + assertEquals(HealthCheckStatus.DOWN, serviceEndpoint.status) + + } + + } + + + @Test + fun testServiceInternalServerError() { + Mockito.`when`(basicAuthRestClientService!!.exchangeResource( + anyString(), + anyString(), + anyString())) + .thenReturn(BlueprintWebClientService.WebClientResponse(500, "failure")) + val healthApiResponse = bluePrintProcessorHealthCheck!!.retrieveEndpointExecutionStatus() + assertNotNull(healthApiResponse) + assertEquals(HealthCheckStatus.DOWN, healthApiResponse.status) + healthApiResponse.checks.forEach { serviceEndpoint -> + assertNotNull(serviceEndpoint) + assertEquals(HealthCheckStatus.DOWN, serviceEndpoint.status) + + } + + } + + @Test + fun testServiceIsRedirected() { + Mockito.`when`(basicAuthRestClientService!!. + exchangeResource( + anyString(), + anyString(), + anyString())) + .thenReturn(BlueprintWebClientService.WebClientResponse(300, "failure")) + val healthApiResponse = bluePrintProcessorHealthCheck!!.retrieveEndpointExecutionStatus() + assertNotNull(healthApiResponse) + assertEquals(HealthCheckStatus.DOWN, healthApiResponse.status) + healthApiResponse.checks.forEach { serviceEndpoint -> + assertNotNull(serviceEndpoint) + assertEquals(HealthCheckStatus.DOWN, serviceEndpoint.status) + + } + } +} diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/SecurityConfigurationTest.kt b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/SecurityConfigurationTest.kt new file mode 100644 index 000000000..e1f7abdb7 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/health-api-common/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/SecurityConfigurationTest.kt @@ -0,0 +1,34 @@ +/* + * Copyright © 2019-2020 Orange. + * + * 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. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.healthapi + +import org.junit.Assert +import org.junit.Test +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.configuration.SecurityEncryptionConfiguration + + +class SecurityConfigurationTest { + + @Test + fun testEncryption() { + val passWord = "ccsdkapps" + val securityConfiguration = SecurityEncryptionConfiguration() + val encryptedValue = securityConfiguration.encrypt(passWord) + println(encryptedValue) + Assert.assertEquals(passWord, securityConfiguration.decrypt(encryptedValue!!)) + } +} |