Search in sources :

Example 71 with JMeterProperty

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

the class HTTPFileArg method setProperty.

private void setProperty(String name, JMeterProperty prop) {
    JMeterProperty jmp = prop.clone();
    jmp.setName(name);
    setProperty(jmp);
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty)

Example 72 with JMeterProperty

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

the class ResponseAssertion method evaluateResponse.

/**
     * Make sure the response satisfies the specified assertion requirements.
     *
     * @param response
     *            an instance of SampleResult
     * @return an instance of AssertionResult
     */
private AssertionResult evaluateResponse(SampleResult response) {
    AssertionResult result = new AssertionResult(getName());
    if (getAssumeSuccess()) {
        // Allow testing of failure codes
        response.setSuccessful(true);
    }
    // The string to check (Url or data)
    String toCheck;
    // What are we testing against?
    if (isScopeVariable()) {
        toCheck = getThreadContext().getVariables().get(getVariableName());
    } else if (isTestFieldResponseData()) {
        // (bug25052)
        toCheck = response.getResponseDataAsString();
    } else if (isTestFieldResponseDataAsDocument()) {
        toCheck = Document.getTextFromDocument(response.getResponseData());
    } else if (isTestFieldResponseCode()) {
        toCheck = response.getResponseCode();
    } else if (isTestFieldResponseMessage()) {
        toCheck = response.getResponseMessage();
    } else if (isTestFieldRequestHeaders()) {
        toCheck = response.getRequestHeaders();
    } else if (isTestFieldResponseHeaders()) {
        toCheck = response.getResponseHeaders();
    } else {
        // Assume it is the URL
        toCheck = "";
        final URL url = response.getURL();
        if (url != null) {
            toCheck = url.toString();
        }
    }
    result.setFailure(false);
    result.setError(false);
    boolean notTest = (NOT & getTestType()) > 0;
    boolean orTest = (OR & getTestType()) > 0;
    // do it once outside loop
    boolean contains = isContainsType();
    boolean equals = isEqualsType();
    boolean substring = isSubstringType();
    boolean matches = isMatchType();
    log.debug("Test Type Info: contains={}, notTest={}, orTest={}", contains, notTest, orTest);
    if (StringUtils.isEmpty(toCheck)) {
        if (notTest) {
            // Not should always succeed against an empty result
            return result;
        }
        if (log.isDebugEnabled()) {
            log.debug("Not checking empty response field in: {}", response.getSampleLabel());
        }
        return result.setResultForNull();
    }
    boolean pass = true;
    boolean hasTrue = false;
    ArrayList<String> allCheckMessage = new ArrayList<>();
    try {
        // Get the Matcher for this thread
        Perl5Matcher localMatcher = JMeterUtils.getMatcher();
        for (JMeterProperty jMeterProperty : getTestStrings()) {
            String stringPattern = jMeterProperty.getStringValue();
            Pattern pattern = null;
            if (contains || matches) {
                pattern = JMeterUtils.getPatternCache().getPattern(stringPattern, Perl5Compiler.READ_ONLY_MASK);
            }
            boolean found;
            if (contains) {
                found = localMatcher.contains(toCheck, pattern);
            } else if (equals) {
                found = toCheck.equals(stringPattern);
            } else if (substring) {
                found = toCheck.contains(stringPattern);
            } else {
                found = localMatcher.matches(toCheck, pattern);
            }
            pass = notTest ? !found : found;
            if (orTest) {
                if (!pass) {
                    log.debug("Failed: {}", stringPattern);
                    allCheckMessage.add(getFailText(stringPattern, toCheck));
                } else {
                    hasTrue = true;
                    break;
                }
            } else {
                if (!pass) {
                    log.debug("Failed: {}", stringPattern);
                    result.setFailure(true);
                    result.setFailureMessage(getFailText(stringPattern, toCheck));
                    break;
                }
                log.debug("Passed: {}", stringPattern);
            }
        }
        if (orTest && !hasTrue) {
            StringBuilder errorMsg = new StringBuilder();
            for (String tmp : allCheckMessage) {
                errorMsg.append(tmp).append('\t');
            }
            result.setFailure(true);
            result.setFailureMessage(errorMsg.toString());
        }
    } catch (MalformedCachePatternException e) {
        result.setError(true);
        result.setFailure(false);
        result.setFailureMessage("Bad test configuration " + e);
    }
    return result;
}
Also used : Pattern(org.apache.oro.text.regex.Pattern) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) MalformedCachePatternException(org.apache.oro.text.MalformedCachePatternException) ArrayList(java.util.ArrayList) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) URL(java.net.URL)

