Package org.apache.jmeter.testelement.property

Examples of org.apache.jmeter.testelement.property.PropertyIterator


        private void setLastSampleStatus(boolean status){
            jmvars.put(JMeterThread.LAST_SAMPLE_OK,Boolean.toString(status));
        }

        private void setRunning(TestElement el){
            PropertyIterator pi = el.propertyIterator();
            while(pi.hasNext()){
                pi.next().setRunningVersion(true);
            }
        }
View Full Code Here


    @Override
    public void configure(TestElement el) {
        super.configure(el);
        if (el instanceof LDAPArguments) {
            tableModel.clearData();
            PropertyIterator iter = ((LDAPArguments) el).iterator();
            while (iter.hasNext()) {
                LDAPArgument arg = (LDAPArgument) iter.next().getObjectValue();
                tableModel.addRow(arg);
            }
        }
        checkDeleteStatus();
    }
View Full Code Here

        assertEquals(1, files.getHTTPFileArgCount());
        assertEquals("hede", ((HTTPFileArg) files.iterator().next().getObjectValue()).getPath());
        HTTPFileArg file = new HTTPFileArg("hodo");
        files.addHTTPFileArg(file);
        assertEquals(2, files.getHTTPFileArgCount());
        PropertyIterator iter = files.iterator();
        assertEquals("hede", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
        assertEquals("hodo", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
        files.addEmptyHTTPFileArg();
        assertEquals(3, files.getHTTPFileArgCount());
        iter = files.iterator();
        assertEquals("hede", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
        assertEquals("hodo", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
        assertEquals("", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
    }
View Full Code Here

        files.addHTTPFileArg("file5");
        files.addHTTPFileArg("file6");
        assertEquals(6, files.getHTTPFileArgCount());
        files.removeHTTPFileArg("file3");
        assertEquals(5, files.getHTTPFileArgCount());
        PropertyIterator iter = files.iterator();
        assertEquals("file1", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
        assertEquals("file2", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
        assertEquals("file4", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
        assertEquals("file5", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
        assertEquals("file6", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
        files.removeHTTPFileArg(file);
        assertEquals(4, files.getHTTPFileArgCount());
        iter = files.iterator();
        assertEquals("file1", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
        assertEquals("file2", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
        assertEquals("file5", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
        assertEquals("file6", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
        files.removeHTTPFileArg(new HTTPFileArg("file5"));
        assertEquals(3, files.getHTTPFileArgCount());
        iter = files.iterator();
        assertEquals("file1", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
        assertEquals("file2", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
        assertEquals("file6", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
        files.removeHTTPFileArg(1);
        assertEquals(2, files.getHTTPFileArgCount());
        iter = files.iterator();
        assertEquals("file1", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
        assertEquals("file6", ((HTTPFileArg) iter.next().getObjectValue()).getPath());
        files.removeAllHTTPFileArgs();
        assertEquals(0, files.getHTTPFileArgCount());
    }
View Full Code Here

            return;
        } else {
            sampler = (HTTPSamplerBase) sam;
        }
        boolean modified = false;
        PropertyIterator iter = sampler.getArguments().iterator();
        while (iter.hasNext()) {
            Argument arg = (Argument) iter.next().getObjectValue();
            modified = modifyArgument(arg);
            if (modified) {
                break;
            }
        }
View Full Code Here

     *
     * @param args collection of {@link Argument} and/or {@link HTTPArgument} entries
     */
    public static void convertArgumentsToHTTP(Arguments args) {
        List<Argument> newArguments = new LinkedList<Argument>();
        PropertyIterator iter = args.getArguments().iterator();
        while (iter.hasNext()) {
            Argument arg = (Argument) iter.next().getObjectValue();
            if (!(arg instanceof HTTPArgument)) {
                newArguments.add(new HTTPArgument(arg));
            } else {
                newArguments.add(arg);
            }
View Full Code Here

            ByteArrayOutputStream bos = new ByteArrayOutputStream();

            // First the multipart start divider
            bos.write(getMultipartDivider());
            // Add any parameters
            PropertyIterator args = sampler.getArguments().iterator();
            while (args.hasNext()) {
                HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
                String parameterName = arg.getName();
                if (arg.isSkippable(parameterName)){
                    continue;
                }
                // End the previous multipart
                bos.write(CRLF);
                // Write multipart for parameter
                writeFormMultipart(bos, parameterName, arg.getValue(), contentEncoding, sampler.getDoBrowserCompatibleMultipart());
            }
            // If there are any files, we need to end the previous multipart
            if(files.length > 0) {
                // End the previous multipart
                bos.write(CRLF);
            }
            bos.flush();
            // Keep the content, will be sent later
            formDataPostBody = bos.toByteArray();
            bos.close();
            contentLength = formDataPostBody.length;

            // Now we just construct any multipart for the files
            // We only construct the file multipart start, we do not write
            // the actual file content
            for (int i=0; i < files.length; i++) {
                HTTPFileArg file = files[i];
                // Write multipart for file
                bos = new ByteArrayOutputStream();
                writeStartFileMultipart(bos, file.getPath(), file.getParamName(), file.getMimeType());
                bos.flush();
                String header = bos.toString(contentEncoding);// TODO is this correct?
                // If this is not the first file we can't write its header now
                // for simplicity we always save it, even if there is only one file
                file.setHeader(header);
                bos.close();
                contentLength += header.length();
                // Add also the length of the file content
                File uploadFile = new File(file.getPath());
                contentLength += uploadFile.length();
                // And the end of the file multipart
                contentLength += getFileMultipartEndDivider().length;
                if(i+1 < files.length) {
                    contentLength += CRLF.length;
                }
            }

            // Add the end of multipart
            contentLength += getMultipartEndDivider().length;

            // Set the content length
            connection.setRequestProperty(HTTPConstants.HEADER_CONTENT_LENGTH, Long.toString(contentLength));

            // Make the connection ready for sending post data
            connection.setDoOutput(true);
            connection.setDoInput(true);
        }
        else {
            // Check if the header manager had a content type header
            // This allows the user to specify his own content-type for a POST request
            String contentTypeHeader = connection.getRequestProperty(HTTPConstants.HEADER_CONTENT_TYPE);
            boolean hasContentTypeHeader = contentTypeHeader != null && contentTypeHeader.length() > 0;

            // If there are no arguments, we can send a file as the body of the request
            if(sampler.getArguments() != null && sampler.getArguments().getArgumentCount() == 0 && sampler.getSendFileAsPostBody()) {
                // we're sure that there is one file because of
                // getSendFileAsPostBody method's return value.
                HTTPFileArg file = files[0];
                if(!hasContentTypeHeader) {
                    // Allow the mimetype of the file to control the content type
                    if(file.getMimeType() != null && file.getMimeType().length() > 0) {
                        connection.setRequestProperty(HTTPConstants.HEADER_CONTENT_TYPE, file.getMimeType());
                    }
                    else {
                        connection.setRequestProperty(HTTPConstants.HEADER_CONTENT_TYPE, HTTPConstants.APPLICATION_X_WWW_FORM_URLENCODED);
                    }
                }
                // Create the content length we are going to write
                File inputFile = new File(file.getPath());
                contentLength = inputFile.length();
            }
            else {
                // We create the post body content now, so we know the size
                ByteArrayOutputStream bos = new ByteArrayOutputStream();

                // If none of the arguments have a name specified, we
                // just send all the values as the post body
                String postBody = null;
                if(!sampler.getSendParameterValuesAsPostBody()) {
                    // Set the content type
                    if(!hasContentTypeHeader) {
                        connection.setRequestProperty(HTTPConstants.HEADER_CONTENT_TYPE, HTTPConstants.APPLICATION_X_WWW_FORM_URLENCODED);
                    }

                    // It is a normal post request, with parameter names and values
                    postBody = sampler.getQueryString(contentEncoding);
                }
                else {
                    // Allow the mimetype of the file to control the content type
                    // This is not obvious in GUI if you are not uploading any files,
                    // but just sending the content of nameless parameters
                    // TODO: needs a multiple file upload scenerio
                    if(!hasContentTypeHeader) {
                        HTTPFileArg file = files.length > 0? files[0] : null;
                        if(file != null && file.getMimeType() != null && file.getMimeType().length() > 0) {
                            connection.setRequestProperty(HTTPConstants.HEADER_CONTENT_TYPE, file.getMimeType());
                        }
                        else {
                            // TODO: is this the correct default?
                            connection.setRequestProperty(HTTPConstants.HEADER_CONTENT_TYPE, HTTPConstants.APPLICATION_X_WWW_FORM_URLENCODED);
                        }
                    }

                    // Just append all the parameter values, and use that as the post body
                    StringBuilder postBodyBuffer = new StringBuilder();
                    PropertyIterator args = sampler.getArguments().iterator();
                    while (args.hasNext()) {
                        HTTPArgument arg = (HTTPArgument) args.next().getObjectValue();
                        postBodyBuffer.append(arg.getEncodedValue(contentEncoding));
                    }
                    postBody = postBodyBuffer.toString();
                }
View Full Code Here

        return cookie;
    }

    private void populateTable(CookieManager manager) {
        tableModel.clearData();
        PropertyIterator iter = manager.getCookies().iterator();
        while (iter.hasNext()) {
            addCookieToTable((Cookie) iter.next().getObjectValue());
        }
    }
View Full Code Here

                log.debug("Selected: "+url.toString());
            }
            sampler.setDomain(url.getDomain());
            sampler.setPath(url.getPath());
            if (url.getMethod().equals(HTTPConstants.POST)) {
                PropertyIterator iter = sampler.getArguments().iterator();
                while (iter.hasNext()) {
                    Argument arg = (Argument) iter.next().getObjectValue();
                    modifyArgument(arg, url.getArguments());
                }
            } else {
                sampler.setArguments(url.getArguments());
                // config.parseArguments(url.getQueryString());
View Full Code Here

    private void modifyArgument(Argument arg, Arguments args) {
        if (log.isDebugEnabled()) {
            log.debug("Modifying argument: " + arg);
        }
        List<Argument> possibleReplacements = new ArrayList<Argument>();
        PropertyIterator iter = args.iterator();
        Argument replacementArg;
        while (iter.hasNext()) {
            replacementArg = (Argument) iter.next().getObjectValue();
            try {
                if (HtmlParsingUtils.isArgumentMatched(replacementArg, arg)) {
                    possibleReplacements.add(replacementArg);
                }
            } catch (Exception ex) {
View Full Code Here

TOP

Related Classes of org.apache.jmeter.testelement.property.PropertyIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.