static ProductUpdateCommand of(final Versioned<Product> versioned, final UpdateAction<Product> updateAction) { return of(versioned, Collections.singletonList(updateAction)); }
static ProductUpdateCommand ofKey(final String key, final Long version, final UpdateAction<Product> updateAction) { return ofKey(key, version, Collections.singletonList(updateAction)); } }
public static ProductUpdateCommand of(final Versioned<Product> versioned, final List<? extends UpdateAction<Product>> updateActions) { return new ProductUpdateCommand(versioned, updateActions); } }
@Test public void updateCommandPlusUpdateActions() { withUpdateableProduct(client(), (Product product) -> { assertThat(product.getMasterData().getStaged().getMasterVariant().getImages()).hasSize(0); final Image image = createExternalImage(); final AddExternalImage updateAction1 = AddExternalImage.of(image, MASTER_VARIANT_ID); final ProductUpdateCommand command = ProductUpdateCommand.of(product, updateAction1); assertThat(command.getUpdateActions()).hasSize(1); assertThat(command.getUpdateActions().get(0)).isEqualTo(updateAction1); final LocalizedString localizedName = en("New Name"); final ChangeName updateAction2 = ChangeName.of(localizedName); final ProductUpdateCommand updatedCommand = command.plusUpdateActions(asList(updateAction2)); assertThat(updatedCommand.getUpdateActions()).hasSize(2); assertThat(updatedCommand.getUpdateActions().get(1)).isEqualTo(updateAction2); final Product updatedProduct = client().executeBlocking(updatedCommand); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).isEqualTo(asList(image)); assertThat(updatedProduct.getMasterData().getStaged().getName()).isEqualTo(localizedName); return updatedProduct; }); }
@Test public void selectAPriceByCurrencyInProductUpdateCommand() { ProductFixtures.withProduct(client(), product -> { final List<PriceDraft> prices = asList(PriceDraft.of(EURO_30), PriceDraft.of(USD_20)); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetPrices.of(1, prices)) .withPriceSelection(PriceSelection.of(EUR)); final Product updatedProduct = client().executeBlocking(cmd); final ProductVariant masterVariant = updatedProduct.getMasterData().getStaged().getMasterVariant(); assertThat(masterVariant.getPrice()).isNotNull().has(price(PriceDraft.of(EURO_30))); }); }
static ProductUpdateCommand of(final Versioned<Product> versioned, final UpdateAction<Product> updateAction) { return of(versioned, Collections.singletonList(updateAction)); }
static ProductUpdateCommand ofKey(final String key, final Long version, final UpdateAction<Product> updateAction) { return ofKey(key, version, Collections.singletonList(updateAction)); } }
public static ProductUpdateCommand of(final Versioned<Product> versioned, final UpdateAction<Product> updateAction) { return of(versioned, asList(updateAction)); }
@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; }); }
static ProductUpdateCommand of(final Versioned<Product> versioned, final UpdateAction<Product> updateAction) { return of(versioned, Collections.singletonList(updateAction)); }
static ProductUpdateCommand ofKey(final String key, final Long version, final List<? extends UpdateAction<Product>> updateActions) { final Versioned<Product> versioned = Versioned.of("key=" + key, version);//hack for simple reuse return of(versioned, updateActions); }
static ProductUpdateCommand ofKey(final String key, final Long version, final List<? extends UpdateAction<Product>> updateActions) { final Versioned<Product> versioned = Versioned.of("key=" + key, version);//hack for simple reuse return of(versioned, updateActions); }
public static void withProductInCategory(final BlockingSphereClient client, final BiConsumer<Product, Category> consumer) { withCategory(client, category -> { final Consumer<Product> user = product -> consumer.accept(product, category); withProduct(client, "withProductAndCategory", product -> { final Product productWithCategory = client.executeBlocking(ProductUpdateCommand.of(product, AddToCategory.of(category))); consumer.accept(productWithCategory, category); }); }); }
public static void withUpdateablePricedProduct(final BlockingSphereClient client, final PriceDraft expectedPrice, final Function<Product, Product> f) { withUpdateableProduct(client, product -> { final ProductUpdateCommand command = ProductUpdateCommand.of(product, AddPrice.of(1, expectedPrice)); return f.apply(client.executeBlocking(command)); }); }
private static ProductUpdateCommand createSetTaxesCommand(final TaxCategory taxCategory, final Product product) { return ProductUpdateCommand.of(product, asList(AddPrice.of(MASTER_VARIANT_ID, PRICE), SetTaxCategory.of(taxCategory), Publish.of())); }
@Test public void publish() throws Exception { withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().isPublished()).isFalse(); final Product publishedProduct = client().executeBlocking(ProductUpdateCommand.of(product, Publish.of())); assertThat(publishedProduct.getMasterData().isPublished()).isTrue(); final Product unpublishedProduct = client().executeBlocking(ProductUpdateCommand.of(publishedProduct, Unpublish.of())); assertThat(unpublishedProduct.getMasterData().isPublished()).isFalse(); return unpublishedProduct; }); }
public void changeSlugWithStaged(final Boolean staged) { withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final LocalizedString newSlug = LocalizedString.ofEnglish("new-slug-" + RANDOM.nextInt()); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, ChangeSlug.of(newSlug, staged))); assertThat(updatedProduct.getMasterData().getStaged().getSlug()).isEqualTo(newSlug); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
public void setDescriptionWithStaged(final Boolean staged) { withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final LocalizedString newDescription = LocalizedString.ofEnglish("new description " + RANDOM.nextInt()); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetDescription.of(newDescription, staged)); final Product updatedProduct = client().executeBlocking(cmd); assertThat(updatedProduct.getMasterData().getStaged().getDescription()).isEqualTo(newDescription); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
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 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; }); }