From: Fiete Ostkamp Date: Wed, 4 Mar 2026 08:10:43 +0000 (+0100) Subject: Reenable tests X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=55c4d15e360a931cfc45ab28caf85a9d4814f1d2;p=ccsdk%2Fcds.git Reenable tests - blueprints-core module (125 tests) - blueprint-validation (4 tests) - health-api (2 tests) - (potentially) fix sonarqube job [0] [0] there may surface new modules that cause the job to fail Issue-ID: CCSDK-4152 Change-Id: Ife650d77b24b3f2ce96a4cae89f61b9a65f46394 Signed-off-by: Fiete Ostkamp --- diff --git a/components/model-catalog/blueprint-model/cba-assembly-descriptor/pom.xml b/components/model-catalog/blueprint-model/cba-assembly-descriptor/pom.xml index f18a5bb5f..941db1d5b 100644 --- a/components/model-catalog/blueprint-model/cba-assembly-descriptor/pom.xml +++ b/components/model-catalog/blueprint-model/cba-assembly-descriptor/pom.xml @@ -29,6 +29,12 @@ Components Model Catalog - Blueprints Model - CBA Assembly Descriptor Shared assembly descriptor + + + true + + diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/pom.xml b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/pom.xml index 73ce4c57d..c544d2e11 100644 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/pom.xml +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/pom.xml @@ -83,6 +83,17 @@ commons-compress + + org.junit.vintage + junit-vintage-engine + test + + + net.bytebuddy + byte-buddy + ${bytebuddy.version} + test + org.jetbrains.kotlin kotlin-test-junit diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/pom.xml b/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/pom.xml index 37e981790..ee20ccfa6 100644 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/pom.xml +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/pom.xml @@ -51,9 +51,21 @@ + + org.junit.vintage + junit-vintage-engine + test + + + net.bytebuddy + byte-buddy + ${bytebuddy.version} + test + org.jetbrains.kotlin kotlin-test-junit + test io.mockk 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 index 1f3d256b3..df4942e64 100644 --- 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 @@ -15,57 +15,96 @@ */ package org.onap.ccsdk.cds.blueprintsprocessor.healthapi -/* + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNotNull +import org.junit.Before import org.junit.Test import org.junit.runner.RunWith -import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintCoreConfiguration -import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ComponentScriptExecutor -import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService -import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService -import org.springframework.beans.factory.annotation.Autowired -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 -*/ +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.ApplicationHealth +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.WebClientEnpointResponse +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.service.CombinedHealthService +import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.service.EndPointExecution +import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.BlueprintWebClientService +import org.springframework.boot.actuate.health.Status /** - *Unit tests for making sure that two endpoints is up and running + * Unit tests for CombinedHealthService verifying health check aggregation logic. * * @author Shaaban Ebrahim * @version 1.0 */ -/* -@RunWith(SpringRunner::class) -@WebFluxTest -@ContextConfiguration( - classes = [BluePrintRuntimeService::class, BluePrintCoreConfiguration::class, - BluePrintCatalogService::class, ComponentScriptExecutor::class] -) -@ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"]) -@TestPropertySource(locations = ["classpath:application-test.properties"]) +@RunWith(MockitoJUnitRunner::class) class HealthCheckApplicationTests { - @Autowired - lateinit var webTestClient: WebTestClient + @Mock + private val endPointExecution: EndPointExecution? = null - @Test - fun testHealthApiUp() { - webTestClient.get().uri("/api/v1/combinedHealth") - .exchange() - .expectStatus().is2xxSuccessful + @Mock + private val healthCheckProperties: HealthCheckProperties? = null + + @InjectMocks + private var combinedHealthService: CombinedHealthService? = null + + @Before + fun setup() { + Mockito.`when`(healthCheckProperties!!.getBluePrintBaseURL()) + .thenReturn("http://cds-blueprints-processor-http:8080/") + Mockito.`when`(healthCheckProperties.getCDSListenerBaseURL()) + .thenReturn("http://cds-sdc-listener:8080/") } @Test - fun testMetricsApiUp() { - webTestClient.get().uri("/api/v1/combinedMetrics") - .exchange() - .expectStatus().is2xxSuccessful + fun testGetCombinedHealthCheckWhenServicesAreDown() { + Mockito.`when`( + endPointExecution!!.retrieveWebClientResponse(anyObject()) + ).thenReturn(WebClientEnpointResponse(BlueprintWebClientService.WebClientResponse(500, ""))) + + val result = combinedHealthService!!.getCombinedHealthCheck() + + assertNotNull(result) + assertEquals(2, result.size) + result.forEach { health -> + assertNotNull(health) + assertEquals(Status.DOWN, health!!.status) + } } -} -*/ + @Test + fun testGetCombinedHealthCheckWhenServicesAreUp() { + val successResponse = WebClientEnpointResponse( + BlueprintWebClientService.WebClientResponse(200, "") + ) + val healthUp = ApplicationHealth(Status.UP, hashMapOf()) + + Mockito.`when`( + endPointExecution!!.retrieveWebClientResponse(anyObject()) + ).thenReturn(successResponse) + Mockito.`when`( + endPointExecution.getHealthFromWebClientEnpointResponse(anyObject()) + ).thenReturn(healthUp) + + val result = combinedHealthService!!.getCombinedHealthCheck() -class HealthCheckApplicationTests + assertNotNull(result) + assertEquals(2, result.size) + result.forEach { health -> + assertNotNull(health) + assertEquals(Status.UP, health!!.status) + } + } + + /** + * Kotlin + Mockito workaround: Mockito.any() returns null, but Kotlin throws NPE + * when null is passed to a non-nullable parameter. Using an unchecked cast tells the + * Kotlin compiler the result is non-null, so it skips the null-check at the call site. + * Mockito intercepts the mock call before any real code runs, so null is never used. + */ + @Suppress("UNCHECKED_CAST") + private fun anyObject(): T = Mockito.any() as T +}