2 * Copyright © 2019-2020 Orange.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.cds.blueprintsprocessor.healthapi
19 import org.junit.Assert
20 import org.junit.Assert.assertEquals
21 import org.junit.Assert.assertNotNull
22 import org.junit.Before
24 import org.junit.runner.RunWith
25 import org.mockito.InjectMocks
26 import org.mockito.Mock
27 import org.mockito.Mockito
28 import org.mockito.Mockito.anyString
29 import org.mockito.junit.MockitoJUnitRunner
30 import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.configuration.HealthCheckProperties
31 import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthCheckStatus
32 import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.ServiceEndpoint
33 import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.service.EndPointExecution
34 import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.service.health.BluePrintProcessorHealthCheck
35 import org.onap.ccsdk.cds.blueprintsprocessor.rest.BasicAuthRestClientProperties
36 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BasicAuthRestClientService
37 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService
38 import java.util.Arrays
40 @RunWith(MockitoJUnitRunner::class)
41 class HealthCheckServiceTest {
44 private val basicAuthRestClientService: BasicAuthRestClientService? = null
47 private val restClientProperties: BasicAuthRestClientProperties? = null
50 private val healthCheckProperties: HealthCheckProperties? = null
53 private var endPointExecution: EndPointExecution? = null
55 private var bluePrintProcessorHealthCheck: BluePrintProcessorHealthCheck? = null
59 endPointExecution = Mockito.spy(endPointExecution!!)
60 Mockito.`when`(healthCheckProperties!!.getBluePrintServiceInformation()).thenReturn(
62 ServiceEndpoint("Execution service ", "http://cds-blueprints-processor-http:8080/api/v1/execution-service/health-check"),
63 ServiceEndpoint("Resources service", "http://cds-blueprints-processor-http:8080/api/v1/resources/health-check"),
64 ServiceEndpoint("Template service", "http://cds-blueprints-processor-http:8080/api/v1/template/health-check")
68 bluePrintProcessorHealthCheck = BluePrintProcessorHealthCheck(endPointExecution!!, healthCheckProperties)
72 fun testSystemIsCompletelyDown() {
75 basicAuthRestClientService!!.exchangeResource(
80 ).thenThrow(RuntimeException())
81 val healthApiResponse = bluePrintProcessorHealthCheck!!.retrieveEndpointExecutionStatus()
82 assertNotNull(healthApiResponse)
83 Assert.assertEquals(HealthCheckStatus.DOWN, healthApiResponse.status)
84 healthApiResponse.checks.forEach { serviceEndpoint ->
85 assertNotNull(serviceEndpoint)
86 assertEquals(HealthCheckStatus.DOWN, serviceEndpoint.status)
91 fun testSystemIsUPAndRunning() {
94 basicAuthRestClientService!!
100 ).thenReturn(BlueprintWebClientService.WebClientResponse(200, "Success"))
101 val healthApiResponse = bluePrintProcessorHealthCheck!!.retrieveEndpointExecutionStatus()
102 assertNotNull(healthApiResponse)
103 assertEquals(HealthCheckStatus.UP, healthApiResponse.status)
104 healthApiResponse.checks.forEach { serviceEndpoint ->
105 assertNotNull(serviceEndpoint)
106 assertEquals(HealthCheckStatus.UP, serviceEndpoint.status)
111 fun testServiceIsNotFound() {
113 basicAuthRestClientService!!.exchangeResource(
118 ).thenReturn(BlueprintWebClientService.WebClientResponse(404, "failure"))
119 val healthApiResponse = bluePrintProcessorHealthCheck!!.retrieveEndpointExecutionStatus()
120 assertNotNull(healthApiResponse)
121 assertEquals(HealthCheckStatus.DOWN, healthApiResponse.status)
122 healthApiResponse.checks.forEach { serviceEndpoint ->
123 assertNotNull(serviceEndpoint)
124 assertEquals(HealthCheckStatus.DOWN, serviceEndpoint.status)
129 fun testServiceInternalServerError() {
131 basicAuthRestClientService!!.exchangeResource(
137 .thenReturn(BlueprintWebClientService.WebClientResponse(500, "failure"))
138 val healthApiResponse = bluePrintProcessorHealthCheck!!.retrieveEndpointExecutionStatus()
139 assertNotNull(healthApiResponse)
140 assertEquals(HealthCheckStatus.DOWN, healthApiResponse.status)
141 healthApiResponse.checks.forEach { serviceEndpoint ->
142 assertNotNull(serviceEndpoint)
143 assertEquals(HealthCheckStatus.DOWN, serviceEndpoint.status)
148 fun testServiceIsRedirected() {
150 basicAuthRestClientService!!
157 .thenReturn(BlueprintWebClientService.WebClientResponse(300, "failure"))
158 val healthApiResponse = bluePrintProcessorHealthCheck!!.retrieveEndpointExecutionStatus()
159 assertNotNull(healthApiResponse)
160 assertEquals(HealthCheckStatus.DOWN, healthApiResponse.status)
161 healthApiResponse.checks.forEach { serviceEndpoint ->
162 assertNotNull(serviceEndpoint)
163 assertEquals(HealthCheckStatus.DOWN, serviceEndpoint.status)