Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. package automation;
  2.  
  3. import java.util.Calendar;
  4. import java.util.List;
  5. import java.util.Random;
  6.  
  7. import SMS.SMS;
  8. import SMS.SmsService;
  9.  
  10. public class TestAutomation {
  11.     public static void main(String[] args) {
  12.     }
  13.    
  14.     public void execute(int hoursToWait){
  15.         long millisToWait = hoursToWait * 3600000;
  16.         StringBuilder report = new StringBuilder("Automation Test report\n");
  17.         Calendar now = Calendar.getInstance();
  18.         while(true){
  19.             try {
  20.                 SmsService service =  SmsService.builder();
  21.                 int numberToCal = randomServiceNumber();
  22.                 String searchText = randomSearchText();
  23.                 SMS sms = new SMS(numberToCal, searchText);
  24.                 service.sendSMS(sms);
  25.                 SMS response = null;
  26.                 int secondsWaintingAnswer = 0;
  27.                 while(secondsWaintingAnswer == 120){
  28.                     List<SMS> receivedSms = service.getAllSMS();
  29.                     if(receivedSms != null && receivedSms.size() > 0){
  30.                         response = receivedSms.get(0);
  31.                         break;
  32.                     }
  33.                     Thread.sleep(1000);
  34.                     secondsWaintingAnswer++;
  35.                 }
  36.                 if(secondsWaintingAnswer == 120 ){
  37.                     service.SMSNotification(sms);
  38.                 }
  39.                
  40.                 Thread.sleep(millisToWait);
  41.             } catch (InterruptedException e) {
  42.                 e.printStackTrace();
  43.             }
  44.         }
  45.     }
  46.  
  47.     private String randomSearchText() {
  48.         Random random = new Random();
  49.         int rand = random.nextInt(2);
  50.         switch(rand){
  51.         case 0:
  52.             return "automation";
  53.         case 1:
  54.             return "atomicbomb";
  55.         default:
  56.             return null;
  57.         }
  58.     }
  59.  
  60.     private int randomServiceNumber() {
  61.         Random random = new Random();
  62.         int rand = random.nextInt(3);
  63.         switch (rand) {
  64.         case 0:
  65.             return 22225;
  66.         case 1:
  67.             return 55554;
  68.         case 2:
  69.             return 66664;
  70.         default:
  71.             return 0;
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement