|
20 | 20 | */
|
21 | 21 | public class VoiceApiTest {
|
22 | 22 |
|
23 |
| - private APIController controller; |
24 |
| - |
25 |
| - @Before |
26 |
| - public void initTest(){ |
27 |
| - BandwidthClient client = new BandwidthClient.Builder() |
28 |
| - .voiceBasicAuthCredentials(USERNAME, PASSWORD) |
29 |
| - .build(); |
30 |
| - |
31 |
| - controller = client.getVoiceClient().getAPIController(); |
32 |
| - } |
33 |
| - |
34 |
| - @Test |
35 |
| - public void testCreateCallAndGetCallState() throws Exception { |
36 |
| - final String answerUrl = BASE_CALLBACK_URL.concat("/callbacks/outbound"); |
37 |
| - |
38 |
| - CreateCallRequest body = new CreateCallRequest.Builder() |
39 |
| - .to(USER_NUMBER) |
40 |
| - .from(BW_NUMBER) |
41 |
| - .applicationId(VOICE_APPLICATION_ID) |
42 |
| - .answerUrl(answerUrl) |
43 |
| - .build(); |
44 |
| - |
45 |
| - ApiResponse<CreateCallResponse> createCallApiResponse = controller.createCall(ACCOUNT_ID, body); |
46 |
| - assertEquals("Response Code is not 201", 201, createCallApiResponse.getStatusCode()); |
47 |
| - |
48 |
| - CreateCallResponse createCallResponse = createCallApiResponse.getResult(); |
49 |
| - assertNotNull("Call ID is null", createCallResponse.getCallId()); |
50 |
| - assertFalse("Call ID is empty", createCallResponse.getCallId().isEmpty()); |
51 |
| - assertEquals("Call ID is not 47 characters", 47, createCallResponse.getCallId().length()); |
52 |
| - assertEquals("Application ID for create call not equal", VOICE_APPLICATION_ID, createCallResponse.getApplicationId()); |
53 |
| - assertEquals("To phone number for create call not equal", USER_NUMBER, createCallResponse.getTo()); |
54 |
| - assertEquals("From phone number for create call not equal", BW_NUMBER, createCallResponse.getFrom()); |
55 |
| - assertNotNull("enqueuedTime is null", createCallResponse.getEnqueuedTime()); |
56 |
| - assertEquals("enqueuedTime is not a LocalDateTime object", LocalDateTime.class, createCallResponse.getEnqueuedTime().getClass()); |
57 |
| - |
58 |
| - //get call state |
59 |
| - Thread.sleep(750); // Wait to get Call because of current system latency issues |
60 |
| - ApiResponse<CallState> callStateApiResponse = controller.getCall(ACCOUNT_ID, createCallResponse.getCallId()); |
61 |
| - assertEquals("Response Code is not 200", 200, callStateApiResponse.getStatusCode()); |
62 |
| - |
63 |
| - CallState callStateResponse = callStateApiResponse.getResult(); |
64 |
| - assertEquals("Application ID for call state not equal", VOICE_APPLICATION_ID, callStateResponse.getApplicationId()); |
65 |
| - assertEquals("To phone number for call state not equal", USER_NUMBER, callStateResponse.getTo()); |
66 |
| - assertEquals("From phone number for call state not equal", BW_NUMBER, callStateResponse.getFrom()); |
67 |
| - assertEquals("Call ID not equal", createCallResponse.getCallId(), callStateResponse.getCallId()); |
68 |
| - assertNotNull("enqueuedTime is null", createCallResponse.getEnqueuedTime()); |
69 |
| - assertEquals("enqueuedTime is not a LocalDateTime object", LocalDateTime.class, createCallResponse.getEnqueuedTime().getClass()); |
70 |
| - } |
71 |
| - |
72 |
| - @Test |
73 |
| - public void testCreateCallWithAmdAndGetCallState() throws Exception { |
74 |
| - final String answerUrl = BASE_CALLBACK_URL.concat("/callbacks/outbound"); |
75 |
| - final String machineDetectionUrl = BASE_CALLBACK_URL.concat("/callbacks/machineDetection"); |
76 |
| - |
77 |
| - MachineDetectionConfiguration machineDetectionConfiguration = new MachineDetectionConfiguration.Builder() |
78 |
| - .mode(ModeEnum.ASYNC) |
79 |
| - .callbackUrl(machineDetectionUrl) |
80 |
| - .callbackMethod(CallbackMethodEnum.POST) |
81 |
| - .detectionTimeout(5.0) |
82 |
| - .silenceTimeout(5.0) |
83 |
| - .speechThreshold(5.0) |
84 |
| - .speechEndThreshold(5.0) |
85 |
| - .delayResult(true) |
86 |
| - .build(); |
87 |
| - |
88 |
| - CreateCallRequest body = new CreateCallRequest.Builder() |
89 |
| - .to(USER_NUMBER) |
90 |
| - .from(BW_NUMBER) |
91 |
| - .applicationId(VOICE_APPLICATION_ID) |
92 |
| - .answerUrl(answerUrl) |
93 |
| - .machineDetection(machineDetectionConfiguration) |
94 |
| - .build(); |
95 |
| - |
96 |
| - ApiResponse<CreateCallResponse> createCallApiResponse = controller.createCall(ACCOUNT_ID, body); |
97 |
| - assertEquals("Response Code is not 201", 201, createCallApiResponse.getStatusCode()); |
98 |
| - |
99 |
| - CreateCallResponse createCallResponse = createCallApiResponse.getResult(); |
100 |
| - assertNotNull("Call ID is null", createCallResponse.getCallId()); |
101 |
| - assertFalse("Call ID is empty", createCallResponse.getCallId().isEmpty()); |
102 |
| - assertEquals("Call ID is not 47 characters", 47, createCallResponse.getCallId().length()); |
103 |
| - assertEquals("Application ID for create call not equal", VOICE_APPLICATION_ID, createCallResponse.getApplicationId()); |
104 |
| - assertEquals("To phone number for create call not equal", USER_NUMBER, createCallResponse.getTo()); |
105 |
| - assertEquals("From phone number for create call not equal", BW_NUMBER, createCallResponse.getFrom()); |
106 |
| - |
107 |
| - //get call state |
108 |
| - Thread.sleep(750); // Wait to get Call because of current system latency issues |
109 |
| - ApiResponse<CallState> callStateApiResponse = controller.getCall(ACCOUNT_ID, createCallResponse.getCallId()); |
110 |
| - CallState callStateResponse = callStateApiResponse.getResult(); |
111 |
| - assertEquals("Application ID for call state not equal", VOICE_APPLICATION_ID, callStateResponse.getApplicationId()); |
112 |
| - assertEquals("To phone number for call state not equal", USER_NUMBER, callStateResponse.getTo()); |
113 |
| - assertEquals("From phone number for call state not equal", BW_NUMBER, callStateResponse.getFrom()); |
114 |
| - assertEquals("Call ID not equal", createCallResponse.getCallId(), callStateResponse.getCallId()); |
115 |
| - } |
116 |
| - |
117 |
| - @Test |
118 |
| - public void testCreateCallWithPriorityAndGetCallState() throws Exception { |
119 |
| - final String answerUrl = BASE_CALLBACK_URL.concat("/callbacks/outbound"); |
120 |
| - final Integer priority = 4; |
121 |
| - |
122 |
| - CreateCallRequest body = new CreateCallRequest.Builder() |
123 |
| - .to(USER_NUMBER) |
124 |
| - .from(BW_NUMBER) |
125 |
| - .applicationId(VOICE_APPLICATION_ID) |
126 |
| - .answerUrl(answerUrl) |
127 |
| - .priority(priority) |
128 |
| - .tag("the tag") |
129 |
| - .build(); |
130 |
| - |
131 |
| - ApiResponse<CreateCallResponse> createCallApiResponse = controller.createCall(ACCOUNT_ID, body); |
132 |
| - assertEquals("Response Code is not 201", 201, createCallApiResponse.getStatusCode()); |
133 |
| - |
134 |
| - CreateCallResponse createCallResponse = createCallApiResponse.getResult(); |
135 |
| - assertNotNull("Call ID is null", createCallResponse.getCallId()); |
136 |
| - assertFalse("Call ID is empty", createCallResponse.getCallId().isEmpty()); |
137 |
| - assertEquals("Call ID is not 47 characters", 47, createCallResponse.getCallId().length()); |
138 |
| - assertEquals("Application ID for create call not equal", VOICE_APPLICATION_ID, createCallResponse.getApplicationId()); |
139 |
| - assertEquals("To phone number for create call not equal", USER_NUMBER, createCallResponse.getTo()); |
140 |
| - assertEquals("From phone number for create call not equal", BW_NUMBER, createCallResponse.getFrom()); |
141 |
| - assertEquals("Priority is not equal", priority, createCallResponse.getPriority()); |
142 |
| - assertEquals("Tag is missing", "the tag", createCallResponse.getTag()); |
143 |
| - } |
144 |
| - |
145 |
| - @Test |
146 |
| - public void testCreateCallInvalidPhoneNumber() throws Exception { |
147 |
| - final String answerUrl = BASE_CALLBACK_URL.concat("/callbacks/outbound"); |
148 |
| - |
149 |
| - CreateCallRequest body = new CreateCallRequest.Builder() |
150 |
| - .to("+1invalid") |
151 |
| - .from(BW_NUMBER) |
152 |
| - .applicationId(VOICE_APPLICATION_ID) |
153 |
| - .answerUrl(answerUrl) |
154 |
| - .build(); |
155 |
| - |
156 |
| - ApiErrorException e = assertThrows( |
157 |
| - "ApiError Exception not thrown", |
158 |
| - ApiErrorException.class, |
159 |
| - ()->controller.createCall(ACCOUNT_ID, body) |
160 |
| - ); |
161 |
| - assertEquals("Response Code is not 400", 400, e.getResponseCode()); |
162 |
| - } |
| 23 | + private APIController controller; |
| 24 | + |
| 25 | + @Before |
| 26 | + public void initTest() { |
| 27 | + BandwidthClient client = new BandwidthClient.Builder() |
| 28 | + .voiceBasicAuthCredentials(USERNAME, PASSWORD) |
| 29 | + .build(); |
| 30 | + |
| 31 | + controller = client.getVoiceClient().getAPIController(); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + public void testCreateCallAndGetCallState() throws Exception { |
| 36 | + final String answerUrl = BASE_CALLBACK_URL.concat("/callbacks/outbound"); |
| 37 | + |
| 38 | + CreateCallRequest body = new CreateCallRequest.Builder() |
| 39 | + .to(USER_NUMBER) |
| 40 | + .from(BW_NUMBER) |
| 41 | + .applicationId(VOICE_APPLICATION_ID) |
| 42 | + .answerUrl(answerUrl) |
| 43 | + .build(); |
| 44 | + |
| 45 | + ApiResponse<CreateCallResponse> createCallApiResponse = controller.createCall(ACCOUNT_ID, body); |
| 46 | + assertEquals("Response Code is not 201", 201, createCallApiResponse.getStatusCode()); |
| 47 | + |
| 48 | + CreateCallResponse createCallResponse = createCallApiResponse.getResult(); |
| 49 | + assertNotNull("Call ID is null", createCallResponse.getCallId()); |
| 50 | + assertFalse("Call ID is empty", createCallResponse.getCallId().isEmpty()); |
| 51 | + assertEquals("Call ID is not 47 characters", 47, createCallResponse.getCallId().length()); |
| 52 | + assertEquals("Application ID for create call not equal", VOICE_APPLICATION_ID, |
| 53 | + createCallResponse.getApplicationId()); |
| 54 | + assertEquals("To phone number for create call not equal", USER_NUMBER, createCallResponse.getTo()); |
| 55 | + assertEquals("From phone number for create call not equal", BW_NUMBER, createCallResponse.getFrom()); |
| 56 | + assertNotNull("enqueuedTime is null", createCallResponse.getEnqueuedTime()); |
| 57 | + assertEquals("enqueuedTime is not a LocalDateTime object", LocalDateTime.class, |
| 58 | + createCallResponse.getEnqueuedTime().getClass()); |
| 59 | + |
| 60 | + // get call state |
| 61 | + Thread.sleep(2000); // Wait to get Call because of current system latency issues |
| 62 | + ApiResponse<CallState> callStateApiResponse = controller.getCall(ACCOUNT_ID, |
| 63 | + createCallResponse.getCallId()); |
| 64 | + assertEquals("Response Code is not 200", 200, callStateApiResponse.getStatusCode()); |
| 65 | + |
| 66 | + CallState callStateResponse = callStateApiResponse.getResult(); |
| 67 | + assertEquals("Application ID for call state not equal", VOICE_APPLICATION_ID, |
| 68 | + callStateResponse.getApplicationId()); |
| 69 | + assertEquals("To phone number for call state not equal", USER_NUMBER, callStateResponse.getTo()); |
| 70 | + assertEquals("From phone number for call state not equal", BW_NUMBER, callStateResponse.getFrom()); |
| 71 | + assertEquals("Call ID not equal", createCallResponse.getCallId(), callStateResponse.getCallId()); |
| 72 | + assertNotNull("enqueuedTime is null", createCallResponse.getEnqueuedTime()); |
| 73 | + assertEquals("enqueuedTime is not a LocalDateTime object", LocalDateTime.class, |
| 74 | + createCallResponse.getEnqueuedTime().getClass()); |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + public void testCreateCallWithAmdAndGetCallState() throws Exception { |
| 79 | + final String answerUrl = BASE_CALLBACK_URL.concat("/callbacks/outbound"); |
| 80 | + final String machineDetectionUrl = BASE_CALLBACK_URL.concat("/callbacks/machineDetection"); |
| 81 | + |
| 82 | + MachineDetectionConfiguration machineDetectionConfiguration = new MachineDetectionConfiguration.Builder() |
| 83 | + .mode(ModeEnum.ASYNC) |
| 84 | + .callbackUrl(machineDetectionUrl) |
| 85 | + .callbackMethod(CallbackMethodEnum.POST) |
| 86 | + .detectionTimeout(5.0) |
| 87 | + .silenceTimeout(5.0) |
| 88 | + .speechThreshold(5.0) |
| 89 | + .speechEndThreshold(5.0) |
| 90 | + .delayResult(true) |
| 91 | + .build(); |
| 92 | + |
| 93 | + CreateCallRequest body = new CreateCallRequest.Builder() |
| 94 | + .to(USER_NUMBER) |
| 95 | + .from(BW_NUMBER) |
| 96 | + .applicationId(VOICE_APPLICATION_ID) |
| 97 | + .answerUrl(answerUrl) |
| 98 | + .machineDetection(machineDetectionConfiguration) |
| 99 | + .build(); |
| 100 | + |
| 101 | + ApiResponse<CreateCallResponse> createCallApiResponse = controller.createCall(ACCOUNT_ID, body); |
| 102 | + assertEquals("Response Code is not 201", 201, createCallApiResponse.getStatusCode()); |
| 103 | + |
| 104 | + CreateCallResponse createCallResponse = createCallApiResponse.getResult(); |
| 105 | + assertNotNull("Call ID is null", createCallResponse.getCallId()); |
| 106 | + assertFalse("Call ID is empty", createCallResponse.getCallId().isEmpty()); |
| 107 | + assertEquals("Call ID is not 47 characters", 47, createCallResponse.getCallId().length()); |
| 108 | + assertEquals("Application ID for create call not equal", VOICE_APPLICATION_ID, |
| 109 | + createCallResponse.getApplicationId()); |
| 110 | + assertEquals("To phone number for create call not equal", USER_NUMBER, createCallResponse.getTo()); |
| 111 | + assertEquals("From phone number for create call not equal", BW_NUMBER, createCallResponse.getFrom()); |
| 112 | + |
| 113 | + // get call state |
| 114 | + Thread.sleep(2000); // Wait to get Call because of current system latency issues |
| 115 | + ApiResponse<CallState> callStateApiResponse = controller.getCall(ACCOUNT_ID, |
| 116 | + createCallResponse.getCallId()); |
| 117 | + CallState callStateResponse = callStateApiResponse.getResult(); |
| 118 | + assertEquals("Application ID for call state not equal", VOICE_APPLICATION_ID, |
| 119 | + callStateResponse.getApplicationId()); |
| 120 | + assertEquals("To phone number for call state not equal", USER_NUMBER, callStateResponse.getTo()); |
| 121 | + assertEquals("From phone number for call state not equal", BW_NUMBER, callStateResponse.getFrom()); |
| 122 | + assertEquals("Call ID not equal", createCallResponse.getCallId(), callStateResponse.getCallId()); |
| 123 | + } |
| 124 | + |
| 125 | + @Test |
| 126 | + public void testCreateCallWithPriorityAndGetCallState() throws Exception { |
| 127 | + final String answerUrl = BASE_CALLBACK_URL.concat("/callbacks/outbound"); |
| 128 | + final Integer priority = 4; |
| 129 | + |
| 130 | + CreateCallRequest body = new CreateCallRequest.Builder() |
| 131 | + .to(USER_NUMBER) |
| 132 | + .from(BW_NUMBER) |
| 133 | + .applicationId(VOICE_APPLICATION_ID) |
| 134 | + .answerUrl(answerUrl) |
| 135 | + .priority(priority) |
| 136 | + .tag("the tag") |
| 137 | + .build(); |
| 138 | + |
| 139 | + ApiResponse<CreateCallResponse> createCallApiResponse = controller.createCall(ACCOUNT_ID, body); |
| 140 | + assertEquals("Response Code is not 201", 201, createCallApiResponse.getStatusCode()); |
| 141 | + |
| 142 | + CreateCallResponse createCallResponse = createCallApiResponse.getResult(); |
| 143 | + assertNotNull("Call ID is null", createCallResponse.getCallId()); |
| 144 | + assertFalse("Call ID is empty", createCallResponse.getCallId().isEmpty()); |
| 145 | + assertEquals("Call ID is not 47 characters", 47, createCallResponse.getCallId().length()); |
| 146 | + assertEquals("Application ID for create call not equal", VOICE_APPLICATION_ID, |
| 147 | + createCallResponse.getApplicationId()); |
| 148 | + assertEquals("To phone number for create call not equal", USER_NUMBER, createCallResponse.getTo()); |
| 149 | + assertEquals("From phone number for create call not equal", BW_NUMBER, createCallResponse.getFrom()); |
| 150 | + assertEquals("Priority is not equal", priority, createCallResponse.getPriority()); |
| 151 | + assertEquals("Tag is missing", "the tag", createCallResponse.getTag()); |
| 152 | + } |
| 153 | + |
| 154 | + @Test |
| 155 | + public void testCreateCallInvalidPhoneNumber() throws Exception { |
| 156 | + final String answerUrl = BASE_CALLBACK_URL.concat("/callbacks/outbound"); |
| 157 | + |
| 158 | + CreateCallRequest body = new CreateCallRequest.Builder() |
| 159 | + .to("+1invalid") |
| 160 | + .from(BW_NUMBER) |
| 161 | + .applicationId(VOICE_APPLICATION_ID) |
| 162 | + .answerUrl(answerUrl) |
| 163 | + .build(); |
| 164 | + |
| 165 | + ApiErrorException e = assertThrows( |
| 166 | + "ApiError Exception not thrown", |
| 167 | + ApiErrorException.class, |
| 168 | + () -> controller.createCall(ACCOUNT_ID, body)); |
| 169 | + assertEquals("Response Code is not 400", 400, e.getResponseCode()); |
| 170 | + } |
163 | 171 | }
|
0 commit comments