Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package automation;
- import java.util.Calendar;
- import java.util.List;
- import java.util.Random;
- import SMS.SMS;
- import SMS.SmsService;
- public class TestAutomation {
- public static void main(String[] args) {
- }
- public void execute(int hoursToWait){
- long millisToWait = hoursToWait * 3600000;
- StringBuilder report = new StringBuilder("Automation Test report\n");
- Calendar now = Calendar.getInstance();
- while(true){
- try {
- SmsService service = SmsService.builder();
- int numberToCal = randomServiceNumber();
- String searchText = randomSearchText();
- SMS sms = new SMS(numberToCal, searchText);
- service.sendSMS(sms);
- SMS response = null;
- int secondsWaintingAnswer = 0;
- while(secondsWaintingAnswer == 120){
- List<SMS> receivedSms = service.getAllSMS();
- if(receivedSms != null && receivedSms.size() > 0){
- response = receivedSms.get(0);
- break;
- }
- Thread.sleep(1000);
- secondsWaintingAnswer++;
- }
- if(secondsWaintingAnswer == 120 ){
- service.SMSNotification(sms);
- }
- Thread.sleep(millisToWait);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- private String randomSearchText() {
- Random random = new Random();
- int rand = random.nextInt(2);
- switch(rand){
- case 0:
- return "automation";
- case 1:
- return "atomicbomb";
- default:
- return null;
- }
- }
- private int randomServiceNumber() {
- Random random = new Random();
- int rand = random.nextInt(3);
- switch (rand) {
- case 0:
- return 22225;
- case 1:
- return 55554;
- case 2:
- return 66664;
- default:
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement