Search in sources :

Example 36 with TestElement

use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.

the class JMeterThread method notifyTestListeners.

void notifyTestListeners() {
    threadVars.incIteration();
    for (TestIterationListener listener : testIterationStartListeners) {
        if (listener instanceof TestElement) {
            listener.testIterationStart(new LoopIterationEvent(threadGroupLoopController, threadVars.getIteration()));
            ((TestElement) listener).recoverRunningVersion();
        } else {
            listener.testIterationStart(new LoopIterationEvent(threadGroupLoopController, threadVars.getIteration()));
        }
    }
}
Also used : TestIterationListener(org.apache.jmeter.testelement.TestIterationListener) TestElement(org.apache.jmeter.testelement.TestElement) AbstractTestElement(org.apache.jmeter.testelement.AbstractTestElement) LoopIterationEvent(org.apache.jmeter.engine.event.LoopIterationEvent)

Example 37 with TestElement

use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.

the class FindTestElementsUpToRootTraverser method getControllersToRoot.

/**
     * Returns all controllers that where in Tree down to nodeToFind in reverse order (from leaf to root)
     * @return List of {@link Controller}
     */
public List<Controller> getControllersToRoot() {
    List<Controller> result = new ArrayList<>(stack.size());
    LinkedList<TestElement> stackLocalCopy = new LinkedList<>(stack);
    while (!stackLocalCopy.isEmpty()) {
        TestElement te = stackLocalCopy.getLast();
        if (te instanceof Controller) {
            result.add((Controller) te);
        }
        stackLocalCopy.removeLast();
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Controller(org.apache.jmeter.control.Controller) TestElement(org.apache.jmeter.testelement.TestElement) LinkedList(java.util.LinkedList)

Example 38 with TestElement

use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.

the class ProxyControl method addTimers.

/**
     * Helper method to replicate any timers found within the Proxy Controller
     * into the provided sampler, while replacing any occurrences of string _T_
     * in the timer's configuration with the provided deltaT.
     * Called from AWT Event thread
     * @param model
     *            Test component tree model
     * @param node
     *            Sampler node in where we will add the timers
     * @param deltaT
     *            Time interval from the previous request
     */
private void addTimers(JMeterTreeModel model, JMeterTreeNode node, long deltaT) {
    TestPlan variables = new TestPlan();
    // $NON-NLS-1$
    variables.addParameter("T", Long.toString(deltaT));
    ValueReplacer replacer = new ValueReplacer(variables);
    JMeterTreeNode mySelf = model.getNodeOf(this);
    Enumeration<JMeterTreeNode> children = mySelf.children();
    while (children.hasMoreElements()) {
        JMeterTreeNode templateNode = children.nextElement();
        if (templateNode.isEnabled()) {
            TestElement template = templateNode.getTestElement();
            if (template instanceof Timer) {
                TestElement timer = (TestElement) template.clone();
                try {
                    timer.setComment("Recorded:" + Long.toString(deltaT) + "ms");
                    replacer.undoReverseReplace(timer);
                    model.addComponent(timer, node);
                } catch (InvalidVariableException | IllegalUserActionException e) {
                    // Not 100% sure, but I believe this can't happen, so
                    // I'll log and throw an error:
                    log.error("Program error", e);
                    throw new Error(e);
                }
            }
        }
    }
}
Also used : InvalidVariableException(org.apache.jmeter.functions.InvalidVariableException) Timer(org.apache.jmeter.timers.Timer) TestPlan(org.apache.jmeter.testelement.TestPlan) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) ValueReplacer(org.apache.jmeter.engine.util.ValueReplacer) TestElement(org.apache.jmeter.testelement.TestElement) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement)

Example 39 with TestElement

use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.

the class ProxyControl method createAuthorization.

/**
     * Detect Header manager in subConfigs,
     * Find(if any) Authorization header
     * Construct Authentication object
     * Removes Authorization if present 
     *
     * @param subConfigs {@link TestElement}[]
     * @param sampler {@link HTTPSamplerBase}
     * @return {@link Authorization}
     */
private Authorization createAuthorization(final TestElement[] testElements, HTTPSamplerBase sampler) {
    Header authHeader;
    Authorization authorization = null;
    // Iterate over subconfig elements searching for HeaderManager
    for (TestElement te : testElements) {
        if (te instanceof HeaderManager) {
            // headers should only contain the correct classes
            @SuppressWarnings("unchecked") List<TestElementProperty> headers = (ArrayList<TestElementProperty>) ((HeaderManager) te).getHeaders().getObjectValue();
            for (Iterator<?> iterator = headers.iterator(); iterator.hasNext(); ) {
                TestElementProperty tep = (TestElementProperty) iterator.next();
                if (tep.getName().equals(HTTPConstants.HEADER_AUTHORIZATION)) {
                    //Construct Authorization object from HEADER_AUTHORIZATION
                    authHeader = (Header) tep.getObjectValue();
                    //$NON-NLS-1$
                    String[] authHeaderContent = authHeader.getValue().split(" ");
                    String authType;
                    String authCredentialsBase64;
                    if (authHeaderContent.length >= 2) {
                        authType = authHeaderContent[0];
                        authCredentialsBase64 = authHeaderContent[1];
                        authorization = new Authorization();
                        try {
                            authorization.setURL(sampler.getUrl().toExternalForm());
                        } catch (MalformedURLException e) {
                            log.error("Error filling url on authorization, message:" + e.getMessage(), e);
                            //$NON-NLS-1$
                            authorization.setURL("${AUTH_BASE_URL}");
                        }
                        // if HEADER_AUTHORIZATION contains "Basic"
                        // then set Mechanism.BASIC_DIGEST, otherwise Mechanism.KERBEROS
                        authorization.setMechanism(authType.equals(BASIC_AUTH) || authType.equals(DIGEST_AUTH) ? AuthManager.Mechanism.BASIC_DIGEST : AuthManager.Mechanism.KERBEROS);
                        if (BASIC_AUTH.equals(authType)) {
                            String authCred = new String(Base64.decodeBase64(authCredentialsBase64));
                            //$NON-NLS-1$
                            String[] loginPassword = authCred.split(":");
                            authorization.setUser(loginPassword[0]);
                            authorization.setPass(loginPassword[1]);
                        } else {
                            // Digest or Kerberos
                            //$NON-NLS-1$
                            authorization.setUser("${AUTH_LOGIN}");
                            //$NON-NLS-1$
                            authorization.setPass("${AUTH_PASSWORD}");
                        }
                    }
                    // remove HEADER_AUTHORIZATION from HeaderManager 
                    // because it's useless after creating Authorization object
                    iterator.remove();
                }
            }
        }
    }
    return authorization;
}
Also used : Authorization(org.apache.jmeter.protocol.http.control.Authorization) MalformedURLException(java.net.MalformedURLException) Header(org.apache.jmeter.protocol.http.control.Header) TestElementProperty(org.apache.jmeter.testelement.property.TestElementProperty) ArrayList(java.util.ArrayList) TestElement(org.apache.jmeter.testelement.TestElement) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement) HeaderManager(org.apache.jmeter.protocol.http.control.HeaderManager)

