Skip to content

Commit

Permalink
chore: added cluster test
Browse files Browse the repository at this point in the history
  • Loading branch information
sbansla committed Sep 27, 2024
1 parent 0850ea7 commit cba6839
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/test/java/com/twilio/ClusterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.twilio.base.Page;
import com.twilio.base.bearertoken.ResourceSet;
import com.twilio.credential.ClientCredentialProvider;
import com.twilio.http.CustomHttpClient;
import com.twilio.http.TwilioRestClient;
import com.twilio.rest.api.v2010.account.IncomingPhoneNumber;
Expand Down Expand Up @@ -30,11 +31,15 @@ public class ClusterTest {
String fromNumber;
String toNumber;
String grantType;
String orgsClientId;
String orgsClientSecret;
String organisationSid;
String clientId;
String clientSecret;
String organisationSid;

String messageSid;
TwilioRestClient customRestClient;

String accountSid;

@Before
public void setUp() {
Expand All @@ -44,14 +49,18 @@ public void setUp() {
toNumber = System.getenv("TWILIO_TO_NUMBER");
String apiKey = System.getenv("TWILIO_API_KEY");
String secret = System.getenv("TWILIO_API_SECRET");
String accountSid = System.getenv("TWILIO_ACCOUNT_SID");
accountSid = System.getenv("TWILIO_ACCOUNT_SID");
Twilio.init(apiKey, secret, accountSid);

grantType = "client_credentials";
clientId = System.getenv("TWILIO_ORGS_CLIENT_ID");
clientSecret = System.getenv("TWILIO_ORGS_CLIENT_SECRET");
orgsClientId = System.getenv("TWILIO_ORGS_CLIENT_ID");
orgsClientSecret = System.getenv("TWILIO_ORGS_CLIENT_SECRET");
organisationSid = System.getenv("TWILIO_ORG_SID");
TwilioOrgsTokenAuth.init(grantType, clientId, clientSecret);
TwilioOrgsTokenAuth.init(grantType, orgsClientId, orgsClientSecret);

clientId = System.getenv("TWILIO_CLIENT_ID");
clientSecret = System.getenv("TWILIO_CLIENT_SECRET");
messageSid = System.getenv("TWILIO_MESSAGE_SID");

// CustomHttpClient
customRestClient = new TwilioRestClient.Builder(apiKey, secret).accountSid(accountSid).httpClient(new CustomHttpClient()).build();
Expand Down Expand Up @@ -161,4 +170,16 @@ public void testMultiPartFormData() {
assertEquals(toNumber, message.getTo().toString());
}

// Note: This test should be last as we are initialising OAuth App creds.
@Test
public void testPublicOAuthFetchMessage() {
Twilio.init(new ClientCredentialProvider(clientId, clientSecret), accountSid);
// Fetching an existing message; if this test fails, the SID might be deleted,
// in that case, change TWILIO_MESSAGE_SID in twilio-java repo env variables
Message message = Message.fetcher(messageSid).fetch();
assertNotNull(message);
assertTrue(message.getBody().contains("Where's Wallace?"));
assertEquals(fromNumber, message.getFrom().toString());
assertEquals(toNumber, message.getTo().toString());
}
}

0 comments on commit cba6839

Please sign in to comment.