Skip to content

Commit ad39e30

Browse files
Added Extra Asserts To Verify Responses
We're actually checking the responses now.
1 parent 2a65cee commit ad39e30

File tree

4 files changed

+158
-19
lines changed

4 files changed

+158
-19
lines changed

src/test/java/com/bandwidth/MessagingApiTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ public void testCreateMessageInvalidPhoneNumber() throws Exception {
6565
}
6666

6767
@Test
68-
public void testUploadDownloadMedia() throws Exception {
68+
public void testUploadDownloadDeleteMedia() throws Exception {
6969
final String fileName = "src/test/resources/mediaUpload.png";
7070
final String contentType = "image/png";
7171

7272
File file = new File(fileName);
7373
byte[] fileContents = Files.readAllBytes(file.toPath());
7474
FileWrapper body = new FileWrapper(file, contentType);
7575

76-
String mediaId = "java-media-test";
76+
final String mediaId = "java-media-test";
7777

7878
controller.uploadMedia(ACCOUNT_ID, mediaId, body, contentType, "no-cache");
7979

@@ -87,5 +87,7 @@ public void testUploadDownloadMedia() throws Exception {
8787
byte[] responseContents = byteArrayOutputStream.toByteArray();
8888

8989
assertArrayEquals("Media download not equal to media upload", fileContents, responseContents);
90+
91+
controller.deleteMedia(ACCOUNT_ID, mediaId);
9092
}
9193
}

src/test/java/com/bandwidth/MfaApiTests.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import com.bandwidth.multifactorauth.controllers.MFAController;
44

55
import com.bandwidth.multifactorauth.exceptions.ErrorWithRequestException;
6-
import com.bandwidth.multifactorauth.models.TwoFactorCodeRequestSchema;
7-
import com.bandwidth.multifactorauth.models.TwoFactorVerifyRequestSchema;
6+
import com.bandwidth.multifactorauth.models.*;
7+
88
import org.junit.*;
9+
import static org.junit.Assert.*;
910

1011
import static com.bandwidth.TestingEnvironmentVariables.*;
1112

@@ -36,7 +37,9 @@ public void testMfaMessaging() throws Exception {
3637
.message("Your temporary {NAME} {SCOPE} code is {CODE}")
3738
.build();
3839

39-
controller.createMessagingTwoFactor(ACCOUNT_ID, body);
40+
TwoFactorMessagingResponse response = controller.createMessagingTwoFactor(ACCOUNT_ID, body).getResult();
41+
assertNotNull("MessageID is null", response.getMessageId());
42+
assertFalse("MessageID is empty", response.getMessageId().isEmpty());
4043
}
4144

4245
@Test
@@ -50,7 +53,9 @@ public void testMfaVoice() throws Exception {
5053
.message("Your temporary {NAME} {SCOPE} code is {CODE}")
5154
.build();
5255

53-
controller.createVoiceTwoFactor(ACCOUNT_ID, body);
56+
TwoFactorVoiceResponse response = controller.createVoiceTwoFactor(ACCOUNT_ID, body).getResult();
57+
assertNotNull("CallID is null", response.getCallId());
58+
assertFalse("CallID is empty", response.getCallId().isEmpty());
5459
}
5560

5661
@Test(expected = ErrorWithRequestException.class)
@@ -84,15 +89,18 @@ public void testMfaVoiceInvalidPhoneNumber() throws Exception {
8489
@Test
8590
public void testMfaVerify() throws Exception {
8691

92+
java.util.Random wheelOfPhoneNumbers = new java.util.Random(System.currentTimeMillis());
93+
8794
TwoFactorVerifyRequestSchema body = new TwoFactorVerifyRequestSchema.Builder()
88-
.to(USER_NUMBER)
95+
.to("+1000" + wheelOfPhoneNumbers.nextInt(10000000))
8996
.applicationId(VOICE_APPLICATION_ID)
9097
.scope("scope")
9198
.code("1234567")
9299
.expirationTimeInMinutes(3)
93100
.build();
94101

95-
controller.createVerifyTwoFactor(ACCOUNT_ID, body);
102+
TwoFactorVerifyCodeResponse response = controller.createVerifyTwoFactor(ACCOUNT_ID, body).getResult();
103+
assertFalse("Code should be invalid", response.getValid());
96104
}
97105

98106
@Test(expected = ErrorWithRequestException.class)

src/test/java/com/bandwidth/TnLookupApiTests.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import com.bandwidth.phonenumberlookup.models.OrderRequest;
66
import com.bandwidth.phonenumberlookup.models.OrderResponse;
77

8+
import com.bandwidth.phonenumberlookup.models.OrderStatus;
89
import org.junit.*;
10+
import static org.junit.Assert.*;
911

1012
import java.util.Collections;
1113

@@ -31,7 +33,24 @@ public void testPhoneNumberLookup() throws Exception {
3133
.build();
3234

3335
OrderResponse orderResponse = controller.createLookupRequest(ACCOUNT_ID, body).getResult();
34-
35-
controller.getLookupRequestStatus(ACCOUNT_ID, orderResponse.getRequestId());
36+
assertNotNull("RequestID is null", orderResponse.getRequestId());
37+
assertFalse("RequestID is empty", orderResponse.getRequestId().isEmpty());
38+
assertTrue(
39+
"Status is not a valid value",
40+
orderResponse.getStatus().equals("COMPLETE") ||
41+
orderResponse.getStatus().equals("PARTIAL_COMPLETE") ||
42+
orderResponse.getStatus().equals("FAILED")
43+
);
44+
45+
OrderStatus statusResponse = controller.getLookupRequestStatus(ACCOUNT_ID, orderResponse.getRequestId()).getResult();
46+
assertNotNull("RequestID is null", statusResponse.getRequestId());
47+
assertFalse("RequestId is empty", statusResponse.getRequestId().isEmpty());
48+
assertTrue(
49+
"Status is not a valid value",
50+
statusResponse.getStatus().equals("COMPLETE") ||
51+
statusResponse.getStatus().equals("PARTIAL_COMPLETE") ||
52+
statusResponse.getStatus().equals("FAILED") ||
53+
statusResponse.getStatus().equals("IN_PROGRESS")
54+
);
3655
}
3756
}

src/test/java/com/bandwidth/WebRtcApiTests.java

Lines changed: 119 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22

33
import 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+
77
import org.junit.*;
88

9+
import java.util.Arrays;
10+
11+
import static org.junit.Assert.*;
12+
913
import static com.bandwidth.TestingEnvironmentVariables.*;
1014

15+
/*
16+
* Integration tests between the SDK and WebRTC API
17+
*/
1118
public 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

Comments
 (0)