public interface XmlVerifiable extends IteratingOverArray, XmlReader
Modifier and Type | Method and Description |
---|---|
XmlArrayVerifiable |
array(String value)
When you want to assert values in a array with a given name, e.g.
|
XmlVerifiable |
index(int index)
Adds an index to xPath
|
XmlVerifiable |
isEqualTo(Boolean value)
Equality comparison with a Boolean
|
XmlVerifiable |
isEqualTo(Number value)
Equality comparison with a Number
|
XmlVerifiable |
isEqualTo(Object value)
Equality comparison with any object
|
XmlVerifiable |
isEqualTo(String value)
Equality comparison with String
|
XmlVerifiable |
isNull()
Equality comparison to null
|
XmlVerifiable |
matches(String value)
Regex matching for strings
|
void |
matchesXPath(String xPath)
Checks if the parsed document matches given XPath
|
XmlVerifiable |
node(String... nodeNames)
Field assertions.
|
XmlVerifiable |
node(String nodeName)
Field assertion.
|
XmlVerifiable |
text()
Adds a
text() call to xPath |
XmlVerifiable |
withAttribute(String attribute)
Adds attribute query to xPath without comparing with any provided value
|
XmlVerifiable |
withAttribute(String attribute,
String attributeValue)
Field assertion.
|
XmlVerifiable |
withoutThrowingException()
Calling this method will setup the fluent interface to ignore any XPath verification
|
String |
xPath()
Returns current XPath expression
|
isAssertingAValueInArray, isIteratingOverArray
XmlVerifiable node(String nodeName)
XmlVerifiable withAttribute(String attribute, String attributeValue)
<?xml version="1.0" encoding="UTF-8" ?>
<some>
<nested>
<json>with "val'ue</json>
<anothervalue>4</anothervalue>
<withattr id="a" id2="b">foo</withattr>
<withlist>
<name>name1</name>
</withlist>
<withlist>
<name>name2</name>
</withlist>
<withlist>
8
</withlist>
<withlist>
<name id="10" surname="kowalski">name3</name>
</withlist>
</nested>
</some>
In order to check the values of the attributes of the withlist
element
with value name3
you'd have to call:
assertThat(xml1).node("some").node("nested").array("withlist").contains("name").isEqualTo("name3").withAttribute("id", "10").withAttribute("surname", "kowalski")
The following XPath would be created:
/some/nested/withlist[name='name3']/name[@id='10'][@surname='kowalski']
XmlVerifiable withAttribute(String attribute)
attribute
- AttributeNameXmlVerifiable
XmlVerifiable text()
text()
call to xPathXmlVerifiable
XmlVerifiable index(int index)
XmlVerifiable
XmlVerifiable node(String... nodeNames)
XmlArrayVerifiable array(String value)
<list>
<element>foo</element>
<element>bar</element>
<complexElement>
<param>baz</param>
</complexElement>
</list>
The code to check it would look like this:
array("list").contains("element").isEqualTo("foo")
array("list").contains("complexElement").node("param").isEqualTo("baz")
The generated XPaths would be
/list/element[text()='foo']
/list/complexElement[param='baz']
XmlVerifiable isEqualTo(String value) throws IllegalStateException
IllegalStateException
- - if XPath is not matched for the parsed XMLXmlVerifiable isEqualTo(Object value) throws IllegalStateException
IllegalStateException
- - if XPath is not matched for the parsed XMLXmlVerifiable isEqualTo(Number value) throws IllegalStateException
IllegalStateException
- - if XPath is not matched for the parsed XMLXmlVerifiable isNull() throws IllegalStateException
IllegalStateException
- - if XPath is not matched for the parsed XMLXmlVerifiable matches(String value) throws IllegalStateException
IllegalStateException
- - if XPath is not matched for the parsed XMLXmlVerifiable isEqualTo(Boolean value) throws IllegalStateException
IllegalStateException
- - if XPath is not matched for the parsed XMLXmlVerifiable withoutThrowingException()
String xPath()
void matchesXPath(String xPath)
Copyright © 2016–2019 Spring. All rights reserved.