From 4c9246c82b12a7b9e0f9ac0230abfdb369ce9ab1 Mon Sep 17 00:00:00 2001 From: Frank Kimmlingen Date: Tue, 7 Mar 2023 16:36:48 +0100 Subject: Enable JUnit tests and porting to java 17 JUnit tests are no more executed: spring-boot-starter-test does not execute any junit4 tests by default Fix enable tests and adopts the tests moslty to java 17 runtime Issue-ID: CCSDK-3859 Signed-off-by: Frank Kimmlingen Signed-off-by: Lukasz Rajewski Change-Id: I02a8d25350ca62262bfc6e07c2865cd8d7b4e6b2 --- .../modules/blueprints/blueprint-core/pom.xml | 5 ++ .../blueprints/blueprint-validation/pom.xml | 4 ++ .../modules/commons/dmaap-lib/pom.xml | 5 ++ .../message/utils/BlueprintMessageUtils.kt | 55 ++++++++++++---------- .../message/utils/BlueprintMessageUtilsTest.kt | 10 ++-- ms/blueprintsprocessor/modules/commons/pom.xml | 10 ++++ .../core/cluster/HazelcastClusterService.kt | 2 +- .../rest/service/RestLoggerService.kt | 2 +- ms/blueprintsprocessor/modules/inbounds/pom.xml | 10 ++++ ms/blueprintsprocessor/modules/services/pom.xml | 10 ++++ 10 files changed, 81 insertions(+), 32 deletions(-) (limited to 'ms/blueprintsprocessor/modules') diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/pom.xml b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/pom.xml index a6188da0f..878a4b491 100644 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-core/pom.xml +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-core/pom.xml @@ -92,6 +92,11 @@ mockk test + + io.mockk + mockk-jvm + test + org.jetbrains.kotlinx kotlinx-coroutines-test diff --git a/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/pom.xml b/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/pom.xml index 4efe77bb2..808201780 100644 --- a/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/pom.xml +++ b/ms/blueprintsprocessor/modules/blueprints/blueprint-validation/pom.xml @@ -57,6 +57,10 @@ io.mockk mockk + + io.mockk + mockk-jvm + org.jetbrains.kotlinx kotlinx-coroutines-test diff --git a/ms/blueprintsprocessor/modules/commons/dmaap-lib/pom.xml b/ms/blueprintsprocessor/modules/commons/dmaap-lib/pom.xml index 698f519f5..57008da11 100644 --- a/ms/blueprintsprocessor/modules/commons/dmaap-lib/pom.xml +++ b/ms/blueprintsprocessor/modules/commons/dmaap-lib/pom.xml @@ -60,6 +60,11 @@ spring-boot-starter-test test + + org.junit.vintage + junit-vintage-engine + test + org.glassfish.jersey.inject jersey-hk2 diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/utils/BlueprintMessageUtils.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/utils/BlueprintMessageUtils.kt index 0d4310c79..cc0681c72 100644 --- a/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/utils/BlueprintMessageUtils.kt +++ b/ms/blueprintsprocessor/modules/commons/message-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/utils/BlueprintMessageUtils.kt @@ -22,31 +22,36 @@ import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.defaultToUUID import kotlin.math.max -class BlueprintMessageUtils { - companion object { - fun kafkaMetricTag(topic: String): MutableList = - mutableListOf( - Tag.of(BluePrintConstants.METRIC_TAG_TOPIC, topic) - ) - - /** - * get OS hostname's last 5 characters - * Used to generate unique client ID. - */ - fun getHostnameSuffix(): String = - System.getenv("HOSTNAME").defaultToUUID().let { - it.substring(max(0, it.length - 5)) - } +object BlueprintMessageUtils { - fun getMessageLogData(message: Any): String = - when (message) { - is CommonExecutionServiceData -> { - val actionIdentifiers = message.actionIdentifiers - val commonHeaders = message.commonHeader - "requestID(${commonHeaders.requestId}), subrequestID(${commonHeaders.subRequestId}) " + - "CBA(${actionIdentifiers.blueprintName}/${actionIdentifiers.blueprintVersion}/${actionIdentifiers.actionName})" - } - else -> "message($message)" - } + fun getHostname(): String? { + return System.getenv("HOSTNAME") + } + + fun kafkaMetricTag(topic: String): MutableList = + mutableListOf( + Tag.of(BluePrintConstants.METRIC_TAG_TOPIC, topic) + ) + + /** + * get OS hostname's last 5 characters + * Used to generate unique client ID. + */ + fun getHostnameSuffix(): String { + return getHostname().defaultToUUID().let { + it.substring(max(0, it.length - 5)) + } } + + fun getMessageLogData(message: Any): String = + when (message) { + is CommonExecutionServiceData -> { + val actionIdentifiers = message.actionIdentifiers + val commonHeaders = message.commonHeader + "requestID(${commonHeaders.requestId}), subrequestID(${commonHeaders.subRequestId}) " + + "CBA(${actionIdentifiers.blueprintName}/${actionIdentifiers.blueprintVersion}/${actionIdentifiers.actionName})" + } + + else -> "message($message)" + } } diff --git a/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/utils/BlueprintMessageUtilsTest.kt b/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/utils/BlueprintMessageUtilsTest.kt index 5d0c89415..aa4d00e16 100644 --- a/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/utils/BlueprintMessageUtilsTest.kt +++ b/ms/blueprintsprocessor/modules/commons/message-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/message/utils/BlueprintMessageUtilsTest.kt @@ -18,7 +18,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.message.utils import io.micrometer.core.instrument.Tag import io.mockk.every -import io.mockk.mockkStatic +import io.mockk.mockkObject import org.junit.Test import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader @@ -41,15 +41,15 @@ class BlueprintMessageUtilsTest { @Test fun testGetHostnameSuffix() { - mockkStatic(System::class) - every { System.getenv("HOSTNAME") } returns "qwertyuiop" + mockkObject(BlueprintMessageUtils) + every { BlueprintMessageUtils.getHostname() } returns "qwertyuiop" assertEquals("yuiop", BlueprintMessageUtils.getHostnameSuffix()) } @Test fun testGetNullHostnameSuffix() { - mockkStatic(System::class) - every { System.getenv("HOSTNAME") } returns null + mockkObject(BlueprintMessageUtils) + every { BlueprintMessageUtils.getHostname() } returns null assertEquals(5, BlueprintMessageUtils.getHostnameSuffix().length) } diff --git a/ms/blueprintsprocessor/modules/commons/pom.xml b/ms/blueprintsprocessor/modules/commons/pom.xml index f653986bd..8bb9b0b68 100755 --- a/ms/blueprintsprocessor/modules/commons/pom.xml +++ b/ms/blueprintsprocessor/modules/commons/pom.xml @@ -53,6 +53,11 @@ mockk test + + io.mockk + mockk-jvm + test + org.powermock powermock-api-mockito2 @@ -63,6 +68,11 @@ spring-boot-starter-test test + + org.junit.vintage + junit-vintage-engine + test + org.jetbrains.kotlin kotlin-test-junit diff --git a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazelcastClusterService.kt b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazelcastClusterService.kt index fb9056776..870e0ed64 100644 --- a/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazelcastClusterService.kt +++ b/ms/blueprintsprocessor/modules/commons/processor-core/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/core/cluster/HazelcastClusterService.kt @@ -180,7 +180,7 @@ open class HazelcastClusterService(private val applicationEventPublisher: Applic } /** Return interface may change and it will be included in BluePrintClusterService */ - @UseExperimental + @OptIn suspend fun clusterScheduler(name: String): IScheduledExecutorService { check(::hazelcast.isInitialized) { "failed to start and join cluster" } return hazelcast.getScheduledExecutorService(name) diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt index 744236685..f5552a691 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/RestLoggerService.kt @@ -150,7 +150,7 @@ suspend fun mdcWebCoroutineScope( replaceWith = ReplaceWith("mdcWebCoroutineScope") ) /** Used in Rest controller API methods to populate MDC context to nested coroutines from reactor web filter context. */ -@UseExperimental(InternalCoroutinesApi::class) +@OptIn(InternalCoroutinesApi::class) fun monoMdc( context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T? diff --git a/ms/blueprintsprocessor/modules/inbounds/pom.xml b/ms/blueprintsprocessor/modules/inbounds/pom.xml index b0fd64cd5..4a5c621f0 100644 --- a/ms/blueprintsprocessor/modules/inbounds/pom.xml +++ b/ms/blueprintsprocessor/modules/inbounds/pom.xml @@ -59,6 +59,11 @@ mockk test + + io.mockk + mockk-jvm + test + org.powermock powermock-api-mockito2 @@ -69,6 +74,11 @@ spring-boot-starter-test test + + org.junit.vintage + junit-vintage-engine + test + org.jetbrains.kotlin kotlin-test-junit diff --git a/ms/blueprintsprocessor/modules/services/pom.xml b/ms/blueprintsprocessor/modules/services/pom.xml index 453c0a08f..b2f033087 100755 --- a/ms/blueprintsprocessor/modules/services/pom.xml +++ b/ms/blueprintsprocessor/modules/services/pom.xml @@ -43,6 +43,11 @@ mockk test + + io.mockk + mockk-jvm + test + org.powermock powermock-api-mockito2 @@ -53,6 +58,11 @@ spring-boot-starter-test test + + org.junit.vintage + junit-vintage-engine + test + org.jetbrains.kotlin kotlin-test-junit -- cgit 1.2.3-korg