diff --git a/CHANGELOG.md b/CHANGELOG.md index e78f3e8..acfd3a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -## [1.0.0-beta1] - 2024-09-?? +## [1.0.0-beta1] - 2024-09-02 ### Added - Video API +### Changed +- Standardised `Existing*` classes to extend `ExistingResource` for consistency + ## [0.9.0] - 2024-08-19 ### Added diff --git a/src/main/kotlin/com/vonage/client/kt/Application.kt b/src/main/kotlin/com/vonage/client/kt/Application.kt index 148c63a..2584cef 100644 --- a/src/main/kotlin/com/vonage/client/kt/Application.kt +++ b/src/main/kotlin/com/vonage/client/kt/Application.kt @@ -30,7 +30,7 @@ class Application internal constructor(private val client: ApplicationClient) { fun application(applicationId: UUID) = application(applicationId.toString()) - inner class ExistingApplication internal constructor(val id: String) { + inner class ExistingApplication internal constructor(id: String): ExistingResource(id) { fun get(): Application = client.getApplication(id) fun update(properties: Application.Builder.() -> Unit): Application = diff --git a/src/main/kotlin/com/vonage/client/kt/ExistingResource.kt b/src/main/kotlin/com/vonage/client/kt/ExistingResource.kt new file mode 100644 index 0000000..e80ae63 --- /dev/null +++ b/src/main/kotlin/com/vonage/client/kt/ExistingResource.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2024 Vonage + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.vonage.client.kt + +open class ExistingResource internal constructor(val id: String) { + + @Override + override fun toString(): String = "${this::class.qualifiedName} {id=$id}" + + @Override + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + other as ExistingResource + return id == other.id + } + + @Override + override fun hashCode(): Int { + return id.hashCode() + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/vonage/client/kt/Subaccounts.kt b/src/main/kotlin/com/vonage/client/kt/Subaccounts.kt index 66253ca..fda755c 100644 --- a/src/main/kotlin/com/vonage/client/kt/Subaccounts.kt +++ b/src/main/kotlin/com/vonage/client/kt/Subaccounts.kt @@ -33,15 +33,15 @@ class Subaccounts internal constructor(private val client: SubaccountsClient) { fun subaccount(subaccountKey: String): ExistingSubaccount = ExistingSubaccount(subaccountKey) - inner class ExistingSubaccount internal constructor(val key: String) { + inner class ExistingSubaccount internal constructor(key: String): ExistingResource(key) { - fun get(): Account = client.getSubaccount(key) + fun get(): Account = client.getSubaccount(id) fun suspended(suspend: Boolean): Account = - client.updateSubaccount(UpdateSubaccountRequest.builder(key).suspended(suspend).build()) + client.updateSubaccount(UpdateSubaccountRequest.builder(id).suspended(suspend).build()) fun update(name: String? = null, usePrimaryAccountBalance: Boolean? = null): Account { - val builder = UpdateSubaccountRequest.builder(key).name(name) + val builder = UpdateSubaccountRequest.builder(id).name(name) if (usePrimaryAccountBalance != null) { builder.usePrimaryAccountBalance(usePrimaryAccountBalance) } diff --git a/src/main/kotlin/com/vonage/client/kt/Users.kt b/src/main/kotlin/com/vonage/client/kt/Users.kt index cbe5812..ef12970 100644 --- a/src/main/kotlin/com/vonage/client/kt/Users.kt +++ b/src/main/kotlin/com/vonage/client/kt/Users.kt @@ -23,26 +23,13 @@ class Users internal constructor(private val client: UsersClient) { fun user(user: BaseUser): ExistingUser = ExistingUser(user.id) - inner class ExistingUser internal constructor(val id: String) { + inner class ExistingUser internal constructor(id: String): ExistingResource(id) { fun get(): User = client.getUser(id) fun update(properties: User.Builder.() -> Unit): User = client.updateUser(id, User.builder().apply(properties).build()) fun delete(): Unit = client.deleteUser(id) - - @Override - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - other as ExistingUser - return id == other.id - } - - @Override - override fun hashCode(): Int { - return id.hashCode() - } } fun create(properties: User.Builder.() -> Unit): User = diff --git a/src/main/kotlin/com/vonage/client/kt/Verify.kt b/src/main/kotlin/com/vonage/client/kt/Verify.kt index 404c08c..5350a3c 100644 --- a/src/main/kotlin/com/vonage/client/kt/Verify.kt +++ b/src/main/kotlin/com/vonage/client/kt/Verify.kt @@ -27,14 +27,14 @@ class Verify(private val client: Verify2Client) { VerificationRequest.builder().brand(brand).apply(init).build() ) - inner class ExistingRequest internal constructor(val id: UUID) { + inner class ExistingRequest internal constructor(private val uuid: UUID): ExistingResource(uuid.toString()) { - fun cancel(): Unit = client.cancelVerification(id) + fun cancel(): Unit = client.cancelVerification(uuid) - fun nextWorkflow(): Unit = client.nextWorkflow(id) + fun nextWorkflow(): Unit = client.nextWorkflow(uuid) fun checkVerificationCode(code: String): VerifyCodeResponse = - client.checkVerificationCode(id, code) + client.checkVerificationCode(uuid, code) fun isValidVerificationCode(code: String): Boolean { try { diff --git a/src/main/kotlin/com/vonage/client/kt/VerifyLegacy.kt b/src/main/kotlin/com/vonage/client/kt/VerifyLegacy.kt index de9ec74..641262c 100644 --- a/src/main/kotlin/com/vonage/client/kt/VerifyLegacy.kt +++ b/src/main/kotlin/com/vonage/client/kt/VerifyLegacy.kt @@ -32,7 +32,7 @@ class VerifyLegacy internal constructor(private val client: VerifyClient) { fun request(response: VerifyResponse): ExistingRequest = request(response.requestId) - inner class ExistingRequest internal constructor(val id: String) { + inner class ExistingRequest internal constructor(id: String): ExistingResource(id) { fun cancel(): ControlResponse = client.cancelVerification(id) @@ -42,18 +42,6 @@ class VerifyLegacy internal constructor(private val client: VerifyClient) { fun search(): SearchVerifyResponse = client.search(id) - @Override - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - other as ExistingRequest - return id == other.id - } - - @Override - override fun hashCode(): Int { - return id.hashCode() - } } } \ No newline at end of file diff --git a/src/main/kotlin/com/vonage/client/kt/Video.kt b/src/main/kotlin/com/vonage/client/kt/Video.kt index e79b4ed..ded55be 100644 --- a/src/main/kotlin/com/vonage/client/kt/Video.kt +++ b/src/main/kotlin/com/vonage/client/kt/Video.kt @@ -25,25 +25,25 @@ class Video(private val client: VideoClient) { fun session(sessionId: String): ExistingSession = ExistingSession(sessionId) - inner class ExistingSession internal constructor(val id: String) { + inner class ExistingSession internal constructor(id: String): ExistingResource(id) { fun stream(streamId: String): ExistingStream = ExistingStream(streamId) - inner class ExistingStream internal constructor(val streamId: String) { + inner class ExistingStream internal constructor(id: String): ExistingResource(id) { - fun info(): GetStreamResponse = client.getStream(id, streamId) + fun info(): GetStreamResponse = client.getStream(this@ExistingSession.id, id) - fun mute(): Unit = client.muteStream(id, streamId) + fun mute(): Unit = client.muteStream(this@ExistingSession.id, id) fun setLayout(vararg layoutClasses: String): Unit = - client.setStreamLayout(id, - SessionStream.builder(streamId).layoutClassList(layoutClasses.toList()).build() + client.setStreamLayout(this@ExistingSession.id, + SessionStream.builder(id).layoutClassList(layoutClasses.toList()).build() ) } fun connection(connectionId: String): ExistingConnection = ExistingConnection(connectionId) - inner class ExistingConnection internal constructor(val id: String) { + inner class ExistingConnection internal constructor(id: String): ExistingResource(id) { fun disconnect(): Unit = client.forceDisconnect(this@ExistingSession.id, id) @@ -99,7 +99,7 @@ class Video(private val client: VideoClient) { fun archive(archiveId: String): ExistingArchive = ExistingArchive(archiveId) - inner class ExistingArchive internal constructor(val id: String) { + inner class ExistingArchive internal constructor(id: String): ExistingResource(id) { fun info(): Archive = client.getArchive(id) @@ -128,7 +128,7 @@ class Video(private val client: VideoClient) { fun broadcast(broadcastId: String): ExistingBroadcast = ExistingBroadcast(broadcastId) - inner class ExistingBroadcast internal constructor(val id: String) { + inner class ExistingBroadcast internal constructor(id: String): ExistingResource(id) { fun info(): Broadcast = client.getBroadcast(id) @@ -158,7 +158,7 @@ class Video(private val client: VideoClient) { fun render(renderId: String): ExistingRender = ExistingRender(renderId) - inner class ExistingRender internal constructor(val id: String) { + inner class ExistingRender internal constructor(id: String): ExistingResource(id) { fun info(): RenderResponse = client.getRender(id) diff --git a/src/main/kotlin/com/vonage/client/kt/Voice.kt b/src/main/kotlin/com/vonage/client/kt/Voice.kt index e90bfb7..6321dcb 100644 --- a/src/main/kotlin/com/vonage/client/kt/Voice.kt +++ b/src/main/kotlin/com/vonage/client/kt/Voice.kt @@ -25,7 +25,7 @@ class Voice internal constructor(private val client: VoiceClient) { fun call(callId: String): ExistingCall = ExistingCall(callId) - inner class ExistingCall internal constructor(val id: String) { + inner class ExistingCall internal constructor(id: String): ExistingResource(id) { fun info(): CallInfo = client.getCallDetails(id) diff --git a/src/test/kotlin/com/vonage/client/kt/AccountTest.kt b/src/test/kotlin/com/vonage/client/kt/AccountTest.kt index ea08ecf..378a8c8 100644 --- a/src/test/kotlin/com/vonage/client/kt/AccountTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/AccountTest.kt @@ -60,7 +60,7 @@ class AccountTest : AbstractTest() { ) ) - val response = invocation.invoke(account) + val response = invocation(account) assertNotNull(response) assertEquals(moCallbackUrl, response.incomingSmsUrl) assertEquals(drCallbackUrl, response.deliveryReceiptUrl) @@ -98,7 +98,7 @@ class AccountTest : AbstractTest() { ) val invocation = { getSecretsObj(withApiKey).list() } - val response = invocation.invoke() + val response = invocation() assertNotNull(response) assertEquals(2, response.size) assertSecretResponse(response[0]) @@ -118,7 +118,7 @@ class AccountTest : AbstractTest() { expectedRequestParams = secretRequest, status = 201, expectedResponseParams = secretResponse ) - assertSecretResponse(invocation.invoke()) + assertSecretResponse(invocation()) assert401ApiResponseException(url, HttpMethod.POST, invocation) } @@ -129,7 +129,7 @@ class AccountTest : AbstractTest() { expectedResponseParams = secretResponse ) val invocation = { getSecretsObj(withApiKey).get(secretId) } - assertSecretResponse(invocation.invoke()) + assertSecretResponse(invocation()) assert401ApiResponseException(url, HttpMethod.GET, invocation) } @@ -137,7 +137,7 @@ class AccountTest : AbstractTest() { val url = getSecretUrl(withApiKey) val invocation = { getSecretsObj(withApiKey).delete(secretId) } mockDelete(url, authType) - invocation.invoke() + invocation() mockRequest(HttpMethod.DELETE, expectedUrl = url, authType = authType) .mockReturn(status = errorCode, errorResponse) diff --git a/src/test/kotlin/com/vonage/client/kt/ApplicationTest.kt b/src/test/kotlin/com/vonage/client/kt/ApplicationTest.kt index ecb32f7..00a9a8e 100644 --- a/src/test/kotlin/com/vonage/client/kt/ApplicationTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/ApplicationTest.kt @@ -226,7 +226,7 @@ class ApplicationTest : AbstractTest() { ) ) ) - val response = invocation.invoke() + val response = invocation() assertNotNull(response) assertEquals(4, response.size) assertEqualsIdOnlyApplication(response[0]) diff --git a/src/test/kotlin/com/vonage/client/kt/NumberVerificationTest.kt b/src/test/kotlin/com/vonage/client/kt/NumberVerificationTest.kt index b549219..7ed0e7f 100644 --- a/src/test/kotlin/com/vonage/client/kt/NumberVerificationTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/NumberVerificationTest.kt @@ -50,7 +50,7 @@ class NumberVerificationTest : AbstractTest() { expectedResponseParams = if (result != null) mapOf("devicePhoneNumberVerified" to result) else mapOf() ) - assertEquals(result ?: false, invocation.invoke(nvClient)) + assertEquals(result ?: false, invocation(nvClient)) } } diff --git a/src/test/kotlin/com/vonage/client/kt/NumbersTest.kt b/src/test/kotlin/com/vonage/client/kt/NumbersTest.kt index 31d7253..4126e83 100644 --- a/src/test/kotlin/com/vonage/client/kt/NumbersTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/NumbersTest.kt @@ -55,7 +55,7 @@ class NumbersTest : AbstractTest() { status = errorCode, authType = authType, expectedResponseParams = errorResponse ) - assertThrows { invocation.invoke(client) } + assertThrows { invocation(client) } } private fun assertThrowsPost(endpoint: String, invocation: Numbers.ExistingNumber.() -> Any) { @@ -63,7 +63,7 @@ class NumbersTest : AbstractTest() { status = errorCode, authType = authType, expectedResponseParams = errorResponse ) - assertThrows { invocation.invoke(existingNumber) } + assertThrows { invocation(existingNumber) } } private fun mockAction(endpoint: String, additionalParams: Map = mapOf()) { @@ -101,7 +101,7 @@ class NumbersTest : AbstractTest() { ) ) - val response = invocation.invoke(client) + val response = invocation(client) assertNotNull(response) assertEquals(count, response.count) val numbers = response.numbers @@ -159,7 +159,7 @@ class NumbersTest : AbstractTest() { ) ) - val response = invocation.invoke(client) + val response = invocation(client) assertNotNull(response) assertEquals(count, response.count) val numbers = response.numbers diff --git a/src/test/kotlin/com/vonage/client/kt/RedactTest.kt b/src/test/kotlin/com/vonage/client/kt/RedactTest.kt index 019b457..9e89b52 100644 --- a/src/test/kotlin/com/vonage/client/kt/RedactTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/RedactTest.kt @@ -30,7 +30,7 @@ class RedactTest : AbstractTest() { "product" to product ) + if (type != null) mapOf("type" to type.name.lowercase()) else mapOf() ) - invocation.invoke(vonage.redact) + invocation(vonage.redact) } @Test diff --git a/src/test/kotlin/com/vonage/client/kt/SimSwapTest.kt b/src/test/kotlin/com/vonage/client/kt/SimSwapTest.kt index 6029618..2d651a0 100644 --- a/src/test/kotlin/com/vonage/client/kt/SimSwapTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/SimSwapTest.kt @@ -66,7 +66,7 @@ class SimSwapTest : AbstractTest() { expectedRequestParams = phoneNumberMap + mapOf("maxAge" to maxAge), expectedResponseParams = if (result != null) mapOf("swapped" to result) else mapOf() ) - assertEquals(result ?: false, invocation.invoke(simSwapClient)) + assertEquals(result == true, invocation(simSwapClient)) } } diff --git a/src/test/kotlin/com/vonage/client/kt/SmsTest.kt b/src/test/kotlin/com/vonage/client/kt/SmsTest.kt index 004d4fb..04c9514 100644 --- a/src/test/kotlin/com/vonage/client/kt/SmsTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/SmsTest.kt @@ -57,7 +57,7 @@ class SmsTest : AbstractTest() { ) ) - val response = invocation.invoke() + val response = invocation() assertNotNull(response) assertEquals(1, response.size) val first = response.first() diff --git a/src/test/kotlin/com/vonage/client/kt/SubaccountsTest.kt b/src/test/kotlin/com/vonage/client/kt/SubaccountsTest.kt index 0c83046..cec5b3d 100644 --- a/src/test/kotlin/com/vonage/client/kt/SubaccountsTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/SubaccountsTest.kt @@ -55,7 +55,7 @@ class SubaccountsTest : AbstractTest() { private fun assertEqualsSampleSubaccount(parsed: Account) { assertNotNull(parsed) assertEquals(secret, parsed.secret) - assertEquals(existingSubaccount.key, parsed.apiKey) + assertEquals(existingSubaccount.id, parsed.apiKey) assertEquals(name, parsed.name) assertEquals(apiKey, parsed.primaryAccountApiKey) assertEquals(usePrimary, parsed.usePrimaryAccountBalance) @@ -71,9 +71,9 @@ class SubaccountsTest : AbstractTest() { expectedRequestParams = mapOf("name" to name) + additionalParams, expectedResponseParams = sampleSubaccountMap ) - assertEqualsSampleSubaccount(invocation.invoke(client)) + assertEqualsSampleSubaccount(invocation(client)) assert401ApiResponseException(subaccountsUrl, HttpMethod.POST) { - invocation.invoke(client) + invocation(client) } } @@ -110,7 +110,7 @@ class SubaccountsTest : AbstractTest() { ) ) - val response = invocation.invoke(client) + val response = invocation(client) assertNotNull(response) assertEquals(BigDecimal.valueOf(amount), response.amount) assertEquals(transferFrom, response.from) @@ -120,7 +120,7 @@ class SubaccountsTest : AbstractTest() { assertEquals(reference, response.reference) assert401ApiResponseException(url, HttpMethod.POST) { - invocation.invoke(client) + invocation(client) } } @@ -149,7 +149,7 @@ class SubaccountsTest : AbstractTest() { ) ) ) - val response = invocation.invoke(client) + val response = invocation(client) assertNotNull(response) assertEquals(2, response.size) val main = response[0] @@ -168,7 +168,7 @@ class SubaccountsTest : AbstractTest() { assertNull(blank.createdAt) assert401ApiResponseException(url, HttpMethod.GET) { - invocation.invoke(client) + invocation(client) } } diff --git a/src/test/kotlin/com/vonage/client/kt/UsersTest.kt b/src/test/kotlin/com/vonage/client/kt/UsersTest.kt index 249d3be..a9659ca 100644 --- a/src/test/kotlin/com/vonage/client/kt/UsersTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/UsersTest.kt @@ -139,7 +139,7 @@ class UsersTest : AbstractTest() { private fun assertUserNotFoundException(method: HttpMethod, invocation: Users.ExistingUser.() -> Any) = assertApiResponseException( url = userUrl, requestMethod = method, - actualCall = { invocation.invoke(existingUser) }, + actualCall = { invocation(existingUser) }, status = 404, title = "Not found.", errorType = "https://developer.vonage.com/api/conversation#user:error:not-found", @@ -173,7 +173,7 @@ class UsersTest : AbstractTest() { ) ) ) - val response = invocation.invoke(client) + val response = invocation(client) assertNotNull(response) val users = response.users assertNotNull(users) @@ -197,7 +197,7 @@ class UsersTest : AbstractTest() { assertEquals(existingUser.id, client.user(idOnlyUser).id) assert401ApiResponseException(baseUrl, HttpMethod.GET) { - invocation.invoke(client) + invocation(client) } } diff --git a/src/test/kotlin/com/vonage/client/kt/VerifyLegacyTest.kt b/src/test/kotlin/com/vonage/client/kt/VerifyLegacyTest.kt index e5f9ee7..aa7adbc 100644 --- a/src/test/kotlin/com/vonage/client/kt/VerifyLegacyTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/VerifyLegacyTest.kt @@ -45,7 +45,7 @@ class VerifyLegacyTest : AbstractTest() { "request_id" to requestId, "status" to "0" )) - val successParsed = invocation.invoke(verifyClient) + val successParsed = invocation(verifyClient) assertNotNull(successParsed) assertEquals(requestId, successParsed.requestId) assertEquals(VerifyStatus.OK, successParsed.status) @@ -58,7 +58,7 @@ class VerifyLegacyTest : AbstractTest() { "error_text" to errorText, "network" to networkCode )) - val failureParsed = invocation.invoke(verifyClient) + val failureParsed = invocation(verifyClient) assertNotNull(failureParsed) assertEquals(requestId, failureParsed.requestId) assertEquals(VerifyStatus.MISSING_PARAMS, failureParsed.status) diff --git a/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt b/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt index 9c6be80..d020586 100644 --- a/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt @@ -23,10 +23,10 @@ import java.util.* import kotlin.test.* class VoiceTest : AbstractTest() { - private val voiceClient = vonage.voice + private val client = vonage.voice private val callsBaseUrl = "/v1/calls" private val callUrl = "$callsBaseUrl/$callIdStr" - private val callObj = voiceClient.call(callIdStr) + private val existingCall = client.call(callIdStr) private val conversationId = "CON-f972836a-550f-45fa-956c-12a2ab5b7d22" private val price = "23.40" private val duration = 60 @@ -139,7 +139,7 @@ class VoiceTest : AbstractTest() { ), status = 204 ) - invocation.invoke() + invocation() assertExistingCall404(callUrl, HttpMethod.PUT, invocation) } @@ -150,7 +150,7 @@ class VoiceTest : AbstractTest() { val streamUrl = "$callUrl/stream" val response = if (invocation == null) { mockDelete(streamUrl, expectedResponseParams = expectedResponseParams) - callObj.stopStream() + existingCall.stopStream() } else { mockPut(streamUrl, status = 200, @@ -160,14 +160,14 @@ class VoiceTest : AbstractTest() { ), expectedResponseParams = expectedResponseParams ) - invocation.invoke() + invocation() } assertNotNull(response) assertEquals(message, response.message) assertEquals(callIdStr, response.uuid) if (invocation != null) assertExistingCall404(streamUrl, HttpMethod.PUT, invocation) - else assertExistingCall404(streamUrl, HttpMethod.DELETE, callObj::stopStream) + else assertExistingCall404(streamUrl, HttpMethod.DELETE, existingCall::stopStream) } private fun testTextToSpeech(expectedRequestParams: Map? = null, invocation: () -> TalkResponse) { @@ -180,7 +180,7 @@ class VoiceTest : AbstractTest() { else { mockDelete(talkUrl, AuthType.JWT, expectedResponseParams) } - val response = invocation.invoke() + val response = invocation() assertNotNull(response) assertEquals(message, response.message) assertEquals(callIdStr, response.uuid) @@ -204,7 +204,7 @@ class VoiceTest : AbstractTest() { ) ) - val callEvent = voiceClient.createCall(call) + val callEvent = this@VoiceTest.client.createCall(call) assertNotNull(callEvent) assertEquals(callIdStr, callEvent.uuid) assertEquals(callStatus, callEvent.status) @@ -248,49 +248,67 @@ class VoiceTest : AbstractTest() { "type" to connectAction.endpoint.first().type) + params)), connectAction ) + @Test + fun `existing call equals and hashCode`() { + val same = client.call(callIdStr) + assertEquals(existingCall, same) + assertEquals(existingCall.hashCode(), same.hashCode()) + assertEquals(callIdStr.hashCode(), existingCall.hashCode()) + assertFalse(existingCall.equals(callIdStr)) + assertFalse(existingCall.equals(null)) + val different = client.call(testUuidStr) + assertNotEquals(existingCall, different) + assertNotEquals(existingCall.hashCode(), different.hashCode()) + } + + @Test + fun `existing call toString`() { + assertEquals("com.vonage.client.kt.Voice.ExistingCall {id=$callIdStr}", existingCall.toString()) + } + @Test fun `terminate call`() { - testModifyCall("hangup", callObj::hangup) + testModifyCall("hangup", existingCall::hangup) } @Test fun `mute call`() { - testModifyCall("mute", callObj::mute) + testModifyCall("mute", existingCall::mute) } @Test fun `umute call`() { - testModifyCall("unmute", callObj::unmute) + testModifyCall("unmute", existingCall::unmute) } @Test fun `earmuff call`() { - testModifyCall("earmuff", callObj::earmuff) + testModifyCall("earmuff", existingCall::earmuff) } @Test fun `umearmuff call`() { - testModifyCall("unearmuff", callObj::unearmuff) + testModifyCall("unearmuff", existingCall::unearmuff) } @Test fun `get call`() { mockGet(expectedUrl = callUrl, expectedResponseParams = callResponseMap) - assertEqualsSampleCall(callObj.info()) + assertEqualsSampleCall(existingCall.info()) } @Test fun `transfer call with answer url`() { testModifyCall(nccoUrl = onAnswerUrl, invocation = { - callObj.transfer(URI.create(onAnswerUrl)) - callObj.transfer(onAnswerUrl) + existingCall.transfer(URI.create(onAnswerUrl)) + existingCall.transfer(onAnswerUrl) }) } @Test fun `transfer call with ncco`() { testModifyCall(nccoAction = mapOf("action" to "talk", "text" to text), invocation = { - callObj.transfer(TalkAction.builder(text).build()) + existingCall.transfer(TalkAction.builder(text).build()) }) } @@ -301,7 +319,7 @@ class VoiceTest : AbstractTest() { expectedRequestParams = mapOf("digits" to dtmf), expectedResponseParams = mapOf("message" to message, "uuid" to callIdStr) ) - val response = callObj.sendDtmf(dtmf) + val response = existingCall.sendDtmf(dtmf) assertNotNull(response) assertEquals(message, response.message) assertEquals(callIdStr, response.uuid) @@ -312,16 +330,16 @@ class VoiceTest : AbstractTest() { val loop = 3 val level = 0.45 testStream { - callObj.streamAudio(streamUrl) + existingCall.streamAudio(streamUrl) } testStream(loop = loop) { - callObj.streamAudio(streamUrl, loop) + existingCall.streamAudio(streamUrl, loop) } testStream(level = level) { - callObj.streamAudio(streamUrl, level = level) + existingCall.streamAudio(streamUrl, level = level) } testStream(loop = loop, level = level) { - callObj.streamAudio(streamUrl, loop = loop, level = level) + existingCall.streamAudio(streamUrl, loop = loop, level = level) } } @@ -341,7 +359,7 @@ class VoiceTest : AbstractTest() { "style" to style, "premium" to premium, "loop" to loop, "level" to level )) { - callObj.startTalk(text) { + existingCall.startTalk(text) { language(TextToSpeechLanguage.SCOTTISH_ENGLISH) style(style); premium(premium); loop(loop); level(level) } @@ -351,14 +369,14 @@ class VoiceTest : AbstractTest() { @Test fun `play text to speech text only`() { testTextToSpeech(mapOf("text" to text)) { - callObj.startTalk(text) + existingCall.startTalk(text) } } @Test fun `stop text to speech`() { testTextToSpeech { - callObj.stopTalk() + existingCall.stopTalk() } } @@ -374,7 +392,7 @@ class VoiceTest : AbstractTest() { "conversation_uuid" to conversationId ), expectedResponseParams = listCallsResponse) - val callsPage = voiceClient.listCalls { + val callsPage = this@VoiceTest.client.listCalls { status(CallStatus.UNANSWERED) dateStart(startTimeStr); dateEnd(endTimeStr) pageSize(pageSize); recordIndex(recordIndex) @@ -387,7 +405,7 @@ class VoiceTest : AbstractTest() { @Test fun `list calls no filter`() { mockGet(callsBaseUrl, expectedResponseParams = listCallsResponse) - assertEqualsSampleCallsPage(voiceClient.listCalls()) + assertEqualsSampleCallsPage(this@VoiceTest.client.listCalls()) } @Test