Skip to content

Commit 071458d

Browse files
committed
api unit tests
1 parent b37c121 commit 071458d

File tree

1 file changed

+226
-0
lines changed

1 file changed

+226
-0
lines changed
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
/*
2+
* Bandwidth
3+
* Bandwidth's Communication APIs
4+
*
5+
* The version of the OpenAPI document: 1.0.0
6+
* Contact: [email protected]
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
13+
package com.bandwidth.sdk.unit.api;
14+
15+
import org.junit.jupiter.api.BeforeAll;
16+
import org.junit.jupiter.api.Disabled;
17+
import org.junit.jupiter.api.Test;
18+
19+
import com.bandwidth.sdk.ApiClient;
20+
import com.bandwidth.sdk.ApiException;
21+
import com.bandwidth.sdk.ApiResponse;
22+
import com.bandwidth.sdk.Configuration;
23+
import com.bandwidth.sdk.api.TollFreeVerificationApi;
24+
import com.bandwidth.sdk.auth.HttpBasicAuth;
25+
import com.bandwidth.sdk.model.Address;
26+
import com.bandwidth.sdk.model.Contact;
27+
import com.bandwidth.sdk.model.LinksObject;
28+
import com.bandwidth.sdk.model.OptInWorkflow;
29+
import com.bandwidth.sdk.model.TelephoneNumber;
30+
import com.bandwidth.sdk.model.TfvBasicAuthentication;
31+
import com.bandwidth.sdk.model.TfvStatus;
32+
import com.bandwidth.sdk.model.TfvStatusEnum;
33+
import com.bandwidth.sdk.model.TfvSubmissionWrapper;
34+
import com.bandwidth.sdk.model.VerificationRequest;
35+
import com.bandwidth.sdk.model.WebhookSubscription;
36+
import com.bandwidth.sdk.model.WebhookSubscriptionBasicAuthentication;
37+
import com.bandwidth.sdk.model.WebhookSubscriptionRequestSchema;
38+
import com.bandwidth.sdk.model.WebhookSubscriptionTypeEnum;
39+
import com.bandwidth.sdk.model.WebhookSubscriptionsListBody;
40+
41+
import static com.bandwidth.sdk.utils.TestingEnvironmentVariables.*;
42+
import static org.hamcrest.MatcherAssert.assertThat;
43+
44+
import java.time.OffsetDateTime;
45+
import java.util.List;
46+
import java.util.UUID;
47+
48+
import static org.hamcrest.CoreMatchers.instanceOf;
49+
import static org.hamcrest.CoreMatchers.is;
50+
51+
@SuppressWarnings("null")
52+
public class TollFreeVerificationApiTest {
53+
private static ApiClient defaultClient = Configuration.getDefaultApiClient();
54+
private static HttpBasicAuth Basic = (HttpBasicAuth) defaultClient.getAuthentication("Basic");
55+
private static TollFreeVerificationApi api = new TollFreeVerificationApi(defaultClient);
56+
57+
private static WebhookSubscriptionRequestSchema webhookSubscriptionRequestSchema = new WebhookSubscriptionRequestSchema()
58+
.basicAuthentication(new TfvBasicAuthentication()
59+
.username("username")
60+
.password("password"))
61+
.callbackUrl("https://example.com")
62+
.sharedSecretKey("shared-secret-key");
63+
64+
@BeforeAll
65+
public static void setUp() {
66+
Basic.setUsername(BW_USERNAME);
67+
Basic.setPassword(BW_PASSWORD);
68+
api.setCustomBaseUrl("http://127.0.0.1:4010");
69+
}
70+
71+
@Test
72+
public void createWebhookSubscriptionTest() throws ApiException {
73+
ApiResponse<WebhookSubscription> response = api.createWebhookSubscriptionWithHttpInfo(BW_ACCOUNT_ID,
74+
webhookSubscriptionRequestSchema);
75+
76+
assertThat(response.getStatusCode(), is(201));
77+
assertThat(response.getData(), instanceOf(WebhookSubscription.class));
78+
assertThat(response.getData().getId(), instanceOf(String.class));
79+
assertThat(response.getData().getAccountId(), instanceOf(String.class));
80+
assertThat(response.getData().getCallbackUrl(), instanceOf(String.class));
81+
assertThat(response.getData().getType(), instanceOf(WebhookSubscriptionTypeEnum.class));
82+
assertThat(response.getData().getBasicAuthentication(),
83+
instanceOf(WebhookSubscriptionBasicAuthentication.class));
84+
assertThat(response.getData().getBasicAuthentication().getUsername(), instanceOf(String.class));
85+
assertThat(response.getData().getBasicAuthentication().getPassword(), instanceOf(String.class));
86+
assertThat(response.getData().getCreatedDate(), instanceOf(OffsetDateTime.class));
87+
assertThat(response.getData().getModifiedDate(), instanceOf(OffsetDateTime.class));
88+
}
89+
90+
@Test
91+
public void deleteWebhookSubscriptionTest() throws ApiException {
92+
ApiResponse<Void> response = api.deleteWebhookSubscriptionWithHttpInfo(BW_ACCOUNT_ID, "test-id-1234");
93+
assertThat(response.getStatusCode(), is(204));
94+
}
95+
96+
@Test
97+
public void getTollFreeVerificationStatusTest() throws ApiException {
98+
ApiResponse<TfvStatus> response = api
99+
.getTollFreeVerificationStatusWithHttpInfo(BW_ACCOUNT_ID, "+18005551234");
100+
101+
assertThat(response.getStatusCode(), is(200));
102+
assertThat(response.getData(), instanceOf(TfvStatus.class));
103+
assertThat(response.getData().getPhoneNumber(), instanceOf(String.class));
104+
assertThat(response.getData().getStatus(), instanceOf(TfvStatusEnum.class));
105+
assertThat(response.getData().getInternalTicketNumber(), instanceOf(UUID.class));
106+
assertThat(response.getData().getDeclineReasonDescription(), instanceOf(String.class));
107+
assertThat(response.getData().getResubmitAllowed(), instanceOf(Boolean.class));
108+
assertThat(response.getData().getCreatedDateTime(), instanceOf(OffsetDateTime.class));
109+
assertThat(response.getData().getModifiedDateTime(), instanceOf(OffsetDateTime.class));
110+
}
111+
112+
@Test
113+
public void listTollFreeUseCasesTest() throws ApiException {
114+
ApiResponse<List<String>> response = api.listTollFreeUseCasesWithHttpInfo();
115+
116+
assertThat(response.getStatusCode(), is(200));
117+
assertThat(response.getData(), instanceOf(List.class));
118+
}
119+
120+
@Test
121+
public void listWebhookSubscriptionsTest() throws ApiException {
122+
ApiResponse<WebhookSubscriptionsListBody> response = api.listWebhookSubscriptionsWithHttpInfo(BW_ACCOUNT_ID);
123+
124+
assertThat(response.getStatusCode(), is(200));
125+
assertThat(response.getData(), instanceOf(WebhookSubscriptionsListBody.class));
126+
assertThat(response.getData().getLinks(), instanceOf(LinksObject.class));
127+
assertThat(response.getData().getLinks().getFirst(), instanceOf(String.class));
128+
assertThat(response.getData().getLinks().getNext(), instanceOf(String.class));
129+
assertThat(response.getData().getLinks().getPrevious(), instanceOf(String.class));
130+
assertThat(response.getData().getLinks().getLast(), instanceOf(String.class));
131+
assertThat(response.getData().getErrors(), instanceOf(List.class));
132+
assertThat(response.getData().getErrors().getFirst().getCode(), instanceOf(Integer.class));
133+
assertThat(response.getData().getErrors().getFirst().getDescription(), instanceOf(String.class));
134+
assertThat(response.getData().getErrors().getFirst().getTelephoneNumbers(), instanceOf(List.class));
135+
assertThat(response.getData().getErrors().getFirst().getTelephoneNumbers().getFirst(),
136+
instanceOf(TelephoneNumber.class));
137+
assertThat(response.getData().getErrors().getFirst().getTelephoneNumbers().getFirst().getTelephoneNumber(),
138+
instanceOf(String.class));
139+
assertThat(response.getData().getData(), instanceOf(List.class));
140+
assertThat(response.getData().getData().getFirst(), instanceOf(WebhookSubscription.class));
141+
assertThat(response.getData().getData().getFirst().getId(), instanceOf(String.class));
142+
assertThat(response.getData().getData().getFirst().getAccountId(), instanceOf(String.class));
143+
assertThat(response.getData().getData().getFirst().getCallbackUrl(), instanceOf(String.class));
144+
assertThat(response.getData().getData().getFirst().getType(), instanceOf(WebhookSubscriptionTypeEnum.class));
145+
assertThat(response.getData().getData().getFirst().getBasicAuthentication(),
146+
instanceOf(WebhookSubscriptionBasicAuthentication.class));
147+
assertThat(response.getData().getData().getFirst().getBasicAuthentication().getUsername(),
148+
instanceOf(String.class));
149+
assertThat(response.getData().getData().getFirst().getBasicAuthentication().getPassword(),
150+
instanceOf(String.class));
151+
assertThat(response.getData().getData().getFirst().getCreatedDate(), instanceOf(OffsetDateTime.class));
152+
assertThat(response.getData().getData().getFirst().getModifiedDate(), instanceOf(OffsetDateTime.class));
153+
}
154+
155+
@Test
156+
public void requestTollFreeVerificationTest() throws ApiException {
157+
VerificationRequest verificationRequest = new VerificationRequest()
158+
.businessAddress(new Address()
159+
.name("name")
160+
.addr1("addr1")
161+
.addr2("addr2")
162+
.city("city")
163+
.state("state")
164+
.zip("zip")
165+
.url("https://example.com"))
166+
.businessContact(new Contact()
167+
.firstName("first-name")
168+
.lastName("last-name")
169+
170+
.phoneNumber("+19195551234"))
171+
.messageVolume(12)
172+
.phoneNumbers(List.of("+18005551234"))
173+
.useCase("useCase")
174+
.useCaseSummary("useCaseSummary")
175+
.productionMessageContent("productionMessageContent")
176+
.optInWorkflow(new OptInWorkflow()
177+
.description("description")
178+
.imageUrls(List.of("https://example.com")))
179+
.additionalInformation("additionalInformation")
180+
.isvReseller("isvReseller");
181+
182+
ApiResponse<Void> response = api.requestTollFreeVerificationWithHttpInfo(BW_ACCOUNT_ID, verificationRequest);
183+
184+
assertThat(response.getStatusCode(), is(202));
185+
}
186+
187+
@Test
188+
public void updateTollFreeVerificationRequestTest() throws ApiException {
189+
TfvSubmissionWrapper tfvSubmissionWrapper = new TfvSubmissionWrapper()
190+
.submission(null);
191+
ApiResponse<Void> response = api.updateTollFreeVerificationRequestWithHttpInfo(BW_ACCOUNT_ID, "+18005551234",
192+
tfvSubmissionWrapper);
193+
194+
assertThat(response.getStatusCode(), is(202));
195+
}
196+
197+
@Test
198+
@Disabled /*
199+
* For some reason this returns a 500 due to:
200+
* "Invalid reference token: callbackUrl"
201+
*/
202+
public void updateWebhookSubscriptionTest() throws ApiException {
203+
ApiResponse<WebhookSubscription> response = api.updateWebhookSubscriptionWithHttpInfo(BW_ACCOUNT_ID,
204+
"test-id-1234",
205+
webhookSubscriptionRequestSchema);
206+
207+
assertThat(response.getStatusCode(), is(200));
208+
assertThat(response.getData(), instanceOf(WebhookSubscription.class));
209+
assertThat(response.getData().getId(), instanceOf(String.class));
210+
assertThat(response.getData().getAccountId(), instanceOf(String.class));
211+
assertThat(response.getData().getCallbackUrl(), instanceOf(String.class));
212+
assertThat(response.getData().getType(),
213+
instanceOf(WebhookSubscriptionTypeEnum.class));
214+
assertThat(response.getData().getBasicAuthentication(),
215+
instanceOf(WebhookSubscriptionBasicAuthentication.class));
216+
assertThat(response.getData().getBasicAuthentication().getUsername(),
217+
instanceOf(String.class));
218+
assertThat(response.getData().getBasicAuthentication().getPassword(),
219+
instanceOf(String.class));
220+
assertThat(response.getData().getCreatedDate(),
221+
instanceOf(OffsetDateTime.class));
222+
assertThat(response.getData().getModifiedDate(),
223+
instanceOf(OffsetDateTime.class));
224+
}
225+
226+
}

0 commit comments

Comments
 (0)