/** Parse a given String into a Date. */
 @SuppressLint("SimpleDateFormat")
 public static Date stringToDate(String rawDate) {
   DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
   Date date = null;
   try {
     date = dateFormat.parse(rawDate);
   } catch (ParseException e) {
     Log.e(TAG, "stringToDate: " + e.getClass() + ": " + e.getLocalizedMessage());
   }
   return date;
 }
  @Override
  public AssertionResult getResult(SampleResult samplerResult) {
    AssertionResult result = new AssertionResult(getName());
    byte[] responseData = samplerResult.getResponseData();
    if (responseData.length == 0) {
      return result.setResultForNull();
    }

    if (isJsonValidationBool()) {
      try {
        if (checkJSONPathWithValidation(
            new String(responseData, "UTF-8"), getJsonPath(), getExpectedValue())) {
          result.setFailure(false);
          result.setFailureMessage("");
        }
      } catch (ParseException e) {
        result.setFailure(true);
        result.setFailureMessage(e.getClass().toString() + " - " + e.getMessage());
      } catch (Exception e) {
        result.setFailure(true);
        result.setFailureMessage(e.getMessage());
      }
    }

    if (!isJsonValidationBool()) {
      try {
        if (checkJSONPathWithoutValidation(new String(responseData), getJsonPath())) {
          result.setFailure(false);
          result.setFailureMessage("");
        }
      } catch (ParseException e) {
        result.setFailure(true);
        result.setFailureMessage(e.getClass().toString() + " - " + e.getMessage());
      } catch (Exception e) {
        result.setFailure(true);
        result.setFailureMessage(e.getMessage());
      }
    }

    return result;
  }
Пример #3
0
 private static Date fromXSDZNotNull(final String dateString) {
   final boolean lenient = (dateString.length() > Const.LENGTH_XSD_Z);
   final String pattern = (lenient ? Const.XSD_MILLI_Z : Const.XSD_Z);
   final DateFormat dateFormat = DateU.getDateFormat(pattern, DateU.Const.TZ_GMT, lenient);
   Date date = null; // NOPMD
   try {
     date = dateFormat.parse(dateString); // NOPMD
   } catch (ParseException e) {
     e.getClass();
   }
   return date;
 }