|
11 | 11 | import com.commercetools.api.defaultconfig.ApiRootBuilder; |
12 | 12 | import com.commercetools.api.models.product.*; |
13 | 13 |
|
| 14 | +import com.commercetools.api.models.product_search.ProductPagedSearchResponse; |
| 15 | +import com.commercetools.api.models.product_search.ProductSearchFacetResult; |
| 16 | +import com.commercetools.api.models.product_search.ProductSearchFacetResultStats; |
14 | 17 | import io.vrap.rmf.base.client.ApiHttpClient; |
15 | 18 | import io.vrap.rmf.base.client.ApiHttpHeaders; |
16 | 19 | import io.vrap.rmf.base.client.ApiHttpRequest; |
@@ -156,4 +159,35 @@ public void testFacetResultsAccessor() { |
156 | 159 | Assertions.assertThat(((TermFacetResult) prices).getTerms().size()).isEqualTo(3); |
157 | 160 | Assertions.assertThat(((TermFacetResult) prices).getTerms().get(0).getTerm()).isEqualTo("S"); |
158 | 161 | } |
| 162 | + |
| 163 | + @Test |
| 164 | + public void testStatsFacetResultsDeserialization() { |
| 165 | + ProductPagedSearchResponse response = JsonUtils.fromJsonString( |
| 166 | + stringFromResource("search_stats_facet_response.json"), ProductPagedSearchResponse.class); |
| 167 | + |
| 168 | + ProductSearchFacetResult facet = response.getFacets().get(0); |
| 169 | + Assertions.assertThat(facet).isInstanceOf(ProductSearchFacetResultStats.class); |
| 170 | + |
| 171 | + ProductSearchFacetResultStats statsFacet = (ProductSearchFacetResultStats) facet; |
| 172 | + Assertions.assertThat(statsFacet.getName()).isEqualTo("price"); |
| 173 | + Assertions.assertThat(statsFacet.getCount()).isEqualTo(42L); |
| 174 | + Assertions.assertThat(statsFacet.getMin()).isEqualTo(1000.); |
| 175 | + Assertions.assertThat(statsFacet.getMax()).isEqualTo(50000.); |
| 176 | + Assertions.assertThat(statsFacet.getMean()).isEqualTo(15000.5); |
| 177 | + Assertions.assertThat(statsFacet.getSum()).isEqualTo(1500050.); |
| 178 | + |
| 179 | + response = JsonUtils.fromJsonString( |
| 180 | + stringFromResource("search_stats_facet_response_1.json"), ProductPagedSearchResponse.class); |
| 181 | + |
| 182 | + facet = response.getFacets().get(0); |
| 183 | + Assertions.assertThat(facet).isInstanceOf(ProductSearchFacetResultStats.class); |
| 184 | + |
| 185 | + statsFacet = (ProductSearchFacetResultStats) facet; |
| 186 | + Assertions.assertThat(statsFacet.getName()).isEqualTo("price"); |
| 187 | + Assertions.assertThat(statsFacet.getCount()).isEqualTo(859016); |
| 188 | + Assertions.assertThat(statsFacet.getMin()).isEqualTo(199.0); |
| 189 | + Assertions.assertThat(statsFacet.getMax()).isEqualTo(3599900.0); |
| 190 | + Assertions.assertThat(statsFacet.getMean()).isEqualTo(233019.64729760564); |
| 191 | + Assertions.assertThat(statsFacet.getSum()).isEqualTo(2.00167605343E11); |
| 192 | + } |
159 | 193 | } |
0 commit comments