From 82bc8ef6785a8758e2864a2c42a3e10648cd4638 Mon Sep 17 00:00:00 2001 From: Saeed Rezaee Date: Thu, 29 Feb 2024 17:45:08 +0100 Subject: [PATCH] Refactor the tests This commit primarily refactors the existing forced/soft update tests to reduce the generation of unnecessary reports during build time. Signed-off-by: Saeed Rezaee --- .gitignore | 3 +- .../hara/ddi/api/model/SerializationTest.kt | 2 +- .../DdiClientHttpRequestsTest.kt | 14 +- ...tTest.kt => DeploymentDownloadOnlyTest.kt} | 19 +- .../DeploymentForcedAndSoftTest.kt | 347 ++++++++++++++++++ ...cedTest.kt => DeploymentTimeForcedTest.kt} | 23 +- .../integrationtest/ForcePingTest.kt | 17 +- .../PingBackoffStrategyTest.kt | 9 +- .../integrationtest/SuccessfulForcedUpdate.kt | 159 -------- ...pdateWithDownloadAndUpdateAlwaysAllowed.kt | 64 ---- .../abstractions/AbstractClientTest.kt | 126 ------- .../abstractions/AbstractDeploymentTest.kt | 42 +-- .../abstractions/AbstractTest.kt | 6 +- .../api/management/ManagementApi.kt | 4 +- .../ddiclient/integrationtest/utils/Utils.kt | 160 +------- 15 files changed, 432 insertions(+), 563 deletions(-) rename src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/{HawkbitDownloadOnlyDeploymentTest.kt => DeploymentDownloadOnlyTest.kt} (82%) create mode 100644 src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/DeploymentForcedAndSoftTest.kt rename src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/{HawkbitTimeForcedTest.kt => DeploymentTimeForcedTest.kt} (85%) delete mode 100644 src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/SuccessfulForcedUpdate.kt delete mode 100644 src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/SuccessfulSoftUpdateWithDownloadAndUpdateAlwaysAllowed.kt delete mode 100644 src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/abstractions/AbstractClientTest.kt diff --git a/.gitignore b/.gitignore index df838c8..cb5cf14 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,5 @@ **/out/** local.properties -detekt-baseline.xml \ No newline at end of file +detekt-baseline.xml +gradle.properties \ No newline at end of file diff --git a/ddi-consumer/ddi-api/src/test/kotlin/org/eclipse/hara/ddi/api/model/SerializationTest.kt b/ddi-consumer/ddi-api/src/test/kotlin/org/eclipse/hara/ddi/api/model/SerializationTest.kt index cf4d914..ca378ee 100644 --- a/ddi-consumer/ddi-api/src/test/kotlin/org/eclipse/hara/ddi/api/model/SerializationTest.kt +++ b/ddi-consumer/ddi-api/src/test/kotlin/org/eclipse/hara/ddi/api/model/SerializationTest.kt @@ -22,7 +22,7 @@ class SerializationTest { @DataProvider(name = "Serialization") fun objectsToSerialize(): Array { val cfgDataReq = ConfigurationDataRequest.of(emptyMap(), ConfigurationDataRequest.Mode.merge) - return arrayOf(cfgDataReq.copy(data = mapOf("ciao" to "miao"))) + return arrayOf(cfgDataReq.copy(data = mapOf("foo" to "bar"))) } @Test(dataProvider = "Serialization") diff --git a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/DdiClientHttpRequestsTest.kt b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/DdiClientHttpRequestsTest.kt index e100108..0b17e8e 100644 --- a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/DdiClientHttpRequestsTest.kt +++ b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/DdiClientHttpRequestsTest.kt @@ -19,6 +19,7 @@ import org.eclipse.hara.ddiclient.api.MessageListener import org.eclipse.hara.ddiclient.api.MessageListener.Message.Event.Polling import org.eclipse.hara.ddiclient.api.MessageListener.Message.State.Idle import org.eclipse.hara.ddiclient.integrationtest.abstractions.AbstractHaraMessageTest +import org.eclipse.hara.ddiclient.integrationtest.api.management.HawkbitTargetInfo import org.eclipse.hara.ddiclient.integrationtest.api.management.ServerSystemConfig import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.basic @@ -33,7 +34,6 @@ import kotlin.time.Duration.Companion.seconds class DdiClientHttpRequestsTest : AbstractHaraMessageTest() { - override val targetId: String = "DoubleToken" private var expectedServerResponses = mutableListOf() override val expectedMessagesList: MutableList> by lazy { @@ -52,6 +52,7 @@ class DdiClientHttpRequestsTest : AbstractHaraMessageTest() { } companion object { + const val TARGET_ID = "DoubleToken" const val TEST_TARGET_SECURITY_TOKEN = "r2m3ixxc86a2v4q81wntpyhr78zy08we" } @@ -63,6 +64,15 @@ class DdiClientHttpRequestsTest : AbstractHaraMessageTest() { override fun beforeTest() { super.beforeTest() setPollingTime("00:00:05") + createTestTarget() + } + + private fun createTestTarget() { + runBlocking { + managementApi.createTarget( + basic, listOf(HawkbitTargetInfo(TARGET_ID, + securityToken = TEST_TARGET_SECURITY_TOKEN))) + } } @AfterClass @@ -95,7 +105,7 @@ class DdiClientHttpRequestsTest : AbstractHaraMessageTest() { return clientFromTargetId( okHttpClientBuilder = okHttpClient, targetToken = targetToken, - gatewayToken = gatewayToken).invoke(targetId) + gatewayToken = gatewayToken).invoke(TARGET_ID) } @Suppress("UNUSED_VARIABLE") diff --git a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/HawkbitDownloadOnlyDeploymentTest.kt b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/DeploymentDownloadOnlyTest.kt similarity index 82% rename from src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/HawkbitDownloadOnlyDeploymentTest.kt rename to src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/DeploymentDownloadOnlyTest.kt index 24ca619..2127a10 100644 --- a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/HawkbitDownloadOnlyDeploymentTest.kt +++ b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/DeploymentDownloadOnlyTest.kt @@ -18,16 +18,15 @@ import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.endMessagesOnSuccessUpdate import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.messagesOnSoftUpdateAuthorization import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.messagesOnSuccessfullyDownloadDistribution -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.targetRetrievedUpdateAction import org.testng.annotations.BeforeClass import org.testng.annotations.Test -class HawkbitDownloadOnlyDeploymentTest : AbstractDeploymentTest() { +class DeploymentDownloadOnlyTest : AbstractDeploymentTest() { private var actionId: Int = 0 - override val targetId: String = "DownloadOnlyTest" companion object { + const val TARGET_ID: String = "DownloadOnlyTest" const val DISTRIBUTION_ID = 3 } @@ -40,12 +39,12 @@ class HawkbitDownloadOnlyDeploymentTest : AbstractDeploymentTest() { @Test(enabled = true, timeOut = 60_000, priority = 14) fun testDownloadOnlyWhileWaitingForUpdateAuthorization() = runBlocking { - reCreateTestTargetOnServer() + reCreateTestTargetOnServer(TARGET_ID) assignDownloadOnlyDistribution() val client = createHaraClientWithAuthorizationPermissions( - downloadAllowed = false, updateAllowed = true) + TARGET_ID, downloadAllowed = false, updateAllowed = true) startTheTestAndWaitForResult(client, createTargetTestDeployment(expectedActionsAfterDownloadOnlyDeployment)) @@ -54,7 +53,7 @@ class HawkbitDownloadOnlyDeploymentTest : AbstractDeploymentTest() { private suspend fun assignDownloadOnlyDistribution() { val distribution = HawkbitAssignDistributionBody(DISTRIBUTION_ID, AssignDistributionType.DOWNLOAD_ONLY, 0) - actionId = assignDistributionToTheTarget(distribution) + actionId = assignDistributionToTheTarget(TARGET_ID, distribution) } private fun createTargetTestDeployment( @@ -64,12 +63,11 @@ class HawkbitDownloadOnlyDeploymentTest : AbstractDeploymentTest() { TestUtils.test1Artifact) to TestUtils.locationOfFileNamed("test1")) return TestUtils.TargetDeployments( - targetId = targetId, + targetId = TARGET_ID, targetToken = "", deploymentInfo = listOf( TestUtils.TargetDeployments.DeploymentInfo( actionId = actionId, - actionStatusOnStart = expectedActionOnStart, actionStatusOnFinish = actionsOnFinish, filesDownloadedPairedWithServerFile = filesDownloadedPairedToServerFile ) @@ -82,9 +80,8 @@ class HawkbitDownloadOnlyDeploymentTest : AbstractDeploymentTest() { *endMessagesOnSuccessUpdate, *messagesOnSoftUpdateAuthorization, *messagesOnSuccessfullyDownloadDistribution( - TestUtils.md5OfFileNamed("test1"), targetId, + TestUtils.md5OfFileNamed("test1"), TARGET_ID, "1", "test_1"), - targetRetrievedUpdateAction, - TestUtils.firstActionWithAssignmentEntry + *TestUtils.firstActionsOnTargetDeployment )) } \ No newline at end of file diff --git a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/DeploymentForcedAndSoftTest.kt b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/DeploymentForcedAndSoftTest.kt new file mode 100644 index 0000000..31bc1e6 --- /dev/null +++ b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/DeploymentForcedAndSoftTest.kt @@ -0,0 +1,347 @@ +/* + * Copyright © 2017-2024 Kynetics LLC + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.hara.ddiclient.integrationtest + +import kotlinx.coroutines.runBlocking +import org.eclipse.hara.ddiclient.integrationtest.abstractions.AbstractDeploymentTest +import org.eclipse.hara.ddiclient.integrationtest.api.management.ActionStatus +import org.eclipse.hara.ddiclient.integrationtest.api.management.AssignDistributionType +import org.eclipse.hara.ddiclient.integrationtest.api.management.HawkbitAssignDistributionBody +import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils +import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.endMessagesOnSuccessUpdate +import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.md5OfFileNamed +import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.pathResolver +import org.eclipse.hara.ddiclient.integrationtest.utils.logCurrentFunctionName +import org.testng.annotations.BeforeClass +import org.testng.annotations.Test + +class DeploymentForcedAndSoftTest : AbstractDeploymentTest() { + + private val cancellingTestTargetId = "CancelActionTest" + private val osOnlyTestTargetId = "OsOnlySoftwareModuleTest" + private val osWithAppsForcedUpdateTestTargetId = "OsWithAppsForcedUpdateTest" + private val osWithAppsSoftUpdateTestTargetId = "OsWithAppsSoftUpdateTest" + + @BeforeClass + override fun beforeTest() { + super.beforeTest() + setPollingTime("00:00:10") + } + + @Test(enabled = true, timeOut = 30_000, priority = 30) + private fun testDeployingNewUpdateCancelsTheCurrentActiveOne() { + logCurrentFunctionName() + + runBlocking { + reCreateTestTargetOnServer(cancellingTestTargetId) + + val client = createHaraClientWithAuthorizationPermissions( + cancellingTestTargetId, downloadAllowed = true, updateAllowed = true) + + val deploymentsInfo = mutableListOf() + + val deployment = TestUtils.TargetDeployments( + targetId = cancellingTestTargetId, + targetToken = "", + deploymentInfo = deploymentsInfo + ) + + val actionId = assignCancellingDistributionToTheTarget() + + val cancelDeploymentInfo = getCancellingDeploymentInfo(actionId) + + deploymentsInfo.add(cancelDeploymentInfo) + + val updateDeploymentInfo = + getSuccessfulUpdateDeploymentInfoAfterCancelling(actionId) + + deploymentsInfo.add(updateDeploymentInfo) + + assignSuccessfulUpdateDistributionToTheTarget() + + startTheTestAndWaitForResult(client, deployment) + } + } + + private suspend fun assignSuccessfulUpdateDistributionToTheTarget() { + val distribution = HawkbitAssignDistributionBody( + TestUtils.APP_DISTRIBUTION_ID, AssignDistributionType.FORCED, 0) + assignDistributionToTheTarget(cancellingTestTargetId, distribution) + } + + private suspend fun assignCancellingDistributionToTheTarget(): Int { + val distribution = HawkbitAssignDistributionBody( + TestUtils.OS_DISTRIBUTION_ID, AssignDistributionType.FORCED, 0) + return assignDistributionToTheTarget(cancellingTestTargetId, distribution) + } + + private fun getCancellingDeploymentInfo( + actionId: Int): TestUtils.TargetDeployments.DeploymentInfo { + val contentEntriesOnFinish = ActionStatus( + setOf( + ActionStatus.ContentEntry( + ActionStatus.ContentEntry.Type.canceled, + listOf( + "Update Server: Cancellation confirmed.", + "Update Server: Cancellation completion is finished sucessfully." + ) + ), + ActionStatus.ContentEntry( + ActionStatus.ContentEntry.Type.retrieved, + listOf( + "Update Server: Target retrieved cancel action and should start now the cancellation.") + ), + ActionStatus.ContentEntry( + ActionStatus.ContentEntry.Type.canceling, + listOf("Update Server: cancel obsolete action due to new update") + ), + TestUtils.firstActionWithAssignmentEntry + ) + ) + + return TestUtils.TargetDeployments.DeploymentInfo( + actionId = actionId, + actionStatusOnFinish = contentEntriesOnFinish, + filesDownloadedPairedWithServerFile = emptySet() + ) + } + + private fun getSuccessfulUpdateDeploymentInfoAfterCancelling( + lastActionId: Int): TestUtils.TargetDeployments.DeploymentInfo { + val contentEntriesOnFinish = ActionStatus( + setOf( + *endMessagesOnSuccessUpdate, + *TestUtils.messagesOnSuccessfullyDownloadDistribution( + md5OfFileNamed("test1"), cancellingTestTargetId, + "1", "test_1"), + *TestUtils.firstActionsOnTargetDeployment + ) + ) + + return TestUtils.TargetDeployments.DeploymentInfo( + actionId = lastActionId + 1, + actionStatusOnFinish = contentEntriesOnFinish, + filesDownloadedPairedWithServerFile = emptySet() + ) + } + + + @Test(enabled = true, timeOut = 30_000, priority = 31) + private fun testOsOnlySoftwareModuleUpdate() { + logCurrentFunctionName() + + runBlocking { + reCreateTestTargetOnServer(osOnlyTestTargetId) + + val client = createHaraClientWithAuthorizationPermissions( + osOnlyTestTargetId, downloadAllowed = true, updateAllowed = true) + + val distribution = HawkbitAssignDistributionBody( + TestUtils.OS_DISTRIBUTION_ID, AssignDistributionType.FORCED, 0) + val actionId = assignDistributionToTheTarget(osOnlyTestTargetId, distribution) + + val contentEntriesOnFinish = ActionStatus( + setOf( + *endMessagesOnSuccessUpdate, + *TestUtils.messagesOnSuccessfullyDownloadDistribution( + md5OfFileNamed("test4"), osOnlyTestTargetId, + "3", "test_4"), + *TestUtils.firstActionsOnTargetDeployment + ) + ) + + val filesDownloadedPairedToServerFile = setOf( + pathResolver.fromArtifact(actionId.toString()) + .invoke(TestUtils.test4Artifact) to TestUtils.locationOfFileNamed( + "test4")) + + val deployment = TestUtils.TargetDeployments( + targetId = osOnlyTestTargetId, + targetToken = "0fe7b8c9de2102ec6bf305b6f66df5b2", + deploymentInfo = listOf(TestUtils.TargetDeployments.DeploymentInfo( + actionId = actionId, + actionStatusOnFinish = contentEntriesOnFinish, + filesDownloadedPairedWithServerFile = filesDownloadedPairedToServerFile + + )) + ) + + startTheTestAndWaitForResult(client, deployment) + } + } + + + @Test(enabled = true, timeOut = 30_000, priority = 32) + private fun testOsWithAppsSoftwareModuleUpdate() { + logCurrentFunctionName() + + runBlocking { + reCreateTestTargetOnServer(osWithAppsForcedUpdateTestTargetId) + + val client = createHaraClientWithAuthorizationPermissions( + osWithAppsForcedUpdateTestTargetId, downloadAllowed = true, + updateAllowed = true) + + val distribution = HawkbitAssignDistributionBody( + TestUtils.OS_WITH_APPS_DISTRIBUTION_ID, AssignDistributionType.FORCED, 0) + val actionId = + assignDistributionToTheTarget(osWithAppsForcedUpdateTestTargetId, distribution) + + val contentEntriesOnFinish = ActionStatus( + setOf( + *endMessagesOnSuccessUpdate, + *messagesOnSuccessfullyDownloadOsWithAppDistribution( + osWithAppsForcedUpdateTestTargetId), + *TestUtils.firstActionsOnTargetDeployment + ) + ) + + val deployment = TestUtils.TargetDeployments( + targetId = osWithAppsForcedUpdateTestTargetId, + targetToken = "4a28d893bb841def706073c789c0f3a7", + deploymentInfo = listOf(TestUtils.TargetDeployments.DeploymentInfo( + actionId = actionId, + actionStatusOnFinish = contentEntriesOnFinish, + filesDownloadedPairedWithServerFile = filesDownloadedInOsWithAppsPairedToServerFile( + actionId) + + )) + ) + + startTheTestAndWaitForResult(client, deployment) + } + } + + @Test(enabled = true, timeOut = 30_000, priority = 33) + private fun testOsWithAppsSoftUpdate() { + logCurrentFunctionName() + + runBlocking { + reCreateTestTargetOnServer(osWithAppsSoftUpdateTestTargetId) + + val client = createHaraClientWithAuthorizationPermissions( + osWithAppsSoftUpdateTestTargetId, downloadAllowed = true, updateAllowed = true) + + val distribution = HawkbitAssignDistributionBody( + TestUtils.OS_WITH_APPS_DISTRIBUTION_ID, AssignDistributionType.SOFT, 0) + val actionId = + assignDistributionToTheTarget(osWithAppsSoftUpdateTestTargetId, distribution) + + val contentEntriesOnFinish = ActionStatus( + setOf( + *endMessagesOnSuccessUpdate, + *TestUtils.messagesOnSoftUpdateAuthorization, + *messagesOnSuccessfullyDownloadOsWithAppDistribution( + osWithAppsSoftUpdateTestTargetId), + *TestUtils.messagesOnSoftDownloadAuthorization, + *TestUtils.firstActionsOnTargetDeployment + ) + ) + + val deployment = TestUtils.TargetDeployments( + targetId = osWithAppsSoftUpdateTestTargetId, + targetToken = "", + deploymentInfo = listOf( + TestUtils.TargetDeployments.DeploymentInfo( + actionId = actionId, + actionStatusOnFinish = contentEntriesOnFinish, + filesDownloadedPairedWithServerFile = + filesDownloadedInOsWithAppsPairedToServerFile(actionId) + + )) + ) + + startTheTestAndWaitForResult(client, deployment) + } + } + + private fun messagesOnSuccessfullyDownloadOsWithAppDistribution(target: String) = arrayOf( + ActionStatus.ContentEntry( + ActionStatus.ContentEntry.Type.running, + listOf("Successfully downloaded all files") + ), + ActionStatus.ContentEntry( + ActionStatus.ContentEntry.Type.running, + listOf( + "Successfully downloaded file with md5 ${ + md5OfFileNamed( + "test1" + ) + }" + ) + ), + ActionStatus.ContentEntry( + ActionStatus.ContentEntry.Type.running, + listOf( + "Successfully downloaded file with md5 ${ + md5OfFileNamed( + "test2" + ) + }" + ) + ), + ActionStatus.ContentEntry( + ActionStatus.ContentEntry.Type.running, + listOf( + "Successfully downloaded file with md5 ${ + md5OfFileNamed( + "test3" + ) + }" + ) + ), + ActionStatus.ContentEntry( + ActionStatus.ContentEntry.Type.running, + listOf( + "Successfully downloaded file with md5 ${ + md5OfFileNamed( + "test4" + ) + }" + ) + ), + ActionStatus.ContentEntry( + ActionStatus.ContentEntry.Type.download, + listOf("Update Server: Target downloads /${TestUtils.tenantNameToLower}/controller/v1/$target/softwaremodules/2/artifacts/test_2") + ), + ActionStatus.ContentEntry( + ActionStatus.ContentEntry.Type.download, + listOf("Update Server: Target downloads /${TestUtils.tenantNameToLower}/controller/v1/$target/softwaremodules/2/artifacts/test_3") + ), + ActionStatus.ContentEntry( + ActionStatus.ContentEntry.Type.download, + listOf("Update Server: Target downloads /${TestUtils.tenantNameToLower}/controller/v1/$target/softwaremodules/1/artifacts/test_1") + ), + ActionStatus.ContentEntry( + ActionStatus.ContentEntry.Type.download, + listOf("Update Server: Target downloads /${TestUtils.tenantNameToLower}/controller/v1/$target/softwaremodules/3/artifacts/test_4") + ), + ActionStatus.ContentEntry( + ActionStatus.ContentEntry.Type.running, + listOf("Start downloading 4 files") + ) + ) + + + private fun filesDownloadedInOsWithAppsPairedToServerFile(action: Int) = setOf( + pathResolver.fromArtifact(action.toString()).invoke( + TestUtils.test1Artifact + ) to TestUtils.locationOfFileNamed("test1"), + pathResolver.fromArtifact(action.toString()).invoke( + TestUtils.test2Artifact + ) to TestUtils.locationOfFileNamed("test2"), + pathResolver.fromArtifact(action.toString()).invoke( + TestUtils.test3Artifact + ) to TestUtils.locationOfFileNamed("test3"), + pathResolver.fromArtifact(action.toString()).invoke( + TestUtils.test4Artifact + ) to TestUtils.locationOfFileNamed("test4"), + ) +} diff --git a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/HawkbitTimeForcedTest.kt b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/DeploymentTimeForcedTest.kt similarity index 85% rename from src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/HawkbitTimeForcedTest.kt rename to src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/DeploymentTimeForcedTest.kt index f0bb11b..f806e99 100644 --- a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/HawkbitTimeForcedTest.kt +++ b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/DeploymentTimeForcedTest.kt @@ -16,7 +16,6 @@ import org.eclipse.hara.ddiclient.integrationtest.api.management.AssignDistribut import org.eclipse.hara.ddiclient.integrationtest.api.management.HawkbitAssignDistributionBody import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.endMessagesOnSuccessUpdate -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.firstActionWithAssignmentEntry import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.messagesOnSoftDownloadAuthorization import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.waitingForDownloadAuthorizationMessage import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.waitingForUpdateAuthorizationMessage @@ -24,12 +23,12 @@ import org.testng.annotations.BeforeClass import org.testng.annotations.Test import kotlin.time.Duration.Companion.seconds -class HawkbitTimeForcedTest : AbstractDeploymentTest() { +class DeploymentTimeForcedTest : AbstractDeploymentTest() { private var actionId: Int = 0 - override val targetId: String = "TimeForceTest" companion object { + const val TARGET_ID: String = "TimeForceTest" const val DISTRIBUTION_ID = 3 } @@ -41,12 +40,12 @@ class HawkbitTimeForcedTest : AbstractDeploymentTest() { @Test(enabled = true, timeOut = 150_000, priority = 12) fun testTimeForcedUpdateWhileWaitingForDownloadAuthorization() = runBlocking { - reCreateTestTargetOnServer() + reCreateTestTargetOnServer(TARGET_ID) assignTimeForcedDistributionToTheTarget() val client = createHaraClientWithAuthorizationPermissions( - downloadAllowed = false, updateAllowed = false) + TARGET_ID, downloadAllowed = false, updateAllowed = false) val deployment = createTargetTestDeployment(testingForUpdateAuthorization = false) @@ -56,12 +55,12 @@ class HawkbitTimeForcedTest : AbstractDeploymentTest() { @Test(enabled = true, timeOut = 150_000, priority = 13) fun testTimeForcedUpdateWhileWaitingForUpdateAuthorization() = runBlocking { - reCreateTestTargetOnServer() + reCreateTestTargetOnServer(TARGET_ID) assignTimeForcedDistributionToTheTarget() val client = createHaraClientWithAuthorizationPermissions( - downloadAllowed = true, updateAllowed = false) + TARGET_ID, downloadAllowed = true, updateAllowed = false) val deployment = createTargetTestDeployment(testingForUpdateAuthorization = true) @@ -77,12 +76,11 @@ class HawkbitTimeForcedTest : AbstractDeploymentTest() { return TestUtils.TargetDeployments( - targetId = targetId, + targetId = TARGET_ID, targetToken = "", deploymentInfo = listOf( TestUtils.TargetDeployments.DeploymentInfo( actionId = actionId, - actionStatusOnStart = expectedActionOnStart, actionStatusOnFinish = getExpectedActionsAfterTimeForceDeployment( testingForUpdateAuthorization), filesDownloadedPairedWithServerFile = @@ -105,11 +103,10 @@ class HawkbitTimeForcedTest : AbstractDeploymentTest() { return ActionStatus(setOf( *endMessagesOnSuccessUpdate, *TestUtils.messagesOnSuccessfullyDownloadDistribution( - TestUtils.md5OfFileNamed("test1"), targetId, + TestUtils.md5OfFileNamed("test1"), TARGET_ID, "1", "test_1"), *authorizationMessage, - TestUtils.targetRetrievedUpdateAction, - firstActionWithAssignmentEntry, + *TestUtils.firstActionsOnTargetDeployment )) } @@ -118,6 +115,6 @@ class HawkbitTimeForcedTest : AbstractDeploymentTest() { val distribution = HawkbitAssignDistributionBody( DISTRIBUTION_ID, AssignDistributionType.TIME_FORCED, System.currentTimeMillis() + timeForcedTime) - actionId = assignDistributionToTheTarget(distribution) + actionId = assignDistributionToTheTarget(TARGET_ID, distribution) } } \ No newline at end of file diff --git a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/ForcePingTest.kt b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/ForcePingTest.kt index 9866107..c5575d8 100644 --- a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/ForcePingTest.kt +++ b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/ForcePingTest.kt @@ -32,15 +32,16 @@ import kotlin.time.Duration.Companion.seconds class ForcePingTest : AbstractHaraMessageTest() { - override val targetId: String = "forcePingTest" - + companion object { + const val TARGET_ID = "forcePingTest" + } @BeforeClass override fun beforeTest() { super.beforeTest() setPollingTime("00:00:30") runBlocking { - reCreateTestTargetOnServer() + reCreateTestTargetOnServer(TARGET_ID) } } @@ -59,7 +60,7 @@ class ForcePingTest : AbstractHaraMessageTest() { logCurrentFunctionName() runBlocking { - client = clientFromTargetId().invoke(targetId) + client = clientFromTargetId().invoke(TARGET_ID) expectMessages( Polling, @@ -82,7 +83,7 @@ class ForcePingTest : AbstractHaraMessageTest() { runBlocking { setPollingTime("00:00:30") - client = clientFromTargetId().invoke(targetId) + client = clientFromTargetId().invoke(TARGET_ID) expectMessages( Polling, @@ -114,7 +115,7 @@ class ForcePingTest : AbstractHaraMessageTest() { logCurrentFunctionName() runBlocking { - client = clientFromTargetId().invoke(targetId) + client = clientFromTargetId().invoke(TARGET_ID) expectMessages( Polling, @@ -144,7 +145,7 @@ class ForcePingTest : AbstractHaraMessageTest() { } client = clientFromTargetId(deploymentPermitProvider = deploymentBehavior).invoke( - targetId) + TARGET_ID) expectMessages( Polling, @@ -161,7 +162,7 @@ class ForcePingTest : AbstractHaraMessageTest() { } delay(3.seconds) - assignDistributionToTheTarget( + assignDistributionToTheTarget(TARGET_ID, HawkbitAssignDistributionBody(3, AssignDistributionType.SOFT, 0)) delay(2.seconds) diff --git a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/PingBackoffStrategyTest.kt b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/PingBackoffStrategyTest.kt index 721f14d..dd7dae2 100644 --- a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/PingBackoffStrategyTest.kt +++ b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/PingBackoffStrategyTest.kt @@ -41,9 +41,12 @@ import kotlin.coroutines.cancellation.CancellationException class PingBackoffStrategyTest : AbstractHaraMessageTest() { - override val targetId: String = "PingTimeOutTest" private val testScope = CoroutineScope(Dispatchers.Default) + companion object { + const val TARGET_ID = "PingTimeOutTest" + } + private val expectedTestDuration = Channel(5, BufferOverflow.DROP_OLDEST) private var durationCheckJob: Deferred? = null @@ -77,7 +80,7 @@ class PingBackoffStrategyTest : AbstractHaraMessageTest() { .addInterceptor(TimeoutInterceptor()) .addOkhttpLogger() - client = clientFromTargetId(okHttpClientBuilder = okHttpBuilder).invoke(targetId) + client = clientFromTargetId(okHttpClientBuilder = okHttpBuilder).invoke(TARGET_ID) expectMessages( Polling, @@ -106,7 +109,7 @@ class PingBackoffStrategyTest : AbstractHaraMessageTest() { .addInterceptor(ConnectionLostInterceptor()) .addOkhttpLogger() - client = clientFromTargetId(okHttpClientBuilder = okHttpBuilder).invoke(targetId) + client = clientFromTargetId(okHttpClientBuilder = okHttpBuilder).invoke(TARGET_ID) expectMessages( Polling, diff --git a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/SuccessfulForcedUpdate.kt b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/SuccessfulForcedUpdate.kt deleted file mode 100644 index 1a196f5..0000000 --- a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/SuccessfulForcedUpdate.kt +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright © 2017-2024 Kynetics LLC - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.hara.ddiclient.integrationtest - -import org.eclipse.hara.ddiclient.integrationtest.abstractions.AbstractClientTest -import org.eclipse.hara.ddiclient.integrationtest.api.management.ActionStatus -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.defaultActionStatusOnStart -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.endMessagesOnSuccessUpdate -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.filesDownloadedInOsWithAppsPairedToServerFile -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.firstActionEntry -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.locationOfFileNamed -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.messagesOnSuccefullyDownloadAppDistribution -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.messagesOnSuccefullyDownloadOsDistribution -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.messagesOnSuccessfullyDownloadOsWithAppDistribution -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.pathResolver -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.startMessagesOnUpdateFond -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.test1Artifact -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.test4Artifact -import org.testng.annotations.DataProvider -import org.testng.annotations.Test - -class SuccessfulForcedUpdate : AbstractClientTest() { - - @DataProvider(name = "targetUpdateProvider") - fun dataProvider(): Array { - return arrayOf(target1AcceptFirstCancelRequestThenApplyAppUpdate(), - target2ApplyOsUpdate(), - target3ApplyOsWithAppsUpdate()) - } - - @Test(enabled = true, dataProvider = "targetUpdateProvider") - fun test(targetDeployments: TestUtils.TargetDeployments) { - testTemplate(targetDeployments) - } - - private fun target1AcceptFirstCancelRequestThenApplyAppUpdate(): TestUtils.TargetDeployments { - val targetId = "target1" - val contentEntriesOnFinish2 = ActionStatus( - setOf( - *endMessagesOnSuccessUpdate, - *messagesOnSuccefullyDownloadAppDistribution(targetId), - *startMessagesOnUpdateFond - ) - ) - - val actionStatusOnStart1 = ActionStatus( - setOf( - ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.canceling, - listOf("Update Server: cancel obsolete action due to new update") - ), - firstActionEntry - ) - ) - - val contentEntriesOnFinish1 = ActionStatus( - setOf( - ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.canceled, - listOf( - "Update Server: Cancellation confirmed.", - "Update Server: Cancellation completion is finished sucessfully." - ) - ), - ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.retrieved, - listOf("Update Server: Target retrieved cancel action and should start now the cancellation.") - ), - ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.canceling, - listOf("Update Server: cancel obsolete action due to new update") - ), - firstActionEntry - ) - ) - - val filesDownloadedPairedToServerFile = setOf(pathResolver.fromArtifact("2").invoke(test1Artifact) to locationOfFileNamed("test1")) - - return TestUtils.TargetDeployments( - targetId = targetId, - targetToken = "4a28d893bb841def706073c789c0f3a7", - deploymentInfo = listOf( - TestUtils.TargetDeployments.DeploymentInfo( - actionId = 1, - actionStatusOnStart = actionStatusOnStart1, - actionStatusOnFinish = contentEntriesOnFinish1, - filesDownloadedPairedWithServerFile = emptySet() - ), - TestUtils.TargetDeployments.DeploymentInfo( - actionId = 2, - actionStatusOnStart = defaultActionStatusOnStart, - actionStatusOnFinish = contentEntriesOnFinish2, - filesDownloadedPairedWithServerFile = filesDownloadedPairedToServerFile - ) - ) - ) - } - - private fun target2ApplyOsUpdate(): TestUtils.TargetDeployments { - val targetId = "target2" - - val contentEntriesOnFinish = ActionStatus( - setOf( - *endMessagesOnSuccessUpdate, - *messagesOnSuccefullyDownloadOsDistribution(targetId), - *startMessagesOnUpdateFond - ) - ) - - val filesDownloadedPairedToServerFile = setOf(pathResolver.fromArtifact("3").invoke(test4Artifact) to locationOfFileNamed("test4")) - - return TestUtils.TargetDeployments( - targetId = targetId, - targetToken = "0fe7b8c9de2102ec6bf305b6f66df5b2", - deploymentInfo = listOf( - TestUtils.TargetDeployments.DeploymentInfo( - actionId = 3, - actionStatusOnStart = defaultActionStatusOnStart, - actionStatusOnFinish = contentEntriesOnFinish, - filesDownloadedPairedWithServerFile = filesDownloadedPairedToServerFile - - ) - ) - ) - } - - private fun target3ApplyOsWithAppsUpdate(): TestUtils.TargetDeployments { - val targetId = "target3" - val actionId = 4 - val contentEntriesOnFinish = ActionStatus( - setOf( - *endMessagesOnSuccessUpdate, - *messagesOnSuccessfullyDownloadOsWithAppDistribution(targetId), - *startMessagesOnUpdateFond - ) - ) - return TestUtils.TargetDeployments( - targetId = targetId, - targetToken = "4a28d893bb841def706073c789c0f3a7", - deploymentInfo = listOf( - TestUtils.TargetDeployments.DeploymentInfo( - actionId = actionId, - actionStatusOnStart = defaultActionStatusOnStart, - actionStatusOnFinish = contentEntriesOnFinish, - filesDownloadedPairedWithServerFile = filesDownloadedInOsWithAppsPairedToServerFile(actionId) - - ) - ) - ) - } -} diff --git a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/SuccessfulSoftUpdateWithDownloadAndUpdateAlwaysAllowed.kt b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/SuccessfulSoftUpdateWithDownloadAndUpdateAlwaysAllowed.kt deleted file mode 100644 index 6e781ff..0000000 --- a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/SuccessfulSoftUpdateWithDownloadAndUpdateAlwaysAllowed.kt +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright © 2017-2024 Kynetics LLC - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - */ - -package org.eclipse.hara.ddiclient.integrationtest - -import org.eclipse.hara.ddiclient.integrationtest.abstractions.AbstractClientTest -import org.eclipse.hara.ddiclient.integrationtest.api.management.ActionStatus -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.defaultActionStatusOnStart -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.endMessagesOnSuccessUpdate -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.filesDownloadedInOsWithAppsPairedToServerFile -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.messagesOnSoftDownloadAuthorization -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.messagesOnSoftUpdateAuthorization -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.messagesOnSuccessfullyDownloadOsWithAppDistribution -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.startMessagesOnUpdateFond -import org.testng.annotations.DataProvider -import org.testng.annotations.Test - -class SuccessfulSoftUpdateWithDownloadAndUpdateAlwaysAllowed : AbstractClientTest() { - - @DataProvider(name = "targetUpdateProvider") - fun dataProvider(): Array { - return arrayOf(target4ApplyOsWithAppsUpdate()) - } - - @Test(enabled = true, dataProvider = "targetUpdateProvider") - fun test(targetDeployments: TestUtils.TargetDeployments) { - testTemplate(targetDeployments) - } - - private fun target4ApplyOsWithAppsUpdate(): TestUtils.TargetDeployments { - val targetId = "Target4" - val actionId = 5 - val contentEntriesOnFinish = ActionStatus( - setOf( - *endMessagesOnSuccessUpdate, - *messagesOnSoftUpdateAuthorization, - *messagesOnSuccessfullyDownloadOsWithAppDistribution(targetId), - *messagesOnSoftDownloadAuthorization, - *startMessagesOnUpdateFond - ) - ) - return TestUtils.TargetDeployments( - targetId = targetId, - targetToken = "", - deploymentInfo = listOf( - TestUtils.TargetDeployments.DeploymentInfo( - actionId = actionId, - actionStatusOnStart = defaultActionStatusOnStart, - actionStatusOnFinish = contentEntriesOnFinish, - filesDownloadedPairedWithServerFile = filesDownloadedInOsWithAppsPairedToServerFile(actionId) - - ) - ) - ) - } -} diff --git a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/abstractions/AbstractClientTest.kt b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/abstractions/AbstractClientTest.kt deleted file mode 100644 index fb89fb9..0000000 --- a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/abstractions/AbstractClientTest.kt +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright © 2017-2024 Kynetics LLC - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - */ - -package org.eclipse.hara.ddiclient.integrationtest.abstractions - -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.basic -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.gatewayToken -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.getDownloadDirectoryFromActionId -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.tenantName -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.hawkbitUrl -import kotlinx.coroutines.delay -import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking -import kotlinx.coroutines.withTimeout -import okhttp3.OkHttpClient -import org.eclipse.hara.ddiclient.api.* -import org.eclipse.hara.ddiclient.integrationtest.api.management.Action -import org.eclipse.hara.ddiclient.integrationtest.api.management.ManagementClient -import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils -import org.eclipse.hara.ddiclient.integrationtest.utils.addOkhttpLogger -import org.joda.time.Duration -import org.testng.Assert -import java.io.File -import java.util.LinkedList - -abstract class AbstractClientTest { - - protected var client: HaraClient? = null - - private val queue = LinkedList<() -> Unit >() - - protected open fun defaultClientFromTargetId( - directoryDataProvider: DirectoryForArtifactsProvider = TestUtils.directoryDataProvider, - configDataProvider: ConfigDataProvider = TestUtils.configDataProvider, - updater: Updater = TestUtils.updater, - messageListeners: List = emptyList(), - deploymentPermitProvider: DeploymentPermitProvider = object : DeploymentPermitProvider {}, - downloadBehavior: DownloadBehavior = TestUtils.downloadBehavior - ): (String) -> HaraClient = { targetId -> - val clientData = HaraClientData( - tenantName, - targetId, - hawkbitUrl, - gatewayToken) - - val client = HaraClientDefaultImpl() - - val eventListener = object : MessageListener { - override fun onMessage(message: MessageListener.Message) { - when (message) { - - is MessageListener.Message.Event.UpdateFinished, MessageListener.Message.State.CancellingUpdate -> { - queue.poll().invoke() - } - - else -> { println(message) } - } - } - } - - client.init( - clientData, - directoryDataProvider, - configDataProvider, - deploymentPermitProvider, - listOf(eventListener, *messageListeners.toTypedArray()), - listOf(updater), - downloadBehavior, - httpBuilder = OkHttpClient.Builder().addOkhttpLogger() - ) - client - } - - // todo refactor test - protected fun testTemplate( - deployment: TestUtils.TargetDeployments, - timeout: Long = Duration.standardSeconds(15).millis, - clientFromTargetId: (String) -> HaraClient = defaultClientFromTargetId() - ) = runBlocking { - - withTimeout(timeout) { - client = clientFromTargetId(deployment.targetId) - val managementApi = ManagementClient.newInstance(hawkbitUrl) - - deployment.deploymentInfo.forEach { deploymentInfo -> - - var actionStatus = managementApi.getTargetActionStatusAsync(basic, deployment.targetId, deploymentInfo.actionId) - - Assert.assertEquals(actionStatus, deploymentInfo.actionStatusOnStart) - - queue.add { - launch { - while(managementApi.getActionAsync(basic, deployment.targetId, deploymentInfo.actionId) - .status != Action.Status.finished - ) { - delay(100) - } - actionStatus = managementApi.getTargetActionStatusAsync(basic, deployment.targetId, deploymentInfo.actionId) - - Assert.assertEquals(actionStatus.content, deploymentInfo.actionStatusOnFinish.content) - - deploymentInfo.filesDownloadedPairedWithServerFile.forEach { (fileDownloaded, serverFile) -> - println(File(fileDownloaded).absolutePath) - println(File(serverFile).absolutePath) - Assert.assertEquals(File(fileDownloaded).readText(), File(serverFile).readText()) - } - - getDownloadDirectoryFromActionId(deploymentInfo.actionId.toString()).deleteRecursively() - } - } - } - client?.startAsync() - launch { - while (queue.isNotEmpty()) { - delay(500) } - } - } - } -} diff --git a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/abstractions/AbstractDeploymentTest.kt b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/abstractions/AbstractDeploymentTest.kt index feb3d72..9b6861e 100644 --- a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/abstractions/AbstractDeploymentTest.kt +++ b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/abstractions/AbstractDeploymentTest.kt @@ -30,7 +30,6 @@ import org.eclipse.hara.ddiclient.api.HaraClientDefaultImpl import org.eclipse.hara.ddiclient.api.MessageListener import org.eclipse.hara.ddiclient.api.Updater import org.eclipse.hara.ddiclient.integrationtest.api.management.Action -import org.eclipse.hara.ddiclient.integrationtest.api.management.ActionStatus import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils import org.eclipse.hara.ddiclient.integrationtest.utils.addOkhttpLogger import org.eclipse.hara.ddiclient.integrationtest.utils.internalLog @@ -39,7 +38,7 @@ import java.io.File import kotlin.coroutines.cancellation.CancellationException import kotlin.time.Duration.Companion.seconds -abstract class AbstractDeploymentTest: AbstractTest() { +abstract class AbstractDeploymentTest : AbstractTest() { private var assertServerActionsScope = CoroutineScope(Dispatchers.IO) private var assertServerActionsOnCompleteJob: Deferred? = null @@ -102,6 +101,7 @@ abstract class AbstractDeploymentTest: AbstractTest() { } protected fun createHaraClientWithAuthorizationPermissions( + targetId: String, downloadAllowed: Boolean = true, updateAllowed: Boolean = true): HaraClient { @@ -129,31 +129,31 @@ abstract class AbstractDeploymentTest: AbstractTest() { client: HaraClient, deployment: TestUtils.TargetDeployments): Deferred { return assertServerActionsScope.async(start = CoroutineStart.LAZY) { - val deploymentInfo = deployment.deploymentInfo.first() - while (managementApi.getActionAsync(TestUtils.basic, deployment.targetId, - deploymentInfo.actionId).status != Action.Status.finished - ) { - delay(5.seconds) - } + deployment.deploymentInfo.forEach { deploymentInfo -> - val actionStatus = - managementApi.getTargetActionStatusAsync(TestUtils.basic, deployment.targetId, - deploymentInfo.actionId) - assertEquals(actionStatus.content, - deploymentInfo.actionStatusOnFinish.content) + while (managementApi.getActionAsync(TestUtils.basic, deployment.targetId, + deploymentInfo.actionId).status != Action.Status.finished + ) { + delay(5.seconds) + } + + val actionStatus = + managementApi.getTargetActionStatusAsync(TestUtils.basic, + deployment.targetId, + deploymentInfo.actionId) + assertEquals(actionStatus.content, + deploymentInfo.actionStatusOnFinish.content) + + deploymentInfo.filesDownloadedPairedWithServerFile.forEach { (fileDownloaded, serverFile) -> + assertEquals(File(fileDownloaded).readText(), + File(serverFile).readText()) + File(fileDownloaded).deleteRecursively() + } - deploymentInfo.filesDownloadedPairedWithServerFile.forEach { (fileDownloaded, serverFile) -> - assertEquals(File(fileDownloaded).readText(), - File(serverFile).readText()) - File(fileDownloaded).deleteRecursively() } client.safeStopClient() } } - protected val expectedActionOnStart = ActionStatus(setOf( - TestUtils.firstActionWithAssignmentEntry - )) - } \ No newline at end of file diff --git a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/abstractions/AbstractTest.kt b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/abstractions/AbstractTest.kt index 28739a3..cfe68d6 100644 --- a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/abstractions/AbstractTest.kt +++ b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/abstractions/AbstractTest.kt @@ -43,9 +43,8 @@ import kotlin.coroutines.cancellation.CancellationException abstract class AbstractTest { protected lateinit var managementApi: ManagementApi - abstract val targetId: String - protected val throwableScope = CoroutineScope(Dispatchers.Default) + private val throwableScope = CoroutineScope(Dispatchers.Default) private var throwableJob: Deferred? = null @@ -70,7 +69,7 @@ abstract class AbstractTest { managementApi.setPollingTime(TestUtils.basic, ServerSystemConfig(time)) } - protected suspend fun reCreateTestTargetOnServer() { + protected suspend fun reCreateTestTargetOnServer(targetId: String) { runCatching { managementApi.deleteTarget(TestUtils.basic, targetId) } @@ -81,6 +80,7 @@ abstract class AbstractTest { } protected suspend fun assignDistributionToTheTarget( + targetId: String, distribution: HawkbitAssignDistributionBody): Int { val response = managementApi.assignDistributionToTarget(TestUtils.basic, diff --git a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/api/management/ManagementApi.kt b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/api/management/ManagementApi.kt index 50db2b8..13bf660 100644 --- a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/api/management/ManagementApi.kt +++ b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/api/management/ManagementApi.kt @@ -83,7 +83,7 @@ interface ManagementApi { suspend fun createTarget( @Header("Authorization") auth: String, @Body body: List - ): HawkbitTargetInfo + ): List } object ManagementClient { @@ -132,7 +132,7 @@ object ManagementClient { } override suspend fun createTarget(auth: String, - body: List): HawkbitTargetInfo { + body: List): List { return delegate.createTarget(auth, body) } } diff --git a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/utils/Utils.kt b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/utils/Utils.kt index 3cd4f98..790899f 100644 --- a/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/utils/Utils.kt +++ b/src/test/kotlin/org/eclipse/hara/ddiclient/integrationtest/utils/Utils.kt @@ -30,6 +30,10 @@ val LOG_INTERNAL: Boolean = System.getProperty("LOG_INTERNAL", "false").toBoolea */ object TestUtils { + const val APP_DISTRIBUTION_ID = 3 + const val OS_DISTRIBUTION_ID = 2 + const val OS_WITH_APPS_DISTRIBUTION_ID = 1 + data class TargetDeployments( val targetId: String, val targetToken: String, @@ -37,19 +41,17 @@ object TestUtils { ) { data class DeploymentInfo( val actionId: Int, - val actionStatusOnStart: ActionStatus, val actionStatusOnFinish: ActionStatus, val filesDownloadedPairedWithServerFile: Set> ) } - val tenantName = "DEFAULT" + const val tenantName = "DEFAULT" val tenantNameToLower = tenantName.lowercase().replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() } val basic = Credentials.basic("test", "test") - val hawkbitUrl = "http://localhost:8081" - val downloadRootDirPath = "./build/test/download/" - val gatewayToken = "66076ab945a127dd80b15e9011995109" - val getDownloadDirectoryFromActionId = { actionId: String -> File("$downloadRootDirPath/$actionId") } + const val hawkbitUrl = "http://localhost:8081" + const val downloadRootDirPath = "./build/test/download/" + const val gatewayToken = "66076ab945a127dd80b15e9011995109" val directoryDataProvider = object : DirectoryForArtifactsProvider { override fun directoryForArtifacts(): File = File( downloadRootDirPath ) } @@ -77,7 +79,7 @@ object TestUtils { } } - val serverFilesMappedToLocantionAndMd5 = mapOf( + private val serverFilesMappedToLocantionAndMd5 = mapOf( "test1" to Pair( "docker/test/artifactrepo/$tenantName/4b/5a/b54e43082887d1e7cdb10b7a21fe4a1e56b44b5a", "2490a3d39b0004e4afeb517ef0ddbe2d"), @@ -108,123 +110,6 @@ object TestUtils { md5OfFileNamed("test4") ), 0) - fun messagesOnSuccessfullyDownloadOsWithAppDistribution(target: String) = arrayOf( - ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.running, - listOf("Successfully downloaded all files") - ), - ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.running, - listOf( - "Successfully downloaded file with md5 ${ - md5OfFileNamed( - "test1" - ) - }" - ) - ), - ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.running, - listOf( - "Successfully downloaded file with md5 ${ - md5OfFileNamed( - "test2" - ) - }" - ) - ), - ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.running, - listOf( - "Successfully downloaded file with md5 ${ - md5OfFileNamed( - "test3" - ) - }" - ) - ), - ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.running, - listOf( - "Successfully downloaded file with md5 ${ - md5OfFileNamed( - "test4" - ) - }" - ) - ), - ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.download, - listOf("Update Server: Target downloads /$tenantNameToLower/controller/v1/$target/softwaremodules/2/artifacts/test_2") - ), - ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.download, - listOf("Update Server: Target downloads /$tenantNameToLower/controller/v1/$target/softwaremodules/2/artifacts/test_3") - ), - ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.download, - listOf("Update Server: Target downloads /$tenantNameToLower/controller/v1/$target/softwaremodules/1/artifacts/test_1") - ), - ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.download, - listOf("Update Server: Target downloads /$tenantNameToLower/controller/v1/$target/softwaremodules/3/artifacts/test_4") - ), - ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.running, - listOf("Start downloading 4 files") - ) - ) - - fun messagesOnSuccefullyDownloadOsDistribution(target: String) = arrayOf( - ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.running, - listOf("Successfully downloaded all files") - ), - ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.running, - listOf( - "Successfully downloaded file with md5 ${ - md5OfFileNamed( - "test4" - ) - }" - ) - ), - ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.download, - listOf("Update Server: Target downloads /$tenantNameToLower/controller/v1/$target/softwaremodules/3/artifacts/test_4") - ), - ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.running, - listOf("Start downloading 1 files") - ) - ) - - fun messagesOnSuccefullyDownloadAppDistribution(target: String) = arrayOf( - ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.running, - listOf("Successfully downloaded all files") - ), - ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.running, - listOf( - "Successfully downloaded file with md5 ${ - md5OfFileNamed( - "test1" - ) - }" - ) - ), - ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.download, - listOf("Update Server: Target downloads /$tenantNameToLower/controller/v1/$target/softwaremodules/1/artifacts/test_1") - ), - ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.running, - listOf("Start downloading 1 files") - ) - ) - val endMessagesOnSuccessUpdate = arrayOf( ActionStatus.ContentEntry( ActionStatus.ContentEntry.Type.finished, @@ -266,11 +151,6 @@ object TestUtils { waitingForUpdateAuthorizationMessage ) - val firstActionEntry = ActionStatus.ContentEntry( - ActionStatus.ContentEntry.Type.running, - listOf(null) - ) - val firstActionWithAssignmentEntry = ActionStatus.ContentEntry( ActionStatus.ContentEntry.Type.running, listOf("Assignment initiated by user 'test'") @@ -281,29 +161,11 @@ object TestUtils { listOf("Update Server: Target retrieved update action and should start now the download.") ) - val startMessagesOnUpdateFond = arrayOf( + val firstActionsOnTargetDeployment = arrayOf( targetRetrievedUpdateAction, - firstActionEntry + firstActionWithAssignmentEntry ) - fun filesDownloadedInOsWithAppsPairedToServerFile(action: Int) = setOf( - pathResolver.fromArtifact(action.toString()).invoke( - test1Artifact - ) to locationOfFileNamed("test1"), - pathResolver.fromArtifact(action.toString()).invoke( - test2Artifact - ) to locationOfFileNamed("test2"), - pathResolver.fromArtifact(action.toString()).invoke( - test3Artifact - ) to locationOfFileNamed("test3"), - pathResolver.fromArtifact(action.toString()).invoke( - test4Artifact - ) to locationOfFileNamed("test4"), - ) - - val defaultActionStatusOnStart = - ActionStatus(setOf(firstActionEntry)) - fun messagesOnSuccessfullyDownloadDistribution( md5: String, targetId: String, softwareModuleId: String, fileName: String) = arrayOf(