/**
  * Remove the behavior entry with the specified name.
  *
  * @param behvName the name of the behavior to remove.
  */
 public void removeBehaviorMix(String behvName) {
   PropertyIterator iter = getBehaviorMix().iterator();
   while (iter.hasNext()) {
     BehaviorMixEntry behv = (BehaviorMixEntry) iter.next().getObjectValue();
     if (behv.getName().equals(behvName)) {
       iter.remove();
     }
   }
 }
 /**
  * Remove the specified behavior entry from the list.
  *
  * @param behv the entry to remove.
  */
 public void removeBehaviorMix(BehaviorMixEntry behv) {
   PropertyIterator iter = getBehaviorMix().iterator();
   while (iter.hasNext()) {
     BehaviorMixEntry item = (BehaviorMixEntry) iter.next().getObjectValue();
     if (behv.equals(item)) {
       iter.remove();
     }
   }
 }
 /**
  * Returns the behavior mix as a Map.
  *
  * <p>Each behavior name is used as the entrie's key.
  *
  * @return the behavior mix map.
  */
 public Map<String, BehaviorMixEntry> getBehaviorMixAsMap() {
   PropertyIterator iter = getBehaviorMix().iterator();
   Map behaviorMixMap = new HashMap();
   while (iter.hasNext()) {
     BehaviorMixEntry behv = (BehaviorMixEntry) iter.next().getObjectValue();
     behaviorMixMap.put(behv.getName(), behv);
   }
   return behaviorMixMap;
 }
 /**
  * Create a string representation of the behavior mix.
  *
  * @return the string representation of the behavior mix.
  */
 @Override
 public String toString() {
   StringBuffer str = new StringBuffer();
   PropertyIterator iter = getBehaviorMix().iterator();
   while (iter.hasNext()) {
     BehaviorMixEntry behv = (BehaviorMixEntry) iter.next().getObjectValue();
     str.append(behv.getName() + behv.getRFreq() + behv.getFilename());
     if (iter.hasNext()) {
       str.append("&");
     }
   }
   return str.toString();
 }
Beispiel #5
0
 @Override
 public void configure(TestElement el) {
   super.configure(el);
   if (el instanceof Arguments) {
     tableModel.clearData();
     HTTPArgument.convertArgumentsToHTTP((Arguments) el);
     PropertyIterator iter = ((Arguments) el).getArguments().iterator();
     while (iter.hasNext()) {
       HTTPArgument arg = (HTTPArgument) iter.next().getObjectValue();
       tableModel.addRow(arg);
     }
   }
   checkDeleteStatus();
 }
  public String getQueryString(String contentEncoding) {
    // Check if the sampler has a specified content encoding
    if (JOrphanUtils.isBlank(contentEncoding)) {
      // We use the encoding which should be used according to the HTTP spec, which is UTF-8
      contentEncoding = EncoderCache.URL_ARGUMENT_ENCODING;
    }
    StringBuilder buf = new StringBuilder();
    PropertyIterator iter = getQueryStringParameters().iterator();
    boolean first = true;
    while (iter.hasNext()) {
      HTTPArgument item = null;
      Object objectValue = iter.next().getObjectValue();
      try {
        item = (HTTPArgument) objectValue;
      } catch (ClassCastException e) {
        item = new HTTPArgument((Argument) objectValue);
      }
      final String encodedName = item.getEncodedName();
      if (encodedName.length() == 0) {
        continue; // Skip parameters with a blank name (allows use of optional variables in
                  // parameter lists)
      }
      if (!first) {
        buf.append(QRY_SEP);
      } else {
        first = false;
      }
      buf.append(encodedName);
      if (item.getMetaData() == null) {
        buf.append(ARG_VAL_SEP);
      } else {
        buf.append(item.getMetaData());
      }

      // Encode the parameter value in the specified content encoding
      try {
        buf.append(item.getEncodedValue(contentEncoding));
      } catch (UnsupportedEncodingException e) {
        log.warn(
            "Unable to encode parameter in encoding "
                + contentEncoding
                + ", parameter value not included in query string");
      }
    }
    return buf.toString();
  }
 /**
  * Make sure the response satisfies the specified assertion requirements.
  *
  * @param response an instance of SampleResult
  * @return an instance of AssertionResult
  */
 private AssertionResult evaluateResponse(SampleResult response) {
   boolean pass = true;
   boolean not = (NOT & getTestType()) > 0;
   AssertionResult result = new AssertionResult();
   if (response.getResponseData() == null) {
     return setResultForNull(result);
   }
   String responseString = new String(response.getResponseData());
   try {
     // Get the Matcher for this thread
     Perl5Matcher localMatcher = (Perl5Matcher) matcher.get();
     PropertyIterator iter = getTestStrings().iterator();
     while (iter.hasNext()) {
       String stringPattern = iter.next().getStringValue();
       Pattern pattern = patternCache.getPattern(stringPattern, Perl5Compiler.READ_ONLY_MASK);
       boolean found;
       if ((CONTAINS & getTestType()) > 0) {
         found = localMatcher.contains(responseString, pattern);
       } else {
         found = localMatcher.matches(responseString, pattern);
       }
       pass = not ? !found : found;
       if (!pass) {
         result.setFailure(true);
         result.setFailureMessage(
             "Test Failed, expected " + notMessage + failMessage + stringPattern);
         break;
       }
     }
     if (pass) {
       result.setFailure(false);
     }
     result.setError(false);
   } catch (MalformedCachePatternException e) {
     result.setError(true);
     result.setFailure(false);
     result.setFailureMessage("Bad test configuration" + e);
   }
   return result;
 }
 private void setValues() {
   synchronized (lock) {
     if (log.isDebugEnabled()) {
       log.debug(
           Thread.currentThread().getName() + " Running up named: " + getName()); // $NON-NLS-1$
     }
     PropertyIterator namesIter = getNames().iterator();
     PropertyIterator valueIter = getValues().iterator();
     JMeterVariables jmvars = getThreadContext().getVariables();
     while (namesIter.hasNext() && valueIter.hasNext()) {
       String name = namesIter.next().getStringValue();
       String value = valueIter.next().getStringValue();
       if (log.isDebugEnabled()) {
         log.debug(
             Thread.currentThread().getName()
                 + " saving variable: "
                 + name
                 + "="
                 + value); //$NON-NLS-1$
       }
       jmvars.put(name, value);
     }
   }
 }