Search in sources :

Example 11 with Argument

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

the class SmtpPanel method getHeaderFields.

public CollectionProperty getHeaderFields() {
    CollectionProperty result = new CollectionProperty();
    result.setName(SmtpSampler.HEADER_FIELDS);
    for (JTextField headerName : headerFields.keySet()) {
        String name = headerName.getText();
        String value = headerFields.get(headerName).getText();
        Argument argument = new Argument(name, value);
        result.addItem(argument);
    }
    return result;
}
Also used : CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) Argument(org.apache.jmeter.config.Argument) JTextField(javax.swing.JTextField)

Example 12 with Argument

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

the class LDAPExtSampler method getUserAttributes.

/***************************************************************************
     * Collect all the values from the table (Arguments), using this create the
     * Attributes, this will create the Attributes for the User
     * defined TestCase for Add Test
     *
     * @return The Attributes
     **************************************************************************/
private Attributes getUserAttributes() {
    Attributes attrs = new BasicAttributes(true);
    Attribute attr;
    for (JMeterProperty jMeterProperty : getArguments()) {
        Argument item = (Argument) jMeterProperty.getObjectValue();
        attr = attrs.get(item.getName());
        if (attr == null) {
            attr = getBasicAttribute(item.getName(), item.getValue());
        } else {
            attr.add(item.getValue());
        }
        attrs.put(attr);
    }
    return attrs;
}
Also used : BasicAttributes(javax.naming.directory.BasicAttributes) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) LDAPArgument(org.apache.jmeter.protocol.ldap.config.gui.LDAPArgument) Argument(org.apache.jmeter.config.Argument) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes)

Example 13 with Argument

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

the class LDAPSampler method getUserModAttributes.

/**
     * Collect all the value from the table (Arguments), using this create the
     * basicAttributes. This will create the Basic Attributes for the User
     * defined TestCase for Modify test.
     *
     * @return the BasicAttributes
     */
private ModificationItem[] getUserModAttributes() {
    ModificationItem[] mods = new ModificationItem[getArguments().getArguments().size()];
    BasicAttribute attr;
    PropertyIterator iter = getArguments().iterator();
    int count = 0;
    while (iter.hasNext()) {
        Argument item = (Argument) iter.next().getObjectValue();
        attr = getBasicAttribute(item.getName(), item.getValue());
        mods[count] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, attr);
        count = +1;
    }
    return mods;
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) ModificationItem(javax.naming.directory.ModificationItem) Argument(org.apache.jmeter.config.Argument) PropertyIterator(org.apache.jmeter.testelement.property.PropertyIterator)

Example 14 with Argument

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

the class SystemSampler method sample.

/**
     * Performs a test sample.
     * 
     * @param entry
     *            the Entry for this sample
     * @return test SampleResult
     */
