Coverage Report - kg.apc.jmeter.functions.StrLen
 
Classes in this File Line Coverage Branch Coverage Complexity
StrLen
100%
17/17
75%
3/4
1.4
 
 1  
 package kg.apc.jmeter.functions;
 2  
 
 3  
 import org.apache.jmeter.engine.util.CompoundVariable;
 4  
 import org.apache.jmeter.functions.AbstractFunction;
 5  
 import org.apache.jmeter.functions.InvalidVariableException;
 6  
 import org.apache.jmeter.samplers.SampleResult;
 7  
 import org.apache.jmeter.samplers.Sampler;
 8  
 import org.apache.jmeter.threads.JMeterVariables;
 9  
 
 10  
 import java.util.Collection;
 11  
 import java.util.LinkedList;
 12  
 import java.util.List;
 13  
 
 14  
 /**
 15  
  * Provides a DoubleSum function that adds two or more Double values.
 16  
  * Mostly copied from LongSum
 17  
  */
 18  
 public class StrLen extends AbstractFunction {
 19  
 
 20  1
     private static final List<String> desc = new LinkedList<String>();
 21  
     private static final String KEY = "__strLen";
 22  
 
 23  
     static {
 24  1
         desc.add("String to measure length");
 25  1
         desc.add("Name of variable in which to store the result (optional)");
 26  1
     }
 27  
 
 28  
     private Object[] values;
 29  
 
 30  
     /**
 31  
      * No-arg constructor.
 32  
      */
 33  6
     public StrLen() {
 34  6
     }
 35  
 
 36  
     /**
 37  
      * {@inheritDoc}
 38  
      */
 39  
     @Override
 40  
     public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
 41  
             throws InvalidVariableException {
 42  3
         JMeterVariables vars = getVariables();
 43  3
         Integer len = ((CompoundVariable) values[0]).execute().length();
 44  
 
 45  3
         if (vars != null && values.length > 1) {
 46  1
             String varName = ((CompoundVariable) values[1]).execute().trim();
 47  1
             vars.put(varName, len.toString());
 48  
         }
 49  
 
 50  3
         return len.toString();
 51  
 
 52  
     }
 53  
 
 54  
     /**
 55  
      * {@inheritDoc}
 56  
      */
 57  
     @Override
 58  
     public synchronized void setParameters(Collection<CompoundVariable> parameters) throws InvalidVariableException {
 59  4
         checkMinParameterCount(parameters, 1);
 60  4
         values = parameters.toArray();
 61  4
     }
 62  
 
 63  
     /**
 64  
      * {@inheritDoc}
 65  
      */
 66  
     @Override
 67  
     public String getReferenceKey() {
 68  1
         return KEY;
 69  
     }
 70  
 
 71  
     /**
 72  
      * {@inheritDoc}
 73  
      */
 74  
     public List<String> getArgumentDesc() {
 75  1
         return desc;
 76  
     }
 77  
 }