@Test public void testGetResultTypeIndexSearchResponseDtoSearchResult() { SearchResult searchResult = mock(SearchResult.class); MetricAggregation metricAggregation = mock(MetricAggregation.class); TermsAggregation termsAggregation = mock(TermsAggregation.class); List<TermsAggregation.Entry> buckets = new ArrayList<>(); buckets.add(new TermsAggregation("TermAggregation", new JsonObject()).new Entry(new JsonObject(), "key", 1L)); when(searchResult.getAggregations()).thenReturn(metricAggregation); when(metricAggregation.getTermsAggregation(RESULT_TYPE_AGGS)).thenReturn(termsAggregation); when(termsAggregation.getBuckets()).thenReturn(buckets); List<ResultTypeIndexSearchResponseDto> result = elasticsearchHelper.getResultTypeIndexSearchResponseDto(searchResult); assertThat("Result is null.", result, is(notNullValue())); }
@Test public void testGetResultTypeIndexSearchResponseDto() { SearchResponse searchResponse = mock(SearchResponse.class); Terms terms = mock(Terms.class); Aggregations aggregations = mock(Aggregations.class); Terms.Bucket bucket = mock(Terms.Bucket.class); List<Terms.Bucket> 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); }
/** * Extracts facet information from a {@link SearchResult} object * * @param request The specified {@link IndexSearchRequest} * @param searchResult A given {@link SearchResult} to extract the facet information from * @param bdefActiveIndex the name of the active index for business object definitions * @param tagActiveIndex the name os the active index for tags * * @return A list of {@link Facet} objects */ private List<Facet> extractFacets(IndexSearchRequest request, SearchResult searchResult, final String bdefActiveIndex, final String tagActiveIndex) { ElasticsearchResponseDto elasticsearchResponseDto = new ElasticsearchResponseDto(); if (request.getFacetFields().contains(ElasticsearchHelper.TAG_FACET)) { elasticsearchResponseDto.setNestTagTypeIndexSearchResponseDtos(elasticsearchHelper.getNestedTagTagIndexSearchResponseDto(searchResult)); elasticsearchResponseDto.setTagTypeIndexSearchResponseDtos(elasticsearchHelper.getTagTagIndexSearchResponseDto(searchResult)); } if (request.getFacetFields().contains(ElasticsearchHelper.RESULT_TYPE_FACET)) { elasticsearchResponseDto.setResultTypeIndexSearchResponseDtos(elasticsearchHelper.getResultTypeIndexSearchResponseDto(searchResult)); } return elasticsearchHelper.getFacetsResponse(elasticsearchResponseDto, bdefActiveIndex, tagActiveIndex); }
/** * Extracts facet information from a {@link SearchResult} object * * @param request The specified {@link IndexSearchRequest} * @param searchResult A given {@link SearchResult} to extract the facet information from * @param bdefActiveIndex the name of the active index for business object definitions * @param tagActiveIndex the name os the active index for tags * * @return A list of {@link Facet} objects */ private List<Facet> extractFacets(IndexSearchRequest request, SearchResult searchResult, final String bdefActiveIndex, final String tagActiveIndex) { ElasticsearchResponseDto elasticsearchResponseDto = new ElasticsearchResponseDto(); if (request.getFacetFields().contains(ElasticsearchHelper.TAG_FACET)) { elasticsearchResponseDto.setNestTagTypeIndexSearchResponseDtos(elasticsearchHelper.getNestedTagTagIndexSearchResponseDto(searchResult)); elasticsearchResponseDto.setTagTypeIndexSearchResponseDtos(elasticsearchHelper.getTagTagIndexSearchResponseDto(searchResult)); } if (request.getFacetFields().contains(ElasticsearchHelper.RESULT_TYPE_FACET)) { elasticsearchResponseDto.setResultTypeIndexSearchResponseDtos(elasticsearchHelper.getResultTypeIndexSearchResponseDto(searchResult)); } return elasticsearchHelper.getFacetsResponse(elasticsearchResponseDto, bdefActiveIndex, tagActiveIndex); }
when(elasticsearchHelper.getResultTypeIndexSearchResponseDto(searchResponse)).thenReturn(resultTypeIndexSearchResponseDto); when(elasticsearchHelper .getFacetsResponse(any(ElasticsearchResponseDto.class), eq(BUSINESS_OBJECT_DEFINITION_SEARCH_INDEX_NAME), eq(TAG_SEARCH_INDEX_NAME))) verify(elasticsearchHelper).getResultTypeIndexSearchResponseDto(searchResult);