Search in sources :

Example 26 with StringProperty

use of org.apache.jmeter.testelement.property.StringProperty in project jmeter by apache.

the class TestValueReplacer method testReplaceFunctionWithBackslash.

/*
         * This test should be compared with the one above.
         * Here, the string contains a valid variable reference, so all
         * backslashes are also processed.
         * 
         * See https://bz.apache.org/bugzilla/show_bug.cgi?id=53534
         */
@Test
public void testReplaceFunctionWithBackslash() throws Exception {
    ValueReplacer replacer = new ValueReplacer();
    replacer.setUserDefinedVariables(variables.getUserDefinedVariables());
    TestElement element = new ConfigTestElement();
    String input = "${server} \\ \\\\ \\\\\\ \\, ";
    element.setProperty(new StringProperty("domain", input));
    replacer.replaceValues(element);
    element.setRunningVersion(true);
    assertEquals("jakarta.apache.org \\ \\ \\\\ , ", element.getPropertyAsString("domain"));
}
Also used : StringProperty(org.apache.jmeter.testelement.property.StringProperty) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement) TestElement(org.apache.jmeter.testelement.TestElement) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement) Test(org.junit.Test)

Example 27 with StringProperty

use of org.apache.jmeter.testelement.property.StringProperty in project jmeter by apache.

the class TestValueReplacer method testReverseReplacementXml.

@Test
public void testReverseReplacementXml() throws Exception {
    ValueReplacer replacer = new ValueReplacer(variables);
    assertTrue(variables.getUserDefinedVariables().containsKey("bounded_regex"));
    assertTrue(variables.getUserDefinedVariables().containsKey("normal_regex"));
    assertTrue(replacer.containsKey("bounded_regex"));
    assertTrue(replacer.containsKey("normal_regex"));
    TestElement element = new TestPlan();
    element.setProperty(new StringProperty("domain", "<this><is>xml</this></is>"));
    List<Object> argsin = new ArrayList<>();
    argsin.add("<this><is>xml</this></is>");
    argsin.add("And I say: Hello World.");
    element.setProperty(new CollectionProperty("args", argsin));
    replacer.reverseReplace(element, true);
    @SuppressWarnings("unchecked") List<JMeterProperty> args = (List<JMeterProperty>) element.getProperty("args").getObjectValue();
    assertEquals("${bounded_regex}", element.getPropertyAsString("domain"));
    assertEquals("${bounded_regex}", args.get(0).getStringValue());
}
Also used : CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) TestPlan(org.apache.jmeter.testelement.TestPlan) ArrayList(java.util.ArrayList) StringProperty(org.apache.jmeter.testelement.property.StringProperty) ArrayList(java.util.ArrayList) List(java.util.List) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement) TestElement(org.apache.jmeter.testelement.TestElement) Test(org.junit.Test)

Example 28 with StringProperty

use of org.apache.jmeter.testelement.property.StringProperty in project jmeter by apache.

the class TestSwitchController method testFunction.

/*
         * N.B. Requires ApacheJMeter_functions.jar to be on the classpath,
         * otherwise the function cannot be resolved.
        */