@Override
public SampleResult sample(Entry entry) {
    SampleResult results = new SampleResult();
    results.setDataType(SampleResult.TEXT);
    results.setSampleLabel(getName());
    String command = getCommand();
    Arguments args = getArguments();
    Arguments environment = getEnvironmentVariables();
    boolean checkReturnCode = getCheckReturnCode();
    int expectedReturnCode = getExpectedReturnCode();
    List<String> cmds = new ArrayList<>(args.getArgumentCount() + 1);
    StringBuilder cmdLine = new StringBuilder((null == command) ? "" : command);
    cmds.add(command);
    for (int i = 0; i < args.getArgumentCount(); i++) {
        Argument arg = args.getArgument(i);
        cmds.add(arg.getPropertyAsString(Argument.VALUE));
        cmdLine.append(" ");
        cmdLine.append(cmds.get(i + 1));
    }
    Map<String, String> env = new HashMap<>();
    for (int i = 0; i < environment.getArgumentCount(); i++) {
        Argument arg = environment.getArgument(i);
        env.put(arg.getName(), arg.getPropertyAsString(Argument.VALUE));
    }
    File directory;
    if (StringUtils.isEmpty(getDirectory())) {
        directory = new File(FileServer.getDefaultBase());
        if (log.isDebugEnabled()) {
            log.debug("Using default directory:" + directory.getAbsolutePath());
        }
    } else {
        directory = new File(getDirectory());
        if (log.isDebugEnabled()) {
            log.debug("Using configured directory:" + directory.getAbsolutePath());
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Will run : " + cmdLine + " using working directory:" + directory.getAbsolutePath() + " with environment: " + env);
    }
    results.setSamplerData("Working Directory: " + directory.getAbsolutePath() + "\nEnvironment: " + env + "\nExecuting: " + cmdLine.toString());
    SystemCommand nativeCommand = null;
    try {
        nativeCommand = new SystemCommand(directory, getTimeout(), POLL_INTERVAL, env, getStdin(), getStdout(), getStderr());
        results.sampleStart();
        int returnCode = nativeCommand.run(cmds);
        results.sampleEnd();
        results.setResponseCode(Integer.toString(returnCode));
        if (log.isDebugEnabled()) {
            log.debug("Ran : " + cmdLine + " using working directory: " + directory.getAbsolutePath() + " with execution environment: " + nativeCommand.getExecutionEnvironment() + " => " + returnCode);
        }
        if (checkReturnCode && (returnCode != expectedReturnCode)) {
            results.setSuccessful(false);
            results.setResponseMessage("Unexpected return code.  Expected [" + expectedReturnCode + "]. Actual [" + returnCode + "].");
        } else {
            results.setSuccessful(true);
            results.setResponseMessage("OK");
        }
    } catch (IOException ioe) {
        results.sampleEnd();
        results.setSuccessful(false);
        //$NON-NLS-1$
        results.setResponseCode("500");
        results.setResponseMessage("Exception occurred whilst executing system call: " + ioe);
    } catch (InterruptedException ie) {
        results.sampleEnd();
        results.setSuccessful(false);
        //$NON-NLS-1$
        results.setResponseCode("500");
        results.setResponseMessage("System Sampler interrupted whilst executing system call: " + ie);
        Thread.currentThread().interrupt();
    }
    if (nativeCommand != null) {
        // default charset is deliberate here
        results.setResponseData(nativeCommand.getOutResult().getBytes());
    }
    return results;
}
Also used : Argument(org.apache.jmeter.config.Argument) HashMap(java.util.HashMap) Arguments(org.apache.jmeter.config.Arguments) ArrayList(java.util.ArrayList) SystemCommand(org.apache.jorphan.exec.SystemCommand) IOException(java.io.IOException) SampleResult(org.apache.jmeter.samplers.SampleResult) File(java.io.File)

Example 15 with Argument

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

the class HtmlParsingUtils method isAnchorMatched.

/**
     * Check if anchor matches by checking against:
     * - protocol
     * - domain
     * - path
     * - parameter names
     *
     * @param newLink target to match
     * @param config pattern to match against
     *
     * @return true if target URL matches pattern URL
     */
public static boolean isAnchorMatched(HTTPSamplerBase newLink, HTTPSamplerBase config) {
    String query = null;
    try {
        query = URLDecoder.decode(newLink.getQueryString(), StandardCharsets.UTF_8.name());
    } catch (UnsupportedEncodingException e) {
        // UTF-8 unsupported? You must be joking!
        log.error("UTF-8 encoding not supported!");
        throw new Error("Should not happen: " + e.toString(), e);
    }
    final Arguments arguments = config.getArguments();
    final Perl5Matcher matcher = JMeterUtils.getMatcher();
    final PatternCacheLRU patternCache = JMeterUtils.getPatternCache();
    if (!isEqualOrMatches(newLink.getProtocol(), config.getProtocol(), matcher, patternCache)) {
        return false;
    }
    final String domain = config.getDomain();
    if (domain != null && domain.length() > 0) {
        if (!isEqualOrMatches(newLink.getDomain(), domain, matcher, patternCache)) {
            return false;
        }
    }
    final String path = config.getPath();
    if (!newLink.getPath().equals(path) && !matcher.matches(newLink.getPath(), // $NON-NLS-1$
    patternCache.getPattern(// $NON-NLS-1$
    "[/]*" + path, Perl5Compiler.READ_ONLY_MASK))) {
        return false;
    }
    for (JMeterProperty argument : arguments) {
        Argument item = (Argument) argument.getObjectValue();
        final String name = item.getName();
        if (!query.contains(name + "=")) {
            // $NON-NLS-1$
            if (!(matcher.contains(query, patternCache.getPattern(name, Perl5Compiler.READ_ONLY_MASK)))) {
                return false;
            }
        }
    }
    return true;
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) Argument(org.apache.jmeter.config.Argument) Arguments(org.apache.jmeter.config.Arguments) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) PatternCacheLRU(org.apache.oro.text.PatternCacheLRU)

Aggregations

Argument (org.apache.jmeter.config.Argument)28 Arguments (org.apache.jmeter.config.Arguments)13 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)11 Test (org.junit.Test)7 PropertyIterator (org.apache.jmeter.testelement.property.PropertyIterator)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 BasicAttribute (javax.naming.directory.BasicAttribute)3 CollectionProperty (org.apache.jmeter.testelement.property.CollectionProperty)3 File (java.io.File)2 BasicAttributes (javax.naming.directory.BasicAttributes)2 JTextField (javax.swing.JTextField)2 HTTPSampleResult (org.apache.jmeter.protocol.http.sampler.HTTPSampleResult)2 HTTPSamplerBase (org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase)2 HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)2 HTTPFileArgs (org.apache.jmeter.protocol.http.util.HTTPFileArgs)2 SampleResult (org.apache.jmeter.samplers.SampleResult)2 Sampler (org.apache.jmeter.samplers.Sampler)2 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 BufferedInputStream (java.io.BufferedInputStream)1