Search in sources :

Example 81 with Arguments

use of org.apache.jmeter.config.Arguments 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.jupiter.api.Test)

Example 82 with Arguments

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

the class JavaSampler method sample.

/**
 * Performs a test sample.
 *
 * The <code>sample()</code> method retrieves the reference to the Java
 * client and calls its <code>runTest()</code> method.
 *
 * @see JavaSamplerClient#runTest(JavaSamplerContext)
 *
 * @param entry
 *            the Entry for this sample
 * @return test SampleResult
 */
@Override
public SampleResult sample(Entry entry) {
    Arguments args = getArguments();
    // Allow Sampler access
    args.addArgument(TestElement.NAME, getName());
    // to test element name
    context = new JavaSamplerContext(args);
    if (javaClient == null) {
        if (log.isDebugEnabled()) {
            log.debug("{}\tCreating Java Client", whoAmI());
        }
        javaClient = createJavaClient();
        javaClient.setupTest(context);
    }
    SampleResult result = javaClient.runTest(context);
    // Only set the default label if it has not been set
    if (result != null && result.getSampleLabel().length() == 0) {
        result.setSampleLabel(getName());
    }
    return result;
}
Also used : Arguments(org.apache.jmeter.config.Arguments) SampleResult(org.apache.jmeter.samplers.SampleResult)

Example 83 with Arguments

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

the class SleepTest method getDefaultParameters.

/**
 * Provide a list of parameters which this test supports. Any parameter
 * names and associated values returned by this method will appear in the
 * GUI by default so the user doesn't have to remember the exact names. The
 * user can add other parameters which are not listed here. If this method
 * returns null then no parameters will be listed. If the value for some
 * parameter is null then that parameter will be listed in the GUI with an
 * empty value.
 *
 * @return a specification of the parameters used by this test which should
 *         be listed in the GUI, or null if no parameters should be listed.
 */
@Override
public Arguments getDefaultParameters() {
    Arguments params = new Arguments();
    params.addArgument("SleepTime", String.valueOf(DEFAULT_SLEEP_TIME));
    params.addArgument("SleepMask", "0x" + Long.toHexString(DEFAULT_SLEEP_MASK).toUpperCase(java.util.Locale.ENGLISH));
    return params;
}
Also used : Arguments(org.apache.jmeter.config.Arguments)

Example 84 with Arguments

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

the class JavaTest method getDefaultParameters.

/**
 * Provide a list of parameters which this test supports. Any parameter
 * names and associated values returned by this method will appear in the
 * GUI by default so the user doesn't have to remember the exact names. The
 * user can add other parameters which are not listed here. If this method
 * returns null then no parameters will be listed. If the value for some
 * parameter is null then that parameter will be listed in the GUI with an
 * empty value.
 *
 * @return a specification of the parameters used by this test which should
 *         be listed in the GUI, or null if no parameters should be listed.
 */
@Override
public Arguments getDefaultParameters() {
    Arguments params = new Arguments();
    params.addArgument(SLEEP_NAME, String.valueOf(DEFAULT_SLEEP_TIME));
    params.addArgument(MASK_NAME, DEFAULT_MASK_STRING);
    params.addArgument(LABEL_NAME, "");
    params.addArgument(RESPONSE_CODE_NAME, RESPONSE_CODE_DEFAULT);
    params.addArgument(RESPONSE_MESSAGE_NAME, RESPONSE_MESSAGE_DEFAULT);
    params.addArgument(SUCCESS_NAME, SUCCESS_DEFAULT);
    params.addArgument(SAMPLER_DATA_NAME, SAMPLER_DATA_DEFAULT);
    params.addArgument(RESULT_DATA_NAME, SAMPLER_DATA_DEFAULT);
    return params;
}
Also used : Arguments(org.apache.jmeter.config.Arguments)

Example 85 with Arguments

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

the class TestURLRewritingModifier method testGrabSessionIdURLinJSON.

@Test
public void testGrabSessionIdURLinJSON() throws Exception {
    String html = "<a href=\"#\" onclick=\"$(\'frame\').src=\'/index?param1=bla&sessionid=xyzxyzxyz\\'";
    response = new SampleResult();
    response.setResponseData(html, null);
    mod.setArgumentName("sessionid");
    HTTPSamplerBase sampler = createSampler();
    sampler.addArgument("sessionid", "xyzxyzxyz");
    context.setCurrentSampler(sampler);
    context.setPreviousResult(response);
    mod.process();
    Arguments args = sampler.getArguments();
    assertEquals("xyzxyzxyz", ((Argument) args.getArguments().get(0).getObjectValue()).getValue());
}
Also used : Arguments(org.apache.jmeter.config.Arguments) SampleResult(org.apache.jmeter.samplers.SampleResult) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase) Test(org.junit.jupiter.api.Test)

Aggregations

Arguments (org.apache.jmeter.config.Arguments)102 Test (org.junit.jupiter.api.Test)32 HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)18 SampleResult (org.apache.jmeter.samplers.SampleResult)17 Argument (org.apache.jmeter.config.Argument)15 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)11 HTTPArgument (org.apache.jmeter.protocol.http.util.HTTPArgument)10 Test (org.junit.Test)10 HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)7 JMeterVariables (org.apache.jmeter.threads.JMeterVariables)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)6 TestElement (org.apache.jmeter.testelement.TestElement)6 TestElementProperty (org.apache.jmeter.testelement.property.TestElementProperty)5 HTTPFileArgs (org.apache.jmeter.protocol.http.util.HTTPFileArgs)4 IOException (java.io.IOException)3 URL (java.net.URL)3 Iterator (java.util.Iterator)3 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)3 CollectionProperty (org.apache.jmeter.testelement.property.CollectionProperty)3