org.apache.jmeter.engine.util.CompoundVariable Java Examples

The following examples show how to use org.apache.jmeter.engine.util.CompoundVariable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EnvTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
 * Test of setParameters method, of class Env.
 */
@Test
public void testSetParameters() throws Exception {
    System.out.println("setParameters");
    Collection<CompoundVariable> parameters = new ArrayList<>();
    parameters.add(new CompoundVariable(key));
    Env instance = new Env();
    instance.setParameters(parameters);

    // second parameter
    parameters.add(new CompoundVariable("save_variable"));
    instance.setParameters(parameters);

    // third parameter
    parameters.add(new CompoundVariable("default_value"));
    instance.setParameters(parameters);
}
 
Example #2
Source File: MD5Test.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
 * Test of execute method, of class MD5.
 */
@Test
public void testExecute() throws Exception {
    System.out.println("execute");
    Collection<CompoundVariable> parameters = new ArrayList<CompoundVariable>();
    parameters.add(new CompoundVariable("public void testExecute() throws Exception {}"));
    parameters.add(new CompoundVariable("var"));

    SampleResult previousResult = null;
    Sampler currentSampler = null;
    MD5 instance = new MD5();
    instance.setParameters(parameters);
    String expResult = "cb5b1ca8504cb5a7772f219109e05ccf";
    String result = instance.execute(previousResult, currentSampler);
    Assert.assertEquals(expResult, result);
    Assert.assertEquals(expResult, JMeterContextService.getContext().getVariables().get("var"));
}
 
Example #3
Source File: FifoPopTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
 * Test of execute method, of class FifoPop.
 */
@Test
public void testExecute() throws Exception {
    System.out.println("execute");
    SampleResult previousResult = null;
    Sampler currentSampler = null;
    FifoPop instance = new FifoPop();
    LinkedList<CompoundVariable> list = new LinkedList<>();
    list.add(new CompoundVariable("FifoPoptest"));
    list.add(new CompoundVariable("FifoPoptest"));
    instance.setParameters(list);
    FifoMap.getInstance().put("FifoPoptest", "FifoPoptest");
    String expResult = "FifoPoptest";
    String result = instance.execute(null, null);
    Assert.assertEquals(expResult, result);
}
 
Example #4
Source File: UpperCaseTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
 * Test of execute method, of class UpperCase.
 */
@Test
public void testExecute() throws Exception {
    System.out.println("execute");
    Collection<CompoundVariable> parameters = new ArrayList<>();
    parameters.add(new CompoundVariable("abc"));
    parameters.add(new CompoundVariable("var"));

    SampleResult previousResult = null;
    Sampler currentSampler = null;
    UpperCase instance = new UpperCase();
    instance.setParameters(parameters);
    String expResult = "ABC";
    String result = instance.execute(null, null);
    Assert.assertEquals(expResult, result);
    Assert.assertEquals(expResult, JMeterContextService.getContext().getVariables().get("var"));
}
 
Example #5
Source File: FifoPop.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
        throws InvalidVariableException {
    String fifoName = ((CompoundVariable) values[0]).execute();

    String value = null;
    try {
        Object valueObj = FifoMap.getInstance().pop(fifoName, timeout);
        if (valueObj != null) {
            value = valueObj.toString();
        }
    } catch (InterruptedException ex) {
        log.warn("Interrupted pop from queue " + fifoName);
        value = "INTERRUPTED";
    }

    JMeterVariables vars = getVariables();
    if (vars != null && values.length > 1) {
        String varName = ((CompoundVariable) values[1]).execute().trim();
        vars.put(varName, value);
    }

    return value;
}
 
Example #6
Source File: EnvTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecute_1() throws Exception {
    System.out.println("execute 1");
    SampleResult previousResult = null;
    Sampler currentSampler = null;

    Assert.assertNull(JMeterContextService.getContext().getVariables().get("toto"));
    Collection<CompoundVariable> parameters = new ArrayList<>();
    parameters.add(new CompoundVariable(key));
    parameters.add(new CompoundVariable("toto"));
    Env instance = new Env();
    instance.setParameters(parameters);
    String result = instance.execute(null, null);
    Assert.assertEquals(value, result);
    Assert.assertNotNull(JMeterContextService.getContext().getVariables().remove("toto"));
}
 
