Search in sources :

Example 16 with Argument

use of org.apache.jmeter.config.Argument in project jmeter by apache.

the class AnchorModifier method process.

/**
     * Modifies an Entry object based on HTML response text.
     */
@Override
public void process() {
    JMeterContext context = getThreadContext();
    Sampler sam = context.getCurrentSampler();
    SampleResult res = context.getPreviousResult();
    HTTPSamplerBase sampler;
    HTTPSampleResult result;
    if (!(sam instanceof HTTPSamplerBase) || !(res instanceof HTTPSampleResult)) {
        log.info("Can't apply HTML Link Parser when the previous" + " sampler run is not an HTTP Request.");
        return;
    } else {
        sampler = (HTTPSamplerBase) sam;
        result = (HTTPSampleResult) res;
    }
    List<HTTPSamplerBase> potentialLinks = new ArrayList<>();
    String responseText = result.getResponseDataAsString();
    // $NON-NLS-1$
    int index = responseText.indexOf('<');
    if (index == -1) {
        index = 0;
    }
    if (log.isDebugEnabled()) {
        log.debug("Check for matches against: " + sampler.toString());
    }
    Document html = (Document) HtmlParsingUtils.getDOM(responseText.substring(index));
    addAnchorUrls(html, result, sampler, potentialLinks);
    addFormUrls(html, result, sampler, potentialLinks);
    addFramesetUrls(html, result, sampler, potentialLinks);
    if (!potentialLinks.isEmpty()) {
        HTTPSamplerBase url = potentialLinks.get(ThreadLocalRandom.current().nextInt(potentialLinks.size()));
        if (log.isDebugEnabled()) {
            log.debug("Selected: " + url.toString());
        }
        sampler.setDomain(url.getDomain());
        sampler.setPath(url.getPath());
        if (url.getMethod().equals(HTTPConstants.POST)) {
            for (JMeterProperty jMeterProperty : sampler.getArguments()) {
                Argument arg = (Argument) jMeterProperty.getObjectValue();
                modifyArgument(arg, url.getArguments());
            }
        } else {
            sampler.setArguments(url.getArguments());
        // config.parseArguments(url.getQueryString());
        }
        sampler.setProtocol(url.getProtocol());
    } else {
        log.debug("No matches found");
    }
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) Argument(org.apache.jmeter.config.Argument) JMeterContext(org.apache.jmeter.threads.JMeterContext) HTTPSampleResult(org.apache.jmeter.protocol.http.sampler.HTTPSampleResult) Sampler(org.apache.jmeter.samplers.Sampler) ArrayList(java.util.ArrayList) SampleResult(org.apache.jmeter.samplers.SampleResult) HTTPSampleResult(org.apache.jmeter.protocol.http.sampler.HTTPSampleResult) Document(org.w3c.dom.Document) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)

Example 17 with Argument

use of org.apache.jmeter.config.Argument in project jmeter by apache.

the class RegExUserParameters method process.

@Override
public void process() {
    if (log.isDebugEnabled()) {
        //$NON-NLS-1$
        log.debug(Thread.currentThread().getName() + " Running up named: " + getName());
    }
    Sampler entry = getThreadContext().getCurrentSampler();
    if (!(entry instanceof HTTPSamplerBase)) {
        return;
    }
    Map<String, String> paramMap = buildParamsMap();
    if (paramMap == null || paramMap.isEmpty()) {
        log.info("RegExUserParameters element:" + getName() + " => Referenced RegExp was not found, no parameter will be changed");
        return;
    }
    HTTPSamplerBase sampler = (HTTPSamplerBase) entry;
    for (JMeterProperty jMeterProperty : sampler.getArguments()) {
        Argument arg = (Argument) jMeterProperty.getObjectValue();
        String oldValue = arg.getValue();
        // if parameter name exists in http request
        // then change its value with value obtained with regular expression
        String val = paramMap.get(arg.getName());
        if (val != null) {
            arg.setValue(val);
        }
        if (log.isDebugEnabled()) {
            log.debug("RegExUserParameters element:" + getName() + " => changed parameter: " + arg.getName() + " = " + arg.getValue() + ", was:" + oldValue);
        }
    }
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) Argument(org.apache.jmeter.config.Argument) Sampler(org.apache.jmeter.samplers.Sampler) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)

Example 18 with Argument

use of org.apache.jmeter.config.Argument in project jmeter by apache.

the class TestTreeCloner method testCloning.

