Exemplo n.º 1
0
  @Test
  public void testCreateJSONObjectFromJsonObject() throws JSONException {

    resultString =
        "{\"testID\":\"{id=testID;name=testName;isCustomDirectConnect=false;directConnect=false;isCustomGreeting=false;isCustomForwarding=false;greetingId=0;disabledForwardingIds=[]}\"}";

    testGroupObject.put("obj1", testJSONOb1);

    final JSONObject testObject = Group.createJSONObjectFromJsonObject(testGroupObject);

    Assert.assertEquals(resultString, testObject.toString());
  }
Exemplo n.º 2
0
  @Test
  public void testCreateArrayFromJsonObject() throws JSONException {

    testGroupObject.put(TEST_ID, testJSONOb1);

    final Group[] resultGroupArray = {testGroup};
    final Group[] testGroupArray = Group.createArrayFromJsonObject(testGroupObject);

    Assert.assertEquals(resultGroupArray[0].toString(), testGroupArray[0].toString());
  }
Exemplo n.º 3
0
  @Test
  public void testIsPhoneDisabledFalseNullList() throws JSONException {

    final JSONObject testJSONOb4 = new JSONObject();
    testJSONOb4.put("id", TEST_ID);
    testJSONOb4.put("name", "testName");
    testJSONOb4.put("isCustomForwarding", false);
    testJSONOb4.put("isCustomGreeting", false);
    testJSONOb4.put("isCustomDirectConnect", false);
    testJSONOb4.put("directConnect", false);
    testJSONOb4.put("greetingId", 0);

    final Group testGroup4 = new Group(testJSONOb4);

    final boolean testNullList = testGroup4.isPhoneDisabled(1);

    Assert.assertEquals(false, testNullList);
  }
Exemplo n.º 4
0
  @Before
  public void setUp() throws Exception {

    // Populate DFID List1
    testList1.add(testDFId1);
    testList1.add(testDFId);

    // JSON Array to attempt to mirror populated list.
    testJSArray1.put(3);
    testJSArray1.put(2);

    // New JSON objects to mirror lists above.
    final JSONObject disabledFIDs1 = testJSArray1.toJSONObject(testJSArray1);

    // Construct Object 1
    testJSONOb1.put("id", TEST_ID);
    testJSONOb1.put("name", "testName");
    testJSONOb1.put("isCustomForwarding", false);
    testJSONOb1.put("isCustomGreeting", false);
    testJSONOb1.put("isCustomDirectConnect", false);
    testJSONOb1.put("directConnect", false);
    testJSONOb1.put("greetingId", 0);
    testJSONOb1.put("disabledForwardingIds", disabledFIDs);

    // Construct Object 3
    testJSONOb3.put("id", "testID1");
    testJSONOb3.put("name", "testName1");
    testJSONOb3.put("isCustomForwarding", false);
    testJSONOb3.put("isCustomGreeting", false);
    testJSONOb3.put("isCustomDirectConnect", false);
    testJSONOb3.put("directConnect", false);
    testJSONOb3.put("greetingId", 0);
    testJSONOb3.put("disabledForwardingIds", disabledFIDs1);

    // Instantiate testGroups
    testGroup = new Group(TEST_ID, "testName", false, testList, false, false, false, 0);
    testGroup1 = new Group(testJSONOb1);
    testGroup2 = new Group("testID1", "testName1", false, testList1, false, false, false, 0);
    testGroup3 = new Group(testJSONOb3);
  }
