Coverage Report - kg.apc.jmeter.functions.IsDefined
 
Classes in this File Line Coverage Branch Coverage Complexity
IsDefined
100%
17/17
75%
3/4
1.6
 
 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  
 public class IsDefined extends AbstractFunction {
 15  
 
 16  1
     private static final List<String> desc = new LinkedList<String>();
 17  
     private static final String KEY = "__isDefined";
 18  
 
 19  
     static {
 20  1
         desc.add("Name of variable to test");
 21  1
     }
 22  
 
 23  
     private Object[] values;
 24  
 
 25  5
     public IsDefined() {
 26  5
     }
 27  
 
 28  
     /**
 29  
      * {@inheritDoc}
 30  
      */
 31  
     @Override
 32  
     public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
 33  
             throws InvalidVariableException {
 34  2
         JMeterVariables vars = getVariables();
 35  2
         String res = ((CompoundVariable) values[0]).execute().trim();
 36  
 
 37  2
         if (vars != null) {
 38  2
             Object var = vars.getObject(res);
 39  2
             if (var != null) {
 40  1
                 return "1";
 41  
             }
 42  
         }
 43  
 
 44  1
         return "0";
 45  
 
 46  
     }
 47  
 
 48  
     /**
 49  
      * {@inheritDoc}
 50  
      */
 51  
     @Override
 52  
     public synchronized void setParameters(Collection<CompoundVariable> parameters) throws InvalidVariableException {
 53  3
         checkMinParameterCount(parameters, 1);
 54  3
         values = parameters.toArray();
 55  3
     }
 56  
 
 57  
     /**
 58  
      * {@inheritDoc}
 59  
      */
 60  
     @Override
 61  
     public String getReferenceKey() {
 62  1
         return KEY;
 63  
     }
 64  
 
 65  
     /**
 66  
      * {@inheritDoc}
 67  
      */
 68  
     @Override
 69  
     public List<String> getArgumentDesc() {
 70  1
         return desc;
 71  
     }
 72  
 }