2021-02-05 20:13:16 +01:00
|
|
|
package org.schabi.newpipe.local.playlist
|
|
|
|
|
|
|
|
import org.junit.After
|
|
|
|
import org.junit.Before
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.rules.Timeout
|
|
|
|
import org.schabi.newpipe.database.AppDatabase
|
|
|
|
import org.schabi.newpipe.database.stream.model.StreamEntity
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamType
|
2021-12-08 14:02:16 +01:00
|
|
|
import org.schabi.newpipe.testUtil.TestDatabase
|
2021-02-05 20:13:16 +01:00
|
|
|
import org.schabi.newpipe.testUtil.TrampolineSchedulerRule
|
|
|
|
import java.util.concurrent.TimeUnit
|
|
|
|
|
|
|
|
class LocalPlaylistManagerTest {
|
|
|
|
|
|
|
|
private lateinit var manager: LocalPlaylistManager
|
|
|
|
private lateinit var database: AppDatabase
|
|
|
|
|
|
|
|
@get:Rule
|
|
|
|
val trampolineScheduler = TrampolineSchedulerRule()
|
|
|
|
|
|
|
|
@get:Rule
|
2021-12-08 14:02:16 +01:00
|
|
|
val timeout = Timeout(1, TimeUnit.SECONDS)
|
2021-02-05 20:13:16 +01:00
|
|
|
|
|
|
|
@Before
|
|
|
|
fun setup() {
|
2021-12-08 14:02:16 +01:00
|
|
|
database = TestDatabase.createReplacingNewPipeDatabase()
|
2021-02-05 20:13:16 +01:00
|
|
|
manager = LocalPlaylistManager(database)
|
|
|
|
}
|
|
|
|
|
|
|
|
@After
|
|
|
|
fun cleanUp() {
|
|
|
|
database.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun createPlaylist() {
|
2021-09-22 09:17:53 +02:00
|
|
|
val NEWPIPE_URL = "https://newpipe.net/"
|
2021-02-05 20:13:16 +01:00
|
|
|
val stream = StreamEntity(
|
2021-09-22 09:17:53 +02:00
|
|
|
serviceId = 1, url = NEWPIPE_URL, title = "title",
|
2021-08-11 10:26:13 +02:00
|
|
|
streamType = StreamType.VIDEO_STREAM, duration = 1, uploader = "uploader",
|
2021-09-22 09:17:53 +02:00
|
|
|
uploaderUrl = NEWPIPE_URL
|
2021-02-05 20:13:16 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
val result = manager.createPlaylist("name", listOf(stream))
|
|
|
|
|
|
|
|
// This should not behave like this.
|
|
|
|
// Currently list of all stream ids is returned instead of playlist id
|
|
|
|
result.test().await().assertValue(listOf(1L))
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun createPlaylist_emptyPlaylistMustReturnEmpty() {
|
|
|
|
val result = manager.createPlaylist("name", emptyList())
|
|
|
|
|
|
|
|
// This should not behave like this.
|
|
|
|
// It should throw an error because currently the result is null
|
|
|
|
result.test().await().assertComplete()
|
|
|
|
manager.playlists.test().awaitCount(1).assertValue(emptyList())
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test()
|
|
|
|
fun createPlaylist_nonExistentStreamsAreUpserted() {
|
|
|
|
val stream = StreamEntity(
|
2021-07-19 20:59:29 +02:00
|
|
|
serviceId = 1, url = "https://newpipe.net/", title = "title",
|
2021-08-11 10:26:13 +02:00
|
|
|
streamType = StreamType.VIDEO_STREAM, duration = 1, uploader = "uploader",
|
|
|
|
uploaderUrl = "https://newpipe.net/"
|
2021-02-05 20:13:16 +01:00
|
|
|
)
|
|
|
|
database.streamDAO().insert(stream)
|
|
|
|
val upserted = StreamEntity(
|
2021-07-19 20:59:29 +02:00
|
|
|
serviceId = 1, url = "https://newpipe.net/2", title = "title2",
|
2021-08-11 10:26:13 +02:00
|
|
|
streamType = StreamType.VIDEO_STREAM, duration = 1, uploader = "uploader",
|
|
|
|
uploaderUrl = "https://newpipe.net/"
|
2021-02-05 20:13:16 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
val result = manager.createPlaylist("name", listOf(stream, upserted))
|
|
|
|
|
|
|
|
result.test().await().assertComplete()
|
|
|
|
database.streamDAO().all.test().awaitCount(1).assertValue(listOf(stream, upserted))
|
|
|
|
}
|
|
|
|
}
|