2017-10-17 21:31:33 +02: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-10-17 21:31:33 +02:00
|
|
|
import org.amshove.kluent.`should be`
|
|
|
|
import org.amshove.kluent.`should equal`
|
|
|
|
import org.amshove.kluent.`should not be`
|
|
|
|
import org.junit.Test
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Integration test for [SubsonicAPIClient] for [SubsonicAPIDefinition.getCoverArt] call.
|
|
|
|
*/
|
|
|
|
class SubsonicApiGetCoverArtTest : 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-10-17 21:31:33 +02:00
|
|
|
|
|
|
|
val response = client.getCoverArt("some-id")
|
|
|
|
|
|
|
|
with(response) {
|
|
|
|
stream `should be` null
|
2018-03-24 19:30:03 +01:00
|
|
|
responseHttpCode `should be equal to` 200
|
2018-01-13 10:19:42 +01:00
|
|
|
apiError `should equal` SubsonicError.RequestedDataWasNotFound
|
2017-10-17 21:31:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should handle server error`() {
|
|
|
|
val httpErrorCode = 404
|
|
|
|
mockWebServerRule.mockWebServer.enqueue(MockResponse().setResponseCode(httpErrorCode))
|
|
|
|
|
|
|
|
val response = client.getCoverArt("some-id")
|
|
|
|
|
|
|
|
with(response) {
|
|
|
|
stream `should be` null
|
2017-11-05 22:14:02 +01:00
|
|
|
responseHttpCode `should equal` 404
|
2017-10-17 21:31:33 +02:00
|
|
|
apiError `should be` null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should return successful call stream`() {
|
|
|
|
mockWebServerRule.mockWebServer.enqueue(MockResponse()
|
|
|
|
.setBody(mockWebServerRule.loadJsonResponse("ping_ok.json")))
|
|
|
|
|
|
|
|
val response = client.getCoverArt("some-id")
|
|
|
|
|
|
|
|
with(response) {
|
2018-03-24 19:30:03 +01:00
|
|
|
responseHttpCode `should be equal to` 200
|
2017-10-17 21:31:33 +02: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-10-17 21:31:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should pass id as parameter`() {
|
|
|
|
val id = "ca123994"
|
|
|
|
|
|
|
|
mockWebServerRule.assertRequestParam("ping_ok.json", id) {
|
|
|
|
client.api.getCoverArt(id).execute()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun `Should pass size as a parameter`() {
|
|
|
|
val size = 45600L
|
|
|
|
|
|
|
|
mockWebServerRule.assertRequestParam("ping_ok.json", size.toString()) {
|
|
|
|
client.api.getCoverArt("some-id", size).execute()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|