Search in sources :

Example 71 with CompoundVariable

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

the class TestRegexFunction method testVariableExtraction1b.

// Test with empty output variable name
@Test
public void testVariableExtraction1b() throws Exception {
    params = new LinkedList<>();
    params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
    // template
    params.add(new CompoundVariable("$2$"));
    // match number
    params.add(new CompoundVariable("2"));
    // ALL separator
    params.add(new CompoundVariable("-"));
    params.add(new CompoundVariable("default"));
    params.add(new CompoundVariable(""));
    variable.setParameters(params);
    String match = variable.execute(result, null);
    assertEquals("5", match);
    assertNull(vars.getObject("OUTVAR"));
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) Test(org.junit.Test)

Example 72 with CompoundVariable

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

the class TestRegexFunction method testVariableExtractionFromVariable2.

@Test
public void testVariableExtractionFromVariable2() throws Exception {
    params = new LinkedList<>();
    params.add(new CompoundVariable("(\\d+)\\s+(\\w+)"));
    // template
    params.add(new CompoundVariable("$1$$2$"));
    // match number
    params.add(new CompoundVariable("1"));
    // ALL separator
    params.add(new CompoundVariable("-"));
    params.add(new CompoundVariable("default"));
    params.add(new CompoundVariable("OUTVAR"));
    params.add(new CompoundVariable(INPUT_VARIABLE_NAME));
    variable.setParameters(params);
    String match = variable.execute(result, null);
    assertEquals("1", vars.getObject("OUTVAR_matchNr"));
    assertEquals("123times", match);
    assertEquals("123times", vars.getObject("OUTVAR"));
    assertEquals("123 times", vars.getObject("OUTVAR_g0"));
    assertEquals("123", vars.getObject("OUTVAR_g1"));
    assertEquals("times", vars.getObject("OUTVAR_g2"));
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) Test(org.junit.Test)

Example 73 with CompoundVariable

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

the class TestEscapeOroRegexpChars method testEscape2.

@Test
public void testEscape2() throws Exception {
    params.add(new CompoundVariable("[^\"].+?"));
    function.setParameters(params);
    String ret = function.execute(result, null);
    assertEquals("\\[\\^\\\"\\]\\.\\+\\?", ret);
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) Test(org.junit.Test)

Example 74 with CompoundVariable

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

the class TestFileToString method testReadWithEncodingAndVar.

@Test
public void testReadWithEncodingAndVar() throws Exception {
    File file = new File(JMeterUtils.getJMeterBinDir(), "jmeter.properties");
    params.add(new CompoundVariable(file.getAbsolutePath()));
    params.add(new CompoundVariable("UTF-8"));
    params.add(new CompoundVariable("MY_FILE_AS_TEXT"));
    function.setParameters(params);
    String returnValue = function.execute(result, null);
    Assert.assertTrue(returnValue.indexOf("language=") > 0);
    Assert.assertTrue(vars.get("MY_FILE_AS_TEXT").indexOf("language=") > 0);
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) File(java.io.File) Test(org.junit.Test)

Example 75 with CompoundVariable

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

the class TestFileToString method testRead.

@Test
public void testRead() throws Exception {
    File file = new File(JMeterUtils.getJMeterBinDir(), "jmeter.properties");
    params.add(new CompoundVariable(file.getAbsolutePath()));
    function.setParameters(params);
    String returnValue = function.execute(result, null);
    Assert.assertTrue(returnValue.indexOf("language=") > 0);
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) File(java.io.File) 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