44import com .bandwidth .sdk .ApiResponse ;
55import com .bandwidth .sdk .ApiException ;
66import com .bandwidth .sdk .ApiClient ;
7- import com .bandwidth .sdk .auth .HttpBasicAuth ;
8- import com .bandwidth .sdk .Configuration ;
97import com .bandwidth .sdk .model .CallbackMethodEnum ;
108import com .bandwidth .sdk .model .CreateCall ;
119import com .bandwidth .sdk .model .CreateCallResponse ;
4038import static com .bandwidth .sdk .utils .TestingEnvironmentVariables .*;
4139import static com .bandwidth .sdk .utils .CallCleanup .Cleanup ;
4240
41+ @ SuppressWarnings ("null" )
4342@ TestMethodOrder (MethodOrderer .OrderAnnotation .class )
4443@ TestInstance (TestInstance .Lifecycle .PER_CLASS )
4544public class CallsApiTest {
46- public ApiClient defaultClient = Configuration .getDefaultApiClient ();
47- public HttpBasicAuth Basic = (HttpBasicAuth ) defaultClient .getAuthentication ("Basic" );
48- public final CallsApi api = new CallsApi (defaultClient );
45+ private static ApiClient oauthClient = new ApiClient (BW_CLIENT_ID , BW_CLIENT_SECRET , null );
46+ public final CallsApi api = new CallsApi (oauthClient );
4947
5048 private static List <String > callIdList = new ArrayList <String >();
5149 private static MachineDetectionConfiguration machineDetection = new MachineDetectionConfiguration ();
@@ -132,9 +130,6 @@ public void tearDownAfterClass() throws Exception {
132130 @ Test
133131 @ Order (1 )
134132 public void createCall () throws ApiException {
135- Basic .setUsername (BW_USERNAME );
136- Basic .setPassword (BW_PASSWORD );
137-
138133 ApiResponse <CreateCallResponse > response = api .createCallWithHttpInfo (BW_ACCOUNT_ID , createCallBody );
139134 callIdList .add (response .getData ().getCallId ());
140135
@@ -148,9 +143,6 @@ public void createCall() throws ApiException {
148143
149144 @ Test
150145 public void createCallBadRequest () throws ApiException {
151- Basic .setUsername (BW_USERNAME );
152- Basic .setPassword (BW_PASSWORD );
153-
154146 CreateCall badCallRequest = new CreateCall ();
155147 createCallBody .setTo ("invalid_number" );
156148 createCallBody .setFrom (BW_NUMBER );
@@ -163,45 +155,8 @@ public void createCallBadRequest() throws ApiException {
163155 assertThat (exception .getCode (), is (400 ));
164156 }
165157
166- @ Test
167- public void createCallUnauthorized () throws ApiException {
168- Basic .setUsername ("bad_username" );
169- Basic .setPassword ("bad_password" );
170-
171- CreateCall badCallRequest = new CreateCall ();
172- createCallBody .setTo ("invalid_number" );
173- createCallBody .setFrom (BW_NUMBER );
174- createCallBody .setApplicationId (BW_VOICE_APPLICATION_ID );
175- createCallBody .setAnswerUrl (answerUrl );
176-
177- ApiException exception = Assertions .assertThrows (ApiException .class ,
178- () -> api .createCallWithHttpInfo (BW_ACCOUNT_ID , badCallRequest ));
179-
180- assertThat (exception .getCode (), is (401 ));
181- }
182-
183- @ Test
184- public void createCallForbidden () throws ApiException {
185- Basic .setUsername (FORBIDDEN_USERNAME );
186- Basic .setPassword (FORBIDDEN_PASSWORD );
187-
188- CreateCall badCallRequest = new CreateCall ();
189- createCallBody .setTo ("invalid_number" );
190- createCallBody .setFrom (BW_NUMBER );
191- createCallBody .setApplicationId (BW_VOICE_APPLICATION_ID );
192- createCallBody .setAnswerUrl (answerUrl );
193-
194- ApiException exception = Assertions .assertThrows (ApiException .class ,
195- () -> api .createCallWithHttpInfo (BW_ACCOUNT_ID , badCallRequest ));
196-
197- assertThat (exception .getCode (), is (403 ));
198- }
199-
200158 @ Test
201159 public void getCalls () throws ApiException {
202- Basic .setUsername (BW_USERNAME );
203- Basic .setPassword (BW_PASSWORD );
204-
205160 ApiResponse <List <CallState >> response = api .listCallsWithHttpInfo (BW_ACCOUNT_ID , USER_NUMBER , BW_NUMBER , null ,
206161 null , null , null , null );
207162
@@ -220,9 +175,6 @@ public void getCalls() throws ApiException {
220175 @ Test
221176 @ Order (2 )
222177 public void getCallState () throws ApiException , InterruptedException {
223- Basic .setUsername (BW_USERNAME );
224- Basic .setPassword (BW_PASSWORD );
225-
226178 TimeUnit .SECONDS .sleep (40 );
227179 ApiResponse <CallState > response = api .getCallStateWithHttpInfo (BW_ACCOUNT_ID , callIdList .get (0 ));
228180
@@ -232,33 +184,8 @@ public void getCallState() throws ApiException, InterruptedException {
232184 assertThat (response .getData (), hasProperty ("direction" , is (CallDirectionEnum .OUTBOUND )));
233185 }
234186
235- @ Test
236- public void getCallStateUnauthorized () throws ApiException {
237- Basic .setUsername ("bad_username" );
238- Basic .setPassword ("bad_password" );
239-
240- ApiException exception = Assertions .assertThrows (ApiException .class ,
241- () -> api .getCallStateWithHttpInfo (BW_ACCOUNT_ID , "not a call id" ));
242-
243- assertThat (exception .getCode (), is (401 ));
244- }
245-
246- @ Test
247- public void getCallStateForbidden () throws ApiException {
248- Basic .setUsername (FORBIDDEN_USERNAME );
249- Basic .setPassword (FORBIDDEN_PASSWORD );
250-
251- ApiException exception = Assertions .assertThrows (ApiException .class ,
252- () -> api .getCallStateWithHttpInfo (BW_ACCOUNT_ID , "not a call id" ));
253-
254- assertThat (exception .getCode (), is (403 ));
255- }
256-
257187 @ Test
258188 public void getCallStateNotFound () throws ApiException {
259- Basic .setUsername (BW_USERNAME );
260- Basic .setPassword (BW_PASSWORD );
261-
262189 ApiException exception = Assertions .assertThrows (ApiException .class ,
263190 () -> api .getCallStateWithHttpInfo (BW_ACCOUNT_ID , "not a call id" ));
264191
@@ -268,9 +195,6 @@ public void getCallStateNotFound() throws ApiException {
268195 @ Test
269196 @ Order (3 )
270197 public void updateCall () throws ApiException , InterruptedException {
271- Basic .setUsername (BW_USERNAME );
272- Basic .setPassword (BW_PASSWORD );
273-
274198 // Create call
275199 TimeUnit .SECONDS .sleep (TEST_SLEEP );
276200 ApiResponse <CreateCallResponse > createCallResponse = api .createCallWithHttpInfo (BW_ACCOUNT_ID ,
@@ -296,9 +220,6 @@ public void updateCall() throws ApiException, InterruptedException {
296220
297221 @ Test
298222 public void updateCallBadRequest () throws ApiException , InterruptedException {
299- Basic .setUsername (BW_USERNAME );
300- Basic .setPassword (BW_PASSWORD );
301-
302223 UpdateCall badRequest = new UpdateCall ();
303224 badRequest .state (null );
304225
@@ -314,36 +235,8 @@ public void updateCallBadRequest() throws ApiException, InterruptedException {
314235 assertThat (exception .getCode (), is (400 ));
315236 }
316237
317- @ Test
318- public void updateCallUnauthorized () throws ApiException {
319- Basic .setUsername ("bad_username" );
320- Basic .setPassword ("bad_password" );
321-
322- ApiException exception = Assertions .assertThrows (ApiException .class ,
323- () -> api .updateCallWithHttpInfo (BW_ACCOUNT_ID , testCallId ,
324- new UpdateCall ().state (CallStateEnum .COMPLETED )));
325-
326- assertThat (exception .getCode (), is (401 ));
327-
328- }
329-
330- @ Test
331- public void updateCallForbidden () throws ApiException {
332- Basic .setUsername (FORBIDDEN_USERNAME );
333- Basic .setPassword (FORBIDDEN_PASSWORD );
334-
335- ApiException exception = Assertions .assertThrows (ApiException .class ,
336- () -> api .updateCallWithHttpInfo (BW_ACCOUNT_ID , testCallId ,
337- new UpdateCall ().state (CallStateEnum .COMPLETED )));
338-
339- assertThat (exception .getCode (), is (403 ));
340- }
341-
342238 @ Test
343239 public void updateCallNotFound () throws ApiException {
344- Basic .setUsername (BW_USERNAME );
345- Basic .setPassword (BW_PASSWORD );
346-
347240 ApiException exception = Assertions .assertThrows (ApiException .class ,
348241 () -> api .updateCallWithHttpInfo (BW_ACCOUNT_ID , testCallId ,
349242 new UpdateCall ().state (CallStateEnum .COMPLETED )));
@@ -354,9 +247,6 @@ public void updateCallNotFound() throws ApiException {
354247 @ Test
355248 @ Order (4 )
356249 public void updateCallBxml () throws ApiException , InterruptedException {
357- Basic .setUsername (BW_USERNAME );
358- Basic .setPassword (BW_PASSWORD );
359-
360250 // Create call
361251 TimeUnit .SECONDS .sleep (TEST_SLEEP );
362252 ApiResponse <CreateCallResponse > createCallResponse = api .createCallWithHttpInfo (BW_ACCOUNT_ID ,
@@ -379,45 +269,4 @@ public void updateCallBxml() throws ApiException, InterruptedException {
379269
380270 assertThat (completeCallResponse .getStatusCode (), is (200 ));
381271 }
382-
383- @ Test
384- public void updateCallBxmlBadRequest () throws ApiException {
385-
386- }
387-
388- @ Test
389- public void updateCallBxmlUnauthorized () throws ApiException {
390- Basic .setUsername ("bad_username" );
391- Basic .setPassword ("bad_password" );
392-
393- ApiException exception = Assertions .assertThrows (ApiException .class ,
394- () -> api .updateCallBxmlWithHttpInfo (BW_ACCOUNT_ID , testCallId ,
395- testXmlBody ));
396-
397- assertThat (exception .getCode (), is (401 ));
398- }
399-
400- @ Test
401- public void updateCallBxmlForbidden () throws ApiException {
402- Basic .setUsername (FORBIDDEN_USERNAME );
403- Basic .setPassword (FORBIDDEN_PASSWORD );
404-
405- ApiException exception = Assertions .assertThrows (ApiException .class ,
406- () -> api .updateCallBxmlWithHttpInfo (BW_ACCOUNT_ID , testCallId ,
407- testXmlBody ));
408-
409- assertThat (exception .getCode (), is (403 ));
410- }
411-
412- @ Test
413- public void updateCallBxmlNotFound () throws ApiException {
414- Basic .setUsername (BW_USERNAME );
415- Basic .setPassword (BW_PASSWORD );
416-
417- ApiException exception = Assertions .assertThrows (ApiException .class ,
418- () -> api .updateCallBxmlWithHttpInfo (BW_ACCOUNT_ID , testCallId ,
419- testXmlBody ));
420-
421- assertThat (exception .getCode (), is (404 ));
422- }
423272}
0 commit comments