/** * Creates a new object initialized with the given values. * * @param minimumQuantity initial value for the {@link PriceTier#getMinimumQuantity()} property * @param value initial value for the {@link PriceTier#getValue()} property * @return new object initialized with the given values */ public static PriceTierBuilder of(final Integer minimumQuantity, final MonetaryAmount value) { return new PriceTierBuilder(minimumQuantity, value); }
@Test public void addPriceWithTiers() throws Exception { final List<PriceTier> tiers = Arrays.asList(PriceTierBuilder.of(10, EURO_1).build(), PriceTierBuilder.of(5, EURO_5).build()); final PriceDraft expectedPriceWithTiers = PriceDraftBuilder.of(MoneyImpl.of(123, EUR)) .tiers(tiers) .build(); withUpdateableProduct(client(), product -> { final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, AddPrice.of(1, expectedPriceWithTiers))); final List<Price> prices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices(); assertThat(prices).hasSize(1); final Price actualPrice = prices.get(0); assertThat(expectedPriceWithTiers).isEqualTo(PriceDraft.of(actualPrice)); return updatedProduct; }); }
@Test public void changePriceAddTiers() throws Exception { withUpdateablePricedProduct(client(), product -> { final List<PriceTier> tiers = Arrays.asList(PriceTierBuilder.of(10, EURO_5).build()); final PriceDraft newPrice = PriceDraftBuilder.of(MoneyImpl.of(234, EUR)) .tiers(tiers) .build(); 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 setPrices() throws Exception { final PriceDraft expectedPrice1 = PriceDraft.of(MoneyImpl.of(123, EUR)); final PriceDraft expectedPrice2 = PriceDraft.of(MoneyImpl.of(123, EUR)).withCountry(DE); final List<PriceTier> tiers = Arrays.asList(PriceTierBuilder.of(10, EURO_1).build()); final PriceDraft expectedPriceWithTiers = PriceDraftBuilder.of(MoneyImpl.of(123, EUR)) .country(CountryCode.AT) .tiers(tiers) .build(); final List<PriceDraft> expectedPriceList = asList(expectedPrice1, expectedPrice2, expectedPriceWithTiers); withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, SetPrices.of(1, expectedPriceList))); final List<Price> prices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices(); List<PriceDraft> draftPricesList = prices.stream().map(PriceDraft::of).collect(toList()); assertThat(draftPricesList).containsOnly(expectedPrice1, expectedPrice2, expectedPriceWithTiers); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); 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 PriceTierBuilder of(final PriceTier template) { return new PriceTierBuilder(template.getMinimumQuantity(), template.getValue()); } }
@Test public void createProductWithTiers() { withEmptyProductType(client(), randomKey(), productType -> withUpdateableType(client(), type -> { final List<PriceTier> tiers = Arrays.asList(PriceTierBuilder.of(10, EURO_5).build()); final PriceDraft priceWithTiers = PriceDraftBuilder.of(EURO_1) .tiers(tiers) .build(); final ProductVariantDraft masterVariant = ProductVariantDraftBuilder.of() .price(priceWithTiers) .build(); final ProductDraft productDraft = ProductDraftBuilder.of(productType, randomSlug(), randomSlug(), masterVariant).build(); final Product product = client().executeBlocking(ProductCreateCommand.of(productDraft)); final Price loadedPrice = product.getMasterData().getStaged().getMasterVariant().getPrices().get(0); assertThat(loadedPrice.getValue()).isEqualTo(EURO_1); assertThat(loadedPrice.getTiers()).containsExactlyElementsOf(tiers); client().executeBlocking(ProductDeleteCommand.of(product)); return type; }) ); }