Add getAlbumList2 request.
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
parent
0a22f7bcc7
commit
14fac18978
|
@ -0,0 +1,113 @@
|
|||
package org.moire.ultrasonic.api.subsonic
|
||||
|
||||
import org.amshove.kluent.`should equal to`
|
||||
import org.amshove.kluent.`should equal`
|
||||
import org.junit.Test
|
||||
import org.moire.ultrasonic.api.subsonic.models.Album
|
||||
import org.moire.ultrasonic.api.subsonic.models.AlbumListType
|
||||
import org.moire.ultrasonic.api.subsonic.models.AlbumListType.STARRED
|
||||
|
||||
/**
|
||||
* Integration test for [SubsonicAPIClient] for getAlbumList2() call.
|
||||
*/
|
||||
@Suppress("NamingConventionViolation")
|
||||
class SubsonicApiGetAlbumList2Test : SubsonicAPIClientTest() {
|
||||
@Test
|
||||
fun `Should handle error response`() {
|
||||
val response = checkErrorCallParsed(mockWebServerRule) {
|
||||
client.api.getAlbumList2(STARRED).execute()
|
||||
}
|
||||
|
||||
response.albumList `should equal` emptyList()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should handle ok response`() {
|
||||
mockWebServerRule.enqueueResponse("get_album_list_2_ok.json")
|
||||
|
||||
val response = client.api.getAlbumList2(STARRED).execute()
|
||||
|
||||
assertResponseSuccessful(response)
|
||||
with(response.body().albumList) {
|
||||
this.size `should equal to` 2
|
||||
this[0] `should equal` Album(id = 962, name = "Fury", artist = "Sick Puppies",
|
||||
artistId = 473, coverArt = "al-962", songCount = 13, duration = 2591,
|
||||
created = parseDate("2017-09-02T17:34:51.000Z"), year = 2016,
|
||||
genre = "Alternative Rock")
|
||||
this[1] `should equal` Album(id = 961, name = "Endless Forms Most Beautiful",
|
||||
artist = "Nightwish", artistId = 559, coverArt = "al-961", songCount = 22,
|
||||
duration = 9469, created = parseDate("2017-09-02T16:22:47.000Z"),
|
||||
year = 2015, genre = "Symphonic Metal")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should pass type in request params`() {
|
||||
val type = AlbumListType.SORTED_BY_NAME
|
||||
|
||||
mockWebServerRule.assertRequestParam(responseResourceName = "get_album_list_2_ok.json",
|
||||
expectedParam = "type=${type.typeName}") {
|
||||
client.api.getAlbumList2(type = type).execute()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should pass size in request param`() {
|
||||
val size = 45
|
||||
|
||||
mockWebServerRule.assertRequestParam(responseResourceName = "get_album_list_2_ok.json",
|
||||
expectedParam = "size=$size") {
|
||||
client.api.getAlbumList2(STARRED, size = size).execute()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should pass offset in request param`() {
|
||||
val offset = 33
|
||||
|
||||
mockWebServerRule.assertRequestParam(responseResourceName = "get_album_list_2_ok.json",
|
||||
expectedParam = "offset=$offset") {
|
||||
client.api.getAlbumList2(STARRED, offset = offset).execute()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should pass from year in request params`() {
|
||||
val fromYear = 3030
|
||||
|
||||
mockWebServerRule.assertRequestParam(responseResourceName = "get_album_list_2_ok.json",
|
||||
expectedParam = "fromYear=$fromYear") {
|
||||
client.api.getAlbumList2(STARRED, fromYear = fromYear).execute()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should pass toYear in request param`() {
|
||||
val toYear = 2014
|
||||
|
||||
mockWebServerRule.assertRequestParam(responseResourceName = "get_album_list_2_ok.json",
|
||||
expectedParam = "toYear=$toYear") {
|
||||
client.api.getAlbumList2(STARRED, toYear = toYear).execute()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should pass genre in request param`() {
|
||||
val genre = "MathRock"
|
||||
|
||||
mockWebServerRule.assertRequestParam(responseResourceName = "get_album_list_2_ok.json",
|
||||
expectedParam = "genre=$genre") {
|
||||
client.api.getAlbumList2(STARRED, genre = genre).execute()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should pass music folder id in request param`() {
|
||||
val musicFolderId = 9422L
|
||||
|
||||
mockWebServerRule.assertRequestParam(responseResourceName = "get_album_list_2_ok.json",
|
||||
expectedParam = "musicFolderId=$musicFolderId") {
|
||||
client.api.getAlbumList2(STARRED, musicFolderId = musicFolderId).execute()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"subsonic-response" : {
|
||||
"status" : "ok",
|
||||
"version" : "1.15.0",
|
||||
"albumList2" : {
|
||||
"album" : [ {
|
||||
"id" : "962",
|
||||
"name" : "Fury",
|
||||
"artist" : "Sick Puppies",
|
||||
"artistId" : "473",
|
||||
"coverArt" : "al-962",
|
||||
"songCount" : 13,
|
||||
"duration" : 2591,
|
||||
"created" : "2017-09-02T17:34:51.000Z",
|
||||
"year" : 2016,
|
||||
"genre" : "Alternative Rock"
|
||||
}, {
|
||||
"id" : "961",
|
||||
"name" : "Endless Forms Most Beautiful",
|
||||
"artist" : "Nightwish",
|
||||
"artistId" : "559",
|
||||
"coverArt" : "al-961",
|
||||
"songCount" : 22,
|
||||
"duration" : 9469,
|
||||
"created" : "2017-09-02T16:22:47.000Z",
|
||||
"year" : 2015,
|
||||
"genre" : "Symphonic Metal"
|
||||
} ]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package org.moire.ultrasonic.api.subsonic
|
||||
|
||||
import org.moire.ultrasonic.api.subsonic.models.AlbumListType
|
||||
import org.moire.ultrasonic.api.subsonic.response.GetAlbumList2Response
|
||||
import org.moire.ultrasonic.api.subsonic.response.GetAlbumListResponse
|
||||
import org.moire.ultrasonic.api.subsonic.response.GetAlbumResponse
|
||||
import org.moire.ultrasonic.api.subsonic.response.GetArtistResponse
|
||||
|
@ -134,4 +135,13 @@ interface SubsonicAPIDefinition {
|
|||
@Query("toYear") toYear: Int? = null,
|
||||
@Query("genre") genre: String? = null,
|
||||
@Query("musicFolderId") musicFolderId: Long? = null): Call<GetAlbumListResponse>
|
||||
|
||||
@GET("getAlbumList2.view")
|
||||
fun getAlbumList2(@Query("type") type: AlbumListType,
|
||||
@Query("size") size: Int? = null,
|
||||
@Query("offset") offset: Int? = null,
|
||||
@Query("fromYear") fromYear: Int? = null,
|
||||
@Query("toYear") toYear: Int? = null,
|
||||
@Query("genre") genre: String? = null,
|
||||
@Query("musicFolderId") musicFolderId: Long? = null): Call<GetAlbumList2Response>
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package org.moire.ultrasonic.api.subsonic.response
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicError
|
||||
import org.moire.ultrasonic.api.subsonic.models.Album
|
||||
|
||||
@Suppress("NamingConventionViolation")
|
||||
class GetAlbumList2Response(status: Status,
|
||||
version: SubsonicAPIVersions,
|
||||
error: SubsonicError?)
|
||||
: SubsonicResponse(status, version, error) {
|
||||
@JsonProperty("albumList2") private val albumWrapper2 = AlbumWrapper2()
|
||||
|
||||
val albumList: List<Album>
|
||||
get() = albumWrapper2.albumList
|
||||
}
|
||||
|
||||
@Suppress("NamingConventionViolation")
|
||||
private class AlbumWrapper2(
|
||||
@JsonProperty("album") val albumList: List<Album> = emptyList())
|
Loading…
Reference in New Issue