Skip to content

Commit

Permalink
Test sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Aug 23, 2024
1 parent 4a81c7c commit 4df6899
Show file tree
Hide file tree
Showing 4 changed files with 351 additions and 11 deletions.
12 changes: 9 additions & 3 deletions src/main/kotlin/com/vonage/client/kt/Video.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.vonage.client.kt

import com.vonage.client.video.*
import java.util.*

class Video(private val client: VideoClient) {

Expand Down Expand Up @@ -52,6 +53,11 @@ class Video(private val client: VideoClient) {
fun sendDtmf(digits: String): Unit = client.sendDtmf(sessionId, connectionId, digits)
}

fun muteStreams(active: Boolean = true, vararg excludedStreamIds: String): ProjectDetails =
client.muteSession(sessionId, active,
if (excludedStreamIds.isNotEmpty()) excludedStreamIds.toList() else null
)

fun listStreams(): List<GetStreamResponse> = client.listStreams(sessionId)

fun listArchives(count: Int = 1000, offset: Int = 0): List<Archive> =
Expand All @@ -65,10 +71,10 @@ class Video(private val client: VideoClient) {

fun sendDtmf(digits: String): Unit = client.sendDtmf(sessionId, digits)

fun startCaptions(token: String, properties: CaptionsRequest.Builder.() -> Unit): CaptionsResponse =
fun startCaptions(token: String, properties: CaptionsRequest.Builder.() -> Unit): UUID =
client.startCaptions(CaptionsRequest.builder()
.apply(properties).sessionId(sessionId).token(token).build()
)
).captionsId

fun stopCaptions(captionsId: String): Unit = client.stopCaptions(captionsId)

Expand Down Expand Up @@ -150,7 +156,7 @@ class Video(private val client: VideoClient) {
fun listRenders(count: Int = 1000, offset: Int = 0): List<RenderResponse> =
client.listRenders(ListStreamCompositionsRequest.builder().count(count).offset(offset).build())

fun experienceComposer(renderId: String): ExistingRender = ExistingRender(renderId)
fun render(renderId: String): ExistingRender = ExistingRender(renderId)

inner class ExistingRender internal constructor(val renderId: String) {

Expand Down
13 changes: 10 additions & 3 deletions src/test/kotlin/com/vonage/client/kt/AbstractTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ abstract class AbstractTest {
private val signatureSecretName = "sig"
private val apiSecretName = "api_secret"
private val apiKeyName = "api_key"
private val contentTypeHeaderName = "Content-Type"
private val authHeaderName = "Authorization"
private val basicSecretEncodedHeader = "Basic $apiKeySecretEncoded"
private val jwtBearerPattern = "Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9(\\..+){2}"
Expand All @@ -62,6 +63,7 @@ abstract class AbstractTest {
protected val cursor = "7EjDNQrAcipmOnc0HCzpQRkhBULzY44ljGUX4lXKyUIVfiZay5pv9wg="
protected val vbcExt = "4321"
protected val userName = "Sam_username"
protected val dtmf = "p*123#"
protected val sipUri = "sip:[email protected]"
protected val websocketUri = "wss://example.com/socket"
protected val wsContentType = "audio/l16;rate=8000"
Expand Down Expand Up @@ -156,13 +158,18 @@ abstract class AbstractTest {
}
}

private fun Map<String, Any>.toJson(): String = ObjectMapper().writeValueAsString(this)
private fun Any.toJson(): String = ObjectMapper().writeValueAsString(this)

protected fun mockPostQueryParams(expectedUrl: String, expectedRequestParams: Map<String, Any>,
authType: AuthType? = AuthType.API_KEY_SECRET_QUERY_PARAMS,
status: Int = 200, expectedResponseParams: Map<String, Any>? = null) {
contentType: Boolean = false, status: Int = 200,
expectedResponseParams: Any? = null) {

val stub = post(urlPathEqualTo(expectedUrl))
if (contentType) {
stub.withHeader(contentTypeHeaderName, equalTo(ContentType.FORM_URLENCODED.mime))
}

when (authType) {
AuthType.API_KEY_SECRET_QUERY_PARAMS -> {
stub.withFormParam(apiKeyName, equalTo(apiKey))
Expand Down Expand Up @@ -196,7 +203,7 @@ abstract class AbstractTest {
urlPath equalTo expectedUrl
headers contains "User-Agent" like "vonage-java-sdk\\/.+ java\\/.+"
if (contentType != null) {
headers contains "Content-Type" equalTo contentType.mime
headers contains contentTypeHeaderName equalTo contentType.mime
}
if (accept != null) {
headers contains "Accept" equalTo accept.mime
Expand Down
Loading

0 comments on commit 4df6899

Please sign in to comment.