Class DslJsonAssertion
- java.lang.Object
-
- us.abstracta.jmeter.javadsl.core.testelements.BaseTestElement
-
- us.abstracta.jmeter.javadsl.core.assertions.DslJsonAssertion
-
- All Implemented Interfaces:
DslAssertion,DslTestElement,DslTestPlan.TestPlanChild,BaseSampler.SamplerChild,MultiLevelTestElement,BaseThreadGroup.ThreadGroupChild
public class DslJsonAssertion extends BaseTestElement implements DslAssertion
Allows asserting that part of a JSON response exists or has some value.By default, the assertion will just check for the existence of given JSON JMESPath.
- Since:
- 1.15
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDslJsonAssertion.CodeBuilder
-
Field Summary
Fields Modifier and Type Field Description protected booleanisRegexprotected booleannotprotected Stringqueryprotected DslJsonExtractor.JsonQueryLanguagequeryLanguageprotected booleanvalidateValueprotected Stringvalue-
Fields inherited from class us.abstracta.jmeter.javadsl.core.testelements.BaseTestElement
guiClass, name
-
-
Constructor Summary
Constructors Constructor Description DslJsonAssertion(String name, String query)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.apache.jmeter.testelement.TestElementbuildTestElement()DslJsonAssertionequalsTo(Object value)Specifies to check the value extracted is the given value.DslJsonAssertionequalsToJson(String json)Specifies the raw JSON value to check the extracted value is equals to.DslJsonAssertionmatches(String regex)Specifies to check the value extracted with the given query to match the given regular expression.DslJsonAssertionnot()Allows to check the inverse/negated condition specified by the rest of assertion settings.DslJsonAssertionnot(boolean negated)Sames asnotbut allowing to enable/disable the setting with a variable.DslJsonAssertionqueryLanguage(DslJsonExtractor.JsonQueryLanguage queryLanguage)Allows selecting the query language to use for JSON assertion.-
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
-
query
protected String query
-
isRegex
protected boolean isRegex
-
validateValue
protected boolean validateValue
-
value
protected String value
-
not
protected boolean not
-
queryLanguage
protected DslJsonExtractor.JsonQueryLanguage queryLanguage
-
-
Method Detail
-
matches
public DslJsonAssertion matches(String regex)
Specifies to check the value extracted with the given query to match the given regular expression.- Parameters:
regex- specifies the regular expression to check extracted value with.- Returns:
- the assertion element for further configuration or usage.
-
equalsTo
public DslJsonAssertion equalsTo(Object value)
Specifies to check the value extracted is the given value.Warning: This method serializes the value with Jackson library and then configures JMeter element with such value. If you want to pass the raw JSON to compare with, use
equalsToJson(String)instead.If you want to use a JMeter expression (Eg:
"${VAR}") for checking for some primitive type (like int or boolean), then useequalsToJson(String)instead.- Parameters:
value- specifies the value to check the extracted value against. Here you can pass primitive types (like ints, booleans, etc), Strings, collections (lists, maps), arrays, and even objects to be serialized with Jackson library. You can also specify null if you want to check if extracted value is null.- Returns:
- the assertion element for further configuration or usage.
- See Also:
equalsToJson(String)
-
equalsToJson
public DslJsonAssertion equalsToJson(String json)
Specifies the raw JSON value to check the extracted value is equals to.When using this method you must provide the actual JSON representation of the value. For example, if you want to check the value is a given string, then you have to quote it like
"\"test string\"".In general prefer using
equalsTo(Object)which is simpler.- Parameters:
json- specifies the raw json to check the extracted value against. You can specify here simple values like"1","\"test string\"", or more complex ones like"[1, 2, 3]"or"{\"prop\": 1}". If you want to use a JMeter expression (eg:"${VAR}") for checking for a string value, you should add quotes to it (eg:"\"${VAR}\"").- Returns:
- the assertion element for further configuration or usage.
- Since:
- 1.16
- See Also:
equalsTo(Object)
-
not
public DslJsonAssertion not()
Allows to check the inverse/negated condition specified by the rest of assertion settings.For example, you can use it to check that a given path doesn't exist, or that extracted value is not a given one or does not match a given pattern.
- Returns:
- the assertion element for further configuration or usage.
-
not
public DslJsonAssertion not(boolean negated)
Sames asnotbut allowing to enable/disable the setting with a variable.- Parameters:
negated- when true, specifies to negate the check. When false, specifies to not negate the check.- Returns:
- the assertion element for further configuration or usage.
-
queryLanguage
public DslJsonAssertion queryLanguage(DslJsonExtractor.JsonQueryLanguage queryLanguage)
Allows selecting the query language to use for JSON assertion.- Parameters:
queryLanguage- specifies the query language to use for assertions. When no value is specified, JMESPath is used by default.- Returns:
- the assertion for further configuration and usage.
- See Also:
DslJsonExtractor.JsonQueryLanguage
-
buildTestElement
protected org.apache.jmeter.testelement.TestElement buildTestElement()
- Specified by:
buildTestElementin classBaseTestElement
-
-