Class DslResponseAssertion
- java.lang.Object
-
- us.abstracta.jmeter.javadsl.core.testelements.BaseTestElement
-
- us.abstracta.jmeter.javadsl.core.testelements.DslScopedTestElement<DslResponseAssertion>
-
- us.abstracta.jmeter.javadsl.core.assertions.DslResponseAssertion
-
- All Implemented Interfaces:
DslAssertion,DslTestElement,DslTestPlan.TestPlanChild,BaseSampler.SamplerChild,MultiLevelTestElement,BaseThreadGroup.ThreadGroupChild
public class DslResponseAssertion extends DslScopedTestElement<DslResponseAssertion> implements DslAssertion
Allows marking a request result as success or failure by a specific result field value.- Since:
- 0.11
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDslResponseAssertion.CodeBuilderstatic classDslResponseAssertion.TargetFieldIdentifies a particular field to apply the assertion to.static classDslResponseAssertion.TestStringStrategy-
Nested classes/interfaces inherited from class us.abstracta.jmeter.javadsl.core.testelements.DslScopedTestElement
DslScopedTestElement.Scope, DslScopedTestElement.ScopedTestElementCallBuilder<T extends org.apache.jmeter.testelement.TestElement>
-
-
Field Summary
Fields Modifier and Type Field Description protected booleananyMatchprotected static StringDEFAULT_NAMEprotected DslResponseAssertion.TargetFieldfieldToTestprotected booleanignoreStatusprotected booleaninvertCheckprotected DslResponseAssertion.TestStringStrategytestStrategyprotected List<String>testStrings-
Fields inherited from class us.abstracta.jmeter.javadsl.core.testelements.DslScopedTestElement
scope, scopeVariable
-
Fields inherited from class us.abstracta.jmeter.javadsl.core.testelements.BaseTestElement
guiClass, name
-
-
Constructor Summary
Constructors Constructor Description DslResponseAssertion(String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DslResponseAssertionanyMatch()Specifies that if any check matches then the response assertion is satisfied.DslResponseAssertionanyMatch(boolean enable)Same asanyMatch()but allowing to enable or disable it.protected org.apache.jmeter.testelement.TestElementbuildTestElement()DslResponseAssertioncontainsRegexes(String... regexes)Checks if the configuredfieldToTest(TargetField)contains matches for given regular expressions.DslResponseAssertioncontainsSubstrings(String... substrings)Checks if the specifiedfieldToTest(TargetField)contains the given substrings.DslResponseAssertionequalsToStrings(String... strings)Compares the configuredfieldToTest(TargetField)to the given strings for equality.DslResponseAssertionfieldToTest(DslResponseAssertion.TargetField fieldToTest)Specifies what field to apply the assertion to.DslResponseAssertionignoreStatus()Specifies that any previously status set to the request should be ignored, and request should be marked as success by default.DslResponseAssertionignoreStatus(boolean enable)Same asignoreStatus()but allowing to enable or disable it.DslResponseAssertioninvertCheck()Allows inverting/negating each of the checks applied by the assertion.DslResponseAssertioninvertCheck(boolean enable)Same asinvertCheck()but allowing to enable or disable it.DslResponseAssertionmatchesRegexes(String... regexes)Checks if the configuredfieldToTest(TargetField)matches (completely, and not just part of it) given regular expressions.-
Methods inherited from class us.abstracta.jmeter.javadsl.core.testelements.DslScopedTestElement
scope, scopeVariable, setScopeTo
-
Methods inherited from class us.abstracta.jmeter.javadsl.core.testelements.BaseTestElement
buildConfiguredTestElement, buildTestElementGui, buildTreeUnder, configureTestElement, durationToSeconds, loadBeanProperties, showAndWaitFrameWith, showFrameWith, showInGui, showTestElementGui
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface us.abstracta.jmeter.javadsl.core.DslTestElement
buildTreeUnder, showInGui
-
-
-
-
Field Detail
-
DEFAULT_NAME
protected static final String DEFAULT_NAME
- See Also:
- Constant Field Values
-
fieldToTest
protected DslResponseAssertion.TargetField fieldToTest
-
ignoreStatus
protected boolean ignoreStatus
-
testStrategy
protected DslResponseAssertion.TestStringStrategy testStrategy
-
invertCheck
protected boolean invertCheck
-
anyMatch
protected boolean anyMatch
-
-
Constructor Detail
-
DslResponseAssertion
public DslResponseAssertion(String name)
-
-
Method Detail
-
fieldToTest
public DslResponseAssertion fieldToTest(DslResponseAssertion.TargetField fieldToTest)
Specifies what field to apply the assertion to.When not specified it will apply the given assertion to the response body.
- Parameters:
fieldToTest- specifies the field to apply the assertion to.- Returns:
- the response assertion for further configuration or usage.
- See Also:
DslResponseAssertion.TargetField
-
ignoreStatus
public DslResponseAssertion ignoreStatus()
Specifies that any previously status set to the request should be ignored, and request should be marked as success by default.This allows overriding the default behavior provided by JMeter when marking requests as failed (eg: HTTP status codes like 4xx or 5xx). This is particularly useful when tested application returns an unsuccessful response (eg: 400) but you want to consider some of those cases still as successful using a different criteria to determine when they are actually a failure (an unexpected response).
Take into consideration that if you specify multiple response assertions to the same sampler, then if this flag is enabled, any previous assertion result in same sampler will be ignored (marked as success). So, consider setting this flag in first response assertion only.
- Returns:
- the response assertion for further configuration or usage.
-
ignoreStatus
public DslResponseAssertion ignoreStatus(boolean enable)
Same asignoreStatus()but allowing to enable or disable it.This is helpful when the resolution is taken at runtime.
- Parameters:
enable- specifies to enable or disable the setting. By default, it is set to false.- Returns:
- the response assertion for further configuration or usage.
- Since:
- 1.0
- See Also:
ignoreStatus()
-
containsSubstrings
public DslResponseAssertion containsSubstrings(String... substrings)
Checks if the specifiedfieldToTest(TargetField)contains the given substrings.By default, the main sample (not sub samples) response body will be checked, and all supplied substrings must be contained. Review other methods in this class if you need to check substrings but in some other ways (eg: in response headers, any match is enough, or none of specified substrings should be contained).
- Parameters:
substrings- list of strings to be searched in the given field to test (by default response body).- Returns:
- the response assertion for further configuration or usage.
-
equalsToStrings
public DslResponseAssertion equalsToStrings(String... strings)
Compares the configuredfieldToTest(TargetField)to the given strings for equality.By default, the main sample (not sub samples) response body will be checked, and all supplied strings must be equal to the body (in default setting only makes sense to specify one string). Review other methods in this class if you need to check equality to entire strings but in some other ways (eg: in response headers, any match is enough, or none of specified strings should be equal to the field value).
- Parameters:
strings- list of strings to be compared against the given field to test (by default response body).- Returns:
- the response assertion for further configuration or usage.
-
containsRegexes
public DslResponseAssertion containsRegexes(String... regexes)
Checks if the configuredfieldToTest(TargetField)contains matches for given regular expressions.By default, the main sample (not sub samples) response body will be checked, and all supplied regular expressions must contain a match in the body. Review other methods in this class if you need to check regular expressions matches are contained but in some other ways (eg: in response headers, any regex match is enough, or none of specified regex should be contained in the field value).
By default, regular expressions evaluate in multi-line mode, which means that '.' does not match new lines, '^' matches start of lines and '$' matches end of lines. To use single-line mode prefix '(?s)' to the regular expressions. Regular expressions are also by default case-sensitive, which can be changed to insensitive by adding '(?i)' to the regex.
- Parameters:
regexes- list of regular expressions to search for matches in the field to test (by default response body).- Returns:
- the response assertion for further configuration or usage.
-
matchesRegexes
public DslResponseAssertion matchesRegexes(String... regexes)
Checks if the configuredfieldToTest(TargetField)matches (completely, and not just part of it) given regular expressions.By default, the main sample (not sub samples) response body will be checked, and all supplied regular expressions must match the entire body. Review other methods in this class if you need to check regular expressions matches but in some other ways (eg: in response headers, any regex match is enough, or none of specified regex should be matched with the field value).
By default, regular expressions evaluate in multi-line mode, which means that '.' does not match new lines, '^' matches start of lines and '$' matches end of lines. To use single-line mode prefix '(?s)' to the regular expressions. Regular expressions are also by default case-sensitive, which can be changed to insensitive by adding '(?i)' to the regex.
- Parameters:
regexes- list of regular expressions the field to test (by default response body) must match.- Returns:
- the response assertion for further configuration or usage.
-
invertCheck
public DslResponseAssertion invertCheck()
Allows inverting/negating each of the checks applied by the assertion.This is the same as the "Not" option in Response Assertion in JMeter GUI.
It is important to note that the inversion of the check happens at each check and not to the final result. Eg:
responseAssertion().containsSubstrings("error", "failure").invertCheck()Will check that the response does not contain "error" and does not contain "failure". You can think it as
!(containsSubstring("error")) && !(containsSubstring("failure")).Similar logic applies when using in combination with anyMatch method. Eg:
responseAssertion().containsSubstrings("error", "failure").invertCheck().matchAny()Will check that response does not contain both "error" and "failure" at the same time. This is analogous to
!(containsSubstring("error")) || !(containsSubstring("failure), which is equivalent to!(containsSubstring("error") && containsSubstring("failure)).Keep in mind that order of invocations of methods in response assertion is irrelevant (so
invertCheck().matchAny()gets the same result asmatchAny().invertCheck()).- Returns:
- the response assertion for further configuration or usage.
-
invertCheck
public DslResponseAssertion invertCheck(boolean enable)
Same asinvertCheck()but allowing to enable or disable it.This is helpful when the resolution is taken at runtime.
- Parameters:
enable- specifies to enable or disable the setting. By default, it is set to false.- Returns:
- the response assertion for further configuration or usage.
- Since:
- 1.0
- See Also:
invertCheck()
-
anyMatch
public DslResponseAssertion anyMatch()
Specifies that if any check matches then the response assertion is satisfied.This is the same as the "Or" option in Response Assertion in JMeter GUI.
By default, when you use something like this:
responseAssertion().containsSubstrings("success", "OK")The response assertion will be success when both "success" and "OK" sub strings appear in response body (if one or both don't appear, then it fails). You can think of it like
containsSubstring("success") && containsSubstring("OK").If you want to check that any of them matches then use anyMatch, like this:
responseAssertion().containsSubstrings("success", "OK").anyMatch()Which you can interpret as
containsSubstring("success") || containsSubstring("OK").- Returns:
- the response assertion for further configuration or usage.
-
anyMatch
public DslResponseAssertion anyMatch(boolean enable)
Same asanyMatch()but allowing to enable or disable it.This is helpful when the resolution is taken at runtime.
- Parameters:
enable- specifies to enable or disable the setting. By default, it is set to false.- Returns:
- the response assertion for further configuration or usage.
- Since:
- 1.0
- See Also:
anyMatch()
-
buildTestElement
protected org.apache.jmeter.testelement.TestElement buildTestElement()
- Specified by:
buildTestElementin classBaseTestElement
-
-