Example #7
Source File: EnvTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecute_3() throws Exception {
    System.out.println("execute 1");
    SampleResult previousResult = null;
    Sampler currentSampler = null;
    Assert.assertNull(JMeterContextService.getContext().getVariables().get("toto"));
    Collection<CompoundVariable> parameters = new ArrayList<>();
    String overrideKey = key + "testExecute_3";
    String defaultValue = "defaultValue";
    parameters.add(new CompoundVariable(overrideKey));
    parameters.add(new CompoundVariable(""));
    parameters.add(new CompoundVariable(defaultValue));
    Env instance = new Env();
    instance.setParameters(parameters);
    String result = instance.execute(null, null);
    Assert.assertEquals(defaultValue, result);
    Assert.assertNull(JMeterContextService.getContext().getVariables().get("toto"));
}
 
Example #8
Source File: FifoGet.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
        throws InvalidVariableException {
    String fifoName = ((CompoundVariable) values[0]).execute();

    Object valueObj = FifoMap.getInstance().get(fifoName);
    String value = null;
    if (valueObj != null) {
        value = valueObj.toString();
    }

    JMeterVariables vars = getVariables();
    if (vars != null && values.length > 1) {
        String varName = ((CompoundVariable) values[1]).execute().trim();
        vars.put(varName, value);
    }

    return value;
}
 
Example #9
Source File: FifoSize.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
        throws InvalidVariableException {
    String fifoName = ((CompoundVariable) values[0]).execute();

    int size = FifoMap.getInstance().length(fifoName);
    String value = Integer.toString(size);

    JMeterVariables vars = getVariables();
    if (vars != null && values.length > 1) {
        String varName = ((CompoundVariable) values[1]).execute().trim();
        vars.put(varName, value);
    }

    return value;
}
 
Example #10
Source File: IsDefined.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
        throws InvalidVariableException {
    JMeterVariables vars = getVariables();
    String res = ((CompoundVariable) values[0]).execute().trim();

    if (vars != null) {
        Object var = vars.getObject(res);
        if (var != null) {
            return "1";
        }
    }

    return "0";

}
 
Example #11
Source File: MD5.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
        throws InvalidVariableException {
    JMeterVariables vars = getVariables();
    String str = ((CompoundVariable) values[0]).execute();
    MessageDigest digest;
    try {
        digest = MessageDigest.getInstance("md5");
    } catch (NoSuchAlgorithmException ex) {
        return "Error creating digest: " + ex;
    }

    String res = JOrphanUtils.baToHexString(digest.digest(str.getBytes()));

    if (vars != null && values.length > 1) {
        String varName = ((CompoundVariable) values[1]).execute().trim();
        vars.put(varName, res);
    }

    return res;
}
 
Example #12
Source File: LowerCaseTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
 * Test of execute method, of class LowerCase.
 */
@Test
public void testExecute() throws Exception {
    System.out.println("execute");
    Collection<CompoundVariable> parameters = new ArrayList<CompoundVariable>();
    parameters.add(new CompoundVariable("ABC"));
    parameters.add(new CompoundVariable("var"));

    SampleResult previousResult = null;
    Sampler currentSampler = null;
    LowerCase instance = new LowerCase();
    instance.setParameters(parameters);
    String expResult = "abc";
    String result = instance.execute(previousResult, currentSampler);
    Assert.assertEquals(expResult, result);
    Assert.assertEquals(expResult, JMeterContextService.getContext().getVariables().get("var"));
}
 
Example #13
Source File: EvaluatePanel.java    From jmeter-debugger with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent actionEvent) {
    result.clear();
    if (exprField.getText().isEmpty()) {
        return;
    }

    CompoundVariable masterFunction = new CompoundVariable(exprField.getText());
    SampleResult previousResult = context.getPreviousResult();
    Sampler currentSampler = context.getCurrentSampler();
    try {
        result.setText(masterFunction.execute(previousResult, currentSampler));
    } catch (Throwable e) {
        ByteArrayOutputStream text = new ByteArrayOutputStream(1024);
        e.printStackTrace(new PrintStream(text));
        result.setText(text.toString());
        result.scrollToTop();
    }
}
 
Example #14
Source File: FifoSizeTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
/**
 * Test of execute method, of class FifoSize.
 */
