@Test public void checkProductVaiantAtributes() throws Exception { assertThat(productVariant.getSku().equals("1f92d491-2180-489c-bcef-3966cdc68c0b")); assertThat(productVariant.getPrices()) .as("comparing prices ") .isEqualTo(asList(Price.of(BigDecimal.valueOf(12.34), DefaultCurrencyUnits.EUR).withCountry(CountryCode.DE).withId("70a56289-bd20-4c47-8364-47b498ad993b"))); assertThat(productVariant.getImages().isEmpty()); assertThat(productVariant.getAssets().isEmpty()); assertThat(productVariant.getAttributes().isEmpty()); } }
@Test public void checkProductVaiantAtributes() throws Exception { assertThat(productVariant.getSku().equals("1f92d491-2180-489c-bcef-3966cdc68c0b")); assertThat(productVariant.getPrices()) .as("comparing prices ") .isEqualTo(asList(Price.of(BigDecimal.valueOf(12.34), DefaultCurrencyUnits.EUR).withCountry(CountryCode.DE).withId("70a56289-bd20-4c47-8364-47b498ad993b"))); assertThat(productVariant.getImages().isEmpty()); assertThat(productVariant.getAssets().isEmpty()); assertThat(productVariant.getAttributes().isEmpty()); } }
private Price getFirstPrice(final Product product) { return product.getMasterData().getStaged().getMasterVariant().getPrices().get(0); }
private void testAddPrice(final PriceDraft expectedPrice) throws Exception { withUpdateableProduct(client(), product -> { final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, AddPrice.of(1, expectedPrice))); final List<Price> prices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices(); assertThat(prices).hasSize(1); final Price actualPrice = prices.get(0); assertThat(expectedPrice).isEqualTo(PriceDraft.of(actualPrice)); return updatedProduct; }); }
@Test public void executeValidQuery(){ withUpdateableProductDiscount(client(),((productDiscount, product) -> { final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); assertThat(masterVariant.getPrices()).isNotEmpty(); final Price masterVariantPrice = masterVariant.getPrices().get(0); final ProductDiscount queryedProductDiscount = client().executeBlocking(MatchingProductDiscountGet.of(product.getId(), masterVariant.getId(),true , masterVariantPrice)); assertThat(productDiscount).isEqualTo(queryedProductDiscount); return productDiscount; })); }
@Test public void changePriceToAHigherPrecision() throws Exception { withUpdateablePricedProduct(client(), product -> { final PriceDraft newHighPrecisionPrice = PriceDraft.of(HighPrecisionMoneyImpl.of(new BigDecimal("15.3669996"),EUR,7)); final List<Price> prices = product.getMasterData().getStaged().getMasterVariant() .getPrices(); assertThat(prices.stream().anyMatch(p -> p.equals(newHighPrecisionPrice))).isFalse(); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, ChangePrice.of(prices.get(0), newHighPrecisionPrice))); final Price actualPrice = getFirstPrice(updatedProduct); assertThat(PriceDraft.of(actualPrice)).isEqualTo(newHighPrecisionPrice); return updatedProduct; }); }
@Test public void removePrice() throws Exception { withUpdateablePricedProduct(client(), product -> { final Price oldPrice = getFirstPrice(product); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, RemovePrice.of(oldPrice))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant() .getPrices().stream().anyMatch(p -> p.equals(oldPrice))).isFalse(); return updatedProduct; }); }
public void addPriceByVariantIdWithStaged(final Boolean staged) { final PriceDraft priceDraft = PriceDraft.of(MoneyImpl.of(new BigDecimal("12345"), "JPY")); withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, AddPrice.ofVariantId(1, priceDraft, staged))); final List<Price> prices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices(); assertThat(prices).hasSize(1); final Price actualPrice = prices.get(0); assertThat(priceDraft).isEqualTo(PriceDraft.of(actualPrice)); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
/** * Creates a new object initialized with the fields of the template parameter. * * @param template the template * @return a new object initialized from the template */ public static ProductVariantDraftBuilder of(final ProductVariant template) { return new ProductVariantDraftBuilder(copyAssets(template.getAssets()), copyAttributes(template.getAttributes()), template.getImages(), template.getKey(), copyPrices(template.getPrices()), template.getSku()); } }
@Test public void changePrice() throws Exception { withUpdateablePricedProduct(client(), product -> { final PriceDraft newPrice = PriceDraft.of(MoneyImpl.of(234, EUR)); final List<Price> prices = product.getMasterData().getStaged().getMasterVariant() .getPrices(); assertThat(prices.stream().anyMatch(p -> p.equals(newPrice))).isFalse(); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, ChangePrice.of(prices.get(0), newPrice))); final Price actualPrice = getFirstPrice(updatedProduct); assertThat(PriceDraft.of(actualPrice)).isEqualTo(newPrice); return updatedProduct; }); }
@Test public void addPriceByVariantId() throws Exception { final PriceDraft priceDraft = PriceDraft.of(MoneyImpl.of(new BigDecimal("12345"), "JPY")); withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, AddPrice.ofVariantId(1, priceDraft))); final List<Price> prices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices(); assertThat(prices).hasSize(1); final Price actualPrice = prices.get(0); assertThat(priceDraft).isEqualTo(PriceDraft.of(actualPrice)); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); return updatedProduct; }); }
@Test public void setPricesEmptyList() { withUpdateablePricedProduct(client(), product -> { final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, SetPrices.of(1, emptyList()))); final List<Price> newPrices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices(); assertThat(newPrices).isEmpty(); return updatedProduct; }); }
@Test public void addPrice() throws Exception { final PriceDraft expectedPrice = PriceDraft.of(MoneyImpl.of(123, EUR)); withUpdateableProduct(client(), product -> { final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, AddPrice.of(1, expectedPrice))); final List<Price> prices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices(); assertThat(prices).hasSize(1); final Price actualPrice = prices.get(0); assertThat(expectedPrice).isEqualTo(PriceDraft.of(actualPrice)); return updatedProduct; }); }
public void removePriceWithStaged(final Boolean staged) { withUpdateableProduct(client(), product -> { final ProductUpdateCommand command = ProductUpdateCommand.of(product, AddPrice.ofVariantId(1, PriceDraft.of(MoneyImpl.of(123, EUR)), false)); final Product productWithPrice = client().executeBlocking(command); assertThat(productWithPrice.getMasterData().hasStagedChanges()).isFalse(); final Price oldPrice = getFirstPrice(productWithPrice); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(productWithPrice, RemovePrice.of(oldPrice, staged))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant() .getPrices().stream().anyMatch(p -> p.equals(oldPrice))).isFalse(); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
public void addPriceBySkuWithStaged(final Boolean staged) { final PriceDraft priceDraft = PriceDraft.of(MoneyImpl.of(new BigDecimal("12345"), "JPY")); withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final String sku = product.getMasterData().getStaged().getMasterVariant().getSku(); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, AddPrice.ofSku(sku, priceDraft, staged))); final List<Price> prices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices(); assertThat(prices).hasSize(1); final Price actualPrice = prices.get(0); assertThat(priceDraft).isEqualTo(PriceDraft.of(actualPrice)); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
private void setPricesByVariantIdWithStaged(final Boolean staged) { final PriceDraft priceDraft = PriceDraft.of(MoneyImpl.of(123, EUR)); final PriceDraft priceDraft2 = PriceDraft.of(MoneyImpl.of(123, EUR)).withCountry(DE); final List<PriceDraft> expectedPriceList = asList(priceDraft, priceDraft2); withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, SetPrices.ofVariantId(1, expectedPriceList, staged))); final List<Price> prices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices(); List<PriceDraft> draftPricesList = prices.stream().map(PriceDraft::of).collect(toList()); assertThat(draftPricesList).containsOnly(priceDraft, priceDraft2); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
@Test public void expandedDiscountedPrice() throws Exception { final Product product = SphereJsonUtils.readObjectFromResource("product-with-expanded-discounted-price.json", Product.typeReference()); final Price price = product.getMasterData().getStaged().getMasterVariant().getPrices().get(0); final DiscountedPrice discountedPrice = price.getDiscounted(); final ProductDiscount productDiscount = discountedPrice.getDiscount().getObj(); assertThat(productDiscount.getName().get(Locale.ENGLISH)).isEqualTo("demo product discount"); assertThat(productDiscount.getValue()).isInstanceOf(AbsoluteProductDiscountValue.class); }
@Test public void canExpandCustomerGroupOfPrices() throws Exception { withCustomerGroup(client(), customerGroup -> { withUpdateablePricedProduct(client(), PriceDraft.of(MoneyImpl.of(new BigDecimal("12.34"), EUR)).withCountry(DE).withCustomerGroup(customerGroup), product -> { final ExpansionPath<Product> expansionPath = ProductExpansionModel.of().masterData().staged().masterVariant().prices().customerGroup().expansionPaths().get(0); final Query<Product> query = query(product).withExpansionPaths(expansionPath); final List<Price> prices = client().executeBlocking(query).head().get().getMasterData().getStaged().getMasterVariant().getPrices(); assertThat(prices .stream() .anyMatch(price -> Optional.ofNullable(price.getCustomerGroup()).map(customerGroupReference -> customerGroupReference.getObj() != null).orElse(false))) .isTrue(); return product; }); } ); }
@Test public void canExpandChannelOfPrices() throws Exception { ChannelFixtures.withChannelOfRole(client(), ChannelRole.INVENTORY_SUPPLY, channel -> { withUpdateablePricedProduct(client(), PriceDraft.of(MoneyImpl.of(new BigDecimal("12.34"), EUR)).withCountry(DE).withChannel(channel), product -> { final ExpansionPath<Product> expansionPath = ProductExpansionModel.of().masterData().staged().masterVariant().prices().channel().expansionPaths().get(0); final Query<Product> query = query(product).withExpansionPaths(expansionPath); final List<Price> prices = client().executeBlocking(query).head().get().getMasterData().getStaged().getMasterVariant().getPrices(); assertThat(prices .stream() .anyMatch(price -> Optional.ofNullable(price.getChannel()).map(channelRef -> channelRef.getObj() != null).orElse(false))) .isTrue(); return product; }); }); }
@Test public void assignPricesToMasterVariantAccordingToAChannel() throws Exception { final String channelKey = "assignPricesToMasterVariantAccordingToAChannel"; cleanUpChannelByKey(client(), channelKey); final Product product = createInBackendByName("assignPricesToMasterVariantAccordingToAChannel"); final Channel channel = client().executeBlocking(ChannelCreateCommand.of(ChannelDraft.of(channelKey))); final PriceDraft price = PriceDraft.of(MoneyImpl.of(523, EUR)).withChannel(channel); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, AddPrice.of(MASTER_VARIANT_ID, price))); final Price readPrice = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices().get(0); assertThat(readPrice.getChannel()).isEqualTo(channel.toReference()); client().executeBlocking(ProductUpdateCommand.of(updatedProduct, RemovePrice.of(readPrice))); cleanUpChannelByKey(client(), channelKey); }