@Test public void should_return_valid_result_when_valid_terms_aggregation() { Terms terms = Mockito.mock(Terms.class); Mockito.when(terms.getName()).thenReturn("Name"); Mockito.when(terms.getType()).thenReturn(StringTerms.NAME); Bucket bucket1 = mock(StringTerms.Bucket.class); Mockito.when(bucket1.getKeyAsString()).thenReturn("Value1"); Mockito.when(bucket1.getDocCount()).thenReturn(2L); Bucket bucket2 = mock(StringTerms.Bucket.class); Mockito.when(bucket2.getKeyAsString()).thenReturn("Value2"); Mockito.when(bucket2.getDocCount()).thenReturn(1L); List bucketList = new ArrayList(); bucketList.add(bucket1); bucketList.add(bucket2); Mockito.when(terms.getBuckets()).thenReturn(bucketList); FacetResult facet = ElasticsearchFacetResultHelper.transformFromEsAggregation(terms); assertThat(facet.getName()).isEqualTo("Name"); assertThat(facet.getBuckets()).hasSize(2); assertThat(facet.getBuckets().get(0).getValue()).isEqualTo("Value1"); assertThat(facet.getBuckets().get(0).getCount()).isEqualTo(2L); assertThat(facet.getBuckets().get(1).getValue()).isEqualTo("Value2"); assertThat(facet.getBuckets().get(1).getCount()).isEqualTo(1L); }
public static FacetResult transformFromEsAggregation(Aggregation aggregation) { FacetResult facetResult = new FacetResult(); facetResult.setName(aggregation.getName()); String aggType = aggregation.getType(); switch (aggType) { case DateRangeAggregationBuilder.NAME: facetResult.setBuckets(extractBucketRangeAggregation(aggregation)); break; case StringTerms.NAME: facetResult.setBuckets(extractBucketTermsAggregation(aggregation)); break; case FiltersAggregationBuilder.NAME: facetResult.setBuckets(extractBucketFiltersAggregation(aggregation)); break; case NestedAggregationBuilder.NAME: facetResult.setBuckets(extractBucketNestedAggregation(aggregation)); break; default: break; } return facetResult; }
ElasticsearchFacetResultHelper { public static FacetResult transformFromEsAggregation(Aggregation aggregation) { FacetResult facetResult = new FacetResult(); facetResult.setName(aggregation.getName()); String aggType = aggregation.getType(); switch (aggType) { case DateRangeAggregationBuilder.NAME: facetResult.setBuckets(extractBucketRangeAggregation(aggregation)); break; case StringTerms.NAME: facetResult.setBuckets(extractBucketTermsAggregation(aggregation)); break; case FiltersAggregationBuilder.NAME: facetResult.setBuckets(extractBucketFiltersAggregation(aggregation)); break; case NestedAggregationBuilder.NAME: facetResult.setBuckets(extractBucketNestedAggregation(aggregation)); break; default: break; } return facetResult; } }
ElasticsearchFacetResultHelper { public static FacetResult transformFromEsAggregation(Aggregation aggregation) { FacetResult facetResult = new FacetResult(); facetResult.setName(aggregation.getName()); String aggType = aggregation.getType(); switch (aggType) { case DateRangeAggregationBuilder.NAME: facetResult.setBuckets(extractBucketRangeAggregation(aggregation)); break; case StringTerms.NAME: facetResult.setBuckets(extractBucketTermsAggregation(aggregation)); break; case FiltersAggregationBuilder.NAME: facetResult.setBuckets(extractBucketFiltersAggregation(aggregation)); break; case NestedAggregationBuilder.NAME: facetResult.setBuckets(extractBucketNestedAggregation(aggregation)); break; default: break; } return facetResult; }  }
ElasticsearchFacetResultHelper { public static FacetResult transformFromEsAggregation(Aggregation aggregation) { FacetResult facetResult = new FacetResult(); facetResult.setName(aggregation.getName()); String aggType = aggregation.getType(); switch (aggType) { case DateRangeAggregationBuilder.NAME: facetResult.setBuckets(extractBucketRangeAggregation(aggregation)); break; case StringTerms.NAME: facetResult.setBuckets(extractBucketTermsAggregation(aggregation)); break; case FiltersAggregationBuilder.NAME: facetResult.setBuckets(extractBucketFiltersAggregation(aggregation)); break; case NestedAggregationBuilder.NAME: facetResult.setBuckets(extractBucketNestedAggregation(aggregation)); break; default: break; } return facetResult; }  static FacetResult transformFromEsAggregation(Aggregation aggregation); }
ElasticsearchFacetResultHelper { public static FacetResult transformFromEsAggregation(Aggregation aggregation) { FacetResult facetResult = new FacetResult(); facetResult.setName(aggregation.getName()); String aggType = aggregation.getType(); switch (aggType) { case DateRangeAggregationBuilder.NAME: facetResult.setBuckets(extractBucketRangeAggregation(aggregation)); break; case StringTerms.NAME: facetResult.setBuckets(extractBucketTermsAggregation(aggregation)); break; case FiltersAggregationBuilder.NAME: facetResult.setBuckets(extractBucketFiltersAggregation(aggregation)); break; case NestedAggregationBuilder.NAME: facetResult.setBuckets(extractBucketNestedAggregation(aggregation)); break; default: break; } return facetResult; }  static FacetResult transformFromEsAggregation(Aggregation aggregation);  }