22
33import com .bandwidth .webrtc .controllers .APIController ;
44
5- import com .bandwidth .webrtc .models .Participant ;
6- import com . bandwidth . webrtc . models . Session ;
5+ import com .bandwidth .webrtc .models .* ;
6+
77import org .junit .*;
88
9+ import java .util .Arrays ;
10+
11+ import static org .junit .Assert .*;
12+
913import static com .bandwidth .TestingEnvironmentVariables .*;
1014
15+ /*
16+ * Integration tests between the SDK and WebRTC API
17+ */
1118public class WebRtcApiTests {
1219
1320 private APIController controller ;
@@ -21,19 +28,122 @@ public void initTest(){
2128 controller = client .getWebRtcClient ().getAPIController ();
2229 }
2330
31+ // Break this into multiple tests when we have an actual test environment and there aren't crippling dependency issues
2432 @ Test
2533 public void testWebRtcParticipantSessionManagement () throws Exception {
34+ // Create a participant
35+ Participant participantCreationRequest = new Participant .Builder ()
36+ .callbackUrl (BASE_CALLBACK_URL + "/callbacks/webrtc" )
37+ .publishPermissions (Arrays .asList (PublishPermissionEnum .AUDIO , PublishPermissionEnum .VIDEO ))
38+ .tag ("test" )
39+ .deviceApiVersion (DeviceApiVersionEnum .V3 )
40+ .build ();
41+
42+ AccountsParticipantsResponse participantCreationResponse =
43+ controller .createParticipant (ACCOUNT_ID , participantCreationRequest ).getResult ();
44+ assertNotNull ("Participant is null" , participantCreationResponse .getParticipant ());
45+ assertNotNull ("Participant ID is null" , participantCreationResponse .getParticipant ().getId ());
46+ assertFalse ("Participant ID is empty" , participantCreationResponse .getParticipant ().getId ().isEmpty ());
47+ assertEquals (
48+ "Publish Permissions do not match" ,
49+ participantCreationRequest .getPublishPermissions (),
50+ participantCreationResponse .getParticipant ().getPublishPermissions ()
51+ );
52+ assertEquals (
53+ "Tags do not match" ,
54+ participantCreationRequest .getTag (),
55+ participantCreationResponse .getParticipant ().getTag ()
56+ );
57+ assertEquals (
58+ "DeviceApiVersions do not match" ,
59+ participantCreationRequest .getDeviceApiVersion (),
60+ participantCreationResponse .getParticipant ().getDeviceApiVersion ()
61+ );
62+ assertNotNull ("Token is null" , participantCreationResponse .getToken ());
63+ assertFalse ("Token is empty" , participantCreationResponse .getToken ().isEmpty ());
64+
65+ // Get a participant
66+ Participant participantFetchResponse =
67+ controller .getParticipant (ACCOUNT_ID , participantCreationResponse .getParticipant ().getId ()).getResult ();
68+ assertNotNull ("Participant is null" , participantFetchResponse );
69+ assertNotNull ("Participant ID is null" , participantFetchResponse .getId ());
70+ assertFalse ("Participant ID is empty" , participantFetchResponse .getId ().isEmpty ());
71+ assertEquals (
72+ "Publish Permissions do not match" ,
73+ participantCreationRequest .getPublishPermissions (),
74+ participantFetchResponse .getPublishPermissions ()
75+ );
76+ assertEquals (
77+ "Tags do not match" ,
78+ participantCreationRequest .getTag (),
79+ participantFetchResponse .getTag ()
80+ );
81+ assertEquals (
82+ "DeviceApiVersions do not match" ,
83+ participantCreationRequest .getDeviceApiVersion (),
84+ participantFetchResponse .getDeviceApiVersion ()
85+ );
86+
87+ // Create a session
88+ Session sessionCreationRequest = new Session .Builder ()
89+ .tag ("test" )
90+ .build ();
91+
92+ Session sessionCreationResponse = controller .createSession (ACCOUNT_ID , sessionCreationRequest ).getResult ();
93+ assertNotNull ("Session ID is null" , sessionCreationResponse .getId ());
94+ assertFalse ("Session ID is empty" , sessionCreationResponse .getId ().isEmpty ());
95+ assertEquals ("Session Tags do not match" , sessionCreationRequest .getTag (), sessionCreationResponse .getTag ());
96+
97+ // Get a session
98+ Session sessionFetchResponse = controller .getSession (ACCOUNT_ID , sessionCreationResponse .getId ()).getResult ();
99+ assertEquals ("Session IDs do not match" , sessionCreationResponse .getId (), sessionFetchResponse .getId ());
100+ assertEquals ("Session Tags do not match" , sessionCreationResponse .getTag (), sessionFetchResponse .getTag ());
26101
27- Session session = new Session ();
28- session .setTag ("new-session" );
102+ // Add a participant to a session
103+ controller .addParticipantToSession (ACCOUNT_ID , sessionCreationResponse .getId (), participantCreationResponse .getParticipant ().getId (), null );
104+ // expected response is an empty 204
29105
30- session = controller .createSession (ACCOUNT_ID , session ).getResult ();
106+ // Get session participants
107+ java .util .List <Participant > sessionParticipantFetchResponse =
108+ controller .listSessionParticipants (ACCOUNT_ID , sessionCreationResponse .getId ()).getResult ();
109+ assertFalse ("List of Participants is empty" , sessionParticipantFetchResponse .isEmpty ());
110+ assertEquals ("List of Participants should only contain a single item" , 1 , sessionParticipantFetchResponse .size ());
111+ assertEquals (
112+ "Participant IDs do not match" ,
113+ participantCreationResponse .getParticipant ().getId (),
114+ sessionParticipantFetchResponse .get (0 ).getId ()
115+ );
116+ assertEquals (
117+ "Callback URLs do not match" ,
118+ participantCreationRequest .getCallbackUrl (),
119+ sessionParticipantFetchResponse .get (0 ).getCallbackUrl ()
120+ );
121+ assertEquals (
122+ "Publish Permissions do not match" ,
123+ participantCreationRequest .getPublishPermissions (),
124+ sessionParticipantFetchResponse .get (0 ).getPublishPermissions ()
125+ );
126+ assertEquals (
127+ "Tags do not match" ,
128+ participantCreationRequest .getTag (),
129+ sessionParticipantFetchResponse .get (0 ).getTag ()
130+ );
131+ assertEquals (
132+ "Device API Versions do not match" ,
133+ participantCreationRequest .getDeviceApiVersion (),
134+ sessionParticipantFetchResponse .get (0 ).getDeviceApiVersion ()
135+ );
31136
32- Participant participant = new Participant ();
33- participant .setCallbackUrl (BASE_CALLBACK_URL .concat ("/callbacks/webRtc" ));
137+ // Delete session participant
138+ controller .deleteParticipant (ACCOUNT_ID , participantCreationResponse .getParticipant ().getId ());
139+ // expected response is an empty 204
34140
35- participant = controller .createParticipant (ACCOUNT_ID , participant ).getResult ().getParticipant ();
141+ // Delete session
142+ controller .deleteSession (ACCOUNT_ID , sessionCreationResponse .getId ());
143+ // expected response is an empty 204
36144
37- controller .addParticipantToSession (ACCOUNT_ID , session .getId (), participant .getId (), null );
145+ // Delete participant
146+ controller .deleteParticipant (ACCOUNT_ID , participantCreationResponse .getParticipant ().getId ());
147+ // expected response is an empty 204
38148 }
39149}
0 commit comments