Search in sources :

Example 61 with JMeterProperty

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

the class PackageTest method testParseExample10.

@Test
public void testParseExample10() throws Exception {
    StringProperty prop = new StringProperty("html", "${__regexFunction(\\ " + "(\\\\\\$\\d+\\.\\d+\\,\\\\$\\d+\\.\\d+),$1$)}");
    JMeterProperty newProp = transformer.transformValue(prop);
    newProp.setRunningVersion(true);
    assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName());
    assertEquals("$3.47,$5.67", newProp.getStringValue());
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) StringProperty(org.apache.jmeter.testelement.property.StringProperty) Test(org.junit.Test)

Example 62 with JMeterProperty

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

the class PackageTest method testNestedExample1.

@Test
public void testNestedExample1() throws Exception {
    StringProperty prop = new StringProperty("html", "${__regexFunction(<html>(${my_regex})</html>," + "$1$)}${__regexFunction(<html>(.*o)(.*o)(.*)" + "</html>,$1$$3$)}");
    JMeterProperty newProp = transformer.transformValue(prop);
    newProp.setRunningVersion(true);
    assertEquals("org.apache.jmeter.testelement.property.FunctionProperty", newProp.getClass().getName());
    assertEquals("hello worldhellorld", newProp.getStringValue());
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) StringProperty(org.apache.jmeter.testelement.property.StringProperty) Test(org.junit.Test)

Example 63 with JMeterProperty

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

the class PackageTest method testParseExample12.

// N.B. See Bug 46831 which wanted to changed the behaviour of \$
// It's too late now, as this would invalidate some existing test plans,
// so document the current behaviour with some more tests.
// Escaped dollar commma and backslash with variable reference
@Test
public void testParseExample12() throws Exception {
    StringProperty prop = new StringProperty("html", "\\$a \\, \\\\ \\x \\ ${server} \\$b \\, \\\\ cd");
    JMeterProperty newProp = transformer.transformValue(prop);
    newProp.setRunningVersion(true);
    // N.B. Backslashes are removed before dollar, comma and backslash
    assertEquals("$a , \\ \\x \\ jakarta.apache.org $b , \\ cd", newProp.getStringValue());
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) StringProperty(org.apache.jmeter.testelement.property.StringProperty) Test(org.junit.Test)

Example 64 with JMeterProperty

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

the class PackageTest method testParseExample5.

@Test
public void testParseExample5() throws Exception {
    StringProperty prop = new StringProperty("html", "");
    JMeterProperty newProp = transformer.transformValue(prop);
    newProp.setRunningVersion(true);
    assertEquals("org.apache.jmeter.testelement.property.StringProperty", newProp.getClass().getName());
    assertEquals("", newProp.getStringValue());
}
Also used : JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) StringProperty(org.apache.jmeter.testelement.property.StringProperty) Test(org.junit.Test)

Example 65 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)

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