Exemplo n.º 5
0
  /**
   * @param userName
   * @param pass
   * @param testNr
   */
  private static void runTest(String userName, String pass, int testNr) {
    if (testNr == 0) { // 0: Exit						
      System.out.println("Exiting.");
      System.exit(1);
    }
    try {

      // Voice voice = new Voice();
      //			try {
      if (connectOnStartup) System.out.println(voice.isLoggedIn());
      // Thread.sleep(2000);

      switch (testNr) {
        case 1: // 1: Multi phone enable / disable
          System.out.println("******** Starting Test " + testNr + " ********");
          Phone[] phones = voice.getSettings(false).getPhones();
          // create int Array from all phone ids
          int[] phonesToChangeStatus = new int[phones.length];

          System.out.println("Current phone status:");
          for (int j = 0; j < phones.length; j++) {
            phonesToChangeStatus[j] = phones[j].getId();
            System.out.println(
                phones[j].getName()
                    + " "
                    + phones[j].getId()
                    + " "
                    + !voice.getSettings(false).isPhoneDisabled(phones[j].getId()));
          }

          // Disable all phones
          for (int j = 0; j < phones.length; j++) {
            voice.phoneDisable(phones[j].getId());
          }

          phones = voice.getSettings(true).getPhones();
          // Output
          System.out.println("After deactivate multi:");
          for (int j = 0; j < phones.length; j++) {
            System.out.println(
                phones[j].getName()
                    + " "
                    + phones[j].getId()
                    + " "
                    + !voice.getSettings(false).isPhoneDisabled(phones[j].getId()));
          }

          // Enable all phones
          for (int j = 0; j < phones.length; j++) {
            voice.phoneEnable(phones[j].getId());
          }

          // Output
          phones = voice.getSettings(true).getPhones();
          System.out.println("After activate multi:");
          for (int j = 0; j < phones.length; j++) {
            System.out.println(
                phones[j].getName()
                    + " "
                    + phones[j].getId()
                    + " "
                    + !voice.getSettings(false).isPhoneDisabled(phones[j].getId()));
          }

          System.out.println("******** Finished Test " + testNr + " ********");
          break;

        case 2: // 2: Inbox paging
          System.out.println("******** Starting Test " + testNr + " ********");
          //							Thread.sleep(2000);
          System.out.println(voice.getInboxPage(1000));
          System.out.println("******** Finished Test " + testNr + " ********");
          break;

        case 3: // 3: Call Announcement settings (Presentation)
          System.out.println("******** Starting Test " + testNr + " ********");
          System.out.println("Type 'true' for enable, 'false' for disable");
          boolean choice = false;
          try {
            choice = Boolean.parseBoolean(br.readLine());
          } catch (Exception e) {
            System.out.println("Error trying to read the choice!" + e.getMessage());
            System.exit(1);
          }
          //							Thread.sleep(2000);
          System.out.println(voice.setCallPresentation(choice));
          System.out.println("******** Finished Test " + testNr + " ********");
          break;

        case 4: // 4: Caller ID in
          System.out.println("******** Starting Test " + testNr + " ********");
          for (Iterator<Greeting> iterator = voice.getVoicemailList(true).iterator();
              iterator.hasNext(); ) {
            Greeting type = (Greeting) iterator.next();
            System.out.println(type.toString());
          }
          System.out.println(
              "Choose the id of the voicemail greeting to use. ie '0' system standard or '1','2'");
          String voicemailNr = "0";
          try {
            voicemailNr = br.readLine();
          } catch (Exception e) {
            System.out.println("Error trying to read the choice!" + e.getMessage());
            System.exit(1);
          }
          //							Thread.sleep(2000);
          voice.setVoicemailGreetingId(voicemailNr);
          System.out.println("******** Finished Test " + testNr + " ********");
          break;

        case 5: // 5: Do not disturb
          System.out.println("******** Starting Test " + testNr + " ********");
          System.out.println("Type 'true' for enable, 'false' for disable");
          boolean dndChoice = false;
          try {
            dndChoice = Boolean.parseBoolean(br.readLine());
          } catch (Exception e) {
            System.out.println("Error trying to read the choice!" + e.getMessage());
            System.exit(1);
          }
          voice.setDoNotDisturb(dndChoice);
          System.out.println("******** Finished Test " + testNr + " ********");
          break;

        case 6: // 6: Group settings
          System.out.println("******** Starting Test " + testNr + " ********");
          Group[] groups1 = voice.getSettings(false).getSettings().getGroups();
          String jsonGroups = "";
          for (int i = 0; i < groups1.length; i++) {
            jsonGroups += groups1[i].toJson();
          }
          System.out.println("All to json:" + jsonGroups);
          System.out.println("******** Finished Test " + testNr + " ********");
          break;

        case 7: // 7: Read all settings - cached
          System.out.println("******** Starting Test " + testNr + " ********");
          System.out.println(voice.getSettings(false).getSettings().toJson());
          System.out.println("******** Finished Test " + testNr + " ********");
          break;

        case 8: // 8: Read all settings - uncached
          System.out.println("******** Starting Test " + testNr + " ********");
          System.out.println(voice.getSettings(true).getSettings().toJson());
          System.out.println("******** Finished Test " + testNr + " ********");
          break;

        case 9: // 9: Read all settings - pure json driven
          System.out.println("******** Starting Test " + testNr + " ********");
          try {
            System.out.println("******** Original JSON Data ********");
            JSONObject origSettings = new JSONObject(jsonData);
            System.out.println(origSettings.toString(4));

            System.out.println("******* Parsed back and forth ******");
            AllSettings settings2 = new AllSettings(jsonData);
            System.out.println(settings2.toJsonObject().toString(4));

            System.out.println("******* Creating new AllSettings from old JSON ******");
            AllSettings settings4 = new AllSettings(settings2.toJsonObject().toString());
            System.out.println(settings4.toJsonObject().toString(4));
          } catch (JSONException e) {
            System.out.println("Error displaying json:" + e.getLocalizedMessage());
            e.printStackTrace();
          }
          System.out.println("******** Finished Test " + testNr + " ********");
          break;

        case 10: // 10: Read all settings - pure json driven - account data
          System.out.println("******** Starting Test " + testNr + " ********");
          try {
            System.out.println("******** Original JSON Data ********");
            String lJson =
                ParsingUtil.removeUninterestingParts(
                    voice.getONLYFORTEST("https://www.google.com/voice/settings/tab/groups"),
                    "<json><![CDATA[",
                    "]]></json>",
                    false);
            JSONObject origSettings = new JSONObject(lJson);
            System.out.println(origSettings.toString(4));

            System.out.println("******* JsonObject from AllSettings ******");
            AllSettings settings2 = new AllSettings(lJson);
            JSONObject objFromAllSettings = settings2.toJsonObject();
            System.out.println(objFromAllSettings.toString(4));

            System.out.println("******* Creating new AllSettings from old JSON ******");
            AllSettings settings3 = new AllSettings(objFromAllSettings.toString());
            System.out.println(settings3.toJsonObject().toString(4));

          } catch (JSONException e) {
            System.out.println("Error displaying json:" + e.getLocalizedMessage());
            e.printStackTrace();
          }
          System.out.println("******** Finished Test " + testNr + " ********");
          break;

        case 11: // 11: Update Group settings
          System.out.println("******** Starting Test " + testNr + " ********");
          try {
            System.out.println("******** Before ********");

            AllSettings settings2 = voice.getSettings(false);
            JSONObject objFromAllSettings = settings2.toJsonObject();
            System.out.println(objFromAllSettings.toString(4));

            System.out.println("Choose group to change settings (15)");
            String groupId = "0";
            try {
              groupId = br.readLine();
            } catch (Exception e) {
              System.out.println("Error trying to read the choice!" + e.getMessage());
              System.exit(1);
            }

            Group[] groups = voice.getSettings(false).getSettings().getGroups();
            for (int j = 0; j < groups.length; j++) {
              /* New Settings
              "directConnect": true,
                          "disabledForwardingIds": {"1": true},
                          "greetingId": 2,
                          "id": "15",
                          "isCustomDirectConnect": true,
                          "isCustomForwarding": true,
                          "isCustomGreeting": true,
               */
              if (groups[j].getId().equals(groupId)) {
                System.out.println("Changing settings for Group: " + groups[j].getName());
                groups[j].setCustomDirectConnect(true);
                groups[j].setDirectConnect(true);
                groups[j].setCustomForwarding(true);
                List<DisabledForwardingId> disList = new ArrayList<DisabledForwardingId>();
                disList.add(new DisabledForwardingId("1", true));
                groups[j].setDisabledForwardingIds(disList);
                groups[j].setCustomGreeting(true);
                groups[j].setGreetingId(2);
                voice.setNewGroupSettings(groups[j]);
              }
            }

            System.out.println("******** After  ********");
            AllSettings settings3 = voice.getSettings(true);
            System.out.println(settings3.toJsonObject().toString(4));

          } catch (JSONException e) {
            System.out.println("Error displaying json:" + e.getLocalizedMessage());
            e.printStackTrace();
          }
          System.out.println("******** Finished Test " + testNr + " ********");
          break;

        case 12: // 12: Group isPhoneEnabled Tests
          System.out.println("******** Starting Test " + testNr + " ********");
          try {
            AllSettings settings3 = voice.getSettings(true);
            Group[] groups = settings3.getSettings().getGroups();
            int[] phoneIds = settings3.getPhoneList();
            for (int j = 0; j < groups.length; j++) {
              System.out.println("+++ Disabled Phones in " + groups[j].getName() + " +++");
              for (int j2 = 0; j2 < phoneIds.length; j2++) {
                System.out.println(phoneIds[j2] + ":" + groups[j].isPhoneDisabled(phoneIds[j2]));
              }
            }
          } catch (JSONException e) {
            System.out.println("Error displaying json:" + e.getLocalizedMessage());
            e.printStackTrace();
          }
          System.out.println("******** Finished Test " + testNr + " ********");
          break;

        case 13: // 13: List Default Phones and Enabled/Disabled Setting
          System.out.println("*********Starting Test " + testNr + " *******");

          AllSettings settings3 = voice.getSettings(true);
          List<Integer> phoneList = settings3.getPhoneListAsList();
          Phone[] actualPhoneArray = settings3.getPhones();
          for (Integer phoneint : phoneList) {
            inner:
            for (int ig = 0; ig < actualPhoneArray.length; ig++) {
              if (actualPhoneArray[ig].getId() == phoneint) {
                System.out.println(
                    actualPhoneArray[ig].getId()
                        + " "
                        + actualPhoneArray[ig].getName()
                        + " enabled:"
                        + !settings3.isPhoneDisabled(actualPhoneArray[ig].getId()));
                break inner;
              }
            }
          }

          //							Group[] groupAr = settings3.getSettings().getGroups()
          //							for(String group:groupAr){
          //								settings3.getSettings()
          //							}
          //
          //
          //							settings3.getSettings().getGroups()[0].
          //							}
          break;

        case 14:
          System.out.println("*********Starting Test " + testNr + " SEND SMS*******");
          System.out.println("\n\rEnter Number to Send SMS:");
          String number = br.readLine();
          System.out.println("Enter Message:");
          String txt = br.readLine();
          voice.sendSMS(number, txt);
          break;
        case 15: // 15: Captcha Test
          System.out.println("*********Starting Test " + testNr + " *******");
          System.out.println("Enter Fake Password:"******"\n\rAttempting new Login... " + counter++);
            try {
              voice = null;
              /* (Toby) added here the counter to the tempPass, so that we actually get the CaptchaEx - bc without
               * it I had 300 tries only getting the IO Error, with counter (each time a different password)
               * I got the captcha after 30 tries
               */
              voice =
                  new Voice(
                      userName, tempPass + counter, "GoogleVoiceJavaUnitTests", true, Voice.GOOGLE);
            } catch (CaptchaRequiredException e) {
              System.out.println("Captcha found! - " + e.getLocalizedMessage());
              System.out.println("Token: " + e.getCaptchaToken());
              System.out.println("URL  : " + e.getCaptchaUrl());
              System.out.println("Please enter the captcha challenge response from the URL:");
              String response = br.readLine();
              // create the voice object with the response
              voice =
                  new Voice(
                      userName,
                      pass,
                      "GoogleVoiceJavaUnitTests",
                      true,
                      Voice.GOOGLE,
                      response,
                      e.getCaptchaToken());
              tryAgain = false;
            } catch (IOException e) {
              System.out.println("IO error creating voice! - " + e.getLocalizedMessage());

              // System.out.println("Try Again? (Y/N):");
              // tryAgain = br.readLine().equalsIgnoreCase("Y");
              // System.out.println();
            }
          }

          //							voice = null;
          //							voice = new Voice(userName,
          // tempPass,"GoogleVoiceJavaUnitTests",true,Voice.GOOGLE);

          System.out.println("");
          break;

        case 16:
          System.out.println("*********Starting Test " + testNr + " LIST SMS *******");
          String smsString = voice.getSMS();
          // remove whitespaces
          // StringTokenizer st = new StringTokenizer(smsString," ",false);
          // String t="";
          // while (st.hasMoreElements()) t += st.nextElement();
          // remove newLine
          StringTokenizer st2 = new StringTokenizer(smsString, "\n", false);
          String t2 = "";
          while (st2.hasMoreElements()) t2 += st2.nextElement();
          System.out.println(t2);
          break;

        default:
          System.out.println("Test " + testNr + " not found, exiting.");
          System.exit(1);
          break;
      }

      //				Thread.sleep(2000);

      // System.out.println(voice.getSMS());
      // System.out.println(voice.getInbox());
      //				System.out.println(voice.getInboxPage(1000));
      // System.out.println(voice.getInboxPage(100));
      /*
      System.out.println(voice.getInbox());
      Thread.sleep(2000);
      System.out.println(voice.phoneDisable(6));


      System.out.println(voice.getInbox());
      Thread.sleep(2000);
      System.out.println("**********************************");
      System.out.println(voice.getMissed());
      Thread.sleep(2000);
      System.out.println("**********************************");
      System.out.println(voice.getPlaced());
      Thread.sleep(2000);
      System.out.println("**********************************");
      System.out.println(voice.getReceived());
      Thread.sleep(2000);
      System.out.println("**********************************");

      System.out.println("**********************************");
      System.out.println(voice.getRecorded());
      Thread.sleep(2000);
      System.out.println("**********************************");
      System.out.println(voice.getSMS());
      Thread.sleep(2000);
      System.out.println("**********************************");
      System.out.println(voice.getSpam());
      Thread.sleep(2000);
      System.out.println("**********************************");
      System.out.println(voice.getStarred());
      Thread.sleep(2000);
      System.out.println("**********************************");
      */

      //			} catch (InterruptedException e) {
      //				e.printStackTrace();
      //			}
    } catch (IOException e) {
      e.printStackTrace();
    } catch (JSONException e) {
      e.printStackTrace();
    }
    listTests(); // List the Tests again
  }