diff --git a/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiErrorsTest.kt b/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiErrorsTest.kt index 34234a73..f91e4557 100644 --- a/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiErrorsTest.kt +++ b/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiErrorsTest.kt @@ -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.assertError(expectedError: SubsonicError) = with(body()) { error `should not be` null diff --git a/subsonic-api/src/integrationTest/resources/incompatible_client_protocol_version_error.json b/subsonic-api/src/integrationTest/resources/incompatible_client_protocol_version_error.json new file mode 100644 index 00000000..4cf99209 --- /dev/null +++ b/subsonic-api/src/integrationTest/resources/incompatible_client_protocol_version_error.json @@ -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." + } + } +} diff --git a/subsonic-api/src/integrationTest/resources/incompatible_server_protocol_version_error.json b/subsonic-api/src/integrationTest/resources/incompatible_server_protocol_version_error.json new file mode 100644 index 00000000..bebc9120 --- /dev/null +++ b/subsonic-api/src/integrationTest/resources/incompatible_server_protocol_version_error.json @@ -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." + } + } +} diff --git a/subsonic-api/src/integrationTest/resources/requested_data_was_not_found_error.json b/subsonic-api/src/integrationTest/resources/requested_data_was_not_found_error.json new file mode 100644 index 00000000..c55cc1f6 --- /dev/null +++ b/subsonic-api/src/integrationTest/resources/requested_data_was_not_found_error.json @@ -0,0 +1,10 @@ +{ + "subsonic-response": { + "status": "failed", + "version": "1.15.0", + "error": { + "code": 70, + "message": "Requested data was not found." + } + } +} diff --git a/subsonic-api/src/integrationTest/resources/required_param_missing_error.json b/subsonic-api/src/integrationTest/resources/required_param_missing_error.json new file mode 100644 index 00000000..aa007e48 --- /dev/null +++ b/subsonic-api/src/integrationTest/resources/required_param_missing_error.json @@ -0,0 +1,10 @@ +{ + "subsonic-response": { + "status": "failed", + "version": "1.15.0", + "error": { + "code": 10, + "message": "Param musicFolderId is missing." + } + } +} diff --git a/subsonic-api/src/integrationTest/resources/token_auth_not_supported_for_ldap_error.json b/subsonic-api/src/integrationTest/resources/token_auth_not_supported_for_ldap_error.json new file mode 100644 index 00000000..4f5ff447 --- /dev/null +++ b/subsonic-api/src/integrationTest/resources/token_auth_not_supported_for_ldap_error.json @@ -0,0 +1,10 @@ +{ + "subsonic-response": { + "status": "failed", + "version": "1.15.0", + "error": { + "code": 41, + "message": "Token auth is not supported for ldap users." + } + } +} diff --git a/subsonic-api/src/integrationTest/resources/trial_period_is_over_error.json b/subsonic-api/src/integrationTest/resources/trial_period_is_over_error.json new file mode 100644 index 00000000..2196e7ff --- /dev/null +++ b/subsonic-api/src/integrationTest/resources/trial_period_is_over_error.json @@ -0,0 +1,10 @@ +{ + "subsonic-response": { + "status": "failed", + "version": "1.15.0", + "error": { + "code": 60, + "message": "Trial period is over." + } + } +} diff --git a/subsonic-api/src/integrationTest/resources/user_not_authorized_for_operation_error.json b/subsonic-api/src/integrationTest/resources/user_not_authorized_for_operation_error.json new file mode 100644 index 00000000..ad679b03 --- /dev/null +++ b/subsonic-api/src/integrationTest/resources/user_not_authorized_for_operation_error.json @@ -0,0 +1,10 @@ +{ + "subsonic-response": { + "status": "failed", + "version": "1.15.0", + "error": { + "code": 50, + "message": "User is not authorized for this operation." + } + } +}