ElasticsearchHelper { public List<TagTypeIndexSearchResponseDto> getTagTagIndexSearchResponseDto(SearchResponse searchResponse) { Terms aggregation = getAggregation(searchResponse, TAG_TYPE_FACET_AGGS); return getTagTypeIndexSearchResponseDtosFromTerms(aggregation); }  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 testGetTagTagIndexSearchResponseDto() { SearchResponse searchResponse = mock(SearchResponse.class); MockTerms terms = mock(MockTerms.class); Aggregations aggregations = mock(Aggregations.class); MockBucket tagTypeCodeEntry = mock(MockBucket.class); List<MockBucket> tagTypeCodeEntryList = Collections.singletonList(tagTypeCodeEntry); MockTerms tagTypeDisplayNameAggs = mock(MockTerms.class); MockBucket tagTypeDisplayNameEntry = mock(MockBucket.class); List<MockBucket> tagTypeDisplayNameEntryList = Collections.singletonList(tagTypeDisplayNameEntry); StringTerms tagCodeAggs = mock(StringTerms.class); StringTerms.Bucket tagCodeEntry = mock(StringTerms.Bucket.class); List<StringTerms.Bucket> tagCodeEntryList = Collections.singletonList(tagCodeEntry); MockTerms tagNameAggs = mock(MockTerms.class); MockBucket tagNameEntry = mock(MockBucket.class); List<MockBucket> tagNameEntryList = Collections.singletonList(tagNameEntry); when(searchResponse.getAggregations()).thenReturn(aggregations); when(aggregations.get(TAG_TYPE_FACET_AGGS)).thenReturn(terms); when(terms.getBuckets()).thenReturn(tagTypeCodeEntryList); when(tagTypeCodeEntry.getKeyAsString()).thenReturn(TAG_TYPE_CODE); when(tagTypeCodeEntry.getAggregations()).thenReturn(aggregations); when(aggregations.get(TAGTYPE_NAME_AGGREGATION)).thenReturn(tagTypeDisplayNameAggs); when(tagTypeDisplayNameAggs.getBuckets()).thenReturn(tagTypeDisplayNameEntryList); when(tagTypeDisplayNameEntry.getAggregations()).thenReturn(aggregations); when(tagTypeDisplayNameEntry.getKeyAsString()).thenReturn(TAG_TYPE_DISPLAY_NAME); when(aggregations.get(TAG_CODE_AGGREGATION)).thenReturn(tagCodeAggs); when(tagCodeAggs.getBuckets()).thenReturn(tagCodeEntryList); when(tagCodeEntry.getAggregations()).thenReturn(aggregations); when(tagCodeEntry.getKeyAsString()).thenReturn(TAG_CODE); when(tagCodeEntry.getDocCount()).thenReturn((long) TAG_CODE_COUNT); when(aggregations.get(TAG_NAME_AGGREGATION)).thenReturn(tagNameAggs); when(tagNameAggs.getBuckets()).thenReturn(tagNameEntryList); when(tagNameEntry.getKeyAsString()).thenReturn(TAG_DISPLAY_NAME); List<TagTypeIndexSearchResponseDto> resultList = elasticsearchHelper.getTagTagIndexSearchResponseDto(searchResponse); List<TagTypeIndexSearchResponseDto> expectedList = new ArrayList<>(); List<TagIndexSearchResponseDto> expectedTagList = new ArrayList<>(); expectedTagList.add(new TagIndexSearchResponseDto(TAG_CODE, TAG_CODE_COUNT, TAG_DISPLAY_NAME)); expectedList.add(new TagTypeIndexSearchResponseDto(TAG_TYPE_CODE, expectedTagList, TAG_TYPE_DISPLAY_NAME)); assertEquals(expectedList, resultList); verify(searchResponse).getAggregations(); verify(aggregations).get(TAG_TYPE_FACET_AGGS); verify(terms).getBuckets(); verify(tagTypeCodeEntry).getKeyAsString(); verify(tagTypeCodeEntry).getAggregations(); verify(aggregations).get(TAGTYPE_NAME_AGGREGATION); verify(tagTypeDisplayNameAggs).getBuckets(); verify(tagTypeDisplayNameEntry).getAggregations(); verify(tagTypeDisplayNameEntry).getKeyAsString(); verify(aggregations).get(TAG_CODE_AGGREGATION); verify(tagCodeAggs).getBuckets(); verify(tagCodeEntry).getAggregations(); verify(tagCodeEntry).getKeyAsString(); verify(tagCodeEntry).getDocCount(); verify(aggregations).get(TAG_NAME_AGGREGATION); verify(tagNameAggs).getBuckets(); verify(tagNameEntry).getKeyAsString(); verifyNoMoreInteractions(aggregations, searchResponse, tagCodeAggs, tagCodeEntry, tagNameAggs, tagNameEntry, tagTypeDisplayNameAggs, tagTypeDisplayNameEntry, tagTypeCodeEntry, terms); }