Search in sources :

Example 41 with CollectionProperty

use of org.apache.jmeter.testelement.property.CollectionProperty in project jmeter by apache.

the class SmtpSamplerGui method configure.

/**
 * Copy the data from the test element to the GUI, method has to be implemented by interface
 * @param element Test-element to be used as data-input
 * @see org.apache.jmeter.gui.AbstractJMeterGuiComponent#configure(org.apache.jmeter.testelement.TestElement)
 */
@Override
public void configure(TestElement element) {
    if (smtpPanel == null) {
        smtpPanel = new SmtpPanel();
    }
    smtpPanel.setServer(element.getPropertyAsString(SmtpSampler.SERVER));
    smtpPanel.setPort(element.getPropertyAsString(SmtpSampler.SERVER_PORT));
    smtpPanel.setTimeout(element.getPropertyAsString(SmtpSampler.SERVER_TIMEOUT));
    smtpPanel.setConnectionTimeout(element.getPropertyAsString(SmtpSampler.SERVER_CONNECTION_TIMEOUT));
    smtpPanel.setMailFrom(element.getPropertyAsString(SmtpSampler.MAIL_FROM));
    smtpPanel.setMailReplyTo(element.getPropertyAsString(SmtpSampler.MAIL_REPLYTO));
    smtpPanel.setReceiverTo(element.getPropertyAsString(SmtpSampler.RECEIVER_TO));
    smtpPanel.setReceiverCC(element.getPropertyAsString(SmtpSampler.RECEIVER_CC));
    smtpPanel.setReceiverBCC(element.getPropertyAsString(SmtpSampler.RECEIVER_BCC));
    smtpPanel.setBody(element.getPropertyAsString(SmtpSampler.MESSAGE));
    smtpPanel.setPlainBody(element.getPropertyAsBoolean(SmtpSampler.PLAIN_BODY));
    smtpPanel.setSubject(element.getPropertyAsString(SmtpSampler.SUBJECT));
    smtpPanel.setSuppressSubject(element.getPropertyAsBoolean(SmtpSampler.SUPPRESS_SUBJECT));
    smtpPanel.setIncludeTimestamp(element.getPropertyAsBoolean(SmtpSampler.INCLUDE_TIMESTAMP));
    JMeterProperty headers = element.getProperty(SmtpSampler.HEADER_FIELDS);
    if (headers instanceof CollectionProperty) {
        // Might be NullProperty
        smtpPanel.setHeaderFields((CollectionProperty) headers);
    } else {
        smtpPanel.setHeaderFields(new CollectionProperty());
    }
    smtpPanel.setAttachments(element.getPropertyAsString(SmtpSampler.ATTACH_FILE));
    smtpPanel.setUseEmlMessage(element.getPropertyAsBoolean(SmtpSampler.USE_EML));
    smtpPanel.setEmlMessage(element.getPropertyAsString(SmtpSampler.EML_MESSAGE_TO_SEND));
    SecuritySettingsPanel secPanel = smtpPanel.getSecuritySettingsPanel();
    secPanel.configure(element);
    smtpPanel.setUseAuth(element.getPropertyAsBoolean(SmtpSampler.USE_AUTH));
    smtpPanel.setUsername(element.getPropertyAsString(SmtpSampler.USERNAME));
    smtpPanel.setPassword(element.getPropertyAsString(SmtpSampler.PASSWORD));
    smtpPanel.setMessageSizeStatistic(element.getPropertyAsBoolean(SmtpSampler.MESSAGE_SIZE_STATS));
    smtpPanel.setEnableDebug(element.getPropertyAsBoolean(SmtpSampler.ENABLE_DEBUG));
    super.configure(element);
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty)

Example 42 with CollectionProperty

use of org.apache.jmeter.testelement.property.CollectionProperty in project jmeter by apache.

the class LDAPArguments method clear.

/**
 * Clear the arguments.
 */
