Skip to content

Commit

Permalink
Implement automated tests for forced update feature
Browse files Browse the repository at this point in the history
Added the option to enable test logs from gradle command:
./gradlew test -PlogHttp=true -PlogInternal=true
Cleaned the test classes to separate the management API

Signed-off-by: Saeed Rezaee <[email protected]>
  • Loading branch information
SaeedRe committed Feb 15, 2024
1 parent ba118c2 commit bcfa168
Show file tree
Hide file tree
Showing 10 changed files with 604 additions and 167 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
}

test {
systemProperty("LOG_HTTP", project.findProperty("logHttp") ?: "false")
systemProperty("LOG_INTERNAL", project.findProperty("logInternal") ?: "false")
useTestNG()

afterTest { desc, result ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ 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.utils.Action
import org.eclipse.hara.ddiclient.integrationtest.utils.ManagementClient
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
Expand Down Expand Up @@ -70,7 +72,8 @@ abstract class AbstractClientTest {
deploymentPermitProvider,
listOf(eventListener, *messageListeners.toTypedArray()),
listOf(updater),
downloadBehavior
downloadBehavior,
httpBuilder = OkHttpClient.Builder().addOkhttpLogger()
)
client
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*
* SPDX-License-Identifier: EPL-2.0
*/

package org.eclipse.hara.ddiclient.integrationtest

import kotlinx.coroutines.CancellationException
Expand All @@ -22,7 +21,6 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.eclipse.hara.ddi.security.Authentication
import org.eclipse.hara.ddiclient.api.ConfigDataProvider
import org.eclipse.hara.ddiclient.api.DeploymentPermitProvider
Expand All @@ -35,13 +33,14 @@ 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.api.Updater
import org.eclipse.hara.ddiclient.integrationtest.utils.ManagementApi
import org.eclipse.hara.ddiclient.integrationtest.utils.ManagementClient
import org.eclipse.hara.ddiclient.integrationtest.utils.ServerSystemConfig
import org.eclipse.hara.ddiclient.integrationtest.api.management.ManagementApi
import org.eclipse.hara.ddiclient.integrationtest.api.management.ManagementClient
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
import org.eclipse.hara.ddiclient.integrationtest.utils.TestUtils.gatewayToken
import org.eclipse.hara.ddiclient.integrationtest.utils.log
import org.eclipse.hara.ddiclient.integrationtest.utils.addOkhttpLogger
import org.eclipse.hara.ddiclient.integrationtest.utils.internalLog
import org.eclipse.hara.ddiclient.integrationtest.utils.logCurrentFunctionName
import org.testng.Assert
import org.testng.annotations.AfterTest
Expand Down Expand Up @@ -74,8 +73,6 @@ class DdiClientHttpRequestsTest {
companion object {
const val TEST_TARGET_ID = "DoubleToken"
const val TEST_TARGET_SECURITY_TOKEN = "r2m3ixxc86a2v4q81wntpyhr78zy08we"
const val LOG_HTTP: Boolean = false
const val LOG_INTERNAL: Boolean = false
}

private val messageListener: MessageListener
Expand Down Expand Up @@ -464,7 +461,7 @@ class DdiClientHttpRequestsTest {
}
}
if (expectedMessages.isEmpty() && expectedServerResponses.isEmpty()) {
"INTERNAL: All expected messages received".internalLog()
"All expected messages received".internalLog()
checkExpectedMessagesJob?.cancel()
if (lastTest) {
safeStopClient()
Expand All @@ -485,21 +482,4 @@ class DdiClientHttpRequestsTest {
data class HaraMessage(val message: MessageListener.Message) : ExpectedMessage()
data class OkHttpMessage(val code: Int, val authHeader: String?) : ExpectedMessage()
}

private fun OkHttpClient.Builder.addOkhttpLogger() {
val logger = HttpLoggingInterceptor.Logger { message ->
if (LOG_HTTP) {
"OkHttp: $message".log()
}
}
addInterceptor(HttpLoggingInterceptor(logger).apply {
level = HttpLoggingInterceptor.Level.BODY
})
}

private fun String.internalLog() {
if (LOG_INTERNAL) {
"INTERNAL: $this".log()
}
}
}
Loading

0 comments on commit bcfa168

Please sign in to comment.