Class ElasticsearchAssertions


  • public class ElasticsearchAssertions
    extends java.lang.Object
    • Constructor Detail

      • ElasticsearchAssertions

        public ElasticsearchAssertions()
    • Method Detail

      • 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 specific ClusterBlock.
        Parameters:
        builder - the request builder
        expectedBlockId - 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 specific ClusterBlock.
        Parameters:
        builder - the request builder
        expectedBlock - 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 org.apache.lucene.search.Query> T assertBooleanSubQuery​(org.apache.lucene.search.Query query,
                                                                                         java.lang.Class<T> subqueryType,
                                                                                         int i)
      • assertDisjunctionSubQuery

        public static <T extends org.apache.lucene.search.Query> T assertDisjunctionSubQuery​(org.apache.lucene.search.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 given RestStatus
      • 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 given RestStatus
      • 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 class
        status - RestStatus to check for. Can be null to disable the check
        extraInfo - 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,
                                                                        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
      • awaitLatch

        public static void awaitLatch​(java.util.concurrent.CountDownLatch latch,
                                      long timeout,
                                      java.util.concurrent.TimeUnit unit)
                               throws java.lang.InterruptedException
        Wait for a latch to countdown and provide a useful error message if it does not Often latches are called as assertTrue(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 for
        timeout - The value of the timeout
        unit - The unit of the timeout
        Throws:
        java.lang.InterruptedException - An exception if the waiting is interrupted