Example 73 with JMeterProperty

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

the class AssertionGui method configure.

/**
     * A newly created component can be initialized with the contents of a Test
     * Element object by calling this method. The component is responsible for
     * querying the Test Element object for the relevant information to display
     * in its GUI.
     *
     * @param el
     *            the TestElement to configure
     */
@Override
public void configure(TestElement el) {
    super.configure(el);
    ResponseAssertion model = (ResponseAssertion) el;
    showScopeSettings(model, true);
    if (model.isContainsType()) {
        containsBox.setSelected(true);
    } else if (model.isEqualsType()) {
        equalsBox.setSelected(true);
    } else if (model.isSubstringType()) {
        substringBox.setSelected(true);
    } else {
        matchesBox.setSelected(true);
    }
    notBox.setSelected(model.isNotType());
    orBox.setSelected(model.isOrType());
    if (model.isTestFieldResponseData()) {
        responseStringButton.setSelected(true);
    } else if (model.isTestFieldResponseDataAsDocument()) {
        responseAsDocumentButton.setSelected(true);
    } else if (model.isTestFieldResponseCode()) {
        responseCodeButton.setSelected(true);
    } else if (model.isTestFieldResponseMessage()) {
        responseMessageButton.setSelected(true);
    } else if (model.isTestFieldRequestHeaders()) {
        requestHeadersButton.setSelected(true);
    } else if (model.isTestFieldResponseHeaders()) {
        responseHeadersButton.setSelected(true);
    } else // Assume it is the URL
    {
        urlButton.setSelected(true);
    }
    assumeSuccess.setSelected(model.getAssumeSuccess());
    tableModel.clearData();
    for (JMeterProperty jMeterProperty : model.getTestStrings()) {
        tableModel.addRow(new Object[] { jMeterProperty.getStringValue() });
    }
    if (model.getTestStrings().size() == 0) {
        deletePattern.setEnabled(false);
    } else {
        deletePattern.setEnabled(true);
    }
    tableModel.fireTableDataChanged();
}
Also used : ResponseAssertion(org.apache.jmeter.assertions.ResponseAssertion) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty)

Example 74 with JMeterProperty

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

the class DebugPostProcessor method formatPropertyIterator.

private void formatPropertyIterator(StringBuilder sb, PropertyIterator iter) {
    Map<String, String> map = new HashMap<>();
    while (iter.hasNext()) {
        JMeterProperty item = iter.next();
        map.put(item.getName(), item.getStringValue());
    }
    formatSet(sb, map.entrySet());
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) HashMap(java.util.HashMap)

Example 75 with JMeterProperty

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

the class ThroughputController method getMaxThroughputAsInt.

protected int getMaxThroughputAsInt() {
    JMeterProperty prop = getProperty(MAXTHROUGHPUT);
    int retVal = 1;
    if (prop instanceof IntegerProperty) {
        retVal = ((IntegerProperty) prop).getIntValue();
    } else {
        String valueString = prop.getStringValue();
        try {
            retVal = Integer.parseInt(valueString);
        } catch (NumberFormatException e) {
            log.warn("Error parsing '{}'", valueString, e);
        }
    }
    return retVal;
}
Also used : IntegerProperty(org.apache.jmeter.testelement.property.IntegerProperty) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty)

Aggregations

JMeterProperty (org.apache.jmeter.testelement.property.JMeterProperty)87 StringProperty (org.apache.jmeter.testelement.property.StringProperty)23 Test (org.junit.Test)23 PropertyIterator (org.apache.jmeter.testelement.property.PropertyIterator)13 CollectionProperty (org.apache.jmeter.testelement.property.CollectionProperty)12 Argument (org.apache.jmeter.config.Argument)11 ArrayList (java.util.ArrayList)9 HTTPArgument (org.apache.jmeter.protocol.http.util.HTTPArgument)8 File (java.io.File)7 Arguments (org.apache.jmeter.config.Arguments)7 HTTPFileArg (org.apache.jmeter.protocol.http.util.HTTPFileArg)6 TestElement (org.apache.jmeter.testelement.TestElement)6 ConfigTestElement (org.apache.jmeter.config.ConfigTestElement)5 URL (java.net.URL)4 TestElementProperty (org.apache.jmeter.testelement.property.TestElementProperty)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 HashMap (java.util.HashMap)3 Sampler (org.apache.jmeter.samplers.Sampler)3 TestPlan (org.apache.jmeter.testelement.TestPlan)3 NullProperty (org.apache.jmeter.testelement.property.NullProperty)3