Package org.elasticsearch.test.hamcrest
Class ElasticsearchAssertions
java.lang.Object
org.elasticsearch.test.hamcrest.ElasticsearchAssertions
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertAcked(org.elasticsearch.action.admin.indices.create.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(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequestBuilder builder) static voidassertAcked(org.elasticsearch.action.support.master.AcknowledgedRequestBuilder<?, ?, ?> builder) static voidassertAcked(org.elasticsearch.action.support.master.AcknowledgedResponse response) static voidassertAllSuccessful(org.elasticsearch.action.search.SearchResponse response) static voidassertAllSuccessful(org.elasticsearch.action.support.broadcast.BroadcastResponse response) static voidassertBlocked(org.elasticsearch.action.ActionRequestBuilder<?, ?> builder) Executes the request and fails if the request has not been blocked.static voidassertBlocked(org.elasticsearch.action.ActionRequestBuilder<?, ?> builder, Integer expectedBlockId) Executes the request and fails if the request has not been blocked by a specificClusterBlock.static voidassertBlocked(org.elasticsearch.action.ActionRequestBuilder<?, ?> builder, org.elasticsearch.cluster.block.ClusterBlock expectedBlock) Executes the request and fails if the request has not been blocked by a specificClusterBlock.static voidassertBlocked(org.elasticsearch.action.support.broadcast.BroadcastResponse replicatedBroadcastResponse) Checks that all shard requests of a replicated broadcast request failed due to a cluster blockstatic <T extends org.apache.lucene.search.Query>
TassertBooleanSubQuery(org.apache.lucene.search.Query query, Class<T> subqueryType, int i) static voidassertExists(org.elasticsearch.action.get.GetResponse response) static voidassertFailures(org.elasticsearch.action.search.SearchRequestBuilder searchRequestBuilder, org.elasticsearch.rest.RestStatus restStatus, org.hamcrest.Matcher<String> reasonMatcher) static voidassertFailures(org.elasticsearch.action.search.SearchResponse searchResponse) static voidassertFileExists(Path file) Check if a file existsstatic voidassertFileNotExists(Path file) Check if a file does not existstatic voidassertFirstHit(org.elasticsearch.action.search.SearchResponse searchResponse, org.hamcrest.Matcher<org.elasticsearch.search.SearchHit> matcher) static voidassertFourthHit(org.elasticsearch.action.search.SearchResponse searchResponse, org.hamcrest.Matcher<org.elasticsearch.search.SearchHit> matcher) static <E extends Throwable>
voidassertFutureThrows(org.elasticsearch.action.ActionFuture<?> future, Class<E> exceptionClass) Run future.actionGet() and check that it throws an exception of the right typestatic <E extends Throwable>
voidassertFutureThrows(org.elasticsearch.action.ActionFuture<?> future, Class<E> exceptionClass, String extraInfo) Run future.actionGet() and check that it throws an exception of the right typestatic <E extends Throwable>
voidassertFutureThrows(org.elasticsearch.action.ActionFuture<?> future, Class<E> exceptionClass, org.elasticsearch.rest.RestStatus status) Run future.actionGet() and check that it throws an exception of the right type, with a givenRestStatusstatic <E extends Throwable>
voidassertFutureThrows(org.elasticsearch.action.ActionFuture<?> future, Class<E> exceptionClass, org.elasticsearch.rest.RestStatus status, String extraInfo) Run future.actionGet() and check that it throws an exception of the right type, optionally checking the exception's rest statusstatic voidassertFutureThrows(org.elasticsearch.action.ActionFuture<?> future, org.elasticsearch.rest.RestStatus status) static voidassertFutureThrows(org.elasticsearch.action.ActionFuture<?> future, org.elasticsearch.rest.RestStatus status, String extraInfo) static voidassertHighlight(org.elasticsearch.action.search.SearchResponse resp, int hit, String field, int fragment, int totalFragments, org.hamcrest.Matcher<String> matcher) static voidassertHighlight(org.elasticsearch.action.search.SearchResponse resp, int hit, String field, int fragment, org.hamcrest.Matcher<String> matcher) static voidassertHighlight(org.elasticsearch.search.SearchHit hit, String field, int fragment, int totalFragments, org.hamcrest.Matcher<String> matcher) static voidassertHighlight(org.elasticsearch.search.SearchHit hit, String field, int fragment, org.hamcrest.Matcher<String> matcher) static voidassertHitCount(org.elasticsearch.action.search.SearchResponse countResponse, long expectedHitCount) static voidassertIndexTemplateExists(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse templatesResponse, String name) Assert that an index template existsstatic voidassertIndexTemplateMissing(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse templatesResponse, String name) Assert that an index template is missingstatic voidassertNoFailures(org.elasticsearch.action.bulk.BulkResponse response) static voidassertNoFailures(org.elasticsearch.action.search.SearchResponse searchResponse) static voidassertNoFailures(org.elasticsearch.action.support.broadcast.BroadcastResponse response) static voidassertNoSearchHits(org.elasticsearch.action.search.SearchResponse searchResponse) static voidassertNotHighlighted(org.elasticsearch.action.search.SearchResponse resp, int hit, String field) static voidassertNoTimeout(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder requestBuilder) static voidassertNoTimeout(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse response) static voidassertOrderedSearchHits(org.elasticsearch.action.search.SearchResponse searchResponse, String... ids) static <E extends Throwable>
voidassertRequestBuilderThrows(org.elasticsearch.action.ActionRequestBuilder<?, ?> builder, Class<E> exceptionClass) Run the request from a given builder and check that it throws an exception of the right typestatic <E extends Throwable>
voidassertRequestBuilderThrows(org.elasticsearch.action.ActionRequestBuilder<?, ?> builder, Class<E> exceptionClass, String extraInfo) Run the request from a given builder and check that it throws an exception of the right typestatic <E extends Throwable>
voidassertRequestBuilderThrows(org.elasticsearch.action.ActionRequestBuilder<?, ?> builder, Class<E> exceptionClass, org.elasticsearch.rest.RestStatus status) Run the request from a given builder and check that it throws an exception of the right type, with a givenRestStatusstatic voidassertRequestBuilderThrows(org.elasticsearch.action.ActionRequestBuilder<?, ?> builder, org.elasticsearch.rest.RestStatus status) static voidassertRequestBuilderThrows(org.elasticsearch.action.ActionRequestBuilder<?, ?> builder, org.elasticsearch.rest.RestStatus status, String extraInfo) static voidassertSearchHit(org.elasticsearch.action.search.SearchResponse searchResponse, int number, org.hamcrest.Matcher<org.elasticsearch.search.SearchHit> matcher) static voidassertSearchHits(org.elasticsearch.action.search.SearchResponse searchResponse, String... ids) static org.elasticsearch.action.search.SearchResponseassertSearchResponse(org.elasticsearch.action.search.SearchRequestBuilder request) Applies basic assertions on the SearchResponse.static org.elasticsearch.action.search.SearchResponseassertSearchResponse(org.elasticsearch.action.search.SearchResponse response) Applies basic assertions on the SearchResponse.static voidassertSecondHit(org.elasticsearch.action.search.SearchResponse searchResponse, org.hamcrest.Matcher<org.elasticsearch.search.SearchHit> matcher) static voidassertSortValues(org.elasticsearch.action.search.SearchResponse searchResponse, Object[]... sortValues) static voidassertSuggestion(org.elasticsearch.search.suggest.Suggest searchSuggest, int entry, int ord, String key, String text) static voidassertSuggestion(org.elasticsearch.search.suggest.Suggest searchSuggest, int entry, String key, int size, String... text) Assert suggestion returns size suggestions and the first are the provided text.static voidassertSuggestion(org.elasticsearch.search.suggest.Suggest searchSuggest, int entry, String key, String... text) Assert suggestion returns exactly the provided text.static voidassertSuggestionPhraseCollateMatchExists(org.elasticsearch.search.suggest.Suggest searchSuggest, String key, int numberOfPhraseExists) static voidassertSuggestionSize(org.elasticsearch.search.suggest.Suggest searchSuggest, int entry, int size, String key) static voidassertThirdHit(org.elasticsearch.action.search.SearchResponse searchResponse, org.hamcrest.Matcher<org.elasticsearch.search.SearchHit> matcher) static voidassertToXContentEquivalent(org.elasticsearch.common.bytes.BytesReference expected, org.elasticsearch.common.bytes.BytesReference actual, org.elasticsearch.xcontent.XContentType xContentType) Asserts that the providedBytesReferences created throughToXContent.toXContent(XContentBuilder, ToXContent.Params)hold the same content.static voidawaitLatch(CountDownLatch latch, long timeout, 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 messagefieldFromSource(String fieldName) static StringformatShardStatus(org.elasticsearch.action.search.SearchResponse response) static StringformatShardStatus(org.elasticsearch.action.support.broadcast.BroadcastResponse response) static org.hamcrest.Matcher<org.elasticsearch.search.SearchHit>static org.hamcrest.Matcher<org.elasticsearch.search.SearchHit>static <T,V> org.hamcrest.core.CombinableMatcher<T> hasProperty(Function<? super T, ? extends V> property, org.hamcrest.Matcher<V> valueMatcher) static org.hamcrest.Matcher<org.elasticsearch.search.SearchHit>hasScore(float score)
-
Constructor Details
-
ElasticsearchAssertions
public ElasticsearchAssertions()
-
-
Method Details
-
assertAcked
public static void assertAcked(org.elasticsearch.action.support.master.AcknowledgedRequestBuilder<?, ?, ?> builder) -
assertNoTimeout
public static void assertNoTimeout(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder requestBuilder) -
assertNoTimeout
public static void assertNoTimeout(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse response) -
assertAcked
public static void assertAcked(org.elasticsearch.action.support.master.AcknowledgedResponse response) -
assertAcked
public static void assertAcked(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequestBuilder builder) -
assertAcked
public static void assertAcked(org.elasticsearch.action.admin.indices.create.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(org.elasticsearch.action.ActionRequestBuilder<?, ?> builder) Executes the request and fails if the request has not been blocked.- Parameters:
builder- the request builder
-
assertBlocked
public static void assertBlocked(org.elasticsearch.action.support.broadcast.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(org.elasticsearch.action.ActionRequestBuilder<?, ?> builder, @Nullable 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(org.elasticsearch.action.ActionRequestBuilder<?, ?> builder, @Nullable org.elasticsearch.cluster.block.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 String formatShardStatus(org.elasticsearch.action.support.broadcast.BroadcastResponse response) -
formatShardStatus
-
assertNoSearchHits
public static void assertNoSearchHits(org.elasticsearch.action.search.SearchResponse searchResponse) -
assertSearchHits
public static void assertSearchHits(org.elasticsearch.action.search.SearchResponse searchResponse, String... ids) -
assertSortValues
public static void assertSortValues(org.elasticsearch.action.search.SearchResponse searchResponse, Object[]... sortValues) -
assertOrderedSearchHits
public static void assertOrderedSearchHits(org.elasticsearch.action.search.SearchResponse searchResponse, String... ids) -
assertHitCount
public static void assertHitCount(org.elasticsearch.action.search.SearchResponse countResponse, long expectedHitCount) -
assertExists
public static void assertExists(org.elasticsearch.action.get.GetResponse response) -
assertFirstHit
public static void assertFirstHit(org.elasticsearch.action.search.SearchResponse searchResponse, org.hamcrest.Matcher<org.elasticsearch.search.SearchHit> matcher) -
assertSecondHit
public static void assertSecondHit(org.elasticsearch.action.search.SearchResponse searchResponse, org.hamcrest.Matcher<org.elasticsearch.search.SearchHit> matcher) -
assertThirdHit
public static void assertThirdHit(org.elasticsearch.action.search.SearchResponse searchResponse, org.hamcrest.Matcher<org.elasticsearch.search.SearchHit> matcher) -
assertFourthHit
public static void assertFourthHit(org.elasticsearch.action.search.SearchResponse searchResponse, org.hamcrest.Matcher<org.elasticsearch.search.SearchHit> matcher) -
assertSearchHit
public static void assertSearchHit(org.elasticsearch.action.search.SearchResponse searchResponse, int number, org.hamcrest.Matcher<org.elasticsearch.search.SearchHit> matcher) -
assertNoFailures
public static void assertNoFailures(org.elasticsearch.action.search.SearchResponse searchResponse) -
assertFailures
public static void assertFailures(org.elasticsearch.action.search.SearchResponse searchResponse) -
assertNoFailures
public static void assertNoFailures(org.elasticsearch.action.bulk.BulkResponse response) -
assertFailures
public static void assertFailures(org.elasticsearch.action.search.SearchRequestBuilder searchRequestBuilder, org.elasticsearch.rest.RestStatus restStatus, org.hamcrest.Matcher<String> reasonMatcher) -
assertNoFailures
public static void assertNoFailures(org.elasticsearch.action.support.broadcast.BroadcastResponse response) -
assertAllSuccessful
public static void assertAllSuccessful(org.elasticsearch.action.support.broadcast.BroadcastResponse response) -
assertAllSuccessful
public static void assertAllSuccessful(org.elasticsearch.action.search.SearchResponse response) -
assertHighlight
-
assertHighlight
-
assertHighlight
-
assertHighlight
-
assertNotHighlighted
public static void assertNotHighlighted(org.elasticsearch.action.search.SearchResponse resp, int hit, String field) -
assertSuggestionSize
public static void assertSuggestionSize(org.elasticsearch.search.suggest.Suggest searchSuggest, int entry, int size, String key) -
assertSuggestionPhraseCollateMatchExists
public static void assertSuggestionPhraseCollateMatchExists(org.elasticsearch.search.suggest.Suggest searchSuggest, String key, int numberOfPhraseExists) -
assertSuggestion
-
assertSuggestion
public static void assertSuggestion(org.elasticsearch.search.suggest.Suggest searchSuggest, int entry, String key, String... text) Assert suggestion returns exactly the provided text. -
assertSuggestion
public static void assertSuggestion(org.elasticsearch.search.suggest.Suggest searchSuggest, int entry, String key, int size, String... text) Assert suggestion returns size suggestions and the first are the provided text. -
assertIndexTemplateMissing
public static void assertIndexTemplateMissing(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse templatesResponse, String name) Assert that an index template is missing -
assertIndexTemplateExists
public static void assertIndexTemplateExists(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse templatesResponse, String name) Assert that an index template exists -
hasId
-
hasIndex
-
hasScore
public static org.hamcrest.Matcher<org.elasticsearch.search.SearchHit> hasScore(float score) -
hasProperty
public static <T,V> org.hamcrest.core.CombinableMatcher<T> hasProperty(Function<? super T, ? extends V> property, org.hamcrest.Matcher<V> valueMatcher) -
fieldFromSource
-
assertBooleanSubQuery
public static <T extends org.apache.lucene.search.Query> T assertBooleanSubQuery(org.apache.lucene.search.Query query, Class<T> subqueryType, int i) -
assertRequestBuilderThrows
public static <E extends Throwable> void assertRequestBuilderThrows(org.elasticsearch.action.ActionRequestBuilder<?, ?> builder, Class<E> exceptionClass) Run the request from a given builder and check that it throws an exception of the right type -
assertRequestBuilderThrows
public static <E extends Throwable> void assertRequestBuilderThrows(org.elasticsearch.action.ActionRequestBuilder<?, ?> builder, Class<E> exceptionClass, org.elasticsearch.rest.RestStatus status) Run the request from a given builder and check that it throws an exception of the right type, with a givenRestStatus -
assertRequestBuilderThrows
public static <E extends Throwable> void assertRequestBuilderThrows(org.elasticsearch.action.ActionRequestBuilder<?, ?> builder, Class<E> exceptionClass, 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
-
assertFutureThrows
public static <E extends Throwable> void assertFutureThrows(org.elasticsearch.action.ActionFuture<?> future, Class<E> exceptionClass) Run future.actionGet() and check that it throws an exception of the right type -
assertFutureThrows
public static <E extends Throwable> void assertFutureThrows(org.elasticsearch.action.ActionFuture<?> future, Class<E> exceptionClass, org.elasticsearch.rest.RestStatus status) Run future.actionGet() and check that it throws an exception of the right type, with a givenRestStatus -
assertFutureThrows
public static <E extends Throwable> void assertFutureThrows(org.elasticsearch.action.ActionFuture<?> future, Class<E> exceptionClass, 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
-
assertFutureThrows
public static <E extends Throwable> void assertFutureThrows(org.elasticsearch.action.ActionFuture<?> future, Class<E> exceptionClass, @Nullable org.elasticsearch.rest.RestStatus status, @Nullable 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.
-
assertRequestBuilderThrows
public static void assertRequestBuilderThrows(org.elasticsearch.action.ActionRequestBuilder<?, ?> builder, org.elasticsearch.rest.RestStatus status) -
assertRequestBuilderThrows
public static void assertRequestBuilderThrows(org.elasticsearch.action.ActionRequestBuilder<?, ?> builder, org.elasticsearch.rest.RestStatus status, String extraInfo) -
assertFutureThrows
public static void assertFutureThrows(org.elasticsearch.action.ActionFuture<?> future, org.elasticsearch.rest.RestStatus status) -
assertFutureThrows
public static void assertFutureThrows(org.elasticsearch.action.ActionFuture<?> future, org.elasticsearch.rest.RestStatus status, String extraInfo) -
assertSearchResponse
public static org.elasticsearch.action.search.SearchResponse assertSearchResponse(org.elasticsearch.action.search.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 org.elasticsearch.action.search.SearchResponse assertSearchResponse(org.elasticsearch.action.search.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
Check if a file exists -
assertFileNotExists
Check if a file does not exist -
assertToXContentEquivalent
public static void assertToXContentEquivalent(org.elasticsearch.common.bytes.BytesReference expected, org.elasticsearch.common.bytes.BytesReference actual, org.elasticsearch.xcontent.XContentType xContentType) throws 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:
IOException
-
awaitLatch
public static void awaitLatch(CountDownLatch latch, long timeout, TimeUnit unit) throws InterruptedException 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 message- Parameters:
latch- The latch to wait fortimeout- The value of the timeoutunit- The unit of the timeout- Throws:
InterruptedException- An exception if the waiting is interrupted
-