Example 40 with TestElement

use of org.apache.jmeter.testelement.TestElement in project jmeter by apache.

the class ProxyControl method findApplicableElements.

/**
     * Finds all configuration objects of the given class applicable to the
     * recorded samplers, that is:
     * <ul>
     * <li>All such elements directly within the HTTP(S) Test Script Recorder (these have
     * the highest priority).
     * <li>All such elements directly within the target controller (higher
     * priority) or directly within any containing controller (lower priority),
     * including the Test Plan itself (lowest priority).
     * </ul>
     *
     * @param myTarget
     *            tree node for the recording target controller.
     * @param myClass
     *            Class of the elements to be found.
     * @param ascending
     *            true if returned elements should be ordered in ascending
     *            priority, false if they should be in descending priority.
     *
     * @return a collection of applicable objects of the given class.
     */
// TODO - could be converted to generic class?
private Collection<?> findApplicableElements(JMeterTreeNode myTarget, Class<? extends TestElement> myClass, boolean ascending) {
    JMeterTreeModel treeModel = getJmeterTreeModel();
    LinkedList<TestElement> elements = new LinkedList<>();
    // Look for elements directly within the HTTP proxy:
    Enumeration<?> kids = treeModel.getNodeOf(this).children();
    while (kids.hasMoreElements()) {
        JMeterTreeNode subNode = (JMeterTreeNode) kids.nextElement();
        if (subNode.isEnabled()) {
            TestElement element = (TestElement) subNode.getUserObject();
            if (myClass.isInstance(element)) {
                if (ascending) {
                    elements.addFirst(element);
                } else {
                    elements.add(element);
                }
            }
        }
    }
    // Look for arguments elements in the target controller or higher up:
    for (JMeterTreeNode controller = myTarget; controller != null; controller = (JMeterTreeNode) controller.getParent()) {
        kids = controller.children();
        while (kids.hasMoreElements()) {
            JMeterTreeNode subNode = (JMeterTreeNode) kids.nextElement();
            if (subNode.isEnabled()) {
                TestElement element = (TestElement) subNode.getUserObject();
                if (myClass.isInstance(element)) {
                    log.debug("Applicable: " + element.getName());
                    if (ascending) {
                        elements.addFirst(element);
                    } else {
                        elements.add(element);
                    }
                }
                // Special case for the TestPlan's Arguments sub-element:
                if (element instanceof TestPlan) {
                    TestPlan tp = (TestPlan) element;
                    Arguments args = tp.getArguments();
                    if (myClass.isInstance(args)) {
                        if (ascending) {
                            elements.addFirst(args);
                        } else {
                            elements.add(args);
                        }
                    }
                }
            }
        }
    }
    return elements;
}
Also used : JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) TestPlan(org.apache.jmeter.testelement.TestPlan) Arguments(org.apache.jmeter.config.Arguments) JMeterTreeNode(org.apache.jmeter.gui.tree.JMeterTreeNode) TestElement(org.apache.jmeter.testelement.TestElement) ConfigTestElement(org.apache.jmeter.config.ConfigTestElement) LinkedList(java.util.LinkedList)

Aggregations

TestElement (org.apache.jmeter.testelement.TestElement)83 Test (org.junit.Test)27 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)26 TestSampler (org.apache.jmeter.junit.stubs.TestSampler)21 JMeterTreeNode (org.apache.jmeter.gui.tree.JMeterTreeNode)18 TestPlan (org.apache.jmeter.testelement.TestPlan)12 ArrayList (java.util.ArrayList)9 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)9 StringProperty (org.apache.jmeter.testelement.property.StringProperty)7 Controller (org.apache.jmeter.control.Controller)6 JMeterTreeModel (org.apache.jmeter.gui.tree.JMeterTreeModel)6 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)6 TreePath (javax.swing.tree.TreePath)5 GuiPackage (org.apache.jmeter.gui.GuiPackage)5 ActionEvent (java.awt.event.ActionEvent)4 IOException (java.io.IOException)4 LinkedList (java.util.LinkedList)4 Arguments (org.apache.jmeter.config.Arguments)4 WorkBench (org.apache.jmeter.testelement.WorkBench)4 TestElementProperty (org.apache.jmeter.testelement.property.TestElementProperty)4