@Test
public void testExecute() throws Exception {
    System.out.println("execute");
    SampleResult previousResult = null;
    Sampler currentSampler = null;
    LinkedList<CompoundVariable> list;
    list = new LinkedList<>();
    list.add(new CompoundVariable("test"));
    list.add(new CompoundVariable("test"));
    FifoSize instance = new FifoSize();
    instance.setParameters(list);
    String expResult = "0";
    String result = instance.execute(null, null);
    Assert.assertEquals(expResult, result);
}
 
Example #15
Source File: ChooseRandomTest.java    From jmeter-plugins with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecute() throws Exception {
    System.out.println("execute");
    SampleResult previousResult = null;
    Sampler currentSampler = null;
    Collection<CompoundVariable> parameters = new ArrayList<>();
    for (int i = 0; i < 1000; i++) {
        parameters.add(new CompoundVariable(String.valueOf(i)));

    }
    parameters.add(new CompoundVariable("4.3346"));
    parameters.add(new CompoundVariable("5.3346"));
    ChooseRandom instance = new ChooseRandom();
    instance.setParameters(parameters);
    String result1 = instance.execute(null, null);
    String result2 = instance.execute(null, null);
    Assert.assertTrue(!result1.equals(result2));
}
 
Example #16
Source File: StrLenTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute_fromVar() throws Exception {
    System.out.println("execute 1");
    SampleResult previousResult = null;
    Sampler currentSampler = null;
    JMeterContextService.getContext().getVariables().put("varName", "test string 123");
    Collection<CompoundVariable> parameters = new ArrayList<CompoundVariable>();
    parameters.add(new CompoundVariable("${varName}"));
    StrLen instance = new StrLen();
    instance.setParameters(parameters);
    String expResult = "15";
    String result = instance.execute(previousResult, currentSampler);
    Assert.assertEquals(expResult, result);
}
 
Example #17
Source File: StrLenTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute_toVar() throws Exception {
    System.out.println("execute 2");
    SampleResult previousResult = null;
    Sampler currentSampler = null;
    Collection<CompoundVariable> parameters = new ArrayList<CompoundVariable>();
    parameters.add(new CompoundVariable("test string"));
    parameters.add(new CompoundVariable("varName"));
    StrLen instance = new StrLen();
    instance.setParameters(parameters);
    String expResult = "11";
    String result = instance.execute(previousResult, currentSampler);
    Assert.assertEquals(expResult, result);
    Assert.assertEquals(expResult, JMeterContextService.getContext().getVariables().get("varName"));
}
 
Example #18
Source File: EnvTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
/**
 * Test of execute method, of class Env.
 */
@Test
public void testExecute() throws Exception {
    System.out.println("execute 1");
    SampleResult previousResult = null;
    Sampler currentSampler = null;
    Assert.assertNull(JMeterContextService.getContext().getVariables().get("toto"));
    Collection<CompoundVariable> parameters = new ArrayList<>();
    parameters.add(new CompoundVariable(key));
    Env instance = new Env();
    instance.setParameters(parameters);
    String result = instance.execute(null, null);
    Assert.assertEquals(value, result);
    Assert.assertNull(JMeterContextService.getContext().getVariables().get("toto"));
}
 
Example #19
Source File: LowerCaseTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
/**
 * Test of setParameters method, of class LowerCase.
 */
@Test
public void testSetParameters() throws Exception {
    System.out.println("setParameters");
    Collection<CompoundVariable> parameters = new ArrayList<CompoundVariable>();
    parameters.add(new CompoundVariable("abc"));
    parameters.add(new CompoundVariable("var"));
    LowerCase instance = new LowerCase();
    instance.setParameters(parameters);
}
 
Example #20
Source File: EnvTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecute_2() throws Exception {
    System.out.println("execute 1");
    SampleResult previousResult = null;
    Sampler currentSampler = null;
    Assert.assertNull(JMeterContextService.getContext().getVariables().get("toto"));
    Collection<CompoundVariable> parameters = new ArrayList<>();
    String overrideKey = key + "testExecute_2";
    parameters.add(new CompoundVariable(overrideKey));
    Env instance = new Env();
    instance.setParameters(parameters);
    String result = instance.execute(null, null);
    Assert.assertEquals(overrideKey, result);
    Assert.assertNull(JMeterContextService.getContext().getVariables().get("toto"));
}
 
Example #21
Source File: EnvTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Test(expected = InvalidVariableException.class)
public void testSetParametersException() throws Exception {
    System.out.println("setParameters");
    Collection<CompoundVariable> parameters = new ArrayList<>();
    Env instance = new Env();
    instance.setParameters(parameters);
}
 
Example #22
Source File: EnvTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Test(expected = InvalidVariableException.class)
public void testSetParametersException2() throws Exception {
    System.out.println("setParameters");
    Collection<CompoundVariable> parameters = new ArrayList<>();
    parameters.add(new CompoundVariable(key));
    parameters.add(new CompoundVariable("save_variable"));
    parameters.add(new CompoundVariable("default_value"));
    parameters.add(new CompoundVariable("Error"));
    Env instance = new Env();
    instance.setParameters(parameters);
}
 
Example #23
Source File: ChooseRandomTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetParameters() throws Exception {
    System.out.println("setParameters");
    Collection<CompoundVariable> parameters = new ArrayList<>();
    parameters.add(new CompoundVariable("1.256"));
    parameters.add(new CompoundVariable("4.3346"));
    parameters.add(new CompoundVariable("5.3346"));
    ChooseRandom instance = new ChooseRandom();
    instance.setParameters(parameters);
}
 
Example #24
Source File: StrLenTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
/**
 * Test of execute method, of class StrLen.
 */
@Test
public void testExecute() throws Exception {
    System.out.println("execute 1");
    SampleResult previousResult = null;
    Sampler currentSampler = null;
    Collection<CompoundVariable> parameters = new ArrayList<CompoundVariable>();
    parameters.add(new CompoundVariable("test string"));
    StrLen instance = new StrLen();
    instance.setParameters(parameters);
    String expResult = "11";
    String result = instance.execute(previousResult, currentSampler);
    Assert.assertEquals(expResult, result);
}
 
Example #25
Source File: MD5Test.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
/**
 * Test of setParameters method, of class MD5.
 */
@Test
public void testSetParameters() throws Exception {
    System.out.println("setParameters");
    Collection<CompoundVariable> parameters = new ArrayList<CompoundVariable>();
    parameters.add(new CompoundVariable("abc"));
    parameters.add(new CompoundVariable("var"));
    MD5 instance = new MD5();
    instance.setParameters(parameters);
}
 
Example #26
Source File: UpperCaseTest.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
/**
 * Test of setParameters method, of class UpperCase.
 */
@Test
public void testSetParameters() throws Exception {
    System.out.println("setParameters");
    Collection<CompoundVariable> parameters = new ArrayList<>();
    parameters.add(new CompoundVariable("abc"));
    parameters.add(new CompoundVariable("var"));
    UpperCase instance = new UpperCase();
    instance.setParameters(parameters);
}
 
Example #27
Source File: UpperCase.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
        throws InvalidVariableException {
    JMeterVariables vars = getVariables();
    String res = ((CompoundVariable) values[0]).execute().toUpperCase();

    if (vars != null && values.length > 1) {
        String varName = ((CompoundVariable) values[1]).execute().trim();
        vars.put(varName, res);
    }

    return res;

}
 
Example #28
Source File: ChooseRandom.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
        throws InvalidVariableException {
    JMeterVariables vars = getVariables();
    String varName = ((CompoundVariable) values[values.length - 1]).execute().trim();
    int index = random.nextInt(values.length - 1);
    String choice = ((CompoundVariable) values[index]).execute();

    if (vars != null && varName != null && varName.length() > 0) {// vars will be null on TestPlan
        vars.put(varName, choice);
    }

    return choice;
}
 
Example #29
Source File: LowerCase.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
        throws InvalidVariableException {
    JMeterVariables vars = getVariables();
    String res = ((CompoundVariable) values[0]).execute().toLowerCase();

    if (vars != null && values.length > 1) {
        String varName = ((CompoundVariable) values[1]).execute().trim();
        vars.put(varName, res);
    }

    return res;

}
 
Example #30
Source File: StrLen.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public synchronized String execute(SampleResult previousResult, Sampler currentSampler)
        throws InvalidVariableException {
    JMeterVariables vars = getVariables();
    Integer len = ((CompoundVariable) values[0]).execute().length();

    if (vars != null && values.length > 1) {
        String varName = ((CompoundVariable) values[1]).execute().trim();
        vars.put(varName, len.toString());
    }

    return len.toString();

}