@Test
public void testCloning() throws Exception {
    ListedHashTree original = new ListedHashTree();
    GenericController controller = new GenericController();
    controller.setName("controller");
    Arguments args = new Arguments();
    args.setName("args");
    TestPlan plan = new TestPlan();
    plan.addParameter("server", "jakarta");
    original.add(controller, args);
    original.add(plan);
    ResultCollector listener = new ResultCollector();
    listener.setName("Collector");
    original.add(controller, listener);
    TreeCloner cloner = new TreeCloner();
    original.traverse(cloner);
    ListedHashTree newTree = cloner.getClonedTree();
    assertTrue(original != newTree);
    assertEquals(original.size(), newTree.size());
    assertEquals(original.getTree(original.getArray()[0]).size(), newTree.getTree(newTree.getArray()[0]).size());
    assertTrue(original.getArray()[0] != newTree.getArray()[0]);
    assertEquals(((GenericController) original.getArray()[0]).getName(), ((GenericController) newTree.getArray()[0]).getName());
    assertSame(original.getTree(original.getArray()[0]).getArray()[1], newTree.getTree(newTree.getArray()[0]).getArray()[1]);
    TestPlan clonedTestPlan = (TestPlan) newTree.getArray()[1];
    clonedTestPlan.setRunningVersion(true);
    clonedTestPlan.recoverRunningVersion();
    assertTrue(!plan.getUserDefinedVariablesAsProperty().isRunningVersion());
    assertTrue(clonedTestPlan.getUserDefinedVariablesAsProperty().isRunningVersion());
    Arguments vars = (Arguments) plan.getUserDefinedVariablesAsProperty().getObjectValue();
    PropertyIterator iter = ((CollectionProperty) vars.getProperty(Arguments.ARGUMENTS)).iterator();
    while (iter.hasNext()) {
        JMeterProperty argProp = iter.next();
        assertTrue(!argProp.isRunningVersion());
        assertTrue(argProp.getObjectValue() instanceof Argument);
        Argument arg = (Argument) argProp.getObjectValue();
        arg.setValue("yahoo");
        assertEquals("yahoo", arg.getValue());
    }
    vars = (Arguments) clonedTestPlan.getUserDefinedVariablesAsProperty().getObjectValue();
    iter = vars.propertyIterator();
    while (iter.hasNext()) {
        assertTrue(iter.next().isRunningVersion());
    }
}
Also used : ListedHashTree(org.apache.jorphan.collections.ListedHashTree) CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) Argument(org.apache.jmeter.config.Argument) TestPlan(org.apache.jmeter.testelement.TestPlan) Arguments(org.apache.jmeter.config.Arguments) PropertyIterator(org.apache.jmeter.testelement.property.PropertyIterator) GenericController(org.apache.jmeter.control.GenericController) ResultCollector(org.apache.jmeter.reporters.ResultCollector) Test(org.junit.Test)

Example 19 with Argument

use of org.apache.jmeter.config.Argument in project jmeter by apache.

the class TestArgumentsPanel method testArgumentCreation.

/**
         * Test that adding an argument to the table results in an appropriate
         * TestElement being created.
         * 
         * @throws Exception
         *             if an exception occurred during the test
         */
@Test
public void testArgumentCreation() throws Exception {
    ArgumentsPanel gui = new ArgumentsPanel();
    gui.tableModel.addRow(new Argument());
    gui.tableModel.setValueAt("howdy", 0, 0);
    gui.tableModel.addRow(new Argument());
    gui.tableModel.setValueAt("doody", 0, 1);
    assertEquals("=", ((Argument) ((Arguments) gui.createTestElement()).getArguments().get(0).getObjectValue()).getMetaData());
}
Also used : Argument(org.apache.jmeter.config.Argument) Arguments(org.apache.jmeter.config.Arguments) Test(org.junit.Test)

Example 20 with Argument

use of org.apache.jmeter.config.Argument in project jmeter by apache.

the class TestHTTPSamplers method testParseArguments2.

// Parse arguments all at once
@Test
public void testParseArguments2() {
    HTTPSamplerBase sampler = new HTTPNullSampler();
    Arguments args;
    Argument arg;
    args = sampler.getArguments();
    assertEquals(0, args.getArgumentCount());
    assertEquals(0, sampler.getHTTPFileCount());
    sampler.parseArguments("&name1&name2=&name3=value3");
    args = sampler.getArguments();
    assertEquals(3, args.getArgumentCount());
    assertEquals(0, sampler.getHTTPFileCount());
    arg = args.getArgument(0);
    assertEquals("name1", arg.getName());
    assertEquals("", arg.getMetaData());
    assertEquals("", arg.getValue());
    assertEquals(0, sampler.getHTTPFileCount());
    arg = args.getArgument(1);
    assertEquals("name2", arg.getName());
    assertEquals("=", arg.getMetaData());
    assertEquals("", arg.getValue());
    assertEquals(0, sampler.getHTTPFileCount());
    arg = args.getArgument(2);
    assertEquals("name3", arg.getName());
    assertEquals("=", arg.getMetaData());
    assertEquals("value3", arg.getValue());
    assertEquals(0, sampler.getHTTPFileCount());
}
Also used : Argument(org.apache.jmeter.config.Argument) Arguments(org.apache.jmeter.config.Arguments) Test(org.junit.Test)

Aggregations

Argument (org.apache.jmeter.config.Argument)28 Arguments (org.apache.jmeter.config.Arguments)13 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)11 Test (org.junit.Test)7 PropertyIterator (org.apache.jmeter.testelement.property.PropertyIterator)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 BasicAttribute (javax.naming.directory.BasicAttribute)3 CollectionProperty (org.apache.jmeter.testelement.property.CollectionProperty)3 File (java.io.File)2 BasicAttributes (javax.naming.directory.BasicAttributes)2 JTextField (javax.swing.JTextField)2 HTTPSampleResult (org.apache.jmeter.protocol.http.sampler.HTTPSampleResult)2 HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)2 HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)2 HTTPFileArgs (org.apache.jmeter.protocol.http.util.HTTPFileArgs)2 SampleResult (org.apache.jmeter.samplers.SampleResult)2 Sampler (org.apache.jmeter.samplers.Sampler)2 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 BufferedInputStream (java.io.BufferedInputStream)1