Search in sources :

Example 66 with CompoundVariable

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

the class TestRegexFunction method testVariableExtractionFromVariable7.

@Test
public void testVariableExtractionFromVariable7() throws Exception {
    params = new LinkedList<>();
    params.add(new CompoundVariable("(\\d+)\\s+(\\w+)"));
    // template
    params.add(new CompoundVariable("pre$1$mid$2$post"));
    // 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("pre123midtimespost", match);
    assertEquals("pre123midtimespost", 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 67 with CompoundVariable

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

the class TestRegexFunction method testDefaultValue.

@Test
public void testDefaultValue() throws Exception {
    params = new LinkedList<>();
    params.add(new CompoundVariable("<value,, field=\"(pinposition\\d+)\">(\\d+)</value>"));
    params.add(new CompoundVariable("$2$, "));
    params.add(new CompoundVariable(".333"));
    params.add(new CompoundVariable(""));
    params.add(new CompoundVariable("No Value Found"));
    variable.setParameters(params);
    String match = variable.execute(result, null);
    assertEquals("No Value Found", match);
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) Test(org.junit.Test)

Example 68 with CompoundVariable

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

the class TestRegexFunction method testRandomExtraction.

@Test
public void testRandomExtraction() throws Exception {
    params = new LinkedList<>();
    params.add(new CompoundVariable("<company-xmlext-query-ret>(.+?)</company-xmlext-query-ret>"));
    params.add(new CompoundVariable("$1$"));
    params.add(new CompoundVariable("RAND"));
    params.add(new CompoundVariable(""));
    params.add(new CompoundVariable("No Value Found"));
    variable.setParameters(params);
    String match = variable.execute(result, null);
    assertEquals("<row>" + "<value field=\"RetCode\">" + "LIS_OK</value><value" + " field=\"RetCodeExtension\"></value>" + "<value field=\"alias\"></value><value" + " field=\"positioncount\"></value>" + "<value field=\"invalidpincount\">0</value><value" + " field=\"pinposition1\">1</value><value" + " field=\"pinpositionvalue1\"></value><value" + " field=\"pinposition2\">5</value><value" + " field=\"pinpositionvalue2\"></value><value" + " field=\"pinposition3\">6</value><value" + " field=\"pinpositionvalue3\"></value>" + "</row>", match);
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) Test(org.junit.Test)

Example 69 with CompoundVariable

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

the class TestRegexFunction method testVariableExtractionFromVariable4.

@Test
public void testVariableExtractionFromVariable4() throws Exception {
    params = new LinkedList<>();
    params.add(new CompoundVariable("(\\d+)\\s+(\\w+)"));
    // template
    params.add(new CompoundVariable("pre$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("pretimes", match);
    assertEquals("pretimes", 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 70 with CompoundVariable

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

the class TestRegexFunction method testVariableExtraction3.

@Test
public void testVariableExtraction3() throws Exception {
    params = new LinkedList<>();
    params.add(new CompoundVariable("<value field=\"(pinposition\\d+)\">(\\d+)</value>"));
    params.add(new CompoundVariable("_$1$"));
    params.add(new CompoundVariable("2"));
    variable.setParameters(params);
    String match = variable.execute(result, null);
    assertEquals("_pinposition2", match);
}
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