Search in sources :

Example 11 with ConfigTestElement

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

the class ProxyControl method removeValuesFromSampler.

/**
     * Remove from the sampler all values which match the one provided by the
     * first configuration in the given collection which provides a value for
     * that property.
     *
     * @param sampler
     *            Sampler to remove values from.
     * @param configurations
     *            ConfigTestElements in descending priority.
     */
private void removeValuesFromSampler(HTTPSamplerBase sampler, Collection<ConfigTestElement> configurations) {
    for (PropertyIterator props = sampler.propertyIterator(); props.hasNext(); ) {
        JMeterProperty prop = props.next();
        String name = prop.getName();
        String value = prop.getStringValue();
        // There's a few properties which are excluded from this processing:
        if (name.equals(TestElement.ENABLED) || name.equals(TestElement.GUI_CLASS) || name.equals(TestElement.NAME) || name.equals(TestElement.TEST_CLASS)) {
            // go on with next property.
            continue;
        }
        for (ConfigTestElement config : configurations) {
            String configValue = config.getPropertyAsString(name);
            if (configValue != null && configValue.length() > 0) {
                if (configValue.equals(value)) {
                    // $NON-NLS-1$
                    sampler.setProperty(name, "");
                }
                // this property -- don't look at lower-priority configs:
                break;
            }
        }
    }
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) PropertyIterator(org.apache.jmeter.testelement.property.PropertyIterator) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement)

Example 12 with ConfigTestElement

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

the class ProxyControl method deliverSampler.

/**
     * Receives the recorded sampler from the proxy server for placing in the
     * test tree; this is skipped if the sampler is null (e.g. for recording SSL errors)
     * Always sends the result to any registered sample listeners.
     *
     * @param sampler the sampler, may be null
     * @param testElements the test elements to be added (e.g. header manager) under the Sampler
     * @param result the sample result, not null
     * TODO param serverResponse to be added to allow saving of the
     * server's response while recording.
     */
public synchronized void deliverSampler(final HTTPSamplerBase sampler, final TestElement[] testElements, final SampleResult result) {
    boolean notifySampleListeners = true;
    if (sampler != null) {
        if (ATTEMPT_REDIRECT_DISABLING && (samplerRedirectAutomatically || samplerFollowRedirects) && result instanceof HTTPSampleResult) {
            final HTTPSampleResult httpSampleResult = (HTTPSampleResult) result;
            final String urlAsString = httpSampleResult.getUrlAsString();
            if (urlAsString.equals(LAST_REDIRECT)) {
                // the url matches the last redirect
                sampler.setEnabled(false);
                sampler.setComment("Detected a redirect from the previous sample");
            } else {
                // this is not the result of a redirect
                // so break the chain
                LAST_REDIRECT = null;
            }
            if (httpSampleResult.isRedirect()) {
                // Save Location so resulting sample can be disabled
                if (LAST_REDIRECT == null) {
                    sampler.setComment("Detected the start of a redirect chain");
                }
                LAST_REDIRECT = httpSampleResult.getRedirectLocation();
            } else {
                LAST_REDIRECT = null;
            }
        }
        if (filterContentType(result) && filterUrl(sampler)) {
            JMeterTreeNode myTarget = findTargetControllerNode();
            // OK, because find only returns correct element types
            @SuppressWarnings("unchecked") Collection<ConfigTestElement> defaultConfigurations = (Collection<ConfigTestElement>) findApplicableElements(myTarget, ConfigTestElement.class, false);
            // OK, because find only returns correct element types
            @SuppressWarnings("unchecked") Collection<Arguments> userDefinedVariables = (Collection<Arguments>) findApplicableElements(myTarget, Arguments.class, true);
            removeValuesFromSampler(sampler, defaultConfigurations);
            replaceValues(sampler, testElements, userDefinedVariables);
            sampler.setAutoRedirects(samplerRedirectAutomatically);
            sampler.setFollowRedirects(samplerFollowRedirects);
            sampler.setUseKeepAlive(useKeepAlive);
            sampler.setImageParser(samplerDownloadImages);
            String prefix = getPrefixHTTPSampleName();
            if (!StringUtils.isEmpty(prefix)) {
                sampler.setName(prefix + sampler.getName());
                result.setSampleLabel(prefix + result.getSampleLabel());
            }
            Authorization authorization = createAuthorization(testElements, sampler);
            if (authorization != null) {
                setAuthorization(authorization, myTarget);
            }
            placeSampler(sampler, testElements, myTarget);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Sample excluded based on url or content-type: " + result.getUrlAsString() + " - " + result.getContentType());
            }
            notifySampleListeners = notifyChildSamplerListenersOfFilteredSamples;
            result.setSampleLabel("[" + result.getSampleLabel() + "]");
        }
    }
    if (notifySampleListeners) {
        // SampleEvent is not passed JMeterVariables, because they don't make sense for Proxy Recording
        notifySampleListeners(new SampleEvent(result, "WorkBench"));
    } else {
        log.debug("Sample not delivered to Child Sampler Listener based on url or content-type: " + result.getUrlAsString() + " - " + result.getContentType());
    }
}
Also used : Authorization(org.apache.jmeter.protocol.http.control.Authorization) HTTPSampleResult(org.apache.jmeter.protocol.http.sampler.HTTPSampleResult) Arguments(org.apache.jmeter.config.Arguments) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) Collection(java.util.Collection) SampleEvent(org.apache.jmeter.samplers.SampleEvent) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement)

