public static void logProductRequest(final Logger logger, final ProductProjectionSearch request, final PagedSearchResult<ProductProjection> result) { final HttpRequestIntent httpRequest = request.httpRequestIntent(); final String requestBody = printableRequestBody(httpRequest) .map(body -> " with body {" + body + "}") .orElse(""); logger.debug("Fetched {} out of {} products with request {} {}", result.getCount(), result.getTotal(), httpRequest.getHttpMethod(), httpRequest.getPath() + requestBody); }
@Test public void priceSelectionParameterCanBeAdded() { assertThat(SEARCH_WITH_FULL_PRICE_SELECTION.httpRequestIntent().getBody().toString()) .contains("priceCurrency=EUR&priceCountry=DE&priceCustomerGroup=customer-group-id&priceChannel=channel-id"); assertThat(SEARCH_WITH_FULL_PRICE_SELECTION.getPriceSelection()).isEqualTo(FULL_PRICE_SELECTION); }
@Test public void priceSelectionCanBeRefined() { final PriceSelectionDsl priceSelectionWithoutCustomerGroup = FULL_PRICE_SELECTION.withPriceCustomerGroup(null); final ProductProjectionSearch priceSearchWithoutCustomer = SEARCH_WITH_FULL_PRICE_SELECTION.withPriceSelection(priceSelectionWithoutCustomerGroup); assertThat(priceSearchWithoutCustomer.httpRequestIntent().getBody().toString()) .contains("priceCurrency=EUR&priceCountry=DE&priceChannel=channel-id") .doesNotContain("priceCustomerGroup").doesNotContain("customer-group-id"); assertThat(priceSearchWithoutCustomer.getPriceSelection()).isEqualTo(priceSelectionWithoutCustomerGroup); }
@Test public void unicode() throws Exception { final StringHttpRequestBody body = (StringHttpRequestBody) ProductProjectionSearch.ofStaged().withText(GERMAN, "öón").httpRequestIntent().getBody(); final String path = body.getString(); final String expected = "text.de=%C3%B6%C3%B3n&staged=true"; assertThat(path).isEqualTo(expected); }
@Test public void removePriceSelection() { final ProductProjectionSearch priceSelectionRemoved = SEARCH_WITH_FULL_PRICE_SELECTION.withPriceSelection(null); assertThat(priceSelectionRemoved.httpRequestIntent().getBody().toString()).doesNotContain("price"); assertThat(priceSelectionRemoved.getPriceSelection()).isNull(); }
@Test public void channelsFilterDsl() { final StringHttpRequestBody body = (StringHttpRequestBody) ProductProjectionSearch.ofStaged().plusQueryFilters(m -> m.allVariants().availability().channels().channelId("channel-id-12") .availableQuantity().isGreaterThanOrEqualTo(new BigDecimal(3))).httpRequestIntent().getBody(); assertThat(body.getString()).contains("filter.query=variants.availability.channels.channel-id-12.availableQuantity%3Arange%283+to+*%29"); }
@Test public void channelsRestockableSortDsl() { final StringHttpRequestBody body = (StringHttpRequestBody) ProductProjectionSearch.ofStaged(). plusSort(m -> m.allVariants().availability().channels().channelId("channel-id-500").restockableInDays().asc()).httpRequestIntent().getBody(); assertThat(body.getString()).contains("sort=variants.availability.channels.channel-id-500.restockableInDays+asc"); }