Я работаю с:
- Весенний MVC-тест
- Хэмкрест
Для предмета из коллекции, например:
<collection>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="persona">
<id>087</id>
<nombre>Leonardo</nombre>
<apellido>Jordan</apellido>
<fecha>1981-07-05</fecha>
</item>
....
Следующие работы:
.andExpect(xpath("collection/item[1]").exists())
.andExpect(xpath("collection/item[1]/*").nodeCount(is(4)))
.andExpect(xpath("collection/item[1]/id").exists())
.andExpect(xpath("collection/item[1]/id").string(is("087")))
.andExpect(xpath("collection/item[1]/id").string(is(personasArray[0].getId())))
.andExpect(xpath("collection/item[1]/nombre").exists())
.andExpect(xpath("collection/item[1]/nombre").string(is("Leonardo")))
.andExpect(xpath("collection/item[1]/nombre").string(is(personasArray[0].getNombre())))
.andExpect(xpath("collection/item[1]/apellido").exists())
.andExpect(xpath("collection/item[1]/apellido").string(is("Jordan")))
.andExpect(xpath("collection/item[1]/apellido").string(is(personasArray[0].getApellido())))
Я хочу знать, возможно ли провести прямое сравнение с объектом, а не для каждого поля, рассмотрим объект с 15-45 полями.
Мне нужно что-то вроде этого:
.andExpect(xpath("collection/item[1]/*").how(is(personasArray[0])))
См. часть how
, она показывает, какой правильный метод использовать. То же самое касается содержимого строки path
.