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()));
}
}
}
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;
}
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);
}
}
}
}
}
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;
}
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;
}
Aggregations