Browse Source

RD-205 init project

master
bean 2 years ago
parent
commit
9b77df24d0
  1. 29
      src/main/kotlin/tv/anypoint/dsl/Dsl.kt
  2. 5
      src/main/kotlin/tv/anypoint/dsl/TestCaseStarter.kt
  3. 8
      src/main/kotlin/tv/anypoint/dsl/model/LogInfo.kt
  4. 3
      src/main/kotlin/tv/anypoint/dsl/model/Tc.kt
  5. 4
      src/main/kotlin/tv/anypoint/dsl/model/adb/ExtraKey.kt
  6. 18
      src/main/kotlin/tv/anypoint/dsl/service/TestCase.kt
  7. 11
      src/main/kotlin/tv/anypoint/tc/Base1.kt

29
src/main/kotlin/tv/anypoint/dsl/Dsl.kt

@ -4,6 +4,13 @@ import tv.anypoint.dsl.handler.HttpHandler
import tv.anypoint.dsl.model.adb.ExtraKey import tv.anypoint.dsl.model.adb.ExtraKey
import tv.anypoint.dsl.model.adb.IntentAction import tv.anypoint.dsl.model.adb.IntentAction
import tv.anypoint.dsl.model.Tc import tv.anypoint.dsl.model.Tc
import tv.anypoint.dsl.service.TestCase
import java.time.Duration
import java.time.LocalDateTime
import java.time.Period
import java.time.temporal.ChronoUnit
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
inline fun tc( inline fun tc(
block: Tc.() -> Unit block: Tc.() -> Unit
@ -15,17 +22,29 @@ inline fun <reified T>http(
data class Adb( data class Adb(
val a: IntentAction, val a: IntentAction,
val es: Pair<ExtraKey, String> val es: Map<ExtraKey, String>
) )
inline fun adb( inline fun adb(
a: IntentAction, a: IntentAction,
es: Pair<ExtraKey, String> es: Map<ExtraKey, String>
) { ) {
val adb = Adb(a, es) val adb = Adb(a, es)
println("[ADB] adb shell am broadcast -a $a --es ${es.first} ${es.second}") val aStr = "-a $a"
val esStr: String = es.entries.joinToString(" ") { "--es ${it.key.string} ${it.value}" }
println("[ADB] adb shell am broadcast $aStr $esStr")
} }
fun expected(expectedLog: String) { fun TestCase.expected(
// TODO: logcat 스트림에서 expectedLog 찾기, 제한시간 내에 못찾으면 TimeoutException 뱉기 expectedLog: String,
timeout: Long = 10_000L
) {
val startedAt = LocalDateTime.now()
while (true) {
val now = LocalDateTime.now()
if (ChronoUnit.MILLIS.between(startedAt, now) > timeout) {
throw TimeoutException("failed to find log. expectedLog: $expectedLog, absoluteFilePath: ${this.tc.logInfo.absoluteFilePath}")
}
// TODO: tc 로그에서 expectedLog 찾기 tc.logInfo.cursor ~ 마지막 라인까지의 로그 중에 찾으면 됨
}
} }

5
src/main/kotlin/tv/anypoint/dsl/TestCaseStarter.kt

@ -12,7 +12,8 @@ class TestCaseStarter(
private val testCases: List<TestCase> private val testCases: List<TestCase>
) { ) {
@EventListener(ApplicationReadyEvent::class) @EventListener(ApplicationReadyEvent::class)
fun doSomethingAfterStartup() { fun testAfterStartup() {
// TODO: main.log 덤프 시작
testCases.forEach { testCases.forEach {
it.executeTest() it.executeTest()
} }
@ -27,7 +28,7 @@ class TestCaseStarter(
if (it.tc.result!!) "PASS" else "FAIL", if (it.tc.result!!) "PASS" else "FAIL",
it.tc.startedAt, it.tc.startedAt,
it.tc.finishedAt, it.tc.finishedAt,
it.tc.logAbsoluteFilePath, it.tc.logInfo.absoluteFilePath,
it.tc.recordingInfo?.absoluteFilePath ?: "-" it.tc.recordingInfo?.absoluteFilePath ?: "-"
) )
) )

8
src/main/kotlin/tv/anypoint/dsl/model/LogInfo.kt

@ -0,0 +1,8 @@
package tv.anypoint.dsl.model
class LogInfo(
val absoluteFilePath: String
) {
var cursor: Long = 0
var lastLine: Long = 0
}

3
src/main/kotlin/tv/anypoint/dsl/model/Tc.kt

@ -25,6 +25,7 @@ class Tc {
val startedAt: LocalDateTime = LocalDateTime.now() val startedAt: LocalDateTime = LocalDateTime.now()
lateinit var finishedAt: LocalDateTime lateinit var finishedAt: LocalDateTime
var result: Boolean? = null var result: Boolean? = null
lateinit var logAbsoluteFilePath: String
lateinit var logInfo: LogInfo
var recordingInfo: RecordingInfo? = null var recordingInfo: RecordingInfo? = null
} }

4
src/main/kotlin/tv/anypoint/dsl/model/adb/ExtraKey.kt

@ -2,5 +2,7 @@ package tv.anypoint.dsl.model.adb
enum class ExtraKey(val string: String) { enum class ExtraKey(val string: String) {
EXTRA_JSON("EXTRA_JSON"), EXTRA_JSON("EXTRA_JSON"),
CHANGE_COMMAND("change.command"),
API_ENDPOINT("api.endpoint"),
TEST_DEVICE("test.device")
} }

18
src/main/kotlin/tv/anypoint/dsl/service/TestCase.kt

@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
import tv.anypoint.ApplicationProperties import tv.anypoint.ApplicationProperties
import tv.anypoint.dsl.exception.httpValidationError import tv.anypoint.dsl.exception.httpValidationError
import tv.anypoint.dsl.model.LogInfo
import tv.anypoint.dsl.model.RecordingInfo import tv.anypoint.dsl.model.RecordingInfo
import tv.anypoint.dsl.model.http.AdsResponse import tv.anypoint.dsl.model.http.AdsResponse
import tv.anypoint.dsl.model.http.AssetConvertResponse import tv.anypoint.dsl.model.http.AssetConvertResponse
@ -36,12 +37,13 @@ abstract class TestCase {
try { try {
if (tc.reboot) { if (tc.reboot) {
// TODO
logger.info("[TC-${tc.number}] reboot STB") logger.info("[TC-${tc.number}] reboot STB")
// TODO
} else { } else {
logger.info("[TC-${tc.number}] get systemInfo STB") logger.info("[TC-${tc.number}] get systemInfo STB")
// TODO
} }
startToCollectLog() startToDumpLog()
auth() auth()
ads() ads()
@ -51,7 +53,7 @@ abstract class TestCase {
test() test()
stopRecording(tc) stopRecording(tc)
stopToCollectLog() stopToDumpLog()
} catch (e: Exception) { } catch (e: Exception) {
logger.error("[TC-${tc.number}] FAILED!! ${e.message}", e) logger.error("[TC-${tc.number}] FAILED!! ${e.message}", e)
tc.result = false tc.result = false
@ -63,13 +65,13 @@ abstract class TestCase {
tc.result = true tc.result = true
} }
private fun startToCollectLog() { private fun startToDumpLog() {
tc.logAbsoluteFilePath = "applicationProperties.filePath/TC-${tc.number}.log" tc.logInfo = LogInfo("${applicationProperties.filePath}/TC-${tc.number}.log")
// TODO // TODO 이 함수 호출된 후 main.log 에서 쌓이는 로그를 TC-${tc.number}.log 파일 새로 만들어서 적재 시작
} }
private fun stopToCollectLog() { private fun stopToDumpLog() {
// TODO // TODO main.log >> TC-${tc.number}.log 적재 종료
} }
private fun auth() { private fun auth() {

11
src/main/kotlin/tv/anypoint/tc/Base1.kt

@ -2,10 +2,13 @@ package tv.anypoint.tc
import mu.KLogging import mu.KLogging
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
import tv.anypoint.dsl.adb
import tv.anypoint.dsl.http import tv.anypoint.dsl.http
import tv.anypoint.dsl.service.TestCase import tv.anypoint.dsl.service.TestCase
import tv.anypoint.dsl.tc import tv.anypoint.dsl.tc
import tv.anypoint.dsl.model.Tc import tv.anypoint.dsl.model.Tc
import tv.anypoint.dsl.model.adb.ExtraKey
import tv.anypoint.dsl.model.adb.IntentAction
@Component @Component
class Base1 : TestCase() { class Base1 : TestCase() {
@ -18,8 +21,16 @@ class Base1 : TestCase() {
} }
override fun test() { override fun test() {
adb(
a = IntentAction.CHANGE_TEST_PROPERTY,
es = mapOf(ExtraKey.TEST_DEVICE to "true")
)
logger.debug("started to base1 test") logger.debug("started to base1 test")
logger.debug("finished to base1 test") logger.debug("finished to base1 test")
adb(
a = IntentAction.CHANGE_TEST_PROPERTY,
es = mapOf(ExtraKey.TEST_DEVICE to "false")
)
} }
companion object : KLogging() companion object : KLogging()

Loading…
Cancel
Save