2017-11-05 22:14:02 +01:00
|
|
|
package org.moire.ultrasonic.api.subsonic
|
|
|
|
|
|
|
|
import okhttp3.mockwebserver.MockResponse
|
2018-03-24 19:30:03 +01:00
|
|
|
import org.amshove.kluent.`should be equal to`
|
2017-11-05 22:14:02 +01:00
|
|
|
import org.amshove.kluent.`should be`
|
|
|
|
import org.amshove.kluent.`should not be`
|
|
|
|
import org.junit.Test
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Integration test for [SubsonicAPIClient] for [SubsonicAPIDefinition.stream] call.
|
|
|
|
*/
|
|
|
|
class SubsonicApiStreamTest : SubsonicAPIClientTest() {
|
|
|
|
@Test
|
|
|
|
fun `Should handle api error response`() {
|
2018-01-13 10:19:42 +01:00
|
|
|
mockWebServerRule.enqueueResponse("request_data_not_found_error_response.json")
|
2017-11-05 22:14:02 +01:00
|
|
|
|
|
|
|
val response = client.stream("some-id")
|
|
|
|
|
|
|
|
with(response) {
|
|
|
|
stream `should be` null
|
2018-03-24 19:30:03 +01:00
|
|
|
responseHttpCode `should be equal to` 200
|
2021-05-07 15:36:11 +02:00
|
|
|
apiError `should be equal to` SubsonicError.RequestedDataWasNotFound
|
2017-11-05 22:14:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should handle server error`() {
|
|
|
|
val httpErrorCode = 404
|
|
|
|
mockWebServerRule.mockWebServer.enqueue(MockResponse().setResponseCode(httpErrorCode))
|
|
|
|
|
|
|
|
val response = client.stream("some-id")
|
|
|
|
|
|
|
|
with(response) {
|
|
|
|
stream `should be` null
|
2018-03-24 19:30:03 +01:00
|
|
|
responseHttpCode `should be equal to` httpErrorCode
|
2017-11-05 22:14:02 +01:00
|
|
|
apiError `should be` null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should return successfull call stream`() {
|
2020-06-13 19:04:31 +02:00
|
|
|
mockWebServerRule.mockWebServer.enqueue(
|
|
|
|
MockResponse()
|
|
|
|
.setBody(mockWebServerRule.loadJsonResponse("ping_ok.json"))
|
|
|
|
)
|
2017-11-05 22:14:02 +01:00
|
|
|
|
|
|
|
val response = client.stream("some-id")
|
|
|
|
|
|
|
|
with(response) {
|
2018-03-24 19:30:03 +01:00
|
|
|
responseHttpCode `should be equal to` 200
|
2017-11-05 22:14:02 +01:00
|
|
|
apiError `should be` null
|
|
|
|
stream `should not be` null
|
|
|
|
val expectedContent = mockWebServerRule.loadJsonResponse("ping_ok.json")
|
2018-03-24 19:30:03 +01:00
|
|
|
stream!!.bufferedReader().readText() `should be equal to` expectedContent
|
2017-11-05 22:14:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should pass id as parameter`() {
|
|
|
|
val id = "asdo123"
|
|
|
|
|
|
|
|
mockWebServerRule.assertRequestParam("ping_ok.json", id) {
|
|
|
|
client.api.stream(id = id).execute()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should pass max bit rate as param`() {
|
|
|
|
val maxBitRate = 360
|
|
|
|
|
2020-06-13 19:04:31 +02:00
|
|
|
mockWebServerRule.assertRequestParam(
|
|
|
|
"ping_ok.json",
|
|
|
|
"maxBitRate=$maxBitRate"
|
|
|
|
) {
|
2017-11-05 22:14:02 +01:00
|
|
|
client.api.stream("some-id", maxBitRate = maxBitRate).execute()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should pass format as param`() {
|
|
|
|
val format = "aac"
|
|
|
|
|
2020-06-13 19:04:31 +02:00
|
|
|
mockWebServerRule.assertRequestParam(
|
|
|
|
"ping_ok.json",
|
|
|
|
"format=$format"
|
|
|
|
) {
|
2017-11-05 22:14:02 +01:00
|
|
|
client.api.stream("some-id", format = format).execute()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should pass time offset as param`() {
|
|
|
|
val timeOffset = 155
|
|
|
|
|
2020-06-13 19:04:31 +02:00
|
|
|
mockWebServerRule.assertRequestParam(
|
|
|
|
"ping_ok.json",
|
|
|
|
"timeOffset=$timeOffset"
|
|
|
|
) {
|
2017-11-05 22:14:02 +01:00
|
|
|
client.api.stream("some-id", timeOffset = timeOffset).execute()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should pass video size as param`() {
|
|
|
|
val videoSize = "44144"
|
|
|
|
|
2020-06-13 19:04:31 +02:00
|
|
|
mockWebServerRule.assertRequestParam(
|
|
|
|
"ping_ok.json",
|
|
|
|
"size=$videoSize"
|
|
|
|
) {
|
2017-11-05 22:14:02 +01:00
|
|
|
client.api.stream("some-id", videoSize = videoSize).execute()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should pass estimate content length as param`() {
|
|
|
|
val estimateContentLength = true
|
|
|
|
|
2020-06-13 19:04:31 +02:00
|
|
|
mockWebServerRule.assertRequestParam(
|
|
|
|
"ping_ok.json",
|
|
|
|
"estimateContentLength=$estimateContentLength"
|
|
|
|
) {
|
2017-11-05 22:14:02 +01:00
|
|
|
client.api.stream("some-id", estimateContentLength = estimateContentLength).execute()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should pass converted as param`() {
|
|
|
|
val converted = false
|
|
|
|
|
2020-06-13 19:04:31 +02:00
|
|
|
mockWebServerRule.assertRequestParam(
|
|
|
|
"ping_ok.json",
|
|
|
|
"converted=$converted"
|
|
|
|
) {
|
2017-11-05 22:14:02 +01:00
|
|
|
client.api.stream("some-id", converted = converted).execute()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|