@Nullable @Override public String getKey() { return product.getKey(); } }
@Nullable @Override public String getKey() { return product.getKey(); } }
@Test public void filterByProductKey() { final List<String> keys = Stream.of(product1, product2) .map(product -> product.getKey()) .collect(toList()); final ProductProjectionSearch search = ProductProjectionSearch.ofStaged() .plusQueryFilters(m -> m.key().isIn(keys)); assertEventually(Duration.ofSeconds(45), Duration.ofMillis(200), () -> { final List<ProductProjection> results = client().executeBlocking(search).getResults(); assertThat(results) .extracting(m -> m.getKey()) .containsOnly(keys.get(0), keys.get(1)); }); }
@Test public void setKey() throws Exception { final String key = randomKey(); withProduct(client(), (Product product) -> { final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, SetKey.of(key))); assertThat(updatedProduct.getKey()).isEqualTo(key); }); }
@Test public void productUpdateByKey() throws Exception { final String key = randomKey(); withUpdateableProduct(client(), builder -> builder.key(key), product -> { final LocalizedString newName = LocalizedString.ofEnglish("newName " + RANDOM.nextInt()); final ProductUpdateCommand cmd = ProductUpdateCommand.ofKey(key, product.getVersion(), ChangeName.of(newName)); final Product updatedProduct = client().executeBlocking(cmd); assertThat(updatedProduct.getMasterData().getStaged().getName()).isEqualTo(newName); assertThat(updatedProduct.getKey()).isEqualTo(key); return updatedProduct; }); }
@Test public void setProductVariantKeyByVariantId() throws Exception { final String key = randomKey(); withProduct(client(), (Product product) -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Integer variantId = product.getMasterData().getStaged().getMasterVariant().getId(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetProductVariantKey.ofKeyAndVariantId(key, variantId)); final Product updatedProduct = client().executeBlocking(cmd); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getKey()).isEqualTo(key); assertThat(updatedProduct.getKey()).isNotEqualTo(key); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); }); }
@Test public void setProductVariantKeyBySku() throws Exception { final String key = randomKey(); withProduct(client(), (Product product) -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final String sku = product.getMasterData().getStaged().getMasterVariant().getSku(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetProductVariantKey.ofKeyAndSku(key, sku)); final Product updatedProduct = client().executeBlocking(cmd); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getKey()).isEqualTo(key); assertThat(updatedProduct.getKey()).isNotEqualTo(key); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); }); }
@Test public void selectAPriceByCurrencyInProductProjectionByKeyGet() { final List<PriceDraft> prices = asList(PriceDraft.of(EURO_30), PriceDraft.of(USD_20)); withProductOfPrices(prices, product -> { final ProductProjection productProjection = client().executeBlocking(ProductProjectionByKeyGet.ofStaged(product.getKey()).withPriceSelection(PriceSelection.of(EUR))); final ProductVariant masterVariant = productProjection.getMasterVariant(); assertThat(masterVariant.getPrice()).isNotNull().has(price(PriceDraft.of(EURO_30))); }); }
@Test public void selectAPriceByCurrencyInProductByKeyGet() { final List<PriceDraft> prices = asList(PriceDraft.of(EURO_30), PriceDraft.of(USD_20)); withProductOfPrices(prices, product -> { final Product loadedProduct = client().executeBlocking(ProductByKeyGet.of(product.getKey()).withPriceSelection(PriceSelection.of(EUR))); final ProductVariant masterVariant = loadedProduct.getMasterData().getStaged().getMasterVariant(); assertThat(masterVariant.getPrice()).isNotNull().has(price(PriceDraft.of(EURO_30))); }); }