Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration tests between the player and the analytics #441

Merged
merged 13 commits into from
Feb 21, 2024
1 change: 1 addition & 0 deletions .github/workflows/gradle_wrapper_validation.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Gradle Wrapper validation

on:
merge_group:
push:
branches:
- main
Expand Down
2 changes: 1 addition & 1 deletion .idea/kotlinScripting.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ androidx-media3-ui-leanback = { group = "androidx.media3", name = "media3-ui-lea
androidx-media3-dash = { group = "androidx.media3", name = "media3-exoplayer-dash", version.ref = "androidx-media3" }
androidx-media3-hls = { group = "androidx.media3", name = "media3-exoplayer-hls", version.ref = "androidx-media3" }
androidx-media3-session = { group = "androidx.media3", name = "media3-session", version.ref = "androidx-media3" }
androidx-media3-test-utils = { group = "androidx.media3", name = "media3-test-utils", version.ref = "androidx-media3" }
androidx-media3-test-utils-robolectric = { group = "androidx.media3", name = "media3-test-utils-robolectric", version.ref = "androidx-media3" }
androidx-media3-test-utils = { module = "androidx.media3:media3-test-utils", version.ref = "androidx-media3" }
androidx-media3-test-utils-robolectric = { module = "androidx.media3:media3-test-utils-robolectric", version.ref = "androidx-media3" }
androidx-media = { group = "androidx.media", name = "media", version.ref = "androidx-media" }
okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhttp" }
okhttp-logging-interceptor = { group = "com.squareup.okhttp3", name = "logging-interceptor", version.ref = "okhttp" }
Expand Down
12 changes: 7 additions & 5 deletions lint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
-->
<lint>
<issue id="InvalidPackage">
<ignore regexp="kotlinx.coroutines.debug.AgentPremain" />
</issue>
<!-- https://youtrack.jetbrains.com/issue/KTOR-3690 -->
<issue id="InvalidPackage">
<ignore regexp="io.ktor:ktor-utils-jvm" />
<!-- Robolectric brings these dependencies transitively, but they are not in the Android SDK -->
<ignore regexp="java.awt" />
<ignore regexp="java.lang.management" />
<ignore regexp="javax.imageio" />
<ignore regexp="javax.inject" />
<ignore regexp="javax.naming" />
<ignore regexp="javax.xml" />
</issue>
<issue id="UnsafeOptInUsageError">
<ignore regexp='\(markerClass = androidx\.media3\.common\.util\.UnstableApi\.class\)' />
Expand Down
7 changes: 7 additions & 0 deletions pillarbox-core-business/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,22 @@ dependencies {
implementation(libs.okhttp.logging.interceptor)
api(libs.tagcommander.core)

testImplementation(project(":pillarbox-player-testutils"))

testImplementation(libs.androidx.media3.test.utils)
testImplementation(libs.androidx.media3.test.utils.robolectric)
testImplementation(libs.androidx.test.core)
testImplementation(libs.androidx.test.ext.junit)
testImplementation(libs.androidx.test.monitor)
testImplementation(libs.junit)
testImplementation(libs.kotlin.test)
testImplementation(libs.kotlinx.coroutines.test)
testImplementation(libs.ktor.client.mock)
testImplementation(libs.mockk)
testImplementation(libs.mockk.dsl)
testRuntimeOnly(libs.robolectric)
testImplementation(libs.robolectric.annotations)
testRuntimeOnly(libs.robolectric.shadows.framework)

androidTestImplementation(project(":pillarbox-player-testutils"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package ch.srgssr.pillarbox.core.business

import android.content.Context
import androidx.annotation.VisibleForTesting
import androidx.media3.common.util.Clock
import androidx.media3.datasource.DataSource
import androidx.media3.exoplayer.DefaultLoadControl
import androidx.media3.exoplayer.LoadControl
Expand Down Expand Up @@ -32,7 +34,7 @@ object DefaultPillarbox {
* @param mediaItemTrackerRepository The provider of MediaItemTracker, by default [DefaultMediaItemTrackerRepository].
* @param mediaItemSource The MediaItem source by default [MediaCompositionMediaItemSource].
* @param dataSourceFactory The Http exoplayer data source factory, by default [AkamaiTokenDataSource.Factory].
* @param loadControl The load control, bye default [DefaultLoadControl].
* @param loadControl The load control, by default [DefaultLoadControl].
* @return [PillarboxPlayer] suited for SRG.
*/
operator fun invoke(
Expand All @@ -44,14 +46,50 @@ object DefaultPillarbox {
),
dataSourceFactory: DataSource.Factory = AkamaiTokenDataSource.Factory(),
loadControl: LoadControl = PillarboxLoadControl(),
): PillarboxPlayer {
return DefaultPillarbox(
context = context,
seekIncrement = seekIncrement,
mediaItemTrackerRepository = mediaItemTrackerRepository,
mediaItemSource = mediaItemSource,
dataSourceFactory = dataSourceFactory,
loadControl = loadControl,
clock = Clock.DEFAULT,
)
}

/**
* Invoke create an instance of [PillarboxPlayer]
*
* @param context The context.
* @param seekIncrement The seek increment.
* @param mediaItemTrackerRepository The provider of MediaItemTracker, by default [DefaultMediaItemTrackerRepository].
* @param mediaItemSource The MediaItem source by default [MediaCompositionMediaItemSource].
* @param dataSourceFactory The Http exoplayer data source factory, by default [AkamaiTokenDataSource.Factory].
* @param loadControl The load control, by default [DefaultLoadControl].
* @param clock The internal clock used by the player.
* @return [PillarboxPlayer] suited for SRG.
*/
@VisibleForTesting
operator fun invoke(
context: Context,
seekIncrement: SeekIncrement = defaultSeekIncrement,
mediaItemTrackerRepository: MediaItemTrackerProvider = DefaultMediaItemTrackerRepository(),
mediaItemSource: MediaItemSource = MediaCompositionMediaItemSource(
mediaCompositionDataSource = DefaultMediaCompositionDataSource(),
),
dataSourceFactory: DataSource.Factory = AkamaiTokenDataSource.Factory(),
loadControl: LoadControl = PillarboxLoadControl(),
clock: Clock,
): PillarboxPlayer {
return PillarboxPlayer(
context = context,
seekIncrement = seekIncrement,
dataSourceFactory = dataSourceFactory,
mediaItemSource = mediaItemSource,
mediaItemTrackerProvider = mediaItemTrackerRepository,
loadControl = loadControl
loadControl = loadControl,
clock = clock,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/
package ch.srgssr.pillarbox.core.business.integrationlayer.service

import android.content.Context
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import ch.srgssr.pillarbox.core.business.integrationlayer.service.Vector.getVector
import org.junit.runner.RunWith
import org.robolectric.annotation.Config
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

@RunWith(AndroidJUnit4::class)
class VectorTest {
private lateinit var context: Context

@BeforeTest
fun setup() {
context = ApplicationProvider.getApplicationContext()
}

@Test
fun getVector() {
assertEquals(Vector.MOBILE, context.getVector())
}

@Test
@Config(qualifiers = "appliance")
fun `getVector appliance`() {
assertEquals(Vector.MOBILE, context.getVector())
}

@Test
@Config(qualifiers = "car")
fun `getVector car`() {
assertEquals(Vector.MOBILE, context.getVector())
}

@Test
@Config(qualifiers = "desk")
fun `getVector desk`() {
assertEquals(Vector.MOBILE, context.getVector())
}

@Test
@Config(qualifiers = "television")
fun `getVector television`() {
assertEquals(Vector.TV, context.getVector())
}

@Test
@Config(qualifiers = "vrheadset")
fun `getVector vrheadset`() {
assertEquals(Vector.MOBILE, context.getVector())
}

@Test
@Config(qualifiers = "watch")
fun `getVector watch`() {
assertEquals(Vector.MOBILE, context.getVector())
}
}
Loading
Loading