use of org.elasticsearch.search.aggregations.Aggregations in project herd by FINRAOS.
the class ElasticSearchHelperTest method testGetAggregation.
@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);
}
use of org.elasticsearch.search.aggregations.Aggregations in project herd by FINRAOS.
the class ElasticSearchHelperTest method testGetNestedTagTagIndexSearchResponseDtoSearchResponseParameter.
@Test
public void testGetNestedTagTagIndexSearchResponseDtoSearchResponseParameter() {
SearchResponse searchResponse = mock(SearchResponse.class);
Aggregations aggregations = mock(Aggregations.class);
when(searchResponse.getAggregations()).thenReturn(aggregations);
Nested nestedAggregation = mock(Nested.class);
when(aggregations.get(TAG_FACET_AGGS)).thenReturn(nestedAggregation);
Aggregations aggregationAggregations = mock(Aggregations.class);
when(nestedAggregation.getAggregations()).thenReturn(aggregationAggregations);
Terms subAggregation = mock(Terms.class);
when(aggregationAggregations.get(TAGTYPE_CODE_AGGREGATION)).thenReturn(subAggregation);
List<TagTypeIndexSearchResponseDto> result = elasticsearchHelper.getNestedTagTagIndexSearchResponseDto(searchResponse);
assertThat("Result is null.", result, is(notNullValue()));
}
use of org.elasticsearch.search.aggregations.Aggregations in project herd by FINRAOS.
the class ElasticSearchHelperTest method testGetTagTagIndexSearchResponseDto.
@Test
public void testGetTagTagIndexSearchResponseDto() {
SearchResponse searchResponse = mock(SearchResponse.class);
Terms terms = mock(Terms.class);
Aggregations aggregations = mock(Aggregations.class);
Terms.Bucket tagTypeCodeEntry = mock(Terms.Bucket.class);
List<Terms.Bucket> tagTypeCodeEntryList = Collections.singletonList(tagTypeCodeEntry);
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);
Terms tagTypeDisplayNameAggs = mock(Terms.class);
Terms.Bucket tagTypeDisplayNameEntry = mock(Terms.Bucket.class);
List<Terms.Bucket> tagTypeDisplayNameEntryList = Collections.singletonList(tagTypeDisplayNameEntry);
when(aggregations.get(TAGTYPE_NAME_AGGREGATION)).thenReturn(tagTypeDisplayNameAggs);
when(tagTypeDisplayNameEntry.getAggregations()).thenReturn(aggregations);
when(tagTypeDisplayNameAggs.getBuckets()).thenReturn(tagTypeDisplayNameEntryList);
when(tagTypeDisplayNameEntry.getKeyAsString()).thenReturn(TAG_TYPE_DISPLAY_NAME);
StringTerms tagCodeAggs = mock(StringTerms.class);
StringTerms.Bucket tagCodeEntry = mock(StringTerms.Bucket.class);
List<Terms.Bucket> tagCodeEntryList = Collections.singletonList(tagCodeEntry);
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);
Terms tagNameAggs = mock(Terms.class);
Terms.Bucket tagNameEntry = mock(Terms.Bucket.class);
List<Terms.Bucket> tagNameEntryList = Collections.singletonList(tagNameEntry);
when(tagNameEntry.getAggregations()).thenReturn(aggregations);
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);
}
use of org.elasticsearch.search.aggregations.Aggregations in project herd by FINRAOS.
the class ElasticSearchHelperTest method testGetNestedAggregationNestedAggregationIsNull.
@Test
public void testGetNestedAggregationNestedAggregationIsNull() {
// Create mock search response aggregations.
Aggregations searchResponseAggregations = mock(Aggregations.class);
when(searchResponseAggregations.get(NESTED_AGGREGATION_NAME)).thenReturn(null);
// Create a mock search response.
SearchResponse searchResponse = mock(SearchResponse.class);
when(searchResponse.getAggregations()).thenReturn(searchResponseAggregations);
// Mock the external calls.
when(jsonHelper.objectToJson(searchResponse)).thenReturn(SEARCH_RESPONSE_JSON_STRING);
// Try to call the method under test.
try {
elasticsearchHelper.getNestedAggregation(searchResponse, NESTED_AGGREGATION_NAME, SUB_AGGREGATION_NAME);
fail();
} catch (IllegalStateException e) {
assertEquals("Invalid search result.", e.getMessage());
}
// Verify the external calls.
verify(jsonHelper).objectToJson(searchResponse);
verifyNoMoreInteractionsHelper();
}
use of org.elasticsearch.search.aggregations.Aggregations in project herd by FINRAOS.
the class ElasticSearchHelperTest method testGetNestedAggregation.
@Test
public void testGetNestedAggregation() {
// Create a mock sub-aggregation.
Terms subAggregation = mock(Terms.class);
// Create mock nested aggregations.
Aggregations nestedAggregations = mock(Aggregations.class);
when(nestedAggregations.get(SUB_AGGREGATION_NAME)).thenReturn(subAggregation);
// Create a mock nested aggregation.
Nested nestedAggregation = mock(Nested.class);
when(nestedAggregation.getAggregations()).thenReturn(nestedAggregations);
// Create mock search response aggregations.
Aggregations searchResponseAggregations = mock(Aggregations.class);
when(searchResponseAggregations.get(NESTED_AGGREGATION_NAME)).thenReturn(nestedAggregation);
// Create a mock search response.
SearchResponse searchResponse = mock(SearchResponse.class);
when(searchResponse.getAggregations()).thenReturn(searchResponseAggregations);
// Call the method under test.
Terms result = elasticsearchHelper.getNestedAggregation(searchResponse, NESTED_AGGREGATION_NAME, SUB_AGGREGATION_NAME);
// Verify the external calls.
verifyNoMoreInteractionsHelper();
// Validate the result.
assertEquals(subAggregation, result);
}
Aggregations