Example 13 with ConfigTestElement

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

the class TestValueReplacer method testReplace.

@Test
public void testReplace() throws Exception {
    ValueReplacer replacer = new ValueReplacer();
    replacer.setUserDefinedVariables(variables.getUserDefinedVariables());
    TestElement element = new ConfigTestElement();
    element.setProperty(new StringProperty("domain", "${server}"));
    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 14 with ConfigTestElement

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

the class TestCompiler method saveTransactionControllerConfigs.

private void saveTransactionControllerConfigs(TransactionController tc) {
    List<ConfigTestElement> configs = new LinkedList<>();
    List<Controller> controllers = new LinkedList<>();
    List<SampleListener> listeners = new LinkedList<>();
    List<Timer> timers = new LinkedList<>();
    List<Assertion> assertions = new LinkedList<>();
    LinkedList<PostProcessor> posts = new LinkedList<>();
    LinkedList<PreProcessor> pres = new LinkedList<>();
    for (int i = stack.size(); i > 0; i--) {
        addDirectParentControllers(controllers, stack.get(i - 1));
        for (Object item : testTree.list(stack.subList(0, i))) {
            if (item instanceof SampleListener) {
                listeners.add((SampleListener) item);
            }
            if (item instanceof Assertion) {
                assertions.add((Assertion) item);
            }
        }
    }
    SamplePackage pack = new SamplePackage(configs, listeners, timers, assertions, posts, pres, controllers);
    pack.setSampler(new TransactionSampler(tc, tc.getName()));
    pack.setRunningVersion(true);
    transactionControllerConfigMap.put(tc, pack);
}
Also used : Assertion(org.apache.jmeter.assertions.Assertion) PreProcessor(org.apache.jmeter.processor.PreProcessor) Controller(org.apache.jmeter.control.Controller) TransactionController(org.apache.jmeter.control.TransactionController) SampleListener(org.apache.jmeter.samplers.SampleListener) LinkedList(java.util.LinkedList) Timer(org.apache.jmeter.timers.Timer) TransactionSampler(org.apache.jmeter.control.TransactionSampler) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement) PostProcessor(org.apache.jmeter.processor.PostProcessor)

Example 15 with ConfigTestElement

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

the class LdapConfigGui method createTestElement.

/* Implements JMeterGUIComponent.createTestElement() */
@Override
public TestElement createTestElement() {
    ConfigTestElement element = new ConfigTestElement();
    modifyTestElement(element);
    return element;
}
Also used : ConfigTestElement(org.apache.jmeter.config.ConfigTestElement)

Aggregations

ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)22 TestElement (org.apache.jmeter.testelement.TestElement)7 Test (org.junit.Test)6 StringProperty (org.apache.jmeter.testelement.property.StringProperty)5 Arguments (org.apache.jmeter.config.Arguments)3 TestElementProperty (org.apache.jmeter.testelement.property.TestElementProperty)3 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)2 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 Assertion (org.apache.jmeter.assertions.Assertion)1 LoginConfig (org.apache.jmeter.config.LoginConfig)1 Controller (org.apache.jmeter.control.Controller)1 GenericController (org.apache.jmeter.control.GenericController)1 TransactionController (org.apache.jmeter.control.TransactionController)1 TransactionSampler (org.apache.jmeter.control.TransactionSampler)1 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)1 PostProcessor (org.apache.jmeter.processor.PostProcessor)1 PreProcessor (org.apache.jmeter.processor.PreProcessor)1 HttpDefaultsGui (org.apache.jmeter.protocol.http.config.gui.HttpDefaultsGui)1 Authorization (org.apache.jmeter.protocol.http.control.Authorization)1