From 971c508c3c1e85f91ac1571c90f22f8f855e7869 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 29 Mar 2023 07:36:54 -0400 Subject: [PATCH 1/4] SWI-2187 --- .../bandwidth/voice/bxml/verbs/Record.java | 112 +++-- .../voice/bxml/verbs/StartRecording.java | 84 ++-- src/test/java/com/bandwidth/BxmlTest.java | 450 +++++++++--------- 3 files changed, 357 insertions(+), 289 deletions(-) diff --git a/src/main/java/com/bandwidth/voice/bxml/verbs/Record.java b/src/main/java/com/bandwidth/voice/bxml/verbs/Record.java index c1c3a1ce..e3acbfe0 100644 --- a/src/main/java/com/bandwidth/voice/bxml/verbs/Record.java +++ b/src/main/java/com/bandwidth/voice/bxml/verbs/Record.java @@ -17,7 +17,8 @@ public class Record implements Verb { public static final String TYPE_NAME = "Record"; /** - * (optional) A boolean value. If true, the recording will be submitted for transcription upon completion. Defaults to false. + * (optional) A boolean value. If true, the recording will be submitted + * for transcription upon completion. Defaults to false. */ @XmlAttribute private boolean transcribe; @@ -37,37 +38,43 @@ public class Record implements Verb { private URI transcriptionAvailableUrl; /** - * (optional) The HTTP method to use for the request to transcriptionAvailableUrl. GET or POST. Default Value is POST. + * (optional) The HTTP method to use for the request to + * transcriptionAvailableUrl. GET or POST. Default Value is POST. */ @XmlAttribute private Method transcriptionAvailableMethod; /** - * (optional) URL to send the Record Complete event to once it has ended. Accepts BXML. + * (optional) URL to send the Record Complete event to once it has ended. + * Accepts BXML. */ @XmlAttribute private URI recordCompleteUrl; /** - * (optional) The HTTP method to use for the request to recordCompleteUrl. GET or POST. Default Value is POST. + * (optional) The HTTP method to use for the request to + * recordCompleteUrl. GET or POST. Default Value is POST. */ @XmlAttribute private Method recordCompleteMethod; /** - * (optional) URL to send the Record Complete event to once it has ended. Accepts BXML. + * (optional) URL to send the Record Complete event to once it has ended. + * Accepts BXML. */ @XmlAttribute private URI recordingAvailableUrl; /** - * (optional) The HTTP method to use for the request to recordingAvailableUrl. GET or POST. Default Value is POST. + * (optional) The HTTP method to use for the request to + * recordingAvailableUrl. GET or POST. Default Value is POST. */ @XmlAttribute private Method recordingAvailableMethod; /** - * (optional) A custom string that will be sent with this and all future callbacks unless overwritten by a future tag attribute or cleared. + * (optional) A custom string that will be sent with this and all future + * callbacks unless overwritten by a future tag attribute or cleared. *
* May be cleared by setting tag="" *
@@ -77,36 +84,42 @@ public class Record implements Verb { private String tag; /** - * (optional) The username to send in the HTTP request to recordCompleteUrl or recordingAvailableUrl. If specified, the URLs must be TLS-encrypted (i.e., https). + * (optional) The username to send in the HTTP request to + * recordCompleteUrl or recordingAvailableUrl. If specified, the URLs must be + * TLS-encrypted (i.e., https). */ @XmlAttribute protected String username; /** - * (optional) The password to send in the HTTP request to recordCompleteUrl or recordingAvailableUrl. If specified, the URLs must be TLS-encrypted (i.e., https). + * (optional) The password to send in the HTTP request to + * recordCompleteUrl or recordingAvailableUrl. If specified, the URLs must be + * TLS-encrypted (i.e., https). */ @XmlAttribute protected String password; /** - * (optional) When pressed, this digit will terminate the recording. Default value is “#”. + * (optional) When pressed, this digit will terminate the recording. + * Default value is “#”. */ @XmlAttribute protected String terminatingDigits; /** - * (optional) Maximum length of recording (in seconds). Max 10800 (3 hours). Default value is 60. + * (optional) Maximum length of recording (in seconds). Max 10800 (3 + * hours). Default value is 60. */ @XmlAttribute protected Integer maxDuration; /** - * (optional) The audio format that the recording will be saved as: mp3 or wav. Default value is wav. + * (optional) The audio format that the recording will be saved as: mp3 + * or wav. Default value is wav. */ @XmlAttribute protected String fileFormat; - @XmlAttribute protected String fallbackUsername; @@ -119,13 +132,21 @@ public class Record implements Verb { @XmlAttribute protected Method recordCompleteFallbackMethod; + /** + * (optional) A boolean value to indicate that the recording may not be + * in English, and the transcription service will need to detect the dominant + * language the recording is in and transcribe accordingly. + * Current supported languages are English, French, and Spanish. + */ + @XmlAttribute + protected Boolean detectLanguage; public static class RecordBuilder { /** * (required) URL to send the transcriptionAvailable event to. */ - public RecordBuilder transcriptionAvailableUrl(URI uri ){ + public RecordBuilder transcriptionAvailableUrl(URI uri) { this.transcriptionAvailableUrl = uri; return this; } @@ -133,100 +154,113 @@ public RecordBuilder transcriptionAvailableUrl(URI uri ){ /** * (required) URL to send the transcriptionAvailable event to. */ - public RecordBuilder transcriptionAvailableUrl(String uri){ + public RecordBuilder transcriptionAvailableUrl(String uri) { return transcriptionAvailableUrl(URI.create(uri)); } - public RecordBuilder recordCompleteFallbackUrl(URI uri ){ + public RecordBuilder recordCompleteFallbackUrl(URI uri) { this.recordCompleteFallbackUrl = uri; return this; } - public RecordBuilder recordCompleteFallbackUrl(String uri){ + public RecordBuilder recordCompleteFallbackUrl(String uri) { return recordCompleteFallbackUrl(URI.create(uri)); } /** - * (optional) The HTTP method to use for the request to transcriptionAvailableUrl. GET or POST. Default Value is POST. + * (optional) The HTTP method to use for the request to + * transcriptionAvailableUrl. GET or POST. Default Value is POST. */ - public RecordBuilder transcriptionAvailableMethod(Method method){ + public RecordBuilder transcriptionAvailableMethod(Method method) { this.transcriptionAvailableMethod = method; return this; } /** - * (optional) The HTTP method to use for the request to transcriptionAvailableUrl. GET or POST. Default Value is POST. Converts String to Method using Method.fromValue(method) + * (optional) The HTTP method to use for the request to + * transcriptionAvailableUrl. GET or POST. Default Value is POST. Converts + * String to Method using Method.fromValue(method) */ - public RecordBuilder transcriptionAvailableMethod(String method){ + public RecordBuilder transcriptionAvailableMethod(String method) { return transcriptionAvailableMethod(Method.fromValue(method)); } - public RecordBuilder recordCompleteFallbackMethod(Method method){ + public RecordBuilder recordCompleteFallbackMethod(Method method) { this.recordCompleteFallbackMethod = method; return this; } - public RecordBuilder recordCompleteFallbackMethod(String method){ + public RecordBuilder recordCompleteFallbackMethod(String method) { return recordCompleteFallbackMethod(Method.fromValue(method)); } /** - * (required) URL to send the Record Complete event to once it has ended. Accepts BXML. + * (required) URL to send the Record Complete event to once it has ended. + * Accepts BXML. */ - public RecordBuilder recordCompleteUrl(URI uri ){ + public RecordBuilder recordCompleteUrl(URI uri) { this.recordCompleteUrl = uri; return this; } /** - * (required) URL to request new BXML from. A Record event will be sent to this endpoint. Converts to URI using URI.create(url) + * (required) URL to request new BXML from. A Record event will be sent + * to this endpoint. Converts to URI using URI.create(url) */ - public RecordBuilder recordCompleteUrl(String uri){ + public RecordBuilder recordCompleteUrl(String uri) { return recordCompleteUrl(URI.create(uri)); } /** - * (optional) The HTTP method to use for the request to recordCompleteUrl. GET or POST. Default Value is POST. + * (optional) The HTTP method to use for the request to + * recordCompleteUrl. GET or POST. Default Value is POST. */ - public RecordBuilder recordCompleteMethod(Method method){ + public RecordBuilder recordCompleteMethod(Method method) { this.recordCompleteMethod = method; return this; } /** - * (optional) The HTTP method to use for the request to recordCompleteUrl. GET or POST. Default Value is POST. Converts String to Method using Method.fromValue(method) + * (optional) The HTTP method to use for the request to + * recordCompleteUrl. GET or POST. Default Value is POST. Converts String to + * Method using Method.fromValue(method) */ - public RecordBuilder recordCompleteMethod(String method){ + public RecordBuilder recordCompleteMethod(String method) { return recordCompleteMethod(Method.fromValue(method)); } /** - * (required) URL to send the Recording Available event to once it has been processed. Does not accept BXML. + * (required) URL to send the Recording Available event to once it has + * been processed. Does not accept BXML. */ - public RecordBuilder recordingAvailableUrl(URI uri ){ + public RecordBuilder recordingAvailableUrl(URI uri) { this.recordingAvailableUrl = uri; return this; } /** - * (required) URL to send the Recording Available event to once it has been processed. Does not accept BXML. + * (required) URL to send the Recording Available event to once it has + * been processed. Does not accept BXML. */ - public RecordBuilder recordingAvailableUrl(String uri){ + public RecordBuilder recordingAvailableUrl(String uri) { return recordingAvailableUrl(URI.create(uri)); } /** - * (optional) The HTTP method to use for the request to recordingAvailableUrl. GET or POST. Default Value is POST. + * (optional) The HTTP method to use for the request to + * recordingAvailableUrl. GET or POST. Default Value is POST. */ - public RecordBuilder recordingAvailableMethod(Method method){ + public RecordBuilder recordingAvailableMethod(Method method) { this.recordingAvailableMethod = method; return this; } /** - * (optional) The HTTP method to use for the request to recordingAvailableUrl. GET or POST. Default Value is POST. Converts String to Method using Method.fromValue(method) + * (optional) The HTTP method to use for the request to + * recordingAvailableUrl. GET or POST. Default Value is POST. Converts String to + * Method using Method.fromValue(method) */ - public RecordBuilder recordingAvailableMethod(String method){ + public RecordBuilder recordingAvailableMethod(String method) { return recordingAvailableMethod(Method.fromValue(method)); } } diff --git a/src/main/java/com/bandwidth/voice/bxml/verbs/StartRecording.java b/src/main/java/com/bandwidth/voice/bxml/verbs/StartRecording.java index e9e1db47..2db8447a 100644 --- a/src/main/java/com/bandwidth/voice/bxml/verbs/StartRecording.java +++ b/src/main/java/com/bandwidth/voice/bxml/verbs/StartRecording.java @@ -8,18 +8,20 @@ import javax.xml.bind.annotation.XmlType; /** - * The StartRecording verb allows a segment of a call to be recorded while other verbs are executing. - *
- * All audio on both sides of the call will be recorded until the call ends or the verb is used or the verb is used. + * The StartRecording verb allows a segment of a call to be recorded while other + * verbs are executing. + *
+ * All audio on both sides of the call will be recorded until the call ends or + * the verb is used or the verb is used. */ @Builder @XmlType(name = StartRecording.TYPE_NAME) public class StartRecording implements Verb { public static final String TYPE_NAME = "StartRecording"; - /** - * (optional) A boolean value. If true, the recording will be submitted for transcription upon completion. Defaults to false. + * (optional) A boolean value. If true, the recording will be submitted + * for transcription upon completion. Defaults to false. */ @XmlAttribute private boolean transcribe; @@ -31,25 +33,29 @@ public class StartRecording implements Verb { private URI transcriptionAvailableUrl; /** - * (optional) The HTTP method to use for the request to transcriptionAvailableUrl. GET or POST. Default Value is POST. + * (optional) The HTTP method to use for the request to + * transcriptionAvailableUrl. GET or POST. Default Value is POST. */ @XmlAttribute private Method transcriptionAvailableMethod; /** - * (optional) URL to send the Record Complete event to once it has ended. Accepts BXML. + * (optional) URL to send the Record Complete event to once it has ended. + * Accepts BXML. */ @XmlAttribute private URI recordingAvailableUrl; /** - * (optional) The HTTP method to use for the request to recordingAvailableUrl. GET or POST. Default Value is POST. + * (optional) The HTTP method to use for the request to + * recordingAvailableUrl. GET or POST. Default Value is POST. */ @XmlAttribute private Method recordingAvailableMethod; /** - * (optional) A custom string that will be sent with this and all future callbacks unless overwritten by a future tag attribute or cleared. + * (optional) A custom string that will be sent with this and all future + * callbacks unless overwritten by a future tag attribute or cleared. *
* May be cleared by setting tag="" *
@@ -59,35 +65,51 @@ public class StartRecording implements Verb { private String tag; /** - * (optional) The username to send in the HTTP request to recordCompleteUrl or recordingAvailableUrl. If specified, the URLs must be TLS-encrypted (i.e., https). + * (optional) The username to send in the HTTP request to + * recordCompleteUrl or recordingAvailableUrl. If specified, the URLs must be + * TLS-encrypted (i.e., https). */ @XmlAttribute protected String username; /** - * (optional) The password to send in the HTTP request to recordCompleteUrl or recordingAvailableUrl. If specified, the URLs must be TLS-encrypted (i.e., https). + * (optional) The password to send in the HTTP request to + * recordCompleteUrl or recordingAvailableUrl. If specified, the URLs must be + * TLS-encrypted (i.e., https). */ @XmlAttribute protected String password; /** - * (optional) A boolean value indicating whether or not the recording file should separate each side of the call into its own audio channel. Default value is false. true results in two channels. + * (optional) A boolean value indicating whether or not the recording + * file should separate each side of the call into its own audio channel. + * Default value is false. true results in two channels. */ @XmlAttribute protected boolean multiChannel; /** - * (optional) The audio format that the recording will be saved as: mp3 or wav. Default value is wav. + * (optional) The audio format that the recording will be saved as: mp3 + * or wav. Default value is wav. */ @XmlAttribute protected String fileFormat; + /** + * (optional) A boolean value to indicate that the recording may not be + * in English, and the transcription service will need to detect the dominant + * language the recording is in and transcribe accordingly. + * Current supported languages are English, French, and Spanish. + */ + @XmlAttribute + protected Boolean detectLanguage; + public static class StartRecordingBuilder { /** * (required) URL to send the transcriptionAvailable event to. */ - public StartRecordingBuilder transcriptionAvailableUrl(URI uri ){ + public StartRecordingBuilder transcriptionAvailableUrl(URI uri) { this.transcriptionAvailableUrl = uri; return this; } @@ -95,52 +117,60 @@ public StartRecordingBuilder transcriptionAvailableUrl(URI uri ){ /** * (required) URL to send the transcriptionAvailable event to. */ - public StartRecordingBuilder transcriptionAvailableUrl(String uri){ + public StartRecordingBuilder transcriptionAvailableUrl(String uri) { return transcriptionAvailableUrl(URI.create(uri)); } /** - * (optional) The HTTP method to use for the request to transcriptionAvailableUrl. GET or POST. Default Value is POST. + * (optional) The HTTP method to use for the request to + * transcriptionAvailableUrl. GET or POST. Default Value is POST. */ - public StartRecordingBuilder transcriptionAvailableMethod(Method method){ + public StartRecordingBuilder transcriptionAvailableMethod(Method method) { this.transcriptionAvailableMethod = method; return this; } /** - * (optional) The HTTP method to use for the request to transcriptionAvailableUrl. GET or POST. Default Value is POST. Converts String to Method using Method.fromValue(method) + * (optional) The HTTP method to use for the request to + * transcriptionAvailableUrl. GET or POST. Default Value is POST. Converts + * String to Method using Method.fromValue(method) */ - public StartRecordingBuilder transcriptionAvailableMethod(String method){ + public StartRecordingBuilder transcriptionAvailableMethod(String method) { return transcriptionAvailableMethod(Method.fromValue(method)); } /** - * (required) URL to send the Recording Available event to once it has been processed. Does not accept BXML. + * (required) URL to send the Recording Available event to once it has + * been processed. Does not accept BXML. */ - public StartRecordingBuilder recordingAvailableUrl(URI uri ){ + public StartRecordingBuilder recordingAvailableUrl(URI uri) { this.recordingAvailableUrl = uri; return this; } /** - * (required) URL to send the Recording Available event to once it has been processed. Does not accept BXML. + * (required) URL to send the Recording Available event to once it has + * been processed. Does not accept BXML. */ - public StartRecordingBuilder recordingAvailableUrl(String uri){ + public StartRecordingBuilder recordingAvailableUrl(String uri) { return recordingAvailableUrl(URI.create(uri)); } /** - * (optional) The HTTP method to use for the request to recordingAvailableUrl. GET or POST. Default Value is POST. + * (optional) The HTTP method to use for the request to + * recordingAvailableUrl. GET or POST. Default Value is POST. */ - public StartRecordingBuilder recordingAvailableMethod(Method method){ + public StartRecordingBuilder recordingAvailableMethod(Method method) { this.recordingAvailableMethod = method; return this; } /** - * (optional) The HTTP method to use for the request to recordingAvailableUrl. GET or POST. Default Value is POST. Converts String to Method using Method.fromValue(method) + * (optional) The HTTP method to use for the request to + * recordingAvailableUrl. GET or POST. Default Value is POST. Converts String to + * Method using Method.fromValue(method) */ - public StartRecordingBuilder recordingAvailableMethod(String method){ + public StartRecordingBuilder recordingAvailableMethod(String method) { return recordingAvailableMethod(Method.fromValue(method)); } } diff --git a/src/test/java/com/bandwidth/BxmlTest.java b/src/test/java/com/bandwidth/BxmlTest.java index f37ad6cf..f59658a6 100644 --- a/src/test/java/com/bandwidth/BxmlTest.java +++ b/src/test/java/com/bandwidth/BxmlTest.java @@ -10,7 +10,6 @@ import java.util.ArrayList; - /** * Unit tests for BXML */ @@ -19,25 +18,25 @@ public class BxmlTest { @Test public void testBridge() { Bridge bridge = Bridge.builder() - .callId("c-95ac8d6e-1a31c52e-b38f-4198-93c1-51633ec68f8d") - .bridgeCompleteUrl("https://test.com") - .bridgeCompleteMethod("GET") - .bridgeTargetCompleteUrl("https://test2.com") - .bridgeTargetCompleteMethod("POST") - .username("user") - .password("pass") - .tag("custom tag") - .bridgeCompleteFallbackUrl("https://test3.com") - .bridgeCompleteFallbackMethod("GET") - .bridgeTargetCompleteFallbackUrl("https://test4.com") - .bridgeTargetCompleteFallbackMethod("POST") - .fallbackUsername("fuser") - .fallbackPassword("fpass") - .build(); + .callId("c-95ac8d6e-1a31c52e-b38f-4198-93c1-51633ec68f8d") + .bridgeCompleteUrl("https://test.com") + .bridgeCompleteMethod("GET") + .bridgeTargetCompleteUrl("https://test2.com") + .bridgeTargetCompleteMethod("POST") + .username("user") + .password("pass") + .tag("custom tag") + .bridgeCompleteFallbackUrl("https://test3.com") + .bridgeCompleteFallbackMethod("GET") + .bridgeTargetCompleteFallbackUrl("https://test4.com") + .bridgeTargetCompleteFallbackMethod("POST") + .fallbackUsername("fuser") + .fallbackPassword("fpass") + .build(); String response = new Response() - .add(bridge) - .toBXML(); + .add(bridge) + .toBXML(); String expected = "c-95ac8d6e-1a31c52e-b38f-4198-93c1-51633ec68f8d"; assertEquals("BXML strings not equal", expected, response); @@ -49,20 +48,20 @@ public void testConference() { callIdsToCoach.add("id1"); callIdsToCoach.add("id2"); Conference conference = Conference.builder() - .hold(true) - .mute(true) - .tag("tag1") - .username("user") - .password("pass") - .callIdsToCoach(callIdsToCoach) - .conferenceEventMethod("POST") - .conferenceEventUrl("https://example.com") - .name("my conference") - .build(); + .hold(true) + .mute(true) + .tag("tag1") + .username("user") + .password("pass") + .callIdsToCoach(callIdsToCoach) + .conferenceEventMethod("POST") + .conferenceEventUrl("https://example.com") + .name("my conference") + .build(); String response = new Response() - .add(conference) - .toBXML(); + .add(conference) + .toBXML(); String expected = "my conference"; assertEquals("BXML strings not equal", expected, response); @@ -71,15 +70,15 @@ public void testConference() { @Test public void testSpeakSentence() { SpeakSentence speakSentence = SpeakSentence.builder() - .text("test") - .voice("susan") - .gender("female") - .locale("en_US") - .build(); + .text("test") + .voice("susan") + .gender("female") + .locale("en_US") + .build(); String response = new Response() - .add(speakSentence) - .toBXML(); + .add(speakSentence) + .toBXML(); String expected = "test"; assertEquals("BXML strings not equal", expected, response); @@ -88,12 +87,12 @@ public void testSpeakSentence() { @Test public void testSpeakSentenceWithSsml() { SpeakSentence speakSentence = SpeakSentence.builder() - .text("Hello, you have reached the home of Antonio Mendoza.Please leave a message.") - .build(); + .text("Hello, you have reached the home of Antonio Mendoza.Please leave a message.") + .build(); String response = new Response() - .add(speakSentence) - .toBXML(); + .add(speakSentence) + .toBXML(); String expected = "Hello, you have reached the home of Antonio Mendoza.Please leave a message."; assertEquals("BXML strings not equal", expected, response); @@ -102,14 +101,14 @@ public void testSpeakSentenceWithSsml() { @Test public void testPlayAudio() { PlayAudio playAudio = PlayAudio.builder() - .audioUri("https://test.com") - .username("user") - .password("pass") - .build(); + .audioUri("https://test.com") + .username("user") + .password("pass") + .build(); String response = new Response() - .add(playAudio) - .toBXML(); + .add(playAudio) + .toBXML(); String expected = "https://test.com"; assertEquals("BXML strings not equal", expected, response); @@ -118,25 +117,25 @@ public void testPlayAudio() { @Test public void testGather() { Gather gather = Gather.builder() - .gatherUrl("https://test.com") - .gatherMethod("GET") - .username("user") - .password("pass") - .tag("tag") - .terminatingDigits("123") - .maxDigits(3) - .interDigitTimeout(4.0) - .firstDigitTimeout(5.0) - .repeatCount(6) - .gatherFallbackUrl("https://test2.com") - .gatherFallbackMethod("POST") - .fallbackUsername("fuser") - .fallbackPassword("fpass") - .build(); + .gatherUrl("https://test.com") + .gatherMethod("GET") + .username("user") + .password("pass") + .tag("tag") + .terminatingDigits("123") + .maxDigits(3) + .interDigitTimeout(4.0) + .firstDigitTimeout(5.0) + .repeatCount(6) + .gatherFallbackUrl("https://test2.com") + .gatherFallbackMethod("POST") + .fallbackUsername("fuser") + .fallbackPassword("fpass") + .build(); String response = new Response() - .add(gather) - .toBXML(); + .add(gather) + .toBXML(); String expected = ""; assertEquals("BXML strings not equal", expected, response); @@ -145,22 +144,22 @@ public void testGather() { @Test public void testNestedGatherMultipleVerbs() { SpeakSentence speakSentence = SpeakSentence.builder() - .text("test") - .build(); + .text("test") + .build(); PlayAudio playAudio = PlayAudio.builder() - .audioUri("https://test.com") - .build(); + .audioUri("https://test.com") + .build(); ArrayList audioProducers = new ArrayList(); audioProducers.add(speakSentence); audioProducers.add(playAudio); Gather gather = Gather.builder() - .audioProducer(audioProducers) - .build(); + .audioProducer(audioProducers) + .build(); String response = new Response() - .add(gather) - .toBXML(); + .add(gather) + .toBXML(); String expected = "testhttps://test.com"; assertEquals("BXML strings not equal", expected, response); @@ -169,16 +168,16 @@ public void testNestedGatherMultipleVerbs() { @Test public void testNestedGatherSingleVerb() { SpeakSentence speakSentence = SpeakSentence.builder() - .text("test") - .build(); + .text("test") + .build(); Gather gather = Gather.builder() - .audioProducer(speakSentence) - .build(); + .audioProducer(speakSentence) + .build(); String response = new Response() - .add(gather) - .toBXML(); + .add(gather) + .toBXML(); String expected = "test"; assertEquals("BXML strings not equal", expected, response); @@ -187,7 +186,7 @@ public void testNestedGatherSingleVerb() { @Test public void testResponse() { String response = new Response() - .toBXML(); + .toBXML(); String expected = ""; assertEquals("BXML strings not equal", expected, response); @@ -224,25 +223,25 @@ public void testHangup() { Hangup hangup = Hangup.builder().build(); String response = new Response() - .add(hangup) - .toBXML(); + .add(hangup) + .toBXML(); - String expected = ""; + String expected = ""; - assertEquals("BXML strings not equal", expected, response); + assertEquals("BXML strings not equal", expected, response); } @Test public void testSendDtmf() { SendDtmf sendDtmf = SendDtmf.builder() - .digits("321") - .toneDuration(75.0) - .toneInterval(50.0) - .build(); + .digits("321") + .toneDuration(75.0) + .toneInterval(50.0) + .build(); String response = new Response() - .add(sendDtmf) - .toBXML(); + .add(sendDtmf) + .toBXML(); String expected = "321"; @@ -252,16 +251,16 @@ public void testSendDtmf() { @Test public void testForward() { Forward forward = Forward.builder() - .to("+18887775555") - .from("+8887779999") - .callTimeout(3) - .diversionTreatment("none") - .diversionReason("away") - .build(); + .to("+18887775555") + .from("+8887779999") + .callTimeout(3) + .diversionTreatment("none") + .diversionReason("away") + .build(); String response = new Response() - .add(forward) - .toBXML(); + .add(forward) + .toBXML(); String expected = ""; @@ -271,12 +270,12 @@ public void testForward() { @Test public void testPause() { Pause pause = Pause.builder() - .duration(3.0) - .build(); + .duration(3.0) + .build(); String response = new Response() - .add(pause) - .toBXML(); + .add(pause) + .toBXML(); String expected = ""; @@ -286,20 +285,20 @@ public void testPause() { @Test public void testRedirect() { Redirect redirect = Redirect.builder() - .username("user") - .password("pass") - .redirectUrl("https://test.com") - .redirectMethod("GET") - .tag("tag") - .redirectFallbackUrl("https://test2.com") - .redirectFallbackMethod("POST") - .fallbackUsername("fuser") - .fallbackPassword("fpass") - .build(); + .username("user") + .password("pass") + .redirectUrl("https://test.com") + .redirectMethod("GET") + .tag("tag") + .redirectFallbackUrl("https://test2.com") + .redirectFallbackMethod("POST") + .fallbackUsername("fuser") + .fallbackPassword("fpass") + .build(); String response = new Response() - .add(redirect) - .toBXML(); + .add(redirect) + .toBXML(); String expected = ""; @@ -309,55 +308,55 @@ public void testRedirect() { @Test public void testTransfer() { PhoneNumber phoneNumber = PhoneNumber.builder() - .phoneNumber("+17776665555") - .transferAnswerUrl("https://test.com") - .transferAnswerMethod("GET") - .username("user") - .password("pass") - .tag("tag") - .transferAnswerFallbackUrl("https://test2.com") - .transferAnswerFallbackMethod("POST") - .fallbackUsername("fuser") - .fallbackPassword("fpass") - .build(); + .phoneNumber("+17776665555") + .transferAnswerUrl("https://test.com") + .transferAnswerMethod("GET") + .username("user") + .password("pass") + .tag("tag") + .transferAnswerFallbackUrl("https://test2.com") + .transferAnswerFallbackMethod("POST") + .fallbackUsername("fuser") + .fallbackPassword("fpass") + .build(); ArrayList phoneNumbers = new ArrayList(); phoneNumbers.add(phoneNumber); SipUri sipUri = SipUri.builder() - .sipUri("sip-uri") - .uui("uui") - .transferAnswerUrl("https://test3.com") - .transferAnswerMethod("POST") - .username("user2") - .password("pass2") - .tag("tag2") - .transferAnswerFallbackUrl("https://test4.com") - .transferAnswerFallbackMethod("POST") - .fallbackUsername("fuser2") - .fallbackPassword("fpass2") - .build(); + .sipUri("sip-uri") + .uui("uui") + .transferAnswerUrl("https://test3.com") + .transferAnswerMethod("POST") + .username("user2") + .password("pass2") + .tag("tag2") + .transferAnswerFallbackUrl("https://test4.com") + .transferAnswerFallbackMethod("POST") + .fallbackUsername("fuser2") + .fallbackPassword("fpass2") + .build(); ArrayList sipUris = new ArrayList(); sipUris.add(sipUri); Transfer transfer = Transfer.builder() - .transferCallerId("+18888888888") - .callTimeout(3.0) - .tag("tag3") - .transferCompleteUrl("https://testtransfer.com") - .transferCompleteMethod("GET") - .username("usertransfer") - .password("passtransfer") - .diversionTreatment("none") - .diversionReason("away") - .transferCompleteFallbackUrl("https://test7.com") - .transferCompleteFallbackMethod("POST") - .fallbackUsername("fuser7") - .fallbackPassword("fpass7") - .phoneNumbers(phoneNumbers) - .sipUris(sipUris) - .build(); + .transferCallerId("+18888888888") + .callTimeout(3.0) + .tag("tag3") + .transferCompleteUrl("https://testtransfer.com") + .transferCompleteMethod("GET") + .username("usertransfer") + .password("passtransfer") + .diversionTreatment("none") + .diversionReason("away") + .transferCompleteFallbackUrl("https://test7.com") + .transferCompleteFallbackMethod("POST") + .fallbackUsername("fuser7") + .fallbackPassword("fpass7") + .phoneNumbers(phoneNumbers) + .sipUris(sipUris) + .build(); String response = new Response() - .add(transfer) - .toBXML(); + .add(transfer) + .toBXML(); String expected = "+17776665555sip-uri"; @@ -367,27 +366,28 @@ public void testTransfer() { @Test public void testRecord() { Record record = Record.builder() - .recordCompleteUrl("https://url.com") - .recordCompleteMethod("POST") - .recordingAvailableUrl("https://url.com") - .recordingAvailableMethod("POST") - .username("user") - .password("pass") - .tag("tag") - .terminatingDigits("123") - .maxDuration(3) - .fileFormat("wav") - .recordCompleteFallbackUrl("https://test.com") - .recordCompleteFallbackMethod("GET") - .fallbackUsername("fuser") - .fallbackPassword("fpass") - .build(); + .recordCompleteUrl("https://url.com") + .recordCompleteMethod("POST") + .recordingAvailableUrl("https://url.com") + .recordingAvailableMethod("POST") + .username("user") + .password("pass") + .tag("tag") + .terminatingDigits("123") + .maxDuration(3) + .fileFormat("wav") + .recordCompleteFallbackUrl("https://test.com") + .recordCompleteFallbackMethod("GET") + .fallbackUsername("fuser") + .fallbackPassword("fpass") + .detectLanguage(true) + .build(); String response = new Response() - .add(record) - .toBXML(); + .add(record) + .toBXML(); - String expected = ""; + String expected = ""; assertEquals("BXML strings not equal", expected, response); } @@ -395,20 +395,21 @@ public void testRecord() { @Test public void testStartRecording() { StartRecording startRecording = StartRecording.builder() - .recordingAvailableUrl("https://url.com") - .recordingAvailableMethod("POST") - .username("user") - .password("pass") - .tag("tag") - .fileFormat("wav") - .multiChannel(false) - .build(); + .recordingAvailableUrl("https://url.com") + .recordingAvailableMethod("POST") + .username("user") + .password("pass") + .tag("tag") + .fileFormat("wav") + .multiChannel(false) + .detectLanguage(true) + .build(); String response = new Response() - .add(startRecording) - .toBXML(); + .add(startRecording) + .toBXML(); - String expected = ""; + String expected = ""; assertEquals("BXML strings not equal", expected, response); } @@ -418,8 +419,8 @@ public void testPauseRecording() { PauseRecording pauseRecording = PauseRecording.builder().build(); String response = new Response() - .add(pauseRecording) - .toBXML(); + .add(pauseRecording) + .toBXML(); String expected = ""; @@ -431,8 +432,8 @@ public void testResumeRecording() { ResumeRecording resumeRecording = ResumeRecording.builder().build(); String response = new Response() - .add(resumeRecording) - .toBXML(); + .add(resumeRecording) + .toBXML(); String expected = ""; @@ -444,8 +445,8 @@ public void testStopRecording() { StopRecording stopRecording = StopRecording.builder().build(); String response = new Response() - .add(stopRecording) - .toBXML(); + .add(stopRecording) + .toBXML(); String expected = ""; @@ -455,49 +456,50 @@ public void testStopRecording() { @Test public void testStartStream() { StreamParam streamParam1 = StreamParam.builder() - .name("name1") - .value("value1") - .build(); + .name("name1") + .value("value1") + .build(); StreamParam streamParam2 = StreamParam.builder() - .name("name2") - .value("value2") - .build(); + .name("name2") + .value("value2") + .build(); ArrayList streamParams = new ArrayList(); - streamParams.add(streamParam1); - streamParams.add(streamParam2); + streamParams.add(streamParam1); + streamParams.add(streamParam2); StartStream startStream = StartStream.builder() - .destination("https://url.com") - .streamEventMethod("POST") - .username("user") - .password("pass") - .name("test") - .tracks("inbound") - .streamEventUrl("https://url.com") - .streamParams(streamParams) - .build(); + .destination("https://url.com") + .streamEventMethod("POST") + .username("user") + .password("pass") + .name("test") + .tracks("inbound") + .streamEventUrl("https://url.com") + .streamParams(streamParams) + .build(); String response = new Response() - .add(startStream) - .toBXML(); + .add(startStream) + .toBXML(); String expected = ""; assertEquals("BXML strings not equal", expected, response); - } + } + @Test public void testStopStream() { StopStream stopStream = StopStream.builder() - .name("test") - .build(); + .name("test") + .build(); String response = new Response() - .add(stopStream) - .toBXML(); + .add(stopStream) + .toBXML(); String expected = ""; assertEquals("BXML strings not equal", expected, response); - } + } @Test public void testRing() { @@ -507,8 +509,8 @@ public void testRing() { .build(); String response = new Response() - .add(ring) - .toBXML(); + .add(ring) + .toBXML(); String expected = ""; @@ -530,8 +532,8 @@ public void testStopGather() { StopGather stopGather = StopGather.builder().build(); String response = new Response() - .add(stopGather) - .toBXML(); + .add(stopGather) + .toBXML(); String expected = ""; @@ -543,8 +545,8 @@ public void testStartGather() { StartGather startGather = StartGather.builder().build(); String response = new Response() - .add(startGather) - .toBXML(); + .add(startGather) + .toBXML(); String expected = ""; @@ -553,7 +555,7 @@ public void testStartGather() { @Test public void testGenerateBxmlTwoParams() { - String response = WebRtcTransfer.generateBxml("asdf","c-93d6f3c0-be584596-0b74-4fa2-8015-d8ede84bd1a4"); + String response = WebRtcTransfer.generateBxml("asdf", "c-93d6f3c0-be584596-0b74-4fa2-8015-d8ede84bd1a4"); String expected = "\n" + "\n" + "\tsip:sipx.webrtc.bandwidth.com:5060\n" @@ -563,7 +565,8 @@ public void testGenerateBxmlTwoParams() { @Test public void testGenerateBxmlThreeParams() { - String response = WebRtcTransfer.generateBxml("asdf","c-93d6f3c0-be584596-0b74-4fa2-8015-d8ede84bd1a4", "sip1:sipx.webrtc.bandwidth.com:5060"); + String response = WebRtcTransfer.generateBxml("asdf", "c-93d6f3c0-be584596-0b74-4fa2-8015-d8ede84bd1a4", + "sip1:sipx.webrtc.bandwidth.com:5060"); String expected = "\n" + "\n" + "\tsip1:sipx.webrtc.bandwidth.com:5060\n" @@ -573,7 +576,8 @@ public void testGenerateBxmlThreeParams() { @Test public void testGenerateBxmlVerb() { - String response = WebRtcTransfer.generateTransferVerb("asdf","c-93d6f3c0-be584596-0b74-4fa2-8015-d8ede84bd1a4", "sip:sipx.webrtc.bandwidth.com:5060"); + String response = WebRtcTransfer.generateTransferVerb("asdf", "c-93d6f3c0-be584596-0b74-4fa2-8015-d8ede84bd1a4", + "sip:sipx.webrtc.bandwidth.com:5060"); String expected = "\n" + "\tsip:sipx.webrtc.bandwidth.com:5060\n" + ""; From 92a7e4503ce21db5329032ef71e6df5b8b03e241 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 29 Mar 2023 08:10:01 -0400 Subject: [PATCH 2/4] Update TranscribeRecordingRequest.java --- .../models/TranscribeRecordingRequest.java | 131 +++++++++++++++--- 1 file changed, 113 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/bandwidth/voice/models/TranscribeRecordingRequest.java b/src/main/java/com/bandwidth/voice/models/TranscribeRecordingRequest.java index 16d72f0f..0eae0884 100644 --- a/src/main/java/com/bandwidth/voice/models/TranscribeRecordingRequest.java +++ b/src/main/java/com/bandwidth/voice/models/TranscribeRecordingRequest.java @@ -28,6 +28,7 @@ public class TranscribeRecordingRequest { private OptionalNullable tag; @JsonInclude(JsonInclude.Include.NON_NULL) private OptionalNullable callbackTimeout; + private OptionalNullable detectLanguage; /** * Default constructor. @@ -37,12 +38,14 @@ public TranscribeRecordingRequest() { /** * Initialization constructor. - * @param callbackUrl String value for callbackUrl. - * @param callbackMethod CallbackMethodEnum value for callbackMethod. - * @param username String value for username. - * @param password String value for password. - * @param tag String value for tag. - * @param callbackTimeout Double value for callbackTimeout. + * + * @param callbackUrl String value for callbackUrl. + * @param callbackMethod CallbackMethodEnum value for callbackMethod. + * @param username String value for username. + * @param password String value for password. + * @param tag String value for tag. + * @param callbackTimeout Double value for callbackTimeout. + * @param detectLanguage Boolean value for detectLanguage */ public TranscribeRecordingRequest( String callbackUrl, @@ -50,13 +53,15 @@ public TranscribeRecordingRequest( String username, String password, String tag, - Double callbackTimeout) { + Double callbackTimeout, + Boolean detectLanguage) { this.callbackUrl = callbackUrl; this.callbackMethod = OptionalNullable.of(callbackMethod); this.username = OptionalNullable.of(username); this.password = OptionalNullable.of(password); this.tag = OptionalNullable.of(tag); this.callbackTimeout = OptionalNullable.of(callbackTimeout); + this.detectLanguage = OptionalNullable.of(detectLanguage); } /** @@ -65,17 +70,19 @@ public TranscribeRecordingRequest( protected TranscribeRecordingRequest(String callbackUrl, OptionalNullable callbackMethod, OptionalNullable username, OptionalNullable password, OptionalNullable tag, - OptionalNullable callbackTimeout) { + OptionalNullable callbackTimeout, OptionalNullable detectLanguage) { this.callbackUrl = callbackUrl; this.callbackMethod = callbackMethod; this.username = username; this.password = password; this.tag = tag; this.callbackTimeout = callbackTimeout; + this.detectLanguage = detectLanguage; } /** * Getter for CallbackUrl. + * * @return Returns the String */ @JsonGetter("callbackUrl") @@ -85,6 +92,7 @@ public String getCallbackUrl() { /** * Setter for CallbackUrl. + * * @param callbackUrl Value for String */ @JsonSetter("callbackUrl") @@ -94,6 +102,7 @@ public void setCallbackUrl(String callbackUrl) { /** * Internal Getter for CallbackMethod. + * * @return Returns the Internal CallbackMethodEnum */ @JsonGetter("callbackMethod") @@ -104,6 +113,7 @@ protected OptionalNullable internalGetCallbackMethod() { /** * Getter for CallbackMethod. + * * @return Returns the CallbackMethodEnum */ public CallbackMethodEnum getCallbackMethod() { @@ -112,6 +122,7 @@ public CallbackMethodEnum getCallbackMethod() { /** * Setter for CallbackMethod. + * * @param callbackMethod Value for CallbackMethodEnum */ @JsonSetter("callbackMethod") @@ -128,6 +139,7 @@ public void unsetCallbackMethod() { /** * Internal Getter for Username. + * * @return Returns the Internal String */ @JsonGetter("username") @@ -138,6 +150,7 @@ protected OptionalNullable internalGetUsername() { /** * Getter for Username. + * * @return Returns the String */ public String getUsername() { @@ -146,6 +159,7 @@ public String getUsername() { /** * Setter for Username. + * * @param username Value for String */ @JsonSetter("username") @@ -162,6 +176,7 @@ public void unsetUsername() { /** * Internal Getter for Password. + * * @return Returns the Internal String */ @JsonGetter("password") @@ -172,6 +187,7 @@ protected OptionalNullable internalGetPassword() { /** * Getter for Password. + * * @return Returns the String */ public String getPassword() { @@ -180,6 +196,7 @@ public String getPassword() { /** * Setter for Password. + * * @param password Value for String */ @JsonSetter("password") @@ -196,6 +213,7 @@ public void unsetPassword() { /** * Internal Getter for Tag. + * * @return Returns the Internal String */ @JsonGetter("tag") @@ -206,6 +224,7 @@ protected OptionalNullable internalGetTag() { /** * Getter for Tag. + * * @return Returns the String */ public String getTag() { @@ -214,6 +233,7 @@ public String getTag() { /** * Setter for Tag. + * * @param tag Value for String */ @JsonSetter("tag") @@ -230,6 +250,7 @@ public void unsetTag() { /** * Internal Getter for CallbackTimeout. + * * @return Returns the Internal Double */ @JsonGetter("callbackTimeout") @@ -240,6 +261,7 @@ protected OptionalNullable internalGetCallbackTimeout() { /** * Getter for CallbackTimeout. + * * @return Returns the Double */ public Double getCallbackTimeout() { @@ -248,6 +270,7 @@ public Double getCallbackTimeout() { /** * Setter for CallbackTimeout. + * * @param callbackTimeout Value for Double */ @JsonSetter("callbackTimeout") @@ -262,20 +285,59 @@ public void unsetCallbackTimeout() { callbackTimeout = null; } + /** + * Internal Getter for DetectLanguage. + * + * @return Returns the Internal Boolean + */ + @JsonGetter("detectLanguage") + @JsonSerialize(using = OptionalNullable.Serializer.class) + protected OptionalNullable internalGetDetectLanguage() { + return this.detectLanguage; + } + + /** + * Getter for DetectLanguage. + * + * @return Returns the Boolean + */ + public Boolean getDetectLanguage() { + return OptionalNullable.getFrom(detectLanguage); + } + + /** + * Setter for DetectLanguage. + * + * @param detectLanguage Value for Boolean + */ + @JsonSetter("detectLanguage") + public void setDetectLanguage(Boolean detectLanguage) { + this.detectLanguage = OptionalNullable.of(detectLanguage); + } + + /** + * UnSetter for DetectLanguage. + */ + public void unsetDetectLanguage() { + detectLanguage = null; + } + /** * Converts this TranscribeRecordingRequest into string format. + * * @return String representation of this class */ @Override public String toString() { return "TranscribeRecordingRequest [" + "callbackUrl=" + callbackUrl + ", callbackMethod=" + callbackMethod + ", username=" + username + ", password=" + password + ", tag=" - + tag + ", callbackTimeout=" + callbackTimeout + "]"; + + tag + ", callbackTimeout=" + callbackTimeout + ", detectLanguage=" + detectLanguage + "]"; } /** * Builds a new {@link TranscribeRecordingRequest.Builder} object. * Creates the instance with the state of the current model. + * * @return a new {@link TranscribeRecordingRequest.Builder} object */ public Builder toBuilder() { @@ -286,6 +348,7 @@ public Builder toBuilder() { builder.password = internalGetPassword(); builder.tag = internalGetTag(); builder.callbackTimeout = internalGetCallbackTimeout(); + builder.detectLanguage = internalGetDetectLanguage(); return builder; } @@ -299,12 +362,12 @@ public static class Builder { private OptionalNullable password; private OptionalNullable tag; private OptionalNullable callbackTimeout; - - + private OptionalNullable detectLanguage; /** * Setter for callbackUrl. - * @param callbackUrl String value for callbackUrl. + * + * @param callbackUrl String value for callbackUrl. * @return Builder */ public Builder callbackUrl(String callbackUrl) { @@ -314,7 +377,8 @@ public Builder callbackUrl(String callbackUrl) { /** * Setter for callbackMethod. - * @param callbackMethod CallbackMethodEnum value for callbackMethod. + * + * @param callbackMethod CallbackMethodEnum value for callbackMethod. * @return Builder */ public Builder callbackMethod(CallbackMethodEnum callbackMethod) { @@ -324,6 +388,7 @@ public Builder callbackMethod(CallbackMethodEnum callbackMethod) { /** * UnSetter for callbackMethod. + * * @return Builder */ public Builder unsetCallbackMethod() { @@ -333,7 +398,8 @@ public Builder unsetCallbackMethod() { /** * Setter for username. - * @param username String value for username. + * + * @param username String value for username. * @return Builder */ public Builder username(String username) { @@ -343,6 +409,7 @@ public Builder username(String username) { /** * UnSetter for username. + * * @return Builder */ public Builder unsetUsername() { @@ -352,7 +419,8 @@ public Builder unsetUsername() { /** * Setter for password. - * @param password String value for password. + * + * @param password String value for password. * @return Builder */ public Builder password(String password) { @@ -362,6 +430,7 @@ public Builder password(String password) { /** * UnSetter for password. + * * @return Builder */ public Builder unsetPassword() { @@ -371,7 +440,8 @@ public Builder unsetPassword() { /** * Setter for tag. - * @param tag String value for tag. + * + * @param tag String value for tag. * @return Builder */ public Builder tag(String tag) { @@ -381,6 +451,7 @@ public Builder tag(String tag) { /** * UnSetter for tag. + * * @return Builder */ public Builder unsetTag() { @@ -390,7 +461,8 @@ public Builder unsetTag() { /** * Setter for callbackTimeout. - * @param callbackTimeout Double value for callbackTimeout. + * + * @param callbackTimeout Double value for callbackTimeout. * @return Builder */ public Builder callbackTimeout(Double callbackTimeout) { @@ -400,6 +472,7 @@ public Builder callbackTimeout(Double callbackTimeout) { /** * UnSetter for callbackTimeout. + * * @return Builder */ public Builder unsetCallbackTimeout() { @@ -407,13 +480,35 @@ public Builder unsetCallbackTimeout() { return this; } + /** + * Setter for detectLanguage. + * + * @param detectLanguage Boolean value for detectLanguage. + * @return Builder + */ + public Builder detectLanguage(Boolean detectLanguage) { + this.detectLanguage = OptionalNullable.of(detectLanguage); + return this; + } + + /** + * UnSetter for detectLanguage. + * + * @return Builder + */ + public Builder unsetDetectLanguage() { + detectLanguage = null; + return this; + } + /** * Builds a new {@link TranscribeRecordingRequest} object using the set fields. + * * @return {@link TranscribeRecordingRequest} */ public TranscribeRecordingRequest build() { return new TranscribeRecordingRequest(callbackUrl, callbackMethod, username, password, - tag, callbackTimeout); + tag, callbackTimeout, detectLanguage); } } } From 176c487d0b38b4da379cef7b2e0da86da322fc5c Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 29 Mar 2023 08:43:26 -0400 Subject: [PATCH 3/4] Update VoiceApiTest.java --- src/test/java/com/bandwidth/VoiceApiTest.java | 288 +++++++++--------- 1 file changed, 148 insertions(+), 140 deletions(-) diff --git a/src/test/java/com/bandwidth/VoiceApiTest.java b/src/test/java/com/bandwidth/VoiceApiTest.java index ffc044f9..67764421 100644 --- a/src/test/java/com/bandwidth/VoiceApiTest.java +++ b/src/test/java/com/bandwidth/VoiceApiTest.java @@ -20,144 +20,152 @@ */ public class VoiceApiTest { - private APIController controller; - - @Before - public void initTest(){ - BandwidthClient client = new BandwidthClient.Builder() - .voiceBasicAuthCredentials(USERNAME, PASSWORD) - .build(); - - controller = client.getVoiceClient().getAPIController(); - } - - @Test - public void testCreateCallAndGetCallState() throws Exception { - final String answerUrl = BASE_CALLBACK_URL.concat("/callbacks/outbound"); - - CreateCallRequest body = new CreateCallRequest.Builder() - .to(USER_NUMBER) - .from(BW_NUMBER) - .applicationId(VOICE_APPLICATION_ID) - .answerUrl(answerUrl) - .build(); - - ApiResponse createCallApiResponse = controller.createCall(ACCOUNT_ID, body); - assertEquals("Response Code is not 201", 201, createCallApiResponse.getStatusCode()); - - CreateCallResponse createCallResponse = createCallApiResponse.getResult(); - assertNotNull("Call ID is null", createCallResponse.getCallId()); - assertFalse("Call ID is empty", createCallResponse.getCallId().isEmpty()); - assertEquals("Call ID is not 47 characters", 47, createCallResponse.getCallId().length()); - assertEquals("Application ID for create call not equal", VOICE_APPLICATION_ID, createCallResponse.getApplicationId()); - assertEquals("To phone number for create call not equal", USER_NUMBER, createCallResponse.getTo()); - assertEquals("From phone number for create call not equal", BW_NUMBER, createCallResponse.getFrom()); - assertNotNull("enqueuedTime is null", createCallResponse.getEnqueuedTime()); - assertEquals("enqueuedTime is not a LocalDateTime object", LocalDateTime.class, createCallResponse.getEnqueuedTime().getClass()); - - //get call state - Thread.sleep(750); // Wait to get Call because of current system latency issues - ApiResponse callStateApiResponse = controller.getCall(ACCOUNT_ID, createCallResponse.getCallId()); - assertEquals("Response Code is not 200", 200, callStateApiResponse.getStatusCode()); - - CallState callStateResponse = callStateApiResponse.getResult(); - assertEquals("Application ID for call state not equal", VOICE_APPLICATION_ID, callStateResponse.getApplicationId()); - assertEquals("To phone number for call state not equal", USER_NUMBER, callStateResponse.getTo()); - assertEquals("From phone number for call state not equal", BW_NUMBER, callStateResponse.getFrom()); - assertEquals("Call ID not equal", createCallResponse.getCallId(), callStateResponse.getCallId()); - assertNotNull("enqueuedTime is null", createCallResponse.getEnqueuedTime()); - assertEquals("enqueuedTime is not a LocalDateTime object", LocalDateTime.class, createCallResponse.getEnqueuedTime().getClass()); - } - - @Test - public void testCreateCallWithAmdAndGetCallState() throws Exception { - final String answerUrl = BASE_CALLBACK_URL.concat("/callbacks/outbound"); - final String machineDetectionUrl = BASE_CALLBACK_URL.concat("/callbacks/machineDetection"); - - MachineDetectionConfiguration machineDetectionConfiguration = new MachineDetectionConfiguration.Builder() - .mode(ModeEnum.ASYNC) - .callbackUrl(machineDetectionUrl) - .callbackMethod(CallbackMethodEnum.POST) - .detectionTimeout(5.0) - .silenceTimeout(5.0) - .speechThreshold(5.0) - .speechEndThreshold(5.0) - .delayResult(true) - .build(); - - CreateCallRequest body = new CreateCallRequest.Builder() - .to(USER_NUMBER) - .from(BW_NUMBER) - .applicationId(VOICE_APPLICATION_ID) - .answerUrl(answerUrl) - .machineDetection(machineDetectionConfiguration) - .build(); - - ApiResponse createCallApiResponse = controller.createCall(ACCOUNT_ID, body); - assertEquals("Response Code is not 201", 201, createCallApiResponse.getStatusCode()); - - CreateCallResponse createCallResponse = createCallApiResponse.getResult(); - assertNotNull("Call ID is null", createCallResponse.getCallId()); - assertFalse("Call ID is empty", createCallResponse.getCallId().isEmpty()); - assertEquals("Call ID is not 47 characters", 47, createCallResponse.getCallId().length()); - assertEquals("Application ID for create call not equal", VOICE_APPLICATION_ID, createCallResponse.getApplicationId()); - assertEquals("To phone number for create call not equal", USER_NUMBER, createCallResponse.getTo()); - assertEquals("From phone number for create call not equal", BW_NUMBER, createCallResponse.getFrom()); - - //get call state - Thread.sleep(750); // Wait to get Call because of current system latency issues - ApiResponse callStateApiResponse = controller.getCall(ACCOUNT_ID, createCallResponse.getCallId()); - CallState callStateResponse = callStateApiResponse.getResult(); - assertEquals("Application ID for call state not equal", VOICE_APPLICATION_ID, callStateResponse.getApplicationId()); - assertEquals("To phone number for call state not equal", USER_NUMBER, callStateResponse.getTo()); - assertEquals("From phone number for call state not equal", BW_NUMBER, callStateResponse.getFrom()); - assertEquals("Call ID not equal", createCallResponse.getCallId(), callStateResponse.getCallId()); - } - - @Test - public void testCreateCallWithPriorityAndGetCallState() throws Exception { - final String answerUrl = BASE_CALLBACK_URL.concat("/callbacks/outbound"); - final Integer priority = 4; - - CreateCallRequest body = new CreateCallRequest.Builder() - .to(USER_NUMBER) - .from(BW_NUMBER) - .applicationId(VOICE_APPLICATION_ID) - .answerUrl(answerUrl) - .priority(priority) - .tag("the tag") - .build(); - - ApiResponse createCallApiResponse = controller.createCall(ACCOUNT_ID, body); - assertEquals("Response Code is not 201", 201, createCallApiResponse.getStatusCode()); - - CreateCallResponse createCallResponse = createCallApiResponse.getResult(); - assertNotNull("Call ID is null", createCallResponse.getCallId()); - assertFalse("Call ID is empty", createCallResponse.getCallId().isEmpty()); - assertEquals("Call ID is not 47 characters", 47, createCallResponse.getCallId().length()); - assertEquals("Application ID for create call not equal", VOICE_APPLICATION_ID, createCallResponse.getApplicationId()); - assertEquals("To phone number for create call not equal", USER_NUMBER, createCallResponse.getTo()); - assertEquals("From phone number for create call not equal", BW_NUMBER, createCallResponse.getFrom()); - assertEquals("Priority is not equal", priority, createCallResponse.getPriority()); - assertEquals("Tag is missing", "the tag", createCallResponse.getTag()); - } - - @Test - public void testCreateCallInvalidPhoneNumber() throws Exception { - final String answerUrl = BASE_CALLBACK_URL.concat("/callbacks/outbound"); - - CreateCallRequest body = new CreateCallRequest.Builder() - .to("+1invalid") - .from(BW_NUMBER) - .applicationId(VOICE_APPLICATION_ID) - .answerUrl(answerUrl) - .build(); - - ApiErrorException e = assertThrows( - "ApiError Exception not thrown", - ApiErrorException.class, - ()->controller.createCall(ACCOUNT_ID, body) - ); - assertEquals("Response Code is not 400", 400, e.getResponseCode()); - } + private APIController controller; + + @Before + public void initTest() { + BandwidthClient client = new BandwidthClient.Builder() + .voiceBasicAuthCredentials(USERNAME, PASSWORD) + .build(); + + controller = client.getVoiceClient().getAPIController(); + } + + @Test + public void testCreateCallAndGetCallState() throws Exception { + final String answerUrl = BASE_CALLBACK_URL.concat("/callbacks/outbound"); + + CreateCallRequest body = new CreateCallRequest.Builder() + .to(USER_NUMBER) + .from(BW_NUMBER) + .applicationId(VOICE_APPLICATION_ID) + .answerUrl(answerUrl) + .build(); + + ApiResponse createCallApiResponse = controller.createCall(ACCOUNT_ID, body); + assertEquals("Response Code is not 201", 201, createCallApiResponse.getStatusCode()); + + CreateCallResponse createCallResponse = createCallApiResponse.getResult(); + assertNotNull("Call ID is null", createCallResponse.getCallId()); + assertFalse("Call ID is empty", createCallResponse.getCallId().isEmpty()); + assertEquals("Call ID is not 47 characters", 47, createCallResponse.getCallId().length()); + assertEquals("Application ID for create call not equal", VOICE_APPLICATION_ID, + createCallResponse.getApplicationId()); + assertEquals("To phone number for create call not equal", USER_NUMBER, createCallResponse.getTo()); + assertEquals("From phone number for create call not equal", BW_NUMBER, createCallResponse.getFrom()); + assertNotNull("enqueuedTime is null", createCallResponse.getEnqueuedTime()); + assertEquals("enqueuedTime is not a LocalDateTime object", LocalDateTime.class, + createCallResponse.getEnqueuedTime().getClass()); + + // get call state + Thread.sleep(2000); // Wait to get Call because of current system latency issues + ApiResponse callStateApiResponse = controller.getCall(ACCOUNT_ID, + createCallResponse.getCallId()); + assertEquals("Response Code is not 200", 200, callStateApiResponse.getStatusCode()); + + CallState callStateResponse = callStateApiResponse.getResult(); + assertEquals("Application ID for call state not equal", VOICE_APPLICATION_ID, + callStateResponse.getApplicationId()); + assertEquals("To phone number for call state not equal", USER_NUMBER, callStateResponse.getTo()); + assertEquals("From phone number for call state not equal", BW_NUMBER, callStateResponse.getFrom()); + assertEquals("Call ID not equal", createCallResponse.getCallId(), callStateResponse.getCallId()); + assertNotNull("enqueuedTime is null", createCallResponse.getEnqueuedTime()); + assertEquals("enqueuedTime is not a LocalDateTime object", LocalDateTime.class, + createCallResponse.getEnqueuedTime().getClass()); + } + + @Test + public void testCreateCallWithAmdAndGetCallState() throws Exception { + final String answerUrl = BASE_CALLBACK_URL.concat("/callbacks/outbound"); + final String machineDetectionUrl = BASE_CALLBACK_URL.concat("/callbacks/machineDetection"); + + MachineDetectionConfiguration machineDetectionConfiguration = new MachineDetectionConfiguration.Builder() + .mode(ModeEnum.ASYNC) + .callbackUrl(machineDetectionUrl) + .callbackMethod(CallbackMethodEnum.POST) + .detectionTimeout(5.0) + .silenceTimeout(5.0) + .speechThreshold(5.0) + .speechEndThreshold(5.0) + .delayResult(true) + .build(); + + CreateCallRequest body = new CreateCallRequest.Builder() + .to(USER_NUMBER) + .from(BW_NUMBER) + .applicationId(VOICE_APPLICATION_ID) + .answerUrl(answerUrl) + .machineDetection(machineDetectionConfiguration) + .build(); + + ApiResponse createCallApiResponse = controller.createCall(ACCOUNT_ID, body); + assertEquals("Response Code is not 201", 201, createCallApiResponse.getStatusCode()); + + CreateCallResponse createCallResponse = createCallApiResponse.getResult(); + assertNotNull("Call ID is null", createCallResponse.getCallId()); + assertFalse("Call ID is empty", createCallResponse.getCallId().isEmpty()); + assertEquals("Call ID is not 47 characters", 47, createCallResponse.getCallId().length()); + assertEquals("Application ID for create call not equal", VOICE_APPLICATION_ID, + createCallResponse.getApplicationId()); + assertEquals("To phone number for create call not equal", USER_NUMBER, createCallResponse.getTo()); + assertEquals("From phone number for create call not equal", BW_NUMBER, createCallResponse.getFrom()); + + // get call state + Thread.sleep(2000); // Wait to get Call because of current system latency issues + ApiResponse callStateApiResponse = controller.getCall(ACCOUNT_ID, + createCallResponse.getCallId()); + CallState callStateResponse = callStateApiResponse.getResult(); + assertEquals("Application ID for call state not equal", VOICE_APPLICATION_ID, + callStateResponse.getApplicationId()); + assertEquals("To phone number for call state not equal", USER_NUMBER, callStateResponse.getTo()); + assertEquals("From phone number for call state not equal", BW_NUMBER, callStateResponse.getFrom()); + assertEquals("Call ID not equal", createCallResponse.getCallId(), callStateResponse.getCallId()); + } + + @Test + public void testCreateCallWithPriorityAndGetCallState() throws Exception { + final String answerUrl = BASE_CALLBACK_URL.concat("/callbacks/outbound"); + final Integer priority = 4; + + CreateCallRequest body = new CreateCallRequest.Builder() + .to(USER_NUMBER) + .from(BW_NUMBER) + .applicationId(VOICE_APPLICATION_ID) + .answerUrl(answerUrl) + .priority(priority) + .tag("the tag") + .build(); + + ApiResponse createCallApiResponse = controller.createCall(ACCOUNT_ID, body); + assertEquals("Response Code is not 201", 201, createCallApiResponse.getStatusCode()); + + CreateCallResponse createCallResponse = createCallApiResponse.getResult(); + assertNotNull("Call ID is null", createCallResponse.getCallId()); + assertFalse("Call ID is empty", createCallResponse.getCallId().isEmpty()); + assertEquals("Call ID is not 47 characters", 47, createCallResponse.getCallId().length()); + assertEquals("Application ID for create call not equal", VOICE_APPLICATION_ID, + createCallResponse.getApplicationId()); + assertEquals("To phone number for create call not equal", USER_NUMBER, createCallResponse.getTo()); + assertEquals("From phone number for create call not equal", BW_NUMBER, createCallResponse.getFrom()); + assertEquals("Priority is not equal", priority, createCallResponse.getPriority()); + assertEquals("Tag is missing", "the tag", createCallResponse.getTag()); + } + + @Test + public void testCreateCallInvalidPhoneNumber() throws Exception { + final String answerUrl = BASE_CALLBACK_URL.concat("/callbacks/outbound"); + + CreateCallRequest body = new CreateCallRequest.Builder() + .to("+1invalid") + .from(BW_NUMBER) + .applicationId(VOICE_APPLICATION_ID) + .answerUrl(answerUrl) + .build(); + + ApiErrorException e = assertThrows( + "ApiError Exception not thrown", + ApiErrorException.class, + () -> controller.createCall(ACCOUNT_ID, body)); + assertEquals("Response Code is not 400", 400, e.getResponseCode()); + } } From aedb1efc13ff6623581907826870b753f74b5757 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 29 Mar 2023 13:38:17 -0400 Subject: [PATCH 4/4] Updated sleep timeout to account for latency. --- src/test/java/com/bandwidth/VoiceApiTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/bandwidth/VoiceApiTest.java b/src/test/java/com/bandwidth/VoiceApiTest.java index 67764421..7f664f6d 100644 --- a/src/test/java/com/bandwidth/VoiceApiTest.java +++ b/src/test/java/com/bandwidth/VoiceApiTest.java @@ -58,7 +58,7 @@ public void testCreateCallAndGetCallState() throws Exception { createCallResponse.getEnqueuedTime().getClass()); // get call state - Thread.sleep(2000); // Wait to get Call because of current system latency issues + Thread.sleep(5000); // Wait to get Call because of current system latency issues ApiResponse callStateApiResponse = controller.getCall(ACCOUNT_ID, createCallResponse.getCallId()); assertEquals("Response Code is not 200", 200, callStateApiResponse.getStatusCode()); @@ -111,7 +111,7 @@ public void testCreateCallWithAmdAndGetCallState() throws Exception { assertEquals("From phone number for create call not equal", BW_NUMBER, createCallResponse.getFrom()); // get call state - Thread.sleep(2000); // Wait to get Call because of current system latency issues + Thread.sleep(5000); // Wait to get Call because of current system latency issues ApiResponse callStateApiResponse = controller.getCall(ACCOUNT_ID, createCallResponse.getCallId()); CallState callStateResponse = callStateApiResponse.getResult();