@Test public void should_return_valid_result_when_empty_buckets_terms_aggregation() { Terms terms = Mockito.mock(Terms.class); Mockito.when(terms.getName()).thenReturn("Name"); Mockito.when(terms.getType()).thenReturn(StringTerms.NAME); List bucketList = new ArrayList(); Mockito.when(terms.getBuckets()).thenReturn(bucketList); FacetResult facet = ElasticsearchFacetResultHelper.transformFromEsAggregation(terms); assertThat(facet.getName()).isEqualTo("Name"); assertThat(facet.getBuckets()).hasSize(0); }
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);  }