@Override
public void clear() {
    super.clear();
    setProperty(new CollectionProperty(ARGUMENTS, new ArrayList<>()));
}
Also used : CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) ArrayList(java.util.ArrayList)

Example 43 with CollectionProperty

use of org.apache.jmeter.testelement.property.CollectionProperty in project jmeter by apache.

the class HTTPSamplerBase method downloadPageResources.

/**
 * Download the resources of an HTML page.
 *
 * @param pRes
 *            result of the initial request - must contain an HTML response
 * @param container
 *            for storing the results, if any
 * @param frameDepth
 *            Depth of this target in the frame structure. Used only to
 *            prevent infinite recursion.
 * @return res if no resources exist, otherwise the "Container" result with one subsample per request issued
 */
protected HTTPSampleResult downloadPageResources(final HTTPSampleResult pRes, final HTTPSampleResult container, final int frameDepth) {
    HTTPSampleResult res = pRes;
    Iterator<URL> urls = null;
    try {
        final byte[] responseData = res.getResponseData();
        if (responseData.length > 0) {
            // Bug 39205
            final LinkExtractorParser parser = getParser(res);
            if (parser != null) {
                String userAgent = getUserAgent(res);
                urls = parser.getEmbeddedResourceURLs(userAgent, responseData, res.getURL(), res.getDataEncodingWithDefault());
            }
        }
    } catch (LinkExtractorParseException e) {
        // Don't break the world just because this failed:
        res.addSubResult(errorResult(e, new HTTPSampleResult(res)));
        setParentSampleSuccess(res, false);
    }
    HTTPSampleResult lContainer = container;
    // Iterate through the URLs and download each image:
    if (urls != null && urls.hasNext()) {
        if (lContainer == null) {
            lContainer = new HTTPSampleResult(res);
            lContainer.addRawSubResult(res);
        }
        res = lContainer;
        // Get the URL matcher
        String allowRegex = getEmbeddedUrlRE();
        Perl5Matcher localMatcher = null;
        Pattern allowPattern = null;
        if (allowRegex.length() > 0) {
            try {
                allowPattern = JMeterUtils.getPattern(allowRegex);
                // don't fetch unless pattern compiles
                localMatcher = JMeterUtils.getMatcher();
            } catch (MalformedCachePatternException e) {
                // NOSONAR
                log.warn("Ignoring embedded URL match string: {}", e.getMessage());
            }
        }
        Pattern excludePattern = null;
        String excludeRegex = getEmbededUrlExcludeRE();
        if (excludeRegex.length() > 0) {
            try {
                excludePattern = JMeterUtils.getPattern(excludeRegex);
                if (localMatcher == null) {
                    // don't fetch unless pattern compiles
                    localMatcher = JMeterUtils.getMatcher();
                }
            } catch (MalformedCachePatternException e) {
                // NOSONAR
                log.warn("Ignoring embedded URL exclude string: {}", e.getMessage());
            }
        }
        // For concurrent get resources
        final List<Callable<AsynSamplerResultHolder>> list = new ArrayList<>();
        // init with default value
        int maxConcurrentDownloads = CONCURRENT_POOL_SIZE;
        boolean isConcurrentDwn = isConcurrentDwn();
        if (isConcurrentDwn) {
            try {
                maxConcurrentDownloads = Integer.parseInt(getConcurrentPool());
            } catch (NumberFormatException nfe) {
                log.warn(// $NON-NLS-1$
                "Concurrent download resources selected, " + // $NON-NLS-1$
                "but pool size value is bad. Use default value");
            }
            // no need to use another thread, do the sample on the current thread
            if (maxConcurrentDownloads == 1) {
                log.warn("Number of parallel downloads set to 1, (sampler name={})", getName());
                isConcurrentDwn = false;
            }
        }
        while (urls.hasNext()) {
            // See catch clause below
            Object binURL = urls.next();
            try {
                URL url = (URL) binURL;
                if (url == null) {
                    log.warn("Null URL detected (should not happen)");
                } else {
                    try {
                        url = escapeIllegalURLCharacters(url);
                    } catch (Exception e) {
                        // NOSONAR
                        res.addSubResult(errorResult(new Exception(url.toString() + " is not a correct URI", e), new HTTPSampleResult(res)));
                        setParentSampleSuccess(res, false);
                        continue;
                    }
                    log.debug("allowPattern: {}, excludePattern: {}, localMatcher: {}, url: {}", allowPattern, excludePattern, localMatcher, url);
                    // I don't think localMatcher can be null here, but check just in case
                    if (allowPattern != null && localMatcher != null && !localMatcher.matches(url.toString(), allowPattern)) {
                        // we have a pattern and the URL does not match, so skip it
                        continue;
                    }
                    if (excludePattern != null && localMatcher != null && localMatcher.matches(url.toString(), excludePattern)) {
                        // we have a pattern and the URL does not match, so skip it
                        continue;
                    }
                    try {
                        url = url.toURI().normalize().toURL();
                    } catch (MalformedURLException | URISyntaxException e) {
                        res.addSubResult(errorResult(new Exception(url.toString() + " URI can not be normalized", e), new HTTPSampleResult(res)));
                        setParentSampleSuccess(res, false);
                        continue;
                    }
                    if (isConcurrentDwn) {
                        // if concurrent download emb. resources, add to a list for async gets later
                        list.add(new ASyncSample(url, HTTPConstants.GET, false, frameDepth + 1, getCookieManager(), this));
                    } else {
                        // default: serial download embedded resources
                        HTTPSampleResult binRes = sample(url, HTTPConstants.GET, false, frameDepth + 1);
                        res.addSubResult(binRes);
                        setParentSampleSuccess(res, res.isSuccessful() && (binRes == null || binRes.isSuccessful()));
                    }
                }
            } catch (ClassCastException e) {
                // NOSONAR
                res.addSubResult(errorResult(new Exception(binURL + " is not a correct URI", e), new HTTPSampleResult(res)));
                setParentSampleSuccess(res, false);
            }
        }
        // IF for download concurrent embedded resources
        if (isConcurrentDwn && !list.isEmpty()) {
            ResourcesDownloader resourcesDownloader = ResourcesDownloader.getInstance();
            try {
                // sample all resources
                final List<Future<AsynSamplerResultHolder>> retExec = resourcesDownloader.invokeAllAndAwaitTermination(maxConcurrentDownloads, list);
                CookieManager cookieManager = getCookieManager();
                // add result to main sampleResult
                for (Future<AsynSamplerResultHolder> future : retExec) {
                    // this call will not block as the futures return by invokeAllAndAwaitTermination
                    // are either done or cancelled
                    AsynSamplerResultHolder binRes = future.get();
                    if (cookieManager != null) {
                        CollectionProperty cookies = binRes.getCookies();
                        for (JMeterProperty jMeterProperty : cookies) {
                            Cookie cookie = (Cookie) jMeterProperty.getObjectValue();
                            cookieManager.add(cookie);
                        }
                    }
                    res.addSubResult(binRes.getResult());
                    setParentSampleSuccess(res, res.isSuccessful() && (binRes.getResult() != null ? binRes.getResult().isSuccessful() : true));
                }
            } catch (InterruptedException ie) {
                // $NON-NLS-1$
                log.warn("Interrupted fetching embedded resources", ie);
                Thread.currentThread().interrupt();
            } catch (ExecutionException ee) {
                // $NON-NLS-1$
                log.warn("Execution issue when fetching embedded resources", ee);
            }
        }
    }
    return res;
}
Also used : MalformedURLException(java.net.MalformedURLException) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) ArrayList(java.util.ArrayList) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL) Callable(java.util.concurrent.Callable) LinkExtractorParser(org.apache.jmeter.protocol.http.parser.LinkExtractorParser) ExecutionException(java.util.concurrent.ExecutionException) AsynSamplerResultHolder(org.apache.jmeter.protocol.http.sampler.ResourcesDownloader.AsynSamplerResultHolder) LinkExtractorParseException(org.apache.jmeter.protocol.http.parser.LinkExtractorParseException) CookieManager(org.apache.jmeter.protocol.http.control.CookieManager) Cookie(org.apache.jmeter.protocol.http.control.Cookie) Pattern(org.apache.oro.text.regex.Pattern) CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) MalformedCachePatternException(org.apache.oro.text.MalformedCachePatternException) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedCachePatternException(org.apache.oro.text.MalformedCachePatternException) MalformedURLException(java.net.MalformedURLException) LinkExtractorParseException(org.apache.jmeter.protocol.http.parser.LinkExtractorParseException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Future(java.util.concurrent.Future)

Example 44 with CollectionProperty

use of org.apache.jmeter.testelement.property.CollectionProperty in project jmeter by apache.

the class TestHTTPArgument method testConversion.

@Test
public void testConversion() throws Exception {
    Arguments args = new Arguments();
    args.addArgument("name.?", "value_ here");
    args.addArgument("name$of property", "value_.+");
    HTTPArgument.convertArgumentsToHTTP(args);
    CollectionProperty argList = args.getArguments();
    HTTPArgument httpArg = (HTTPArgument) argList.get(0).getObjectValue();
    assertEquals("name.%3F", httpArg.getEncodedName());
    assertEquals("value_+here", httpArg.getEncodedValue());
    httpArg = (HTTPArgument) argList.get(1).getObjectValue();
    assertEquals("name%24of+property", httpArg.getEncodedName());
    assertEquals("value_.%2B", httpArg.getEncodedValue());
}
Also used : CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) Arguments(org.apache.jmeter.config.Arguments) Test(org.junit.jupiter.api.Test)

