Search in sources :

Example 51 with CompoundVariable

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

the class TestTimeShiftFunction method testNowWithComplexPeriod.

@Test
public void testNowWithComplexPeriod() throws Exception {
    Collection<CompoundVariable> params = makeParams("YYYY-MM-dd'T'HH:mm:ss", "", "P10DT-1H-5M5S", "");
    function.setParameters(params);
    value = function.execute(result, null);
    LocalDateTime futureDate = LocalDateTime.now().plusDays(10).plusHours(-1).plusMinutes(-5).plusSeconds(5);
    LocalDateTime futureDateFromFunction = LocalDateTime.parse(value);
    assertThat(futureDateFromFunction, within(1, ChronoUnit.SECONDS, futureDate));
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) LocalDateTime(java.time.LocalDateTime) Test(org.junit.Test)

Example 52 with CompoundVariable

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

the class TestTimeShiftFunction method testDefault.

@Test
public void testDefault() throws Exception {
    Collection<CompoundVariable> params = makeParams("", "", "", "");
    function.setParameters(params);
    value = function.execute(result, null);
    long resultat = Long.parseLong(value);
    LocalDateTime nowFromFunction = LocalDateTime.ofInstant(Instant.ofEpochMilli(resultat), TimeZone.getDefault().toZoneId());
    assertThat(nowFromFunction, within(5, ChronoUnit.SECONDS, LocalDateTime.now()));
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) LocalDateTime(java.time.LocalDateTime) Test(org.junit.Test)

Example 53 with CompoundVariable

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

the class TestTimeShiftFunction method testWrongAmountToAdd.

@Test
public void testWrongAmountToAdd() throws Exception {
    // Nothing is add with wrong value, so check if return is now
    Collection<CompoundVariable> params = makeParams("", "", "qefv1Psd", "");
    function.setParameters(params);
    value = function.execute(result, null);
    long resultat = Long.parseLong(value);
    LocalDateTime nowFromFunction = LocalDateTime.ofInstant(Instant.ofEpochMilli(resultat), TimeZone.getDefault().toZoneId());
    assertThat(nowFromFunction, within(5, ChronoUnit.SECONDS, LocalDateTime.now()));
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) LocalDateTime(java.time.LocalDateTime) Test(org.junit.Test)

Example 54 with CompoundVariable

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

the class TestUrlEncodeDecode method testUrlEncode.

@Test
public void testUrlEncode() throws Exception {
    AbstractFunction function = new UrlEncode();
    params.add(new CompoundVariable("Veni, vidi, vici ?"));
    function.setParameters(params);
    String returnValue = function.execute(result, null);
    assertEquals("Veni%2C+vidi%2C+vici+%3F", returnValue);
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) Test(org.junit.Test)

Example 55 with CompoundVariable

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

the class VariableTest method variableTest1.

@Test
public void variableTest1() throws Exception {
    Variable r = new Variable();
    vars.put("A_1", "a1");
    vars.put("A_2", "a2");
    vars.put("one", "1");
    vars.put("two", "2");
    vars.put("V", "A");
    Collection<CompoundVariable> parms;
    String s;
    parms = makeParams("V", null, null);
    r.setParameters(parms);
    s = r.execute(null, null);
    assertEquals("A", s);
    parms = makeParams("X", null, null);
    r.setParameters(parms);
    s = r.execute(null, null);
    assertEquals("X", s);
    parms = makeParams("A${X}", null, null);
    r.setParameters(parms);
    s = r.execute(null, null);
    assertEquals("A${X}", s);
    parms = makeParams("A_1", null, null);
    r.setParameters(parms);
    s = r.execute(null, null);
    assertEquals("a1", s);
    parms = makeParams("A_2", null, null);
    r.setParameters(parms);
    s = r.execute(null, null);
    assertEquals("a2", s);
    parms = makeParams("A_${two}", null, null);
    r.setParameters(parms);
    s = r.execute(null, null);
    assertEquals("a2", s);
    parms = makeParams("${V}_${one}", null, null);
    r.setParameters(parms);
    s = r.execute(null, null);
    assertEquals("a1", s);
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) 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