From 88357f1771e21d0eb9df5c5cfb44f8a1c497bf99 Mon Sep 17 00:00:00 2001 From: firemaples Date: Wed, 3 Jan 2024 19:40:27 +0900 Subject: [PATCH] test --- .github/workflows/ms_svc_test.yml | 27 ++++++++++++++ .../MicrosoftAzureAPIServiceTest.kt | 36 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 .github/workflows/ms_svc_test.yml create mode 100644 main/src/test/java/tw/firemaples/onscreenocr/MicrosoftAzureAPIServiceTest.kt diff --git a/.github/workflows/ms_svc_test.yml b/.github/workflows/ms_svc_test.yml new file mode 100644 index 00000000..3c6a9fa2 --- /dev/null +++ b/.github/workflows/ms_svc_test.yml @@ -0,0 +1,27 @@ +name: CI + +on: + push: + branches: [ "*" ] + workflow_dispatch: + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: gradle + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Build with Gradle + env: + MS_KEY_1: ${{ secrets.MS_KEY_1 }} + run: ./gradlew :main:testDevDebug --tests "tw.firemaples.onscreenocr.MicrosoftAzureAPIServiceTest" diff --git a/main/src/test/java/tw/firemaples/onscreenocr/MicrosoftAzureAPIServiceTest.kt b/main/src/test/java/tw/firemaples/onscreenocr/MicrosoftAzureAPIServiceTest.kt new file mode 100644 index 00000000..10911835 --- /dev/null +++ b/main/src/test/java/tw/firemaples/onscreenocr/MicrosoftAzureAPIServiceTest.kt @@ -0,0 +1,36 @@ +package tw.firemaples.onscreenocr + +import kotlinx.coroutines.test.runTest +import org.junit.Assert.assertEquals +import org.junit.Test +import retrofit2.Retrofit +import retrofit2.converter.moshi.MoshiConverterFactory +import tw.firemaples.onscreenocr.translator.azure.MicrosoftAzureAPIService +import tw.firemaples.onscreenocr.translator.azure.TranslateRequest + +class MicrosoftAzureAPIServiceTest { + private val retrofit: Retrofit by lazy { + Retrofit.Builder() + .baseUrl("http://localhost/") + .addConverterFactory(MoshiConverterFactory.create()) + .build() + } + + private val apiService: MicrosoftAzureAPIService by lazy { + retrofit.create(MicrosoftAzureAPIService::class.java) + } + + @Test + fun test() = runTest { + val key = System.getenv().getOrDefault("MS_KEY_1", "") + + val result = apiService.translate( + subscriptionKey = key, + to = "fr", + request = TranslateRequest.single("Hello"), + ) + + val actual = result.body()?.firstOrNull()?.translations?.firstOrNull()?.text + assertEquals("Bonjour", actual) + } +}