summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org
diff options
context:
space:
mode:
authorBrinda Santh Muthuramalingam <brindasanth@in.ibm.com>2019-09-16 23:55:45 +0000
committerGerrit Code Review <gerrit@onap.org>2019-09-16 23:55:45 +0000
commit4e089ab6271e00389ea2c4e995d785acf2046720 (patch)
tree107ada21bfce9f60b59f6843ca787cdaf5e80077 /ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org
parent8a5e40f28ee1cf4fbe4ace0fe81c95c1be35ac97 (diff)
parentbf30532b84d21e98cb266f20fe961ba280909dca (diff)
Merge "add health-api project"
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org')
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckApplicationTests.kt55
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckServiceTest.java137
2 files changed, 192 insertions, 0 deletions
diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckApplicationTests.kt b/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckApplicationTests.kt
new file mode 100644
index 000000000..cd02b65dc
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckApplicationTests.kt
@@ -0,0 +1,55 @@
+/*
+ * 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.Test
+import org.junit.runner.RunWith
+import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration
+import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.boot.autoconfigure.security.SecurityProperties
+import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
+import org.springframework.context.annotation.ComponentScan
+import org.springframework.test.context.ContextConfiguration
+import org.springframework.test.context.TestPropertySource
+import org.springframework.test.context.junit4.SpringRunner
+import org.springframework.test.web.reactive.server.WebTestClient
+
+
+@RunWith(SpringRunner::class)
+@WebFluxTest
+@ContextConfiguration(classes = [BluePrintCoreConfiguration::class,
+ BluePrintCatalogService::class, SecurityProperties::class])
+@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"])
+@TestPropertySource(locations = ["classpath:application-test.properties"])
+class HealthCheckApplicationTests {
+
+
+ @Autowired
+ lateinit var webTestClient: WebTestClient
+
+ @Test
+ fun testHealthApiUp() {
+ val result = webTestClient.get().uri("/api/v1/health")
+ .exchange()
+ .expectStatus().is2xxSuccessful
+ println(result)
+ }
+
+
+}
diff --git a/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckServiceTest.java b/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckServiceTest.java
new file mode 100644
index 000000000..8fb5e58fc
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/health-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/healthapi/HealthCheckServiceTest.java
@@ -0,0 +1,137 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.anyString;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+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.service.HealthCheckService;
+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.WebClientResponse;
+import org.springframework.http.HttpMethod;
+
+@RunWith(MockitoJUnitRunner.class)
+public class HealthCheckServiceTest {
+
+ @Mock
+ private BasicAuthRestClientService basicAuthRestClientService;
+
+ @Mock
+ private BasicAuthRestClientProperties restClientProperties;
+
+ @InjectMocks
+ private HealthCheckService healthCheckService = new HealthCheckService();
+
+ @Before
+ public void setup() {
+ }
+
+ @Test
+ public void testSystemIsCompletelyDown() {
+
+ Mockito.when(basicAuthRestClientService.exchangeResource(anyString(), anyString(), anyString())).
+ thenThrow(new RuntimeException());
+ HealthApiResponse healthApiResponse = healthCheckService.retrieveSystemStatus();
+ assertNotNull(healthApiResponse);
+ Assert.assertEquals(healthApiResponse.getStatus(), HealthCheckStatus.DOWN);
+ healthApiResponse.getChecks().stream().forEach(serviceEndpoint -> {
+ assertNotNull(serviceEndpoint);
+ assertEquals(serviceEndpoint.getStatus(), HealthCheckStatus.DOWN);
+
+ });
+
+ }
+
+
+ @Test
+ public void testSystemIsUPAndRunning() {
+
+ Mockito.when(basicAuthRestClientService.exchangeResource(eq(HttpMethod.GET.name()), anyString(), anyString())).
+ thenReturn(new WebClientResponse<>(200, "Success"));
+ HealthApiResponse healthApiResponse = healthCheckService.retrieveSystemStatus();
+ assertNotNull(healthApiResponse);
+ assertEquals(healthApiResponse.getStatus(), HealthCheckStatus.UP);
+ healthApiResponse.getChecks().stream().forEach(serviceEndpoint -> {
+ assertNotNull(serviceEndpoint);
+ assertEquals(serviceEndpoint.getStatus(), HealthCheckStatus.UP);
+
+ });
+
+ }
+
+ @Test
+ public void testServiceIsNotFound() {
+ Mockito.when(basicAuthRestClientService.exchangeResource(eq(HttpMethod.GET.name()), any(), anyString())).
+ thenReturn(new WebClientResponse<>(404, "failure"));
+ HealthApiResponse healthApiResponse = healthCheckService.retrieveSystemStatus();
+ assertNotNull(healthApiResponse);
+ assertEquals(healthApiResponse.getStatus(), HealthCheckStatus.DOWN);
+ healthApiResponse.getChecks().stream().forEach(serviceEndpoint -> {
+ assertNotNull(serviceEndpoint);
+ assertEquals(serviceEndpoint.getStatus(), HealthCheckStatus.DOWN);
+
+ });
+
+ }
+
+
+ @Test
+ public void testServiceInternalServerError() {
+ Mockito.when(basicAuthRestClientService.exchangeResource(eq(HttpMethod.GET.name()), any(), anyString()))
+ .thenReturn(new WebClientResponse<>(500, "failure"));
+ HealthApiResponse healthApiResponse = healthCheckService.retrieveSystemStatus();
+ assertNotNull(healthApiResponse);
+ assertEquals(healthApiResponse.getStatus(), HealthCheckStatus.DOWN);
+ healthApiResponse.getChecks().stream().forEach(serviceEndpoint -> {
+ assertNotNull(serviceEndpoint);
+ assertEquals(serviceEndpoint.getStatus(), HealthCheckStatus.DOWN);
+
+ });
+
+ }
+
+ @Test
+ public void testServiceIsRedirected() {
+ Mockito.when(basicAuthRestClientService.exchangeResource(eq(HttpMethod.GET.name()), any(), anyString()))
+ .thenReturn(new WebClientResponse<>(300, "failure"));
+ HealthApiResponse healthApiResponse = healthCheckService.retrieveSystemStatus();
+ assertNotNull(healthApiResponse);
+ assertEquals(healthApiResponse.getStatus(), HealthCheckStatus.DOWN);
+ healthApiResponse.getChecks().stream().forEach(serviceEndpoint -> {
+ assertNotNull(serviceEndpoint);
+ assertEquals(serviceEndpoint.getStatus(), HealthCheckStatus.DOWN);
+
+ });
+
+ }
+
+}