@Test
public void testFunction() throws Exception {
    JMeterContext jmctx = JMeterContextService.getContext();
    Map<String, String> variables = new HashMap<>();
    ReplaceStringWithFunctions transformer = new ReplaceStringWithFunctions(new CompoundVariable(), variables);
    jmctx.setVariables(new JMeterVariables());
    JMeterVariables jmvars = jmctx.getVariables();
    jmvars.put("VAR", "100");
    StringProperty prop = new StringProperty(SwitchController.SWITCH_VALUE, "${__counter(TRUE,VAR)}");
    JMeterProperty newProp = transformer.transformValue(prop);
    newProp.setRunningVersion(true);
    GenericController controller = new GenericController();
    SwitchController switch_cont = new SwitchController();
    switch_cont.setProperty(newProp);
    controller.addTestElement(new TestSampler("before"));
    controller.addTestElement(switch_cont);
    switch_cont.addTestElement(new TestSampler("0"));
    switch_cont.addTestElement(new TestSampler("1"));
    switch_cont.addTestElement(new TestSampler("2"));
    switch_cont.addTestElement(new TestSampler("3"));
    controller.addTestElement(new TestSampler("after"));
    controller.initialize();
    assertEquals("100", jmvars.get("VAR"));
    for (int i = 1; i <= 3; i++) {
        assertEquals("Loop " + i, "before", nextName(controller));
        assertEquals("Loop " + i, "" + i, nextName(controller));
        assertEquals("Loop " + i, "" + i, jmvars.get("VAR"));
        assertEquals("Loop " + i, "after", nextName(controller));
        assertNull(nextName(controller));
    }
    int i = 4;
    assertEquals("Loop " + i, "before", nextName(controller));
    assertEquals("Loop " + i, "0", nextName(controller));
    assertEquals("Loop " + i, "" + i, jmvars.get("VAR"));
    assertEquals("Loop " + i, "after", nextName(controller));
    assertNull(nextName(controller));
    assertEquals("4", jmvars.get("VAR"));
}
Also used : CompoundVariable(org.apache.jmeter.engine.util.CompoundVariable) ReplaceStringWithFunctions(org.apache.jmeter.engine.util.ReplaceStringWithFunctions) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) HashMap(java.util.HashMap) StringProperty(org.apache.jmeter.testelement.property.StringProperty) JMeterVariables(org.apache.jmeter.threads.JMeterVariables) JMeterContext(org.apache.jmeter.threads.JMeterContext) TestSampler(org.apache.jmeter.junit.stubs.TestSampler) Test(org.junit.Test)

Example 29 with StringProperty

use of org.apache.jmeter.testelement.property.StringProperty in project jmeter by apache.

the class PackageTest method testParseExample14.

// Escaped dollar commma and backslash with missing function reference
@Test
public void testParseExample14() throws Exception {
    StringProperty prop = new StringProperty("html", "\\$a \\, \\\\ \\x \\ ${__missing(a)} \\$b \\, \\\\ cd");
    JMeterProperty newProp = transformer.transformValue(prop);
    newProp.setRunningVersion(true);
    // N.B. Backslashes are removed before dollar, comma and backslash
    assertEquals("$a , \\ \\x \\ ${__missing(a)} $b , \\ cd", newProp.getStringValue());
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) StringProperty(org.apache.jmeter.testelement.property.StringProperty) Test(org.junit.Test)

Example 30 with StringProperty

use of org.apache.jmeter.testelement.property.StringProperty in project jmeter by apache.

the class PackageTest method testParseExample9.

@Test
public void testParseExample9() throws Exception {
    StringProperty prop = new StringProperty("html", "${__regexFunction(([$]\\d+\\.\\d+),$1$)}");
    JMeterProperty newProp = transformer.transformValue(prop);
    newProp.setRunningVersion(true);
    assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName());
    assertEquals("$3.47", newProp.getStringValue());
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) StringProperty(org.apache.jmeter.testelement.property.StringProperty) Test(org.junit.Test)

Aggregations

StringProperty (org.apache.jmeter.testelement.property.StringProperty)47 Test (org.junit.Test)26 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)23 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)9 TestElement (org.apache.jmeter.testelement.TestElement)7 TestPlan (org.apache.jmeter.testelement.TestPlan)4 TestElementProperty (org.apache.jmeter.testelement.property.TestElementProperty)3 BeanInfo (java.beans.BeanInfo)2 IntrospectionException (java.beans.IntrospectionException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ResourceBundle (java.util.ResourceBundle)2 CompoundVariable (org.apache.jmeter.engine.util.CompoundVariable)2 ReplaceStringWithFunctions (org.apache.jmeter.engine.util.ReplaceStringWithFunctions)2 TestSampler (org.apache.jmeter.junit.stubs.TestSampler)2 BooleanProperty (org.apache.jmeter.testelement.property.BooleanProperty)2 CollectionProperty (org.apache.jmeter.testelement.property.CollectionProperty)2 NullProperty (org.apache.jmeter.testelement.property.NullProperty)2 JMeterContext (org.apache.jmeter.threads.JMeterContext)2