As many Elasticsearch tests are checking for a similar output, like the amount of hits or the first hit or special highlighting, a couple of predefined assertions have been created. Those have been put into the ElasticsearchAssertions
class. There is also a specific geo assertions in ElasticsearchGeoAssertions
.
|
Checks hit count of a search or count request |
|
Ensure the a request has been acknowledged by the master |
|
Asserts a search response contains specific ids |
|
Asserts a matching count from a percolation response |
|
Asserts the first hit hits the specified matcher |
|
Asserts the second hit hits the specified matcher |
|
Asserts the third hit hits the specified matcher |
|
Assert a certain element in a search response hits the specified matcher |
|
Asserts that no shard failures have occurred in the response |
|
Asserts that shard failures have happened during a search request |
|
Assert specific highlights matched |
|
Assert for specific suggestions |
|
Assert for specific suggestion count |
|
Assert a specific exception has been thrown |
Common matchers
|
Matcher to check for a search hit id |
|
Matcher to check for a search hit type |
|
Matcher to check for a search hit index |
|
Matcher to check for a certain score of a hit |
|
Matcher to check for a certain |
Usually, you would combine assertions and matchers in your test like this
SearchResponse searchResponse = client().prepareSearch() ...; assertHitCount(searchResponse, 4); assertFirstHit(searchResponse, hasId("4")); assertSearchHits(searchResponse, "1", "2", "3", "4");