diff --git a/src/main/kotlin/com/vonage/client/kt/Voice.kt b/src/main/kotlin/com/vonage/client/kt/Voice.kt index 1534b9c..62af4fa 100644 --- a/src/main/kotlin/com/vonage/client/kt/Voice.kt +++ b/src/main/kotlin/com/vonage/client/kt/Voice.kt @@ -34,10 +34,8 @@ class Voice(private val voiceClient: VoiceClient) { fun sendDtmf(digits: String): DtmfResponse = voiceClient.sendDtmf(callId, digits) - fun streamAudio(streamUrl: String, loop: Int? = null, level: Double? = null): StreamResponse = - if (loop != null && level != null) voiceClient.startStream(callId, streamUrl, loop, level) - else if (loop != null) voiceClient.startStream(callId, streamUrl, loop) - else voiceClient.startStream(callId, streamUrl) + fun streamAudio(streamUrl: String, loop: Int = 1, level: Double = 0.0): StreamResponse = + voiceClient.startStream(callId, streamUrl, loop, level) fun stopStream(): StreamResponse = voiceClient.stopStream(callId) diff --git a/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt b/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt index 14e0233..5199af9 100644 --- a/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/AbstractTest.kt @@ -188,17 +188,20 @@ abstract class AbstractTest { protected inline fun assertApiResponseException( url: String, requestMethod: HttpMethod, actualCall: () -> Any, status: Int, - errorType: String, title: String, detail: String, instance: String): E { + errorType: String? = null, title: String? = null, + detail: String? = null, instance: String? = null): E { - mockRequest(requestMethod, url).mockReturn(status, mapOf( - "type" to errorType, "title" to title, - "detail" to detail, "instance" to instance - )) + val responseParams = mutableMapOf() + if (errorType != null) responseParams["type"] = errorType + if (title != null) responseParams["title"] = title + if (detail != null) responseParams["detail"] = detail + if (instance != null) responseParams["instance"] = instance + mockRequest(requestMethod, url).mockReturn(status, responseParams) val exception = assertThrows { actualCall.invoke() } assertEquals(status, exception.statusCode) - assertEquals(URI.create(errorType), exception.type) + assertEquals(if (errorType != null) URI.create(errorType) else null, exception.type) assertEquals(title, exception.title) assertEquals(instance, exception.instance) assertEquals(detail, exception.detail) diff --git a/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt b/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt index dd74b46..e12aa1b 100644 --- a/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt +++ b/src/test/kotlin/com/vonage/client/kt/VoiceTest.kt @@ -99,6 +99,12 @@ class VoiceTest : AbstractTest() { assertEqualsSampleCall(infos[1]) } + private fun assertExistingCall404(url: String, requestMethod: HttpMethod, invocation: () -> Any) { + assertApiResponseException(url, requestMethod, invocation, 404, + title = "Not Found", detail = "Call $callIdStr doesn't exist." + ) + } + private fun testModifyCall(actionName: String = "transfer", invocation: () -> Unit, nccoAction: Map? = null, nccoUrl: String? = null) { mockPut(expectedUrl = callUrl, @@ -112,21 +118,22 @@ class VoiceTest : AbstractTest() { status = 204 ) invocation.invoke() + assertExistingCall404(callUrl, HttpMethod.PUT, invocation) } private fun testStream(loop: Int = 1, level: Double = 0.0, invocation: (() -> StreamResponse)? = null) { val message = "Stream ${if (invocation == null) "stopped" else "started"}" val expectedResponseParams = mapOf("message" to message, "uuid" to callIdStr) - val expectedUrl = "$callUrl/stream" + val streamUrl = "$callUrl/stream" val response = if (invocation == null) { - mockDelete(expectedUrl, expectedResponseParams = expectedResponseParams) + mockDelete(streamUrl, expectedResponseParams = expectedResponseParams) callObj.stopStream() } else { - mockPut(expectedUrl, status = 200, + mockPut(streamUrl, status = 200, expectedRequestParams = mapOf( - "stream_url" to listOf(streamUrl), + "stream_url" to listOf(this.streamUrl), "loop" to loop, "level" to level ), expectedResponseParams = expectedResponseParams @@ -136,6 +143,9 @@ class VoiceTest : AbstractTest() { 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) } private fun testTextToSpeech(expectedRequestParams: Map? = null, invocation: () -> TalkResponse) { @@ -152,6 +162,11 @@ class VoiceTest : AbstractTest() { assertNotNull(response) assertEquals(message, response.message) assertEquals(callIdStr, response.uuid) + + assertExistingCall404(talkUrl, + if (expectedRequestParams != null) HttpMethod.PUT else HttpMethod.DELETE, + invocation + ) } @Test