Add more test for error responses.
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
parent
3e1dbe3476
commit
fff0762e08
|
@ -5,6 +5,13 @@ import org.amshove.kluent.`should not be`
|
|||
import org.amshove.kluent.`should throw`
|
||||
import org.junit.Test
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicError.Generic
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicError.IncompatibleClientProtocolVersion
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicError.IncompatibleServerProtocolVersion
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicError.RequestedDataWasNotFound
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicError.RequiredParamMissing
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicError.TokenAuthNotSupportedForLDAP
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicError.TrialPeriodIsOver
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicError.UserNotAuthorizedForOperation
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicError.WrongUsernameOrPassword
|
||||
import org.moire.ultrasonic.api.subsonic.response.SubsonicResponse
|
||||
import retrofit2.Response
|
||||
|
@ -43,6 +50,69 @@ class SubsonicApiErrorsTest : SubsonicAPIClientTest() {
|
|||
fail `should throw` IOException::class
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should parse required param missing error`() {
|
||||
mockWebServerRule.enqueueResponse("required_param_missing_error.json")
|
||||
|
||||
val response = client.api.ping().execute()
|
||||
|
||||
response.assertError(RequiredParamMissing)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should parse incompatible client protocol version error`() {
|
||||
mockWebServerRule.enqueueResponse("incompatible_client_protocol_version_error.json")
|
||||
|
||||
val response = client.api.ping().execute()
|
||||
|
||||
response.assertError(IncompatibleClientProtocolVersion)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should parse incompatible server protocol version error`() {
|
||||
mockWebServerRule.enqueueResponse("incompatible_server_protocol_version_error.json")
|
||||
|
||||
val response = client.api.ping().execute()
|
||||
|
||||
response.assertError(IncompatibleServerProtocolVersion)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should parse token auth not supported for ldap error`() {
|
||||
mockWebServerRule.enqueueResponse("token_auth_not_supported_for_ldap_error.json")
|
||||
|
||||
val response = client.api.ping().execute()
|
||||
|
||||
response.assertError(TokenAuthNotSupportedForLDAP)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should parse user not authorized for operation error`() {
|
||||
mockWebServerRule.enqueueResponse("user_not_authorized_for_operation_error.json")
|
||||
|
||||
val response = client.api.ping().execute()
|
||||
|
||||
response.assertError(UserNotAuthorizedForOperation)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should parse trial period is over error`() {
|
||||
mockWebServerRule.enqueueResponse("trial_period_is_over_error.json")
|
||||
|
||||
val response = client.api.ping().execute()
|
||||
|
||||
response.assertError(TrialPeriodIsOver)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should parse requested data was not found error`() {
|
||||
mockWebServerRule.enqueueResponse("requested_data_was_not_found_error.json")
|
||||
|
||||
val response = client.api.ping().execute()
|
||||
|
||||
response.assertError(RequestedDataWasNotFound)
|
||||
}
|
||||
|
||||
private fun Response<SubsonicResponse>.assertError(expectedError: SubsonicError) =
|
||||
with(body()) {
|
||||
error `should not be` null
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"subsonic-response": {
|
||||
"status": "failed",
|
||||
"version": "1.15.0",
|
||||
"error": {
|
||||
"code": 20,
|
||||
"message": "Client protocol version 1.17.0 is not supported."
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"subsonic-response": {
|
||||
"status": "failed",
|
||||
"version": "1.15.0",
|
||||
"error": {
|
||||
"code": 30,
|
||||
"message": "Server doesn't support 1.10.0 protocol version."
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"subsonic-response": {
|
||||
"status": "failed",
|
||||
"version": "1.15.0",
|
||||
"error": {
|
||||
"code": 70,
|
||||
"message": "Requested data was not found."
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"subsonic-response": {
|
||||
"status": "failed",
|
||||
"version": "1.15.0",
|
||||
"error": {
|
||||
"code": 10,
|
||||
"message": "Param musicFolderId is missing."
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"subsonic-response": {
|
||||
"status": "failed",
|
||||
"version": "1.15.0",
|
||||
"error": {
|
||||
"code": 41,
|
||||
"message": "Token auth is not supported for ldap users."
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"subsonic-response": {
|
||||
"status": "failed",
|
||||
"version": "1.15.0",
|
||||
"error": {
|
||||
"code": 60,
|
||||
"message": "Trial period is over."
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"subsonic-response": {
|
||||
"status": "failed",
|
||||
"version": "1.15.0",
|
||||
"error": {
|
||||
"code": 50,
|
||||
"message": "User is not authorized for this operation."
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue