Search in sources :

Example 6 with HTTPSamplerBase

use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.

the class HTTPFileArgsPanel method modifyTestElement.

/**
 * Save the GUI data in the HTTPSamplerBase element.
 *
 * @param testElement {@link TestElement} to modify
 */
public void modifyTestElement(TestElement testElement) {
    GuiUtils.stopTableEditing(table);
    if (testElement instanceof HTTPSamplerBase) {
        HTTPSamplerBase base = (HTTPSamplerBase) testElement;
        int rows = tableModel.getRowCount();
        // we only put HTTPFileArgs in it
        @SuppressWarnings("unchecked") Iterator<HTTPFileArg> modelData = (Iterator<HTTPFileArg>) tableModel.iterator();
        HTTPFileArg[] files = new HTTPFileArg[rows];
        int row = 0;
        while (modelData.hasNext()) {
            HTTPFileArg file = modelData.next();
            files[row++] = file;
        }
        base.setHTTPFiles(files);
    }
}
Also used : Iterator(java.util.Iterator) HTTPFileArg(org.apache.jmeter.protocol.http.util.HTTPFileArg) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)

Example 7 with HTTPSamplerBase

use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.

the class HtmlParsingUtils method recurseForm.

// N.B. Since the tags are extracted from an HTML Form, any values must already have been encoded
@SuppressWarnings("JdkObsolete")
private static boolean recurseForm(Node tempNode, LinkedList<HTTPSamplerBase> urlConfigs, URL context, String selectName, boolean inForm) {
    NamedNodeMap nodeAtts = tempNode.getAttributes();
    String tag = tempNode.getNodeName();
    try {
        if (inForm) {
            HTTPSamplerBase url = urlConfigs.getLast();
            if (tag.equalsIgnoreCase("form")) {
                // $NON-NLS-1$
                try {
                    urlConfigs.add(createFormUrlConfig(tempNode, context));
                } catch (MalformedURLException e) {
                    inForm = false;
                }
            } else if (tag.equalsIgnoreCase("input")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                url.addEncodedArgument(// $NON-NLS-1$
                getAttributeValue(nodeAtts, "name"), // $NON-NLS-1$
                getAttributeValue(nodeAtts, "value"));
            } else if (tag.equalsIgnoreCase("textarea")) {
                // $NON-NLS-1$
                try {
                    // $NON-NLS-1$
                    url.addEncodedArgument(// $NON-NLS-1$
                    getAttributeValue(nodeAtts, "name"), tempNode.getFirstChild().getNodeValue());
                } catch (NullPointerException e) {
                    // $NON-NLS-1$
                    url.addArgument(getAttributeValue(nodeAtts, "name"), "");
                }
            } else if (tag.equalsIgnoreCase("select")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                selectName = getAttributeValue(nodeAtts, "name");
            } else if (tag.equalsIgnoreCase("option")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                String value = getAttributeValue(nodeAtts, "value");
                if (value == null) {
                    try {
                        value = tempNode.getFirstChild().getNodeValue();
                    } catch (NullPointerException e) {
                        // $NON-NLS-1$
                        value = "";
                    }
                }
                url.addEncodedArgument(selectName, value);
            }
        } else if (tag.equalsIgnoreCase("form")) {
            // $NON-NLS-1$
            try {
                urlConfigs.add(createFormUrlConfig(tempNode, context));
                inForm = true;
            } catch (MalformedURLException e) {
                inForm = false;
            }
        }
    } catch (Exception ex) {
        log.warn("Some bad HTML {}", printNode(tempNode), ex);
    }
    NodeList childNodes = tempNode.getChildNodes();
    for (int x = 0; x < childNodes.getLength(); x++) {
        inForm = recurseForm(childNodes.item(x), urlConfigs, context, selectName, inForm);
    }
    return inForm;
}
Also used : MalformedURLException(java.net.MalformedURLException) NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) MalformedURLException(java.net.MalformedURLException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)

Example 8 with HTTPSamplerBase

use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.

the class TestCookieManagerThreadIteration method testJmeterVariableCookieWhenThreadIterationIsANewUser.

@Test
public void testJmeterVariableCookieWhenThreadIterationIsANewUser() {
    jmvars.putObject(SAME_USER, true);
    jmctx.setVariables(jmvars);
    HTTPSamplerBase sampler = (HTTPSamplerBase) new HttpTestSampleGui().createTestElement();
    CookieManager cookieManager = new CookieManager();
    cookieManager.setControlledByThread(true);
    sampler.setCookieManager(cookieManager);
    sampler.setThreadContext(jmctx);
    boolean res = (boolean) cookieManager.getThreadContext().getVariables().getObject(SAME_USER);
    assertTrue("When test different users on the different iternations, the cookie should be cleared", res);
}
Also used : HttpTestSampleGui(org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase) Test(org.junit.jupiter.api.Test)

Example 9 with HTTPSamplerBase

use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.

the class TestCookieManagerThreadIteration method testJmeterVariableCookieWhenThreadIterationIsSameUser.

@Test
public void testJmeterVariableCookieWhenThreadIterationIsSameUser() {
    jmvars.putObject(SAME_USER, false);
    jmctx.setVariables(jmvars);
    HTTPSamplerBase sampler = (HTTPSamplerBase) new HttpTestSampleGui().createTestElement();
    CookieManager cookieManager = new CookieManager();
    cookieManager.setControlledByThread(true);
    sampler.setCookieManager(cookieManager);
    sampler.setThreadContext(jmctx);
    boolean res = (boolean) cookieManager.getThreadContext().getVariables().getObject(SAME_USER);
    assertFalse("When test same user on the different iternations, the cookie shouldn't be cleared", res);
}
Also used : HttpTestSampleGui(org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase) Test(org.junit.jupiter.api.Test)

Example 10 with HTTPSamplerBase

use of org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase in project jmeter by apache.

the class DnsManagerTest method badDnsInCustomResolverShouldFailHttpSampler.

@ParameterizedTest
@MethodSource("org.apache.jmeter.protocol.http.sampler.HTTPSamplerFactory#getImplementations")
void badDnsInCustomResolverShouldFailHttpSampler(String httpImplementation, WireMockServer server) {
    Assumptions.assumeTrue(!HTTPSamplerFactory.IMPL_JAVA.equals(httpImplementation), "Java implementation does not support custom DNS resolver yet");
    DNSCacheManager dns = new DNSCacheManager();
    dns.setCustomResolver(true);
    dns.addServer("20.0.118.11");
    // By default it uses 3 retries (see org.xbill.DNS.ExtendedResolver#setRetries)
    dns.setTimeoutMs(2000);
    HTTPSamplerBase http = HTTPSamplerFactory.newInstance(httpImplementation);
    http.setDNSResolver(dns);
    http.setMethod(HTTPSampler.GET);
    http.setPort(server.port());
    http.setDomain("localhost");
    http.setPath("/index.html");
    http.setRunningVersion(true);
    SampleResult result = http.sample();
    Assertions.assertEquals("Non HTTP response message: Failed to resolve host name: localhost", result.getResponseMessage(), () -> "HTTP is using a custom DNS resolver, so it must fail resolving localhost \n" + ResultAsString.toString(result));
}
Also used : SampleResult(org.apache.jmeter.samplers.SampleResult) HTTPSamplerBase(org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)65 Test (org.junit.jupiter.api.Test)40 SampleResult (org.apache.jmeter.samplers.SampleResult)20 Arguments (org.apache.jmeter.config.Arguments)18 HTTPSampleResult (org.apache.jmeter.protocol.http.sampler.HTTPSampleResult)14 HTTPNullSampler (org.apache.jmeter.protocol.http.sampler.HTTPNullSampler)6 HttpTestSampleGui (org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui)5 NodeList (org.w3c.dom.NodeList)4 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)3 Sampler (org.apache.jmeter.samplers.Sampler)3 NamedNodeMap (org.w3c.dom.NamedNodeMap)3 ClientCookie (org.apache.http.cookie.ClientCookie)2 BasicClientCookie (org.apache.http.impl.cookie.BasicClientCookie)2 Argument (org.apache.jmeter.config.Argument)2 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)2 JMeterContext (org.apache.jmeter.threads.JMeterContext)2 Node (org.w3c.dom.Node)2