ElasticsearchHelper { public List<ResultTypeIndexSearchResponseDto> getResultTypeIndexSearchResponseDto(SearchResponse searchResponse) { List<ResultTypeIndexSearchResponseDto> list = new ArrayList<>(); Terms aggregation = getAggregation(searchResponse, RESULT_TYPE_AGGS); for (Terms.Bucket resultTypeEntry : aggregation.getBuckets()) { ResultTypeIndexSearchResponseDto dto = new ResultTypeIndexSearchResponseDto(); dto.setResultTypeCode(resultTypeEntry.getKeyAsString()); dto.setResultTypeDisplayName(resultTypeEntry.getKeyAsString()); dto.setCount(resultTypeEntry.getDocCount()); list.add(dto); } return list; }  SearchRequestBuilder addFacetFieldAggregations(Set<String> facetFieldsList, SearchRequestBuilder searchRequestBuilder); BoolQueryBuilder addIndexSearchFilterBooleanClause(List<IndexSearchFilter> indexSearchFilters, String bdefActiveIndex, String tagActiveIndex); List<ResultTypeIndexSearchResponseDto> getResultTypeIndexSearchResponseDto(SearchResponse searchResponse); List<TagTypeIndexSearchResponseDto> getTagTagIndexSearchResponseDto(SearchResponse searchResponse); List<TagTypeIndexSearchResponseDto> getNestedTagTagIndexSearchResponseDto(SearchResponse searchResponse); List<Facet> getFacetsResponse(ElasticsearchResponseDto elasticsearchResponseDto, final String bdefActiveIndex, final String tagActiveIndex); Terms getAggregation(SearchResponse searchResponse, String aggregationName); Terms getNestedAggregation(SearchResponse searchResponse, String nestedAggregationName, String subAggregationName); String getSearchIndexType(final String indexName, final String bdefActiveIndex, final String tagActiveIndex); static final String DISPLAY_NAME_SOURCE; static final String NESTED_BDEFTAGS_PATH; static final String TAGTYPE_CODE_FIELD_TAG_INDEX; static final String TAGTYPE_NAME_FIELD_TAG_INDEX; static final String TAG_CODE_FIELD_TAG_INDEX; static final String TAG_NAME_FIELD_TAG_INDEX; static final String BDEF_TAGTYPE_CODE_FIELD; static final String BDEF_TAGTYPE_NAME_FIELD; static final String BDEF_TAG_CODE_FIELD; static final String BDEF_TAG_NAME_FIELD; static final String TAG_TAG_CODE_FIELD; static final String TAG_TAGTYPE_CODE_FIELD; static final String TAG_FACET_AGGS; static final String TAGTYPE_CODE_AGGREGATION; static final String TAGTYPE_NAME_AGGREGATION; static final String TAG_CODE_AGGREGATION; static final String TAG_NAME_AGGREGATION; static final String TAG_FACET; static final String RESULT_TYPE_FACET; static final String TAG_TYPE_FACET_AGGS; static final String RESULT_TYPE_AGGS; static final String RESULT_TYPE_FIELD; }
@Test public void testGetResultTypeIndexSearchResponseDtoSearchResult() { SearchResponse searchResponse = mock(SearchResponse.class); Aggregations aggregations = mock(Aggregations.class); MockTerms terms = mock(MockTerms.class); MockBucket bucket = mock(MockBucket.class); List<MockBucket> bucketList = Collections.singletonList(bucket); when(searchResponse.getAggregations()).thenReturn(aggregations); when(aggregations.get(RESULT_TYPE_AGGS)).thenReturn(terms); when(terms.getBuckets()).thenReturn(bucketList); List<ResultTypeIndexSearchResponseDto> result = elasticsearchHelper.getResultTypeIndexSearchResponseDto(searchResponse); assertThat("Result is null.", result, is(notNullValue())); verify(searchResponse).getAggregations(); verify(aggregations).get(RESULT_TYPE_AGGS); verify(terms).getBuckets(); verify(bucket, times(2)).getKeyAsString(); verify(bucket).getDocCount(); verifyNoMoreInteractions(aggregations, bucket, searchResponse, terms); }
@Test public void testGetResultTypeIndexSearchResponseDto() { SearchResponse searchResponse = mock(SearchResponse.class); Aggregations aggregations = mock(Aggregations.class); MockTerms terms = mock(MockTerms.class); MockBucket bucket = mock(MockBucket.class); List<MockBucket> buckets = Collections.singletonList(bucket); when(searchResponse.getAggregations()).thenReturn(aggregations); when(aggregations.get(RESULT_TYPE_AGGS)).thenReturn(terms); when(terms.getBuckets()).thenReturn(buckets); when(bucket.getKeyAsString()).thenReturn(TAG_CODE); when(bucket.getDocCount()).thenReturn(TAG_COUNT); List<ResultTypeIndexSearchResponseDto> expectedList = new ArrayList<>(); expectedList.add(new ResultTypeIndexSearchResponseDto(TAG_CODE, TAG_COUNT, TAG_CODE)); List<ResultTypeIndexSearchResponseDto> resultList = elasticsearchHelper.getResultTypeIndexSearchResponseDto(searchResponse); assertEquals(expectedList, resultList); verify(searchResponse).getAggregations(); verify(aggregations).get(RESULT_TYPE_AGGS); verify(terms).getBuckets(); verify(bucket, times(2)).getKeyAsString(); verify(bucket).getDocCount(); verifyNoMoreInteractions(aggregations, bucket, searchResponse, terms); }