/** * get tag index search response dto * * @param searchResponse elastic search response * * @return list of tag type index search response dto */ public List<TagTypeIndexSearchResponseDto> getTagTagIndexSearchResponseDto(SearchResponse searchResponse) { Terms aggregation = getAggregation(searchResponse, TAG_TYPE_FACET_AGGS); return getTagTypeIndexSearchResponseDtosFromTerms(aggregation); }
/** * get tag index search response dto * * @param searchResponse elastic search response * * @return list of tag type index search response dto */ public List<TagTypeIndexSearchResponseDto> getTagTagIndexSearchResponseDto(SearchResponse searchResponse) { Terms aggregation = getAggregation(searchResponse, TAG_TYPE_FACET_AGGS); return getTagTypeIndexSearchResponseDtosFromTerms(aggregation); }
/** * Creates result type facet response dto * * @param searchResponse search response * * @return result type facet response dto list */ 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; }
@Test public void testGetAggregation() { // Create a mock aggregation. Terms aggregation = mock(Terms.class); // Create mock aggregations. Aggregations aggregations = mock(Aggregations.class); when(aggregations.get(AGGREGATION_NAME)).thenReturn(aggregation); // Create a mock search response. SearchResponse searchResponse = mock(SearchResponse.class); when(searchResponse.getAggregations()).thenReturn(aggregations); // Call the method under test. Terms result = elasticsearchHelper.getAggregation(searchResponse, AGGREGATION_NAME); // Verify the external calls. verifyNoMoreInteractionsHelper(); // Validate the result. assertEquals(aggregation, result); }
/** * Creates result type facet response dto * * @param searchResponse search response * * @return result type facet response dto list */ 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; }
@Test public void testGetAggregationAggregationIsNull() { // Create mock aggregations. Aggregations aggregations = mock(Aggregations.class); when(aggregations.get(AGGREGATION_NAME)).thenReturn(null); // Create a mock search response. SearchResponse searchResponse = mock(SearchResponse.class); when(searchResponse.getAggregations()).thenReturn(aggregations); // Mock the external calls. when(jsonHelper.objectToJson(searchResponse)).thenReturn(SEARCH_RESPONSE_JSON_STRING); // Try to call the method under test. try { elasticsearchHelper.getAggregation(searchResponse, AGGREGATION_NAME); fail(); } catch (IllegalStateException e) { assertEquals("Invalid search result.", e.getMessage()); } // Verify the external calls. verify(jsonHelper).objectToJson(searchResponse); verifyNoMoreInteractionsHelper(); }