Skip to content

Commit

Permalink
Refactor the tests
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
SaeedRe committed Mar 8, 2024
1 parent cc584f3 commit 82bc8ef
Show file tree
Hide file tree
Showing 15 changed files with 432 additions and 563 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@
**/out/**

local.properties
detekt-baseline.xml
detekt-baseline.xml
gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SerializationTest {
@DataProvider(name = "Serialization")
fun objectsToSerialize(): Array<Any> {
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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,7 +34,6 @@ import kotlin.time.Duration.Companion.seconds

class DdiClientHttpRequestsTest : AbstractHaraMessageTest() {

override val targetId: String = "DoubleToken"
private var expectedServerResponses = mutableListOf<ExpectedMessage>()

override val expectedMessagesList: MutableList<MutableList<ExpectedMessage>> by lazy {
Expand All @@ -52,6 +52,7 @@ class DdiClientHttpRequestsTest : AbstractHaraMessageTest() {
}

companion object {
const val TARGET_ID = "DoubleToken"
const val TEST_TARGET_SECURITY_TOKEN = "r2m3ixxc86a2v4q81wntpyhr78zy08we"
}

Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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))
Expand All @@ -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(
Expand All @@ -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
)
Expand All @@ -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
))
}
Loading

0 comments on commit 82bc8ef

Please sign in to comment.