Search in sources :

Example 16 with CompoundVariable

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

the class TestTimeFunction method testDefault2.

@Test
public void testDefault2() throws Exception {
    params.add(new CompoundVariable());
    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)

Example 17 with CompoundVariable

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

the class TestTimeFunction method testFixed.

@Test
public void testFixed() throws Exception {
    params.add(new CompoundVariable("'Fixed text'"));
    variable.setParameters(params);
    value = variable.execute(result, null);
    assertEquals("Fixed text", value);
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) Test(org.junit.Test)

Example 18 with CompoundVariable

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

the class TestTimeShiftFunction method testNowPlusOneDay.

@Test
public void testNowPlusOneDay() throws Exception {
    Collection<CompoundVariable> params = makeParams("YYYY-MM-dd", "", "P1d", "");
    function.setParameters(params);
    value = function.execute(result, null);
    LocalDate tomorrow = LocalDate.now().plusDays(1);
    LocalDate tomorrowFromFunction = LocalDate.parse(value);
    assertThat(tomorrowFromFunction, sameDay(tomorrow));
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 19 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 20 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)

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