2017-08-25 21:32:36 +02:00
|
|
|
package org.moire.ultrasonic.api.subsonic
|
|
|
|
|
2018-03-24 19:30:03 +01:00
|
|
|
import org.amshove.kluent.`should be equal to`
|
2017-08-25 21:32:36 +02:00
|
|
|
import org.amshove.kluent.`should equal`
|
2017-08-29 22:18:53 +02:00
|
|
|
import org.amshove.kluent.`should not be`
|
2017-08-25 21:32:36 +02:00
|
|
|
import org.junit.Test
|
|
|
|
import org.moire.ultrasonic.api.subsonic.models.Artist
|
|
|
|
import org.moire.ultrasonic.api.subsonic.models.MusicDirectoryChild
|
2017-08-29 22:18:53 +02:00
|
|
|
import org.moire.ultrasonic.api.subsonic.models.SearchTwoResult
|
2017-08-25 21:32:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Integration test for [SubsonicAPIClient] for search2 call.
|
|
|
|
*/
|
|
|
|
class SubsonicApiSearchTwoTest : SubsonicAPIClientTest() {
|
|
|
|
@Test
|
|
|
|
fun `Should handle error response`() {
|
2017-08-29 22:18:53 +02:00
|
|
|
val response = checkErrorCallParsed(mockWebServerRule) {
|
2017-08-25 21:32:36 +02:00
|
|
|
client.api.search2("some-query").execute()
|
2017-08-29 22:18:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
response.searchResult `should not be` null
|
|
|
|
response.searchResult `should equal` SearchTwoResult()
|
2017-08-25 21:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should parse ok response`() {
|
|
|
|
mockWebServerRule.enqueueResponse("search2_ok.json")
|
|
|
|
|
|
|
|
val response = client.api.search2("some-query").execute()
|
|
|
|
|
|
|
|
assertResponseSuccessful(response)
|
2018-03-24 18:57:18 +01:00
|
|
|
with(response.body()!!.searchResult) {
|
2018-03-24 19:30:03 +01:00
|
|
|
artistList.size `should be equal to` 1
|
2017-12-16 19:50:57 +01:00
|
|
|
artistList[0] `should equal` Artist(id = "522", name = "The Prodigy")
|
2018-03-24 19:30:03 +01:00
|
|
|
albumList.size `should be equal to` 1
|
2017-12-21 10:44:19 +01:00
|
|
|
albumList[0] `should equal` MusicDirectoryChild(id = "8867", parent = "522",
|
|
|
|
isDir = true, title = "Always Outnumbered, Never Outgunned",
|
2017-08-25 21:32:36 +02:00
|
|
|
album = "Always Outnumbered, Never Outgunned", artist = "The Prodigy",
|
|
|
|
year = 2004, genre = "Electronic", coverArt = "8867", playCount = 0,
|
|
|
|
created = parseDate("2016-10-23T20:57:27.000Z"))
|
2018-03-24 19:30:03 +01:00
|
|
|
songList.size `should be equal to` 1
|
2017-12-21 10:44:19 +01:00
|
|
|
songList[0] `should equal` MusicDirectoryChild(id = "5831", parent = "5766",
|
|
|
|
isDir = false,
|
2017-08-25 21:32:36 +02:00
|
|
|
title = "You'll Be Under My Wheels", album = "Need for Speed Most Wanted",
|
|
|
|
artist = "The Prodigy", track = 17, year = 2005, genre = "Rap",
|
|
|
|
coverArt = "5766", size = 5607024, contentType = "audio/mpeg",
|
|
|
|
suffix = "mp3", duration = 233, bitRate = 192,
|
2017-12-21 10:44:19 +01:00
|
|
|
path = "Compilations/Need for Speed Most Wanted/17 You'll Be Under My Wheels" +
|
|
|
|
".mp3",
|
2017-08-25 21:32:36 +02:00
|
|
|
isVideo = false, playCount = 0, discNumber = 1,
|
|
|
|
created = parseDate("2016-10-23T20:09:02.000Z"),
|
2017-12-16 21:28:18 +01:00
|
|
|
albumId = "568", artistId = "505", type = "music")
|
2017-08-25 21:32:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should pass query id in request param`() {
|
|
|
|
val query = "some"
|
|
|
|
|
2017-08-29 22:18:53 +02:00
|
|
|
mockWebServerRule.assertRequestParam(responseResourceName = "search2_ok.json",
|
|
|
|
expectedParam = "query=$query") {
|
2017-08-25 21:32:36 +02:00
|
|
|
client.api.search2(query).execute()
|
2017-08-29 22:18:53 +02:00
|
|
|
}
|
2017-08-25 21:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should pass artist count in request param`() {
|
|
|
|
val artistCount = 45
|
|
|
|
|
2017-08-29 22:18:53 +02:00
|
|
|
mockWebServerRule.assertRequestParam(responseResourceName = "search2_ok.json",
|
|
|
|
expectedParam = "artistCount=$artistCount") {
|
2017-08-25 21:32:36 +02:00
|
|
|
client.api.search2("some", artistCount = artistCount).execute()
|
2017-08-29 22:18:53 +02:00
|
|
|
}
|
2017-08-25 21:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should pass artist offset in request param`() {
|
|
|
|
val artistOffset = 13
|
|
|
|
|
2017-08-29 22:18:53 +02:00
|
|
|
mockWebServerRule.assertRequestParam(responseResourceName = "search2_ok.json",
|
|
|
|
expectedParam = "artistOffset=$artistOffset") {
|
2017-08-25 21:32:36 +02:00
|
|
|
client.api.search2("some", artistOffset = artistOffset).execute()
|
2017-08-29 22:18:53 +02:00
|
|
|
}
|
2017-08-25 21:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should pass album count in request param`() {
|
|
|
|
val albumCount = 30
|
|
|
|
|
2017-08-29 22:18:53 +02:00
|
|
|
mockWebServerRule.assertRequestParam(responseResourceName = "search2_ok.json",
|
|
|
|
expectedParam = "albumCount=$albumCount") {
|
2017-08-25 21:32:36 +02:00
|
|
|
client.api.search2("some", albumCount = albumCount).execute()
|
2017-08-29 22:18:53 +02:00
|
|
|
}
|
2017-08-25 21:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should pass album offset in request param`() {
|
|
|
|
val albumOffset = 91
|
|
|
|
|
2017-08-29 22:18:53 +02:00
|
|
|
mockWebServerRule.assertRequestParam(responseResourceName = "search2_ok.json",
|
|
|
|
expectedParam = "albumOffset=$albumOffset") {
|
2017-08-25 21:32:36 +02:00
|
|
|
client.api.search2("some", albumOffset = albumOffset).execute()
|
2017-08-29 22:18:53 +02:00
|
|
|
}
|
2017-08-25 21:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should pass song count in request param`() {
|
|
|
|
val songCount = 22
|
|
|
|
|
2017-08-29 22:18:53 +02:00
|
|
|
mockWebServerRule.assertRequestParam(responseResourceName = "search2_ok.json",
|
|
|
|
expectedParam = "songCount=$songCount") {
|
2017-08-25 21:32:36 +02:00
|
|
|
client.api.search2("some", songCount = songCount).execute()
|
2017-08-29 22:18:53 +02:00
|
|
|
}
|
2017-08-25 21:32:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should pass music folder id in request param`() {
|
2017-12-16 22:14:01 +01:00
|
|
|
val musicFolderId = "565"
|
2017-08-25 21:32:36 +02:00
|
|
|
|
2017-08-29 22:18:53 +02:00
|
|
|
mockWebServerRule.assertRequestParam(responseResourceName = "search2_ok.json",
|
|
|
|
expectedParam = "musicFolderId=$musicFolderId") {
|
2017-08-25 21:32:36 +02:00
|
|
|
client.api.search2("some", musicFolderId = musicFolderId).execute()
|
2017-08-29 22:18:53 +02:00
|
|
|
}
|
2017-08-25 21:32:36 +02:00
|
|
|
}
|
|
|
|
}
|