|
10 | 10 | * Do not edit the class manually. |
11 | 11 | */ |
12 | 12 |
|
13 | | - |
14 | 13 | package com.bandwidth.sdk.api; |
15 | 14 |
|
| 15 | +import com.bandwidth.sdk.ApiResponse; |
16 | 16 | import com.bandwidth.sdk.ApiException; |
| 17 | +import com.bandwidth.sdk.ApiClient; |
| 18 | +import com.bandwidth.sdk.auth.HttpBasicAuth; |
| 19 | +import com.bandwidth.sdk.Configuration; |
| 20 | +import com.bandwidth.sdk.model.CallbackMethodEnum; |
| 21 | +import com.bandwidth.sdk.model.CreateCall; |
| 22 | +import com.bandwidth.sdk.model.CreateCallResponse; |
| 23 | +import com.bandwidth.sdk.model.CallDirectionEnum; |
| 24 | +import com.bandwidth.sdk.model.CallState; |
| 25 | +import com.bandwidth.sdk.model.CallStateEnum; |
| 26 | +import com.bandwidth.sdk.model.UpdateCall; |
17 | 27 | import com.bandwidth.sdk.model.CallTranscriptionMetadata; |
18 | 28 | import com.bandwidth.sdk.model.CallTranscriptionResponse; |
19 | 29 | import com.bandwidth.sdk.model.VoiceApiError; |
20 | | -import org.junit.jupiter.api.Disabled; |
| 30 | + |
21 | 31 | import org.junit.jupiter.api.Test; |
| 32 | +import org.junit.jupiter.api.TestInstance; |
| 33 | +import org.junit.jupiter.api.TestMethodOrder; |
| 34 | +import org.junit.jupiter.api.Assertions; |
22 | 35 |
|
| 36 | +import java.net.URI; |
| 37 | +import java.net.URISyntaxException; |
23 | 38 | import java.util.ArrayList; |
24 | | -import java.util.HashMap; |
25 | 39 | import java.util.List; |
| 40 | +import java.util.HashMap; |
26 | 41 | import java.util.Map; |
| 42 | +import java.time.OffsetDateTime; |
| 43 | +import java.util.concurrent.TimeUnit; |
| 44 | + |
| 45 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 46 | +import static org.hamcrest.CoreMatchers.instanceOf; |
| 47 | +import static org.hamcrest.Matchers.is; |
| 48 | +import static org.hamcrest.Matchers.anyOf; |
| 49 | +import static org.hamcrest.beans.HasPropertyWithValue.hasProperty; |
| 50 | + |
| 51 | +import static com.bandwidth.sdk.utils.TestingEnvironmentVariables.*; |
| 52 | + |
| 53 | +@TestInstance(TestInstance.Lifecycle.PER_CLASS) |
| 54 | + |
27 | 55 |
|
28 | 56 | /** |
29 | 57 | * API tests for TranscriptionsApi |
30 | 58 | */ |
31 | | -@Disabled |
32 | 59 | public class TranscriptionsApiTest { |
33 | 60 |
|
34 | | - private final TranscriptionsApi api = new TranscriptionsApi(); |
| 61 | + ApiClient defaultClient = Configuration.getDefaultApiClient(); |
| 62 | + HttpBasicAuth Basic = (HttpBasicAuth) defaultClient.getAuthentication("Basic"); |
| 63 | + private final CallsApi callsApi = new CallsApi(defaultClient); |
| 64 | + private final TranscriptionsApi transcriptionsApi = new TranscriptionsApi(defaultClient); |
35 | 65 |
|
36 | | - /** |
37 | | - * Delete a specific transcription |
38 | | - * |
39 | | - * Delete the specified transcription that was created on this call via [startTranscription](/docs/voice/bxml/startTranscription). Note: After the deletion is requested and a `204` is returned, the transcription will not be accessible anymore. However, it is not deleted immediately. This deletion process, while transparent and irreversible, can take an additional 24 to 48 hours. |
40 | | - * |
41 | | - * @throws ApiException if the Api call fails |
42 | | - */ |
43 | | - @Test |
44 | | - public void deleteRealTimeTranscriptionTest() throws ApiException { |
45 | | - String accountId = null; |
46 | | - String callId = null; |
47 | | - String transcriptionId = null; |
48 | | - api.deleteRealTimeTranscription(accountId, callId, transcriptionId); |
49 | | - // TODO: test validations |
50 | | - } |
51 | 66 |
|
52 | | - /** |
53 | | - * Retrieve a specific transcription |
54 | | - * |
55 | | - * Retrieve the specified transcription that was created on this call via [startTranscription](/docs/voice/bxml/startTranscription). |
56 | | - * |
57 | | - * @throws ApiException if the Api call fails |
58 | | - */ |
59 | | - @Test |
60 | | - public void getRealTimeTranscriptionTest() throws ApiException { |
61 | | - String accountId = null; |
62 | | - String callId = null; |
63 | | - String transcriptionId = null; |
64 | | - CallTranscriptionResponse response = api.getRealTimeTranscription(accountId, callId, transcriptionId); |
65 | | - // TODO: test validations |
66 | | - } |
| 67 | + private static CreateCall createMantecaCallBody = new CreateCall(); |
| 68 | + private static UpdateCall completeMantecaCallBody = new UpdateCall(); |
| 69 | + private static URI mantecaAnswerUrl; |
| 70 | + private static String bxmlBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Bxml><SpeakSentence locale=\"en_US\" gender=\"female\" voice=\"susan\">This is a bxml start transcription test.</SpeakSentence><StartTranscription tracks=\"both\"></StartTranscription><SpeakSentence voice=\"bridget\">Ideally this part is being transcribed.</SpeakSentence><Pause duration=\"3\"/></Response></Bxml>"; |
| 71 | + private static int TEST_SLEEP = 6; |
| 72 | + |
67 | 73 |
|
68 | | - /** |
69 | | - * Enumerate transcriptions made with StartTranscription |
70 | | - * |
71 | | - * Enumerates the transcriptions created on this call via [startTranscription](/docs/voice/bxml/startTranscription). |
72 | | - * |
73 | | - * @throws ApiException if the Api call fails |
74 | | - */ |
75 | 74 | @Test |
76 | | - public void listRealTimeTranscriptionsTest() throws ApiException { |
77 | | - String accountId = null; |
78 | | - String callId = null; |
79 | | - List<CallTranscriptionMetadata> response = api.listRealTimeTranscriptions(accountId, callId); |
80 | | - // TODO: test validations |
81 | | - } |
| 75 | + public void getAndDeleteRealTimeTranscriptionsTest() throws ApiException, InterruptedException, URISyntaxException { |
| 76 | + Basic.setUsername(BW_USERNAME); |
| 77 | + Basic.setPassword(BW_PASSWORD); |
| 78 | + mantecaAnswerUrl = new URI(MANTECA_BASE_URL + "/bxml/pause"); |
| 79 | + |
| 80 | + createMantecaCallBody.setFrom(MANTECA_ACTIVE_NUMBER); |
| 81 | + createMantecaCallBody.setTo(MANTECA_IDLE_NUMBER); |
| 82 | + createMantecaCallBody.setApplicationId(MANTECA_APPLICATION_ID); |
| 83 | + createMantecaCallBody.setAnswerUrl(mantecaAnswerUrl); |
| 84 | + completeMantecaCallBody.setState(CallStateEnum.COMPLETED); |
| 85 | + |
| 86 | + |
| 87 | + // Create call |
| 88 | + TimeUnit.SECONDS.sleep(TEST_SLEEP); |
| 89 | + ApiResponse<CreateCallResponse> createCallResponse = callsApi.createCallWithHttpInfo(BW_ACCOUNT_ID, |
| 90 | + createMantecaCallBody); |
82 | 91 |
|
| 92 | + assertThat(createCallResponse.getStatusCode(), is(201)); |
| 93 | + |
| 94 | + // Redirect call to different url |
| 95 | + TimeUnit.SECONDS.sleep(TEST_SLEEP); |
| 96 | + ApiResponse<Void> updateCallResponse = callsApi.updateCallBxmlWithHttpInfo(BW_ACCOUNT_ID, |
| 97 | + createCallResponse.getData().getCallId(), bxmlBody); |
| 98 | + |
| 99 | + assertThat(updateCallResponse.getStatusCode(), is(204)); |
| 100 | + |
| 101 | + // Complete call |
| 102 | + TimeUnit.SECONDS.sleep(TEST_SLEEP); |
| 103 | + ApiResponse<Void> completeCallResponse = callsApi.updateCallWithHttpInfo(BW_ACCOUNT_ID, |
| 104 | + createCallResponse.getData().getCallId(), completeMantecaCallBody); |
| 105 | + |
| 106 | + assertThat(completeCallResponse.getStatusCode(), is(200)); |
| 107 | + |
| 108 | + |
| 109 | + ApiResponse<List<CallTranscriptionMetadata>> listRealTimeTranscriptionResponse = transcriptionsApi.listRealTimeTranscriptionsWithHttpInfo(BW_ACCOUNT_ID, createCallResponse.getData().getCallId()); |
| 110 | + |
| 111 | + String transcriptionId = listRealTimeTranscriptionResponse.getData().get(0).getTranscriptionId(); |
| 112 | + TimeUnit.SECONDS.sleep(TEST_SLEEP); |
| 113 | + |
| 114 | + ApiResponse<CallTranscriptionResponse> getRealTimeTranscriptionResponse = transcriptionsApi.getRealTimeTranscriptionWithHttpInfo(BW_ACCOUNT_ID, createCallResponse.getData().getCallId(), transcriptionId); |
| 115 | + |
| 116 | + assertThat(getRealTimeTranscriptionResponse.getStatusCode(), is(200)); |
| 117 | + |
| 118 | + |
| 119 | + ApiResponse<Void> deleteRealTimeTranscriptionResponse = transcriptionsApi.deleteRealTimeTranscriptionWithHttpInfo(BW_ACCOUNT_ID, createCallResponse.getData().getCallId(), transcriptionId); |
| 120 | + |
| 121 | + assertThat(deleteRealTimeTranscriptionResponse.getStatusCode(), is(204)); |
| 122 | + |
| 123 | + } |
83 | 124 | } |
| 125 | + |
| 126 | + |
0 commit comments