Search in sources :

Example 21 with StringProperty

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

the class HttpDefaultsGui method modifyTestElement.

/**
     * Modifies a given TestElement to mirror the data in the gui components.
     *
     * @see org.apache.jmeter.gui.JMeterGUIComponent#modifyTestElement(TestElement)
     */
@Override
public void modifyTestElement(TestElement config) {
    ConfigTestElement cfg = (ConfigTestElement) config;
    ConfigTestElement el = (ConfigTestElement) urlConfigGui.createTestElement();
    cfg.clear();
    cfg.addConfigElement(el);
    super.configureTestElement(config);
    if (retrieveEmbeddedResources.isSelected()) {
        config.setProperty(new BooleanProperty(HTTPSamplerBase.IMAGE_PARSER, true));
    } else {
        config.removeProperty(HTTPSamplerBase.IMAGE_PARSER);
    }
    enableConcurrentDwn(retrieveEmbeddedResources.isSelected());
    if (concurrentDwn.isSelected()) {
        config.setProperty(new BooleanProperty(HTTPSamplerBase.CONCURRENT_DWN, true));
    } else {
        // The default is false, so we can remove the property to simplify JMX files
        // This also allows HTTPDefaults to work for this checkbox
        config.removeProperty(HTTPSamplerBase.CONCURRENT_DWN);
    }
    if (!StringUtils.isEmpty(concurrentPool.getText())) {
        config.setProperty(new StringProperty(HTTPSamplerBase.CONCURRENT_POOL, concurrentPool.getText()));
    } else {
        config.setProperty(new StringProperty(HTTPSamplerBase.CONCURRENT_POOL, String.valueOf(HTTPSamplerBase.CONCURRENT_POOL_SIZE)));
    }
    if (useMD5.isSelected()) {
        config.setProperty(new BooleanProperty(HTTPSamplerBase.MD5, true));
    } else {
        config.removeProperty(HTTPSamplerBase.MD5);
    }
    if (!StringUtils.isEmpty(embeddedRE.getText())) {
        config.setProperty(new StringProperty(HTTPSamplerBase.EMBEDDED_URL_RE, embeddedRE.getText()));
    } else {
        config.removeProperty(HTTPSamplerBase.EMBEDDED_URL_RE);
    }
    if (!StringUtils.isEmpty(sourceIpAddr.getText())) {
        config.setProperty(new StringProperty(HTTPSamplerBase.IP_SOURCE, sourceIpAddr.getText()));
        config.setProperty(new IntegerProperty(HTTPSamplerBase.IP_SOURCE_TYPE, sourceIpType.getSelectedIndex()));
    } else {
        config.removeProperty(HTTPSamplerBase.IP_SOURCE);
        config.removeProperty(HTTPSamplerBase.IP_SOURCE_TYPE);
    }
    config.setProperty(HTTPSamplerBase.PROXYHOST, proxyHost.getText(), "");
    config.setProperty(HTTPSamplerBase.PROXYPORT, proxyPort.getText(), "");
    config.setProperty(HTTPSamplerBase.PROXYUSER, proxyUser.getText(), "");
    config.setProperty(HTTPSamplerBase.PROXYPASS, String.valueOf(proxyPass.getPassword()), "");
    config.setProperty(HTTPSamplerBase.IMPLEMENTATION, httpImplementation.getSelectedItem().toString(), "");
    config.setProperty(HTTPSamplerBase.CONNECT_TIMEOUT, connectTimeOut.getText());
    config.setProperty(HTTPSamplerBase.RESPONSE_TIMEOUT, responseTimeOut.getText());
}
Also used : IntegerProperty(org.apache.jmeter.testelement.property.IntegerProperty) BooleanProperty(org.apache.jmeter.testelement.property.BooleanProperty) StringProperty(org.apache.jmeter.testelement.property.StringProperty) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement)

Example 22 with StringProperty

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

the class TestLoopController method testBug54467.

@Test
public void testBug54467() throws Exception {
    JMeterContext jmctx = JMeterContextService.getContext();
    LoopController loop = new LoopController();
    Map<String, String> variables = new HashMap<>();
    ReplaceStringWithFunctions transformer = new ReplaceStringWithFunctions(new CompoundVariable(), variables);
    jmctx.setVariables(new JMeterVariables());
    StringProperty prop = new StringProperty(LoopController.LOOPS, "${__Random(1,12,)}");
    JMeterProperty newProp = transformer.transformValue(prop);
    newProp.setRunningVersion(true);
    loop.setProperty(newProp);
    loop.addTestElement(new TestSampler("random run"));
    loop.setRunningVersion(true);
    loop.initialize();
    int loops = loop.getLoops();
    for (int i = 0; i < loops; i++) {
        Sampler s = loop.next();
        assertNotNull(s);
    }
    assertNull(loop.next());
}
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) Sampler(org.apache.jmeter.samplers.Sampler) TestSampler(org.apache.jmeter.junit.stubs.TestSampler) Test(org.junit.Test)

Example 23 with StringProperty

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

the class TestValueReplacer method testReplaceStringWithBackslash.

@Test
public void testReplaceStringWithBackslash() 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(input, 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 24 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 25 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)

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