Example 45 with CollectionProperty

use of org.apache.jmeter.testelement.property.CollectionProperty in project jmeter by apache.

the class UserParametersGui method configure.

@Override
public void configure(TestElement el) {
    initTableModel();
    paramTable.setModel(tableModel);
    UserParameters params = (UserParameters) el;
    CollectionProperty names = params.getNames();
    CollectionProperty threadValues = params.getThreadLists();
    tableModel.setColumnData(0, (List<?>) names.getObjectValue());
    PropertyIterator iter = threadValues.iterator();
    if (iter.hasNext()) {
        tableModel.setColumnData(1, (List<?>) iter.next().getObjectValue());
    }
    int count = 2;
    while (iter.hasNext()) {
        String colName = getUserColName(count);
        tableModel.addNewColumn(colName, String.class);
        tableModel.setColumnData(count, (List<?>) iter.next().getObjectValue());
        count++;
    }
    setColumnWidths();
    perIterationCheck.setSelected(params.isPerIteration());
    super.configure(el);
}
Also used : UserParameters(org.apache.jmeter.modifiers.UserParameters) CollectionProperty(org.apache.jmeter.testelement.property.CollectionProperty) PropertyIterator(org.apache.jmeter.testelement.property.PropertyIterator)

Aggregations

CollectionProperty (org.apache.jmeter.testelement.property.CollectionProperty)91 JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)29 ArrayList (java.util.ArrayList)19 NullProperty (org.apache.jmeter.testelement.property.NullProperty)13 Test (org.junit.Test)11 PropertyIterator (org.apache.jmeter.testelement.property.PropertyIterator)8 Test (org.junit.jupiter.api.Test)7 IOException (java.io.IOException)5 List (java.util.List)4 StringProperty (org.apache.jmeter.testelement.property.StringProperty)4 File (java.io.File)3 Argument (org.apache.jmeter.config.Argument)3 PowerTableModel (org.apache.jmeter.gui.util.PowerTableModel)3 TestPlan (org.apache.jmeter.testelement.TestPlan)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Field (java.lang.reflect.Field)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 UnknownHostException (java.net.UnknownHostException)2 LinkedList (java.util.LinkedList)2