22
33import org .openapitools .client .ApiResponse ;
44import org .openapitools .client .ApiClient ;
5+ import org .openapitools .client .ApiException ;
56import org .openapitools .client .auth .HttpBasicAuth ;
67import org .openapitools .client .Configuration ;
78import org .openapitools .client .model .CallRecordingMetadata ;
2829import org .junit .jupiter .api .MethodOrderer ;
2930import org .junit .jupiter .api .Order ;
3031import org .junit .jupiter .api .AfterAll ;
32+ import org .junit .jupiter .api .Assertions ;
3133import org .junit .jupiter .api .Test ;
3234import org .junit .jupiter .api .TestInstance ;
3335import org .junit .jupiter .api .TestMethodOrder ;
@@ -55,12 +57,13 @@ public class RecordingsApiTest {
5557 private static final OkHttpClient mantecaClient = new OkHttpClient ();
5658 public static final MediaType jsonMediaType = MediaType .get ("application/json; charset=utf-8" );
5759
60+ public static TranscribeRecording transcribeRecording = new TranscribeRecording ();
61+
5862 private static String testId ;
5963 private static URI answerUrl ;
60- private static URI updateAnswerUrl ;
61- private static List < String > callIdList = new ArrayList < String >() ;
64+ private static String callId ;
65+ private static String recordingId ;
6266 private static int TEST_SLEEP = 3 ;
63- private static int TEST_SLEEP_LONG = 10 ;
6467 private static int MAX_RETRIES = 40 ;
6568
6669 private static CreateCall createCallBody = new CreateCall ();
@@ -69,13 +72,15 @@ public class RecordingsApiTest {
6972 public static void setUpBeforeClass () throws URISyntaxException {
7073 // answerUrl = new URI(MANTECA_BASE_URL + "/bxml/startRecording");
7174 answerUrl = new URI (MANTECA_BASE_URL + "/bxml/startLongRecording" );
72- updateAnswerUrl = new URI (MANTECA_BASE_URL + "/bxml/startLongRecording" );
75+
76+ transcribeRecording .callbackUrl (new URI (MANTECA_BASE_URL + "/transcriptions" ));
77+ transcribeRecording .setTag (testId );
7378 }
7479
7580 @ AfterAll
7681 public void tearDownAfterClass () throws Exception {
7782 TimeUnit .SECONDS .sleep (TEST_SLEEP );
78- Cleanup (this , callIdList );
83+ Cleanup (this , callId );
7984 }
8085
8186 static final String constructMantecaJsonBody (String os , String language ) {
@@ -141,30 +146,29 @@ public void testCallRecordingAndTranscription() throws Exception {
141146 // Create Call
142147 CreateCallResponse callResponse = callsApi .createCall (BW_ACCOUNT_ID , createCallBody );
143148 System .out .println (callResponse .getCallId ());
144- String shortRecordingCallId = callResponse .getCallId ();
145- callIdList .add (callResponse .getCallId ());
149+ callId = callResponse .getCallId ();
146150
147151 // Update Recording
148152 TimeUnit .SECONDS .sleep (TEST_SLEEP );
149153 UpdateCallRecording updateRecording = new UpdateCallRecording ();
150154 updateRecording .setState (RecordingStateEnum .PAUSED );
151155
152156 ApiResponse <Void > pauseRecordingResponse = recordingsApi .updateCallRecordingStateWithHttpInfo (BW_ACCOUNT_ID ,
153- shortRecordingCallId , updateRecording );
157+ callId , updateRecording );
154158 assertThat (pauseRecordingResponse .getStatusCode (), is (200 ));
155159
156160 // Update Recording
157161 TimeUnit .SECONDS .sleep (TEST_SLEEP );
158162 updateRecording .setState (RecordingStateEnum .RECORDING );
159163
160164 ApiResponse <Void > resumeRecordingResponse = recordingsApi .updateCallRecordingStateWithHttpInfo (BW_ACCOUNT_ID ,
161- shortRecordingCallId , updateRecording );
165+ callId , updateRecording );
162166 assertThat (resumeRecordingResponse .getStatusCode (), is (200 ));
163167
164168 // Terminate the call
165169 UpdateCall updateCall = new UpdateCall ();
166170 updateCall .setState (CallStateEnum .COMPLETED );
167- ApiResponse <Void > updateCallResponse = callsApi .updateCallWithHttpInfo (BW_ACCOUNT_ID , shortRecordingCallId ,
171+ ApiResponse <Void > updateCallResponse = callsApi .updateCallWithHttpInfo (BW_ACCOUNT_ID , callId ,
168172 updateCall );
169173 assertThat (updateCallResponse .getStatusCode (), is (200 ));
170174
@@ -180,21 +184,16 @@ public void testCallRecordingAndTranscription() throws Exception {
180184
181185 // Validate the recording metadata endpoint
182186 ApiResponse <List <CallRecordingMetadata >> listRecordingMetadataResponse = recordingsApi
183- .listCallRecordingsWithHttpInfo (BW_ACCOUNT_ID , shortRecordingCallId );
187+ .listCallRecordingsWithHttpInfo (BW_ACCOUNT_ID , callId );
184188 assertThat (listRecordingMetadataResponse .getStatusCode (), is (200 ));
185- String shortRecordingId = listRecordingMetadataResponse .getData ().get (0 ).getRecordingId ();
189+ recordingId = listRecordingMetadataResponse .getData ().get (0 ).getRecordingId ();
186190
187191 ApiResponse <CallRecordingMetadata > recordingMetadataResponse = recordingsApi .getCallRecordingWithHttpInfo (
188- BW_ACCOUNT_ID , shortRecordingCallId , shortRecordingId );
192+ BW_ACCOUNT_ID , callId , recordingId );
189193 assertThat (recordingMetadataResponse .getStatusCode (), is (200 ));
190194
191- // Create a transcription request for the recording
192- TranscribeRecording transcribeRecordingBody = new TranscribeRecording ();
193- transcribeRecordingBody .callbackUrl (new URI (MANTECA_BASE_URL + "/transcriptions" ));
194- transcribeRecordingBody .setTag (testId );
195-
196195 ApiResponse <Void > requestTranscriptionResponse = recordingsApi .transcribeCallRecordingWithHttpInfo (
197- BW_ACCOUNT_ID , shortRecordingCallId , shortRecordingId , transcribeRecordingBody );
196+ BW_ACCOUNT_ID , callId , recordingId , transcribeRecording );
198197 assertThat (requestTranscriptionResponse .getStatusCode (), is (204 ));
199198
200199 // Make sure its been transcribed by fetching status from manteca
@@ -209,22 +208,221 @@ public void testCallRecordingAndTranscription() throws Exception {
209208
210209 // Validate the transcription metadata endpoint
211210 ApiResponse <TranscriptionList > listTranscriptionsResponse = recordingsApi
212- .getCallTranscriptionWithHttpInfo (BW_ACCOUNT_ID , shortRecordingCallId , shortRecordingId );
211+ .getCallTranscriptionWithHttpInfo (BW_ACCOUNT_ID , callId , recordingId );
213212 assertThat (listTranscriptionsResponse .getStatusCode (), is (200 ));
214213
215214 // Delete transcription
216215 ApiResponse <Void > deleteTranscriptionResponse = recordingsApi .deleteCallTranscriptionWithHttpInfo (BW_ACCOUNT_ID ,
217- shortRecordingCallId , shortRecordingId );
216+ callId , recordingId );
218217 assertThat (deleteTranscriptionResponse .getStatusCode (), is (204 ));
219218
220219 // Delete recording media
221220 ApiResponse <Void > deleteRecordingMediaResponse = recordingsApi .deleteRecordingMediaWithHttpInfo (BW_ACCOUNT_ID ,
222- shortRecordingCallId , shortRecordingId );
221+ callId , recordingId );
223222 assertThat (deleteRecordingMediaResponse .getStatusCode (), is (204 ));
224223
225224 // Delete recording metadata
226225 ApiResponse <Void > deleteRecordingMetadataResponse = recordingsApi .deleteRecordingWithHttpInfo (BW_ACCOUNT_ID ,
227- shortRecordingCallId , shortRecordingId );
226+ callId , recordingId );
228227 assertThat (deleteRecordingMetadataResponse .getStatusCode (), is (204 ));
229228 }
229+
230+ @ Test
231+ public void testGetAccountRecordings () throws ApiException {
232+ Basic .setUsername (BW_USERNAME );
233+ Basic .setPassword (BW_PASSWORD );
234+
235+ ApiResponse <List <CallRecordingMetadata >> response = recordingsApi
236+ .listAccountCallRecordingsWithHttpInfo (BW_ACCOUNT_ID , null , null , null , null );
237+
238+ assertThat (response .getStatusCode (), is (200 ));
239+ }
240+
241+ @ Test
242+ public void testGetAccountRecordingsUnauthorized () {
243+ Basic .setUsername ("bad_username" );
244+ Basic .setPassword ("bad_password" );
245+
246+ ApiException exception = Assertions .assertThrows (ApiException .class ,
247+ () -> recordingsApi .listAccountCallRecordingsWithHttpInfo (BW_ACCOUNT_ID , null , null , null , null ));
248+
249+ assertThat (exception .getCode (), is (401 ));
250+ }
251+
252+ @ Test
253+ public void testGetAccountRecordingsForbidden () {
254+ Basic .setUsername (FORBIDDEN_USERNAME );
255+ Basic .setPassword (FORBIDDEN_PASSWORD );
256+
257+ ApiException exception = Assertions .assertThrows (ApiException .class ,
258+ () -> recordingsApi .listAccountCallRecordingsWithHttpInfo (BW_ACCOUNT_ID , null , null , null , null ));
259+
260+ assertThat (exception .getCode (), is (403 ));
261+ }
262+
263+ @ Test
264+ public void testRecordingNotFound () {
265+ Basic .setUsername (BW_USERNAME );
266+ Basic .setPassword (BW_PASSWORD );
267+
268+ ApiException exception = Assertions .assertThrows (ApiException .class ,
269+ () -> recordingsApi .getCallRecording (BW_ACCOUNT_ID , "not a call" , "not a recording" ));
270+
271+ assertThat (exception .getCode (), is (404 ));
272+ }
273+
274+ @ Test
275+ public void testUnauthorizedGetRecording () {
276+ Basic .setUsername ("bad_username" );
277+ Basic .setPassword ("bad_password" );
278+
279+ ApiException exception = Assertions .assertThrows (ApiException .class ,
280+ () -> recordingsApi .getCallRecording (BW_ACCOUNT_ID , callId , recordingId ));
281+
282+ assertThat (exception .getCode (), is (401 ));
283+ }
284+
285+ @ Test
286+ public void testForbiddenGetRecording () {
287+ Basic .setUsername (FORBIDDEN_USERNAME );
288+ Basic .setPassword (FORBIDDEN_PASSWORD );
289+
290+ ApiException exception = Assertions .assertThrows (ApiException .class ,
291+ () -> recordingsApi .getCallRecording (BW_ACCOUNT_ID , callId , recordingId ));
292+
293+ assertThat (exception .getCode (), is (403 ));
294+ }
295+
296+ @ Test
297+ public void testUnauthorizedDeleteRecording () {
298+ Basic .setUsername ("bad_username" );
299+ Basic .setPassword ("bad_password" );
300+
301+ ApiException exception = Assertions .assertThrows (ApiException .class ,
302+ () -> recordingsApi .deleteRecording (BW_ACCOUNT_ID , callId , recordingId ));
303+
304+ assertThat (exception .getCode (), is (401 ));
305+ }
306+
307+ @ Test
308+ public void testForbiddenDeleteRecording () {
309+ Basic .setUsername (FORBIDDEN_USERNAME );
310+ Basic .setPassword (FORBIDDEN_PASSWORD );
311+
312+ ApiException exception = Assertions .assertThrows (ApiException .class ,
313+ () -> recordingsApi .deleteRecording (BW_ACCOUNT_ID , callId , recordingId ));
314+
315+ assertThat (exception .getCode (), is (403 ));
316+ }
317+
318+ @ Test
319+ public void testUnauthorizedDownloadRecording () {
320+ Basic .setUsername ("bad_username" );
321+ Basic .setPassword ("bad_password" );
322+
323+ ApiException exception = Assertions .assertThrows (ApiException .class ,
324+ () -> recordingsApi .downloadCallRecording (BW_ACCOUNT_ID , callId , recordingId ));
325+
326+ assertThat (exception .getCode (), is (401 ));
327+ }
328+
329+ @ Test
330+ public void testForbiddenDownloadRecording () {
331+ Basic .setUsername (FORBIDDEN_USERNAME );
332+ Basic .setPassword (FORBIDDEN_PASSWORD );
333+
334+ ApiException exception = Assertions .assertThrows (ApiException .class ,
335+ () -> recordingsApi .downloadCallRecording (BW_ACCOUNT_ID , callId , recordingId ));
336+
337+ assertThat (exception .getCode (), is (403 ));
338+ }
339+
340+ @ Test
341+ public void testUnauthorizedDeleteRecordingMedia () {
342+ Basic .setUsername ("bad_username" );
343+ Basic .setPassword ("bad_password" );
344+
345+ ApiException exception = Assertions .assertThrows (ApiException .class ,
346+ () -> recordingsApi .deleteRecording (BW_ACCOUNT_ID , callId , recordingId ));
347+
348+ assertThat (exception .getCode (), is (401 ));
349+ }
350+
351+ @ Test
352+ public void testForbiddenDeleteRecordingMedia () {
353+ Basic .setUsername (FORBIDDEN_USERNAME );
354+ Basic .setPassword (FORBIDDEN_PASSWORD );
355+
356+ ApiException exception = Assertions .assertThrows (ApiException .class ,
357+ () -> recordingsApi .deleteRecording (BW_ACCOUNT_ID , callId , recordingId ));
358+
359+ assertThat (exception .getCode (), is (403 ));
360+ }
361+
362+ @ Test
363+ public void testUnauthorizedGetTranscription () {
364+ Basic .setUsername ("bad_username" );
365+ Basic .setPassword ("bad_password" );
366+
367+ ApiException exception = Assertions .assertThrows (ApiException .class ,
368+ () -> recordingsApi .deleteCallTranscription (BW_ACCOUNT_ID , callId , recordingId ));
369+
370+ assertThat (exception .getCode (), is (401 ));
371+ }
372+
373+ @ Test
374+ public void testForbiddenGetTranscription () {
375+ Basic .setUsername (FORBIDDEN_USERNAME );
376+ Basic .setPassword (FORBIDDEN_PASSWORD );
377+
378+ ApiException exception = Assertions .assertThrows (ApiException .class ,
379+ () -> recordingsApi .deleteCallTranscription (BW_ACCOUNT_ID , callId , recordingId ));
380+
381+ assertThat (exception .getCode (), is (403 ));
382+ }
383+
384+ @ Test
385+ public void testUnauthorizedCreateTranscriptionRequest () {
386+ Basic .setUsername ("bad_username" );
387+ Basic .setPassword ("bad_password" );
388+
389+ ApiException exception = Assertions .assertThrows (ApiException .class ,
390+ () -> recordingsApi .transcribeCallRecording (BW_ACCOUNT_ID , callId , recordingId , transcribeRecording ));
391+
392+ assertThat (exception .getCode (), is (401 ));
393+ }
394+
395+ @ Test
396+ public void testForbiddenCreateTranscriptionRequest () {
397+ Basic .setUsername (FORBIDDEN_USERNAME );
398+ Basic .setPassword (FORBIDDEN_PASSWORD );
399+
400+ ApiException exception = Assertions .assertThrows (ApiException .class ,
401+ () -> recordingsApi .transcribeCallRecording (BW_ACCOUNT_ID , callId , recordingId , transcribeRecording ));
402+
403+ System .out .println (exception .getCode ());
404+ assertThat (exception .getCode (), is (403 ));
405+ }
406+
407+ @ Test
408+ public void testUnauthorizedDeleteTranscription () throws ApiException {
409+ Basic .setUsername ("bad_username" );
410+ Basic .setPassword ("bad_password" );
411+
412+ ApiException exception = Assertions .assertThrows (ApiException .class ,
413+ () -> recordingsApi .deleteCallTranscription (BW_ACCOUNT_ID , callId , recordingId ));
414+
415+ assertThat (exception .getCode (), is (401 ));
416+ }
417+
418+ @ Test
419+ public void testForbiddenDeleteTranscription () {
420+ Basic .setUsername (FORBIDDEN_USERNAME );
421+ Basic .setPassword (FORBIDDEN_PASSWORD );
422+
423+ ApiException exception = Assertions .assertThrows (ApiException .class ,
424+ () -> recordingsApi .deleteCallTranscription (BW_ACCOUNT_ID , callId , recordingId ));
425+
426+ assertThat (exception .getCode (), is (403 ));
427+ }
230428}
0 commit comments