Package org.elasticsearch.test.hamcrest
Class ElasticsearchAssertions
- java.lang.Object
-
- org.elasticsearch.test.hamcrest.ElasticsearchAssertions
-
public class ElasticsearchAssertions extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description ElasticsearchAssertions()
-
Method Summary
Modifier and Type Method Description static voidassertAcked(CreateIndexResponse response)Assert that an index creation was fully acknowledged, meaning that both the index creation cluster state update was successful and that the requisite number of shard copies were started before returning.static voidassertAcked(DeleteIndexRequestBuilder builder)static voidassertAcked(AcknowledgedRequestBuilder<?,?,?> builder)static voidassertAcked(AcknowledgedResponse response)static voidassertAliasesExist(AliasesExistResponse aliasesExistResponse)Assert that aliases existstatic voidassertAliasesMissing(AliasesExistResponse aliasesExistResponse)Assert that aliases are missingstatic voidassertAllSuccessful(SearchResponse response)static voidassertAllSuccessful(BroadcastResponse response)static voidassertBlocked(ActionRequestBuilder builder)Executes the request and fails if the request has not been blocked.static voidassertBlocked(ActionRequestBuilder builder, java.lang.Integer expectedBlockId)Executes the request and fails if the request has not been blocked by a specificClusterBlock.static voidassertBlocked(ActionRequestBuilder builder, ClusterBlock expectedBlock)Executes the request and fails if the request has not been blocked by a specificClusterBlock.static voidassertBlocked(BroadcastResponse replicatedBroadcastResponse)Checks that all shard requests of a replicated broadcast request failed due to a cluster blockstatic <T extends Query>
TassertBooleanSubQuery(Query query, java.lang.Class<T> subqueryType, int i)static voidassertDirectoryExists(java.nio.file.Path dir)Check if a directory existsstatic <T extends Query>
TassertDisjunctionSubQuery(Query query, java.lang.Class<T> subqueryType, int i)static voidassertExists(GetResponse response)static voidassertFailures(SearchRequestBuilder searchRequestBuilder, RestStatus restStatus, org.hamcrest.Matcher<java.lang.String> reasonMatcher)static voidassertFailures(SearchResponse searchResponse)static voidassertFifthHit(SearchResponse searchResponse, org.hamcrest.Matcher<SearchHit> matcher)static voidassertFileExists(java.nio.file.Path file)Check if a file existsstatic voidassertFileNotExists(java.nio.file.Path file)Check if a file does not existstatic voidassertFirstHit(SearchResponse searchResponse, org.hamcrest.Matcher<SearchHit> matcher)static voidassertFourthHit(SearchResponse searchResponse, org.hamcrest.Matcher<SearchHit> matcher)static voidassertHighlight(SearchResponse resp, int hit, java.lang.String field, int fragment, int totalFragments, org.hamcrest.Matcher<java.lang.String> matcher)static voidassertHighlight(SearchResponse resp, int hit, java.lang.String field, int fragment, org.hamcrest.Matcher<java.lang.String> matcher)static voidassertHighlight(SearchHit hit, java.lang.String field, int fragment, int totalFragments, org.hamcrest.Matcher<java.lang.String> matcher)static voidassertHighlight(SearchHit hit, java.lang.String field, int fragment, org.hamcrest.Matcher<java.lang.String> matcher)static voidassertHitCount(SearchResponse countResponse, long expectedHitCount)static voidassertIndexTemplateExists(GetIndexTemplatesResponse templatesResponse, java.lang.String name)Assert that an index template existsstatic voidassertIndexTemplateMissing(GetIndexTemplatesResponse templatesResponse, java.lang.String name)Assert that an index template is missingstatic voidassertNoFailures(BulkResponse response)static voidassertNoFailures(SearchResponse searchResponse)static voidassertNoFailures(BroadcastResponse response)static voidassertNoSearchHits(SearchResponse searchResponse)static voidassertNotHighlighted(SearchResponse resp, int hit, java.lang.String field)static voidassertNoTimeout(ClusterHealthRequestBuilder requestBuilder)static voidassertNoTimeout(ClusterHealthResponse response)static voidassertOrderedSearchHits(SearchResponse searchResponse, java.lang.String... ids)static voidassertSearchHit(SearchResponse searchResponse, int number, org.hamcrest.Matcher<SearchHit> matcher)static voidassertSearchHits(SearchResponse searchResponse, java.lang.String... ids)static SearchResponseassertSearchResponse(SearchRequestBuilder request)Applies basic assertions on the SearchResponse.static SearchResponseassertSearchResponse(SearchResponse response)Applies basic assertions on the SearchResponse.static voidassertSecondHit(SearchResponse searchResponse, org.hamcrest.Matcher<SearchHit> matcher)static voidassertSortValues(SearchResponse searchResponse, java.lang.Object[]... sortValues)static voidassertSuggestion(Suggest searchSuggest, int entry, int ord, java.lang.String key, java.lang.String text)static voidassertSuggestion(Suggest searchSuggest, int entry, java.lang.String key, int size, java.lang.String... text)Assert suggestion returns size suggestions and the first are the provided text.static voidassertSuggestion(Suggest searchSuggest, int entry, java.lang.String key, java.lang.String... text)Assert suggestion returns exactly the provided text.static voidassertSuggestionPhraseCollateMatchExists(Suggest searchSuggest, java.lang.String key, int numberOfPhraseExists)static voidassertSuggestionSize(Suggest searchSuggest, int entry, int size, java.lang.String key)static voidassertThirdHit(SearchResponse searchResponse, org.hamcrest.Matcher<SearchHit> matcher)static <E extends java.lang.Throwable>
voidassertThrows(ActionFuture future, java.lang.Class<E> exceptionClass)Run future.actionGet() and check that it throws an exception of the right typestatic <E extends java.lang.Throwable>
voidassertThrows(ActionFuture future, java.lang.Class<E> exceptionClass, java.lang.String extraInfo)Run future.actionGet() and check that it throws an exception of the right typestatic <E extends java.lang.Throwable>
voidassertThrows(ActionFuture future, java.lang.Class<E> exceptionClass, RestStatus status)Run future.actionGet() and check that it throws an exception of the right type, with a givenRestStatusstatic <E extends java.lang.Throwable>
voidassertThrows(ActionFuture future, java.lang.Class<E> exceptionClass, RestStatus status, java.lang.String extraInfo)Run future.actionGet() and check that it throws an exception of the right type, optionally checking the exception's rest statusstatic <E extends java.lang.Throwable>
voidassertThrows(ActionFuture future, RestStatus status)static voidassertThrows(ActionFuture future, RestStatus status, java.lang.String extraInfo)static <E extends java.lang.Throwable>
voidassertThrows(ActionRequestBuilder<?,?,?> builder, java.lang.Class<E> exceptionClass)Run the request from a given builder and check that it throws an exception of the right typestatic <E extends java.lang.Throwable>
voidassertThrows(ActionRequestBuilder<?,?,?> builder, java.lang.Class<E> exceptionClass, java.lang.String extraInfo)Run the request from a given builder and check that it throws an exception of the right typestatic <E extends java.lang.Throwable>
voidassertThrows(ActionRequestBuilder<?,?,?> builder, java.lang.Class<E> exceptionClass, RestStatus status)Run the request from a given builder and check that it throws an exception of the right type, with a givenRestStatusstatic <E extends java.lang.Throwable>
voidassertThrows(ActionRequestBuilder<?,?,?> builder, RestStatus status)static <E extends java.lang.Throwable>
voidassertThrows(ActionRequestBuilder<?,?,?> builder, RestStatus status, java.lang.String extraInfo)static voidassertToXContentEquivalent(BytesReference expected, BytesReference actual, XContentType xContentType)Asserts that the providedBytesReferences created throughToXContent.toXContent(XContentBuilder, ToXContent.Params)hold the same content.static voidawaitLatch(java.util.concurrent.CountDownLatch latch, long timeout, java.util.concurrent.TimeUnit unit)Wait for a latch to countdown and provide a useful error message if it does not Often latches are called asassertTrue(latch.await(1, TimeUnit.SECONDS));In case of a failure this will just throw an assertion error without any further messagestatic java.util.function.Function<SearchHit,java.lang.Object>fieldFromSource(java.lang.String fieldName)static java.lang.StringformatShardStatus(SearchResponse response)static java.lang.StringformatShardStatus(BroadcastResponse response)static org.hamcrest.Matcher<SearchHit>hasId(java.lang.String id)static org.hamcrest.Matcher<SearchHit>hasIndex(java.lang.String index)static <T,V>
org.hamcrest.core.CombinableMatcher<T>hasProperty(java.util.function.Function<? super T,? extends V> property, org.hamcrest.Matcher<V> valueMatcher)static org.hamcrest.Matcher<SearchHit>hasScore(float score)static org.hamcrest.Matcher<SearchHit>hasType(java.lang.String type)
-
-
-
Method Detail
-
assertAcked
public static void assertAcked(AcknowledgedRequestBuilder<?,?,?> builder)
-
assertNoTimeout
public static void assertNoTimeout(ClusterHealthRequestBuilder requestBuilder)
-
assertNoTimeout
public static void assertNoTimeout(ClusterHealthResponse response)
-
assertAcked
public static void assertAcked(AcknowledgedResponse response)
-
assertAcked
public static void assertAcked(DeleteIndexRequestBuilder builder)
-
assertAcked
public static void assertAcked(CreateIndexResponse response)
Assert that an index creation was fully acknowledged, meaning that both the index creation cluster state update was successful and that the requisite number of shard copies were started before returning.
-
assertBlocked
public static void assertBlocked(ActionRequestBuilder builder)
Executes the request and fails if the request has not been blocked.- Parameters:
builder- the request builder
-
assertBlocked
public static void assertBlocked(BroadcastResponse replicatedBroadcastResponse)
Checks that all shard requests of a replicated broadcast request failed due to a cluster block- Parameters:
replicatedBroadcastResponse- the response that should only contain failed shard responses
-
assertBlocked
public static void assertBlocked(ActionRequestBuilder builder, @Nullable java.lang.Integer expectedBlockId)
Executes the request and fails if the request has not been blocked by a specificClusterBlock.- Parameters:
builder- the request builderexpectedBlockId- the expected block id
-
assertBlocked
public static void assertBlocked(ActionRequestBuilder builder, @Nullable ClusterBlock expectedBlock)
Executes the request and fails if the request has not been blocked by a specificClusterBlock.- Parameters:
builder- the request builderexpectedBlock- the expected block
-
formatShardStatus
public static java.lang.String formatShardStatus(BroadcastResponse response)
-
formatShardStatus
public static java.lang.String formatShardStatus(SearchResponse response)
-
assertNoSearchHits
public static void assertNoSearchHits(SearchResponse searchResponse)
-
assertSearchHits
public static void assertSearchHits(SearchResponse searchResponse, java.lang.String... ids)
-
assertSortValues
public static void assertSortValues(SearchResponse searchResponse, java.lang.Object[]... sortValues)
-
assertOrderedSearchHits
public static void assertOrderedSearchHits(SearchResponse searchResponse, java.lang.String... ids)
-
assertHitCount
public static void assertHitCount(SearchResponse countResponse, long expectedHitCount)
-
assertExists
public static void assertExists(GetResponse response)
-
assertFirstHit
public static void assertFirstHit(SearchResponse searchResponse, org.hamcrest.Matcher<SearchHit> matcher)
-
assertSecondHit
public static void assertSecondHit(SearchResponse searchResponse, org.hamcrest.Matcher<SearchHit> matcher)
-
assertThirdHit
public static void assertThirdHit(SearchResponse searchResponse, org.hamcrest.Matcher<SearchHit> matcher)
-
assertFourthHit
public static void assertFourthHit(SearchResponse searchResponse, org.hamcrest.Matcher<SearchHit> matcher)
-
assertFifthHit
public static void assertFifthHit(SearchResponse searchResponse, org.hamcrest.Matcher<SearchHit> matcher)
-
assertSearchHit
public static void assertSearchHit(SearchResponse searchResponse, int number, org.hamcrest.Matcher<SearchHit> matcher)
-
assertNoFailures
public static void assertNoFailures(SearchResponse searchResponse)
-
assertFailures
public static void assertFailures(SearchResponse searchResponse)
-
assertNoFailures
public static void assertNoFailures(BulkResponse response)
-
assertFailures
public static void assertFailures(SearchRequestBuilder searchRequestBuilder, RestStatus restStatus, org.hamcrest.Matcher<java.lang.String> reasonMatcher)
-
assertNoFailures
public static void assertNoFailures(BroadcastResponse response)
-
assertAllSuccessful
public static void assertAllSuccessful(BroadcastResponse response)
-
assertAllSuccessful
public static void assertAllSuccessful(SearchResponse response)
-
assertHighlight
public static void assertHighlight(SearchResponse resp, int hit, java.lang.String field, int fragment, org.hamcrest.Matcher<java.lang.String> matcher)
-
assertHighlight
public static void assertHighlight(SearchResponse resp, int hit, java.lang.String field, int fragment, int totalFragments, org.hamcrest.Matcher<java.lang.String> matcher)
-
assertHighlight
public static void assertHighlight(SearchHit hit, java.lang.String field, int fragment, org.hamcrest.Matcher<java.lang.String> matcher)
-
assertHighlight
public static void assertHighlight(SearchHit hit, java.lang.String field, int fragment, int totalFragments, org.hamcrest.Matcher<java.lang.String> matcher)
-
assertNotHighlighted
public static void assertNotHighlighted(SearchResponse resp, int hit, java.lang.String field)
-
assertSuggestionSize
public static void assertSuggestionSize(Suggest searchSuggest, int entry, int size, java.lang.String key)
-
assertSuggestionPhraseCollateMatchExists
public static void assertSuggestionPhraseCollateMatchExists(Suggest searchSuggest, java.lang.String key, int numberOfPhraseExists)
-
assertSuggestion
public static void assertSuggestion(Suggest searchSuggest, int entry, int ord, java.lang.String key, java.lang.String text)
-
assertSuggestion
public static void assertSuggestion(Suggest searchSuggest, int entry, java.lang.String key, java.lang.String... text)
Assert suggestion returns exactly the provided text.
-
assertSuggestion
public static void assertSuggestion(Suggest searchSuggest, int entry, java.lang.String key, int size, java.lang.String... text)
Assert suggestion returns size suggestions and the first are the provided text.
-
assertIndexTemplateMissing
public static void assertIndexTemplateMissing(GetIndexTemplatesResponse templatesResponse, java.lang.String name)
Assert that an index template is missing
-
assertIndexTemplateExists
public static void assertIndexTemplateExists(GetIndexTemplatesResponse templatesResponse, java.lang.String name)
Assert that an index template exists
-
assertAliasesMissing
public static void assertAliasesMissing(AliasesExistResponse aliasesExistResponse)
Assert that aliases are missing
-
assertAliasesExist
public static void assertAliasesExist(AliasesExistResponse aliasesExistResponse)
Assert that aliases exist
-
hasId
public static org.hamcrest.Matcher<SearchHit> hasId(java.lang.String id)
-
hasType
public static org.hamcrest.Matcher<SearchHit> hasType(java.lang.String type)
-
hasIndex
public static org.hamcrest.Matcher<SearchHit> hasIndex(java.lang.String index)
-
hasScore
public static org.hamcrest.Matcher<SearchHit> hasScore(float score)
-
hasProperty
public static <T,V> org.hamcrest.core.CombinableMatcher<T> hasProperty(java.util.function.Function<? super T,? extends V> property, org.hamcrest.Matcher<V> valueMatcher)
-
fieldFromSource
public static java.util.function.Function<SearchHit,java.lang.Object> fieldFromSource(java.lang.String fieldName)
-
assertBooleanSubQuery
public static <T extends Query> T assertBooleanSubQuery(Query query, java.lang.Class<T> subqueryType, int i)
-
assertDisjunctionSubQuery
public static <T extends Query> T assertDisjunctionSubQuery(Query query, java.lang.Class<T> subqueryType, int i)
-
assertThrows
public static <E extends java.lang.Throwable> void assertThrows(ActionRequestBuilder<?,?,?> builder, java.lang.Class<E> exceptionClass)
Run the request from a given builder and check that it throws an exception of the right type
-
assertThrows
public static <E extends java.lang.Throwable> void assertThrows(ActionRequestBuilder<?,?,?> builder, java.lang.Class<E> exceptionClass, RestStatus status)
Run the request from a given builder and check that it throws an exception of the right type, with a givenRestStatus
-
assertThrows
public static <E extends java.lang.Throwable> void assertThrows(ActionRequestBuilder<?,?,?> builder, java.lang.Class<E> exceptionClass, java.lang.String extraInfo)
Run the request from a given builder and check that it throws an exception of the right type- Parameters:
extraInfo- extra information to add to the failure message
-
assertThrows
public static <E extends java.lang.Throwable> void assertThrows(ActionFuture future, java.lang.Class<E> exceptionClass)
Run future.actionGet() and check that it throws an exception of the right type
-
assertThrows
public static <E extends java.lang.Throwable> void assertThrows(ActionFuture future, java.lang.Class<E> exceptionClass, RestStatus status)
Run future.actionGet() and check that it throws an exception of the right type, with a givenRestStatus
-
assertThrows
public static <E extends java.lang.Throwable> void assertThrows(ActionFuture future, java.lang.Class<E> exceptionClass, java.lang.String extraInfo)
Run future.actionGet() and check that it throws an exception of the right type- Parameters:
extraInfo- extra information to add to the failure message
-
assertThrows
public static <E extends java.lang.Throwable> void assertThrows(ActionFuture future, java.lang.Class<E> exceptionClass, @Nullable RestStatus status, @Nullable java.lang.String extraInfo)
Run future.actionGet() and check that it throws an exception of the right type, optionally checking the exception's rest status- Parameters:
exceptionClass- expected exception classstatus-RestStatusto check for. Can be null to disable the checkextraInfo- extra information to add to the failure message. Can be null.
-
assertThrows
public static <E extends java.lang.Throwable> void assertThrows(ActionRequestBuilder<?,?,?> builder, RestStatus status)
-
assertThrows
public static <E extends java.lang.Throwable> void assertThrows(ActionRequestBuilder<?,?,?> builder, RestStatus status, java.lang.String extraInfo)
-
assertThrows
public static <E extends java.lang.Throwable> void assertThrows(ActionFuture future, RestStatus status)
-
assertThrows
public static void assertThrows(ActionFuture future, RestStatus status, java.lang.String extraInfo)
-
assertSearchResponse
public static SearchResponse assertSearchResponse(SearchRequestBuilder request)
Applies basic assertions on the SearchResponse. This method checks if all shards were successful, if any of the shards threw an exception and if the response is serializable.
-
assertSearchResponse
public static SearchResponse assertSearchResponse(SearchResponse response)
Applies basic assertions on the SearchResponse. This method checks if all shards were successful, if any of the shards threw an exception and if the response is serializable.
-
assertFileExists
public static void assertFileExists(java.nio.file.Path file)
Check if a file exists
-
assertFileNotExists
public static void assertFileNotExists(java.nio.file.Path file)
Check if a file does not exist
-
assertDirectoryExists
public static void assertDirectoryExists(java.nio.file.Path dir)
Check if a directory exists
-
assertToXContentEquivalent
public static void assertToXContentEquivalent(BytesReference expected, BytesReference actual, XContentType xContentType) throws java.io.IOException
Asserts that the providedBytesReferences created throughToXContent.toXContent(XContentBuilder, ToXContent.Params)hold the same content. The comparison is done by parsing both into a map and comparing those two, so that keys ordering doesn't matter. Also binary values (byte[]) are properly compared through arrays comparisons.- Throws:
java.io.IOException
-
awaitLatch
public static void awaitLatch(java.util.concurrent.CountDownLatch latch, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedExceptionWait for a latch to countdown and provide a useful error message if it does not Often latches are called asassertTrue(latch.await(1, TimeUnit.SECONDS));In case of a failure this will just throw an assertion error without any further message- Parameters:
latch- The latch to wait fortimeout- The value of the timeoutunit- The unit of the timeout- Throws:
java.lang.InterruptedException- An exception if the waiting is interrupted
-
-