Search in sources :

Example 76 with CompoundVariable

use of org.apache.jmeter.engine.util.CompoundVariable in project jmeter by apache.

the class TestJexl2Function method testSumVar.

@Test
public void testSumVar() throws Exception {
    params.add(new CompoundVariable("1+2+3"));
    params.add(new CompoundVariable("TOTAL"));
    function.setParameters(params);
    String ret = function.execute(result, null);
    assertEquals("6", ret);
    assertEquals("6", vars.get("TOTAL"));
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) Test(org.junit.Test)

Example 77 with CompoundVariable

use of org.apache.jmeter.engine.util.CompoundVariable in project jmeter by apache.

the class TestRandomFromMultipleVars method testExtractionFromMultipleVars.

@Test
public void testExtractionFromMultipleVars() throws Exception {
    String existingVarName1 = "var1";
    String existingVarName2 = "var2";
    vars.put(existingVarName1 + "_matchNr", "1");
    vars.put(existingVarName1 + "_1", "var1_value");
    vars.put(existingVarName2 + "_matchNr", "2");
    vars.put(existingVarName2 + "_1", "var2_value1");
    vars.put(existingVarName2 + "_2", "var2_value2");
    params.add(new CompoundVariable("var1|var2"));
    function.setParameters(params);
    String returnValue = function.execute(result, null);
    Assert.assertThat(returnValue, CoreMatchers.anyOf(CoreMatchers.is("var1_value"), CoreMatchers.is("var2_value1"), CoreMatchers.is("var2_value2")));
    Assert.assertNull(vars.get("outputVar"));
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) Test(org.junit.Test)

Example 78 with CompoundVariable

use of org.apache.jmeter.engine.util.CompoundVariable in project jmeter by apache.

the class TestTimeFunction method testTooMany.

@Test
public void testTooMany() throws Exception {
    params.add(new CompoundVariable("YMD"));
    params.add(new CompoundVariable("NAME"));
    params.add(new CompoundVariable("YMD"));
    try {
        variable.setParameters(params);
        fail("Should have raised InvalidVariableException");
    } catch (InvalidVariableException ignored) {
    }
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) Test(org.junit.Test)

Example 79 with CompoundVariable

use of org.apache.jmeter.engine.util.CompoundVariable in project jmeter by apache.

the class TestTimeFunction method testDivisor.

@Test
public void testDivisor() throws Exception {
    params.add(new CompoundVariable("/1000"));
    variable.setParameters(params);
    long before = System.currentTimeMillis() / 1000;
    value = variable.execute(result, null);
    long now = Long.parseLong(value);
    long after = System.currentTimeMillis() / 1000;
    assertTrue(now >= before && now <= after);
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) Test(org.junit.Test)

Example 80 with CompoundVariable

use of org.apache.jmeter.engine.util.CompoundVariable in project jmeter by apache.

the class TestTimeFunction method testDefault1.

@Test
public void testDefault1() throws Exception {
    params.add(new CompoundVariable());
    variable.setParameters(params);
    long before = System.currentTimeMillis();
    value = variable.execute(result, null);
    long now = Long.parseLong(value);
    long after = System.currentTimeMillis();
    assertTrue(now >= before && now <= after);
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) Test(org.junit.Test)

Aggregations

CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)103 Test (org.junit.Test)77 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)16 LinkedList (java.util.LinkedList)9 JMeterContext (org.apache.jmeter.threads.JMeterContext)7 File (java.io.File)4 IOException (java.io.IOException)3 LocalDateTime (java.time.LocalDateTime)3 HashMap (java.util.HashMap)2 ReplaceStringWithFunctions (org.apache.jmeter.engine.util.ReplaceStringWithFunctions)2 InvalidVariableException (org.apache.jmeter.functions.InvalidVariableException)2 TestSampler (org.apache.jmeter.junit.stubs.TestSampler)2 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)2 StringProperty (org.apache.jmeter.testelement.property.StringProperty)2 JMeterStopThreadException (org.apache.jorphan.util.JMeterStopThreadException)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 DecimalFormat (java.text.DecimalFormat)1 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1