Example #1
0
 public static String[] test(String[] args) {
   try {
     foo(10, 100L, false);
   } catch (TestException ex) {
     String msg = ex.getMessage();
     if (msg == "Hej") {
       return null;
     }
   }
   return args;
 }
  /**
   * Verify the contents of the region, taking into account the keys that were destroyed,
   * invalidated, etc (as specified in keyIntervals) Throw an error of any problems are detected.
   * This must be called repeatedly by the same thread until StopSchedulingTaskOnClientOrder is
   * thrown.
   */
  public void verifyRegionContents() {
    final long LOG_INTERVAL_MILLIS = 10000;
    // we already completed this check once; we can't do it again without reinitializing the
    // verify state variables
    if (verifyRegionContentsCompleted) {
      throw new TestException(
          "Test configuration problem; already verified region contents, "
              + "cannot call this task again without resetting batch variables");
    }

    // iterate keys
    long lastLogTime = System.currentTimeMillis();
    long minTaskGranularitySec = TestConfig.tab().longAt(TestHelperPrms.minTaskGranularitySec);
    long minTaskGranularityMS = minTaskGranularitySec * TestHelper.SEC_MILLI_FACTOR;
    long startTime = System.currentTimeMillis();
    long size = aRegion.size();
    boolean first = true;
    int numKeysToCheck = keyIntervals.getNumKeys() + numNewKeys;
    while (verifyRegionContentsIndex < numKeysToCheck) {
      verifyRegionContentsIndex++;
      if (first) {
        Log.getLogWriter()
            .info(
                "In verifyRegionContents, region has "
                    + size
                    + " keys; starting verify at verifyRegionContentsIndex "
                    + verifyRegionContentsIndex
                    + "; verifying key names with indexes through (and including) "
                    + numKeysToCheck);
        first = false;
      }

      // check region size the first time through the loop to avoid it being called
      // multiple times when this is batched
      if (verifyRegionContentsIndex == 1) {
        if (totalNumKeys != size) {
          String tmpStr = "Expected region size to be " + totalNumKeys + ", but it is size " + size;
          Log.getLogWriter().info(tmpStr);
          verifyRegionContentsErrStr.append(tmpStr + "\n");
        }
      }

      Object key = NameFactory.getObjectNameForCounter(verifyRegionContentsIndex);
      try {
        if (((verifyRegionContentsIndex >= keyIntervals.getFirstKey(KeyIntervals.NONE))
                && (verifyRegionContentsIndex <= keyIntervals.getLastKey(KeyIntervals.NONE)))
            || ((verifyRegionContentsIndex >= keyIntervals.getFirstKey(KeyIntervals.GET))
                && (verifyRegionContentsIndex <= keyIntervals.getLastKey(KeyIntervals.GET)))) {
          // this key was untouched after its creation
          checkContainsKey(key, true, "key was untouched");
          checkContainsValueForKey(key, true, "key was untouched");
          Object value = aRegion.get(key);
          checkValue(key, value);
        } else if ((verifyRegionContentsIndex >= keyIntervals.getFirstKey(KeyIntervals.INVALIDATE))
            && (verifyRegionContentsIndex <= keyIntervals.getLastKey(KeyIntervals.INVALIDATE))) {
          checkContainsKey(key, true, "key was invalidated");
          checkContainsValueForKey(key, false, "key was invalidated");
        } else if ((verifyRegionContentsIndex
                >= keyIntervals.getFirstKey(KeyIntervals.LOCAL_INVALIDATE))
            && (verifyRegionContentsIndex
                <= keyIntervals.getLastKey(KeyIntervals.LOCAL_INVALIDATE))) {
          // this key was locally invalidated
          checkContainsKey(key, true, "key was locally invalidated");
          checkContainsValueForKey(key, true, "key was locally invalidated");
          Object value = aRegion.get(key);
          checkValue(key, value);
        } else if ((verifyRegionContentsIndex >= keyIntervals.getFirstKey(KeyIntervals.DESTROY))
            && (verifyRegionContentsIndex <= keyIntervals.getLastKey(KeyIntervals.DESTROY))) {
          // this key was destroyed
          checkContainsKey(key, false, "key was destroyed");
          checkContainsValueForKey(key, false, "key was destroyed");
        } else if ((verifyRegionContentsIndex
                >= keyIntervals.getFirstKey(KeyIntervals.LOCAL_DESTROY))
            && (verifyRegionContentsIndex <= keyIntervals.getLastKey(KeyIntervals.LOCAL_DESTROY))) {
          // this key was locally destroyed
          checkContainsKey(key, true, "key was locally destroyed");
          checkContainsValueForKey(key, true, "key was locally destroyed");
          Object value = aRegion.get(key);
          checkValue(key, value);
        } else if ((verifyRegionContentsIndex
                >= keyIntervals.getFirstKey(KeyIntervals.UPDATE_EXISTING_KEY))
            && (verifyRegionContentsIndex
                <= keyIntervals.getLastKey(KeyIntervals.UPDATE_EXISTING_KEY))) {
          // this key was updated
          checkContainsKey(key, true, "key was updated");
          checkContainsValueForKey(key, true, "key was updated");
          Object value = aRegion.get(key);
          checkUpdatedValue(key, value);
        } else if (verifyRegionContentsIndex > keyIntervals.getNumKeys()) {
          // key was newly added
          checkContainsKey(key, true, "key was new");
          checkContainsValueForKey(key, true, "key was new");
          Object value = aRegion.get(key);
          checkValue(key, value);
        }
      } catch (TestException e) {
        Log.getLogWriter().info(TestHelper.getStackTrace(e));
        verifyRegionContentsErrStr.append(e.getMessage() + "\n");
      }

      if (System.currentTimeMillis() - lastLogTime > LOG_INTERVAL_MILLIS) {
        Log.getLogWriter()
            .info("Verified key " + verifyRegionContentsIndex + " out of " + totalNumKeys);
        lastLogTime = System.currentTimeMillis();
      }

      if (System.currentTimeMillis() - startTime >= minTaskGranularityMS) {
        Log.getLogWriter()
            .info(
                "In HydraTask_verifyRegionContents, returning before completing verify "
                    + "because of task granularity (this task must be batched to complete); last key verified is "
                    + key);
        return; // task is batched; we are done with this batch
      }
    }
    verifyRegionContentsCompleted = true;
    if (verifyRegionContentsErrStr.length() > 0) {
      throw new TestException(verifyRegionContentsErrStr.toString());
    }
    String aStr =
        "In HydraTask_verifyRegionContents, verified " + verifyRegionContentsIndex + " keys/values";
    Log.getLogWriter().info(aStr);
    throw new StopSchedulingTaskOnClientOrder(aStr);
  }
  public void testLoginValidation() throws TestException {

    try {
      Log.i(TAG, "------It is testLoginValidation()-----------");

      activityName = soloLoginValid.getCurrentActivity().getClass().getSimpleName();

      if (activityName.equalsIgnoreCase("MainActivity")) {
        Log.i(TAG, "------It is MainActivity-----------" + activityName);
        soloLoginValid.waitForActivity("HomeActivity", 2000);

        for (int i = 0; i < 40; i++) {
          activityName = soloLoginValid.getCurrentActivity().getClass().getSimpleName();
          if (activityName.equalsIgnoreCase("HomeActivity")) {

            Log.i(TAG, "------for()-- loop-----");
            break;
          }

          soloLoginValid.waitForActivity("HomeActivity", 2000);
        }

      } else {
        Log.i(TAG, "------ testLoginValidation failed-----------");
        throw new TestException(
            "Current Activity Failed----"
                + soloLoginValid.getCurrentActivity().getClass().getSimpleName()
                + "failed");
      }

      if (activityName.equalsIgnoreCase("HomeActivity")) {
        Log.i(TAG, "------HomeActivity-----------");
        System.out.println(" Activity name ---->" + soloLoginValid.getCurrentActivity());
        ArrayList<View> al = soloLoginValid.getViews();
        Iterator<View> it = al.iterator();
        while (it.hasNext()) {
          String viewName = it.next().getClass().getSimpleName();
          if (viewName.equalsIgnoreCase("ImageView")) {
            Log.i(TAG, "------ImageView found-----------");
            break;
          }
          continue;
        }

      } else {
        Log.i(TAG, "------HomeActivity not  found-----------");
        throw new TestException(
            TAG + soloLoginValid.getCurrentActivity().getClass().getSimpleName() + "failed");
      }
      // click on Loginbutton
      soloLoginValid.waitForActivity("MainActivity", 5000);
      // get the login button view with id i.e home_login_btn
      ImageView loginButton = (ImageView) soloLoginValid.getView(R.id.home_login_btn);
      // click on login button with view id
      soloLoginValid.clickOnView(loginButton);
      // control waits for 2 seconds to activate the screen
      soloLoginValid.waitForActivity("SplashActivity", 2000);
      // clears the text at first Editfield
      EditText emailField = (EditText) soloLoginValid.getView(R.id.txt_email);
      soloLoginValid.clearEditText(emailField);
      // it will type the text at first field which i gave in method
      soloLoginValid.enterText(emailField, "android@");
      // clear the text at second Editfield
      EditText passwordField = (EditText) soloLoginValid.getView(R.id.txt_password);
      soloLoginValid.clearEditText(passwordField);
      // finding the password field view
      // click the password field based on EditText view object
      soloLoginValid.clickOnView(passwordField);
      soloLoginValid.waitForActivity("MainActivity", 1000);
      soloLoginValid.enterText(passwordField, "*****");
      soloLoginValid.waitForActivity("MainActivity", 1000);
      // click on Login button
      ImageView clickLogin = (ImageView) soloLoginValid.getView(R.id.login_btn);
      soloLoginValid.clickOnView(clickLogin);
      // soloSplash.clickOnImageButton(1);
      soloLoginValid.waitForActivity("LoginActivity");
      soloLoginValid.clickOnView(emailField);
      soloLoginValid.waitForActivity("LoginActivity", 1000);
      boolean valid = soloLoginValid.searchText("Invalid Email address!");
      if (valid) {
        assertTrue("Invalid Email address!", valid);
      } else {
        throw new TestException("Testcase failed");
      }
      soloLoginValid.waitForActivity("LoginActivity", 1000);
      // Get the view location of cancel button.
      clickCancel = (ImageView) soloLoginValid.getView(R.id.cancel_btn);
      soloLoginValid.waitForActivity("MainActivity", 1000);
      // click on cancel button
      soloLoginValid.clickOnView(clickCancel);
      soloLoginValid.waitForActivity("LoginActivity", 1000);

    } catch (TestException e) {
      e.printStackTrace();
    }
  }