public static AddExternalImage of(final Image image, final Integer variantId) { return new AddExternalImage(image, variantId); }
public static AddExternalImage ofSku(final String sku, final Image image) { return ofSku(sku, image, null); }
public static AddExternalImage of(final Image image, final Integer variantId) { return ofVariantId(variantId, image); }
@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 publishWithPriceScope() throws Exception { withUpdateableProduct(client(), (Product product) -> { final ProductData stagedData = product.getMasterData().getStaged(); final Product publishedProduct = client().executeBlocking(ProductUpdateCommand.of(product, Publish.of())); final ProductData currentData = publishedProduct.getMasterData().getCurrent(); assertThat(stagedData.getMasterVariant().getImages()).hasSize(0); assertThat(stagedData.getMasterVariant().getPrices()).hasSize(0); assertThat(currentData).isEqualTo(stagedData); final PriceDraft expectedPrice = PriceDraft.of(EURO_10); final Image image = createExternalImage(); final List<UpdateAction<Product>> updateActions = asList( AddExternalImage.of(image, MASTER_VARIANT_ID), AddPrice.of(MASTER_VARIANT_ID, expectedPrice), Publish.ofScope(PublishScope.PRICES) ); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(publishedProduct, updateActions)); List<Price> prices = updatedProduct.getMasterData().getCurrent().getMasterVariant().getPrices(); //Verify published price in the current product assertThat(prices).hasSize(1); assertThat(expectedPrice).isEqualTo(PriceDraft.of(prices.get(0))); //Verify that the image has not been published assertThat(updatedProduct.getMasterData().getCurrent().getMasterVariant().getImages()).hasSize(0); return updatedProduct; }); }
public static AddExternalImage of(final Image image, final int variantId, final ProductUpdateScope productUpdateScope) { return new AddExternalImage(image, variantId, productUpdateScope); }
public static AddExternalImage ofVariantId(final Integer variantId, final Image image) { return ofVariantId(variantId, image, null); }
public static AddExternalImage ofSku(final String sku, final Image image) { return ofSku(sku, image, null); }
@Test public void addExternalImage() throws Exception { withUpdateableProduct(client(), (Product product) -> { assertThat(product.getMasterData().getStaged().getMasterVariant().getImages()).hasSize(0); final Image image = createExternalImage(); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, AddExternalImage.of(image, MASTER_VARIANT_ID))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).isEqualTo(asList(image)); return updatedProduct; }); }
public static AddExternalImage ofSku(final String sku, final Image image, @Nullable final Boolean staged) { return new AddExternalImage(image, null, sku, staged); }
public static AddExternalImage of(final Image image, final Integer variantId) { return ofVariantId(variantId, image); }
public void addExternalImageBySkuWithStaged(final Boolean staged) { withUpdateableProduct(client(), (Product product) -> { final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); assertThat(masterVariant.getImages()).hasSize(0); assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Image image = createExternalImage(); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, AddExternalImage.ofSku(masterVariant.getSku(), image, staged))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).isEqualTo(asList(image)); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
@Test public void publishWithAllScope() throws Exception { withUpdateableProduct(client(), (Product product) -> { final ProductData stagedData = product.getMasterData().getStaged(); final Product publishedProduct = client().executeBlocking(ProductUpdateCommand.of(product, Publish.of())); final ProductData currentData = publishedProduct.getMasterData().getCurrent(); assertThat(stagedData.getMasterVariant().getImages()).hasSize(0); assertThat(stagedData.getMasterVariant().getPrices()).hasSize(0); assertThat(currentData).isEqualTo(stagedData); final PriceDraft expectedPrice = PriceDraft.of(EURO_10); final Image image = createExternalImage(); final List<UpdateAction<Product>> updateActions = asList( AddExternalImage.of(image, MASTER_VARIANT_ID), AddPrice.of(MASTER_VARIANT_ID, expectedPrice), Publish.ofScope(PublishScope.ALL) ); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(publishedProduct, updateActions)); List<Price> prices = updatedProduct.getMasterData().getCurrent().getMasterVariant().getPrices(); assertThat(prices).hasSize(1); assertThat(expectedPrice).isEqualTo(PriceDraft.of(prices.get(0))); assertThat(updatedProduct.getMasterData().getCurrent().getMasterVariant().getImages()).isEqualTo(asList(image)); return updatedProduct; }); }
public static AddExternalImage ofVariantId(final Integer variantId, final Image image, @Nullable final Boolean staged) { return new AddExternalImage(image, variantId, null, staged); }
public static AddExternalImage ofVariantId(final Integer variantId, final Image image) { return ofVariantId(variantId, image, null); }
@Test public void addExternalImageBySku() throws Exception { withUpdateableProduct(client(), (Product product) -> { final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); assertThat(masterVariant.getImages()).hasSize(0); assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Image image = createExternalImage(); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, AddExternalImage.ofSku(masterVariant.getSku(), image))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).isEqualTo(asList(image)); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); return updatedProduct; }); }
@Test public void removeImage() throws Exception { final Image image = createExternalImage(); withUpdateableProduct(client(), product -> { final Product productWithImage = client().executeBlocking(ProductUpdateCommand.of(product, AddExternalImage.of(image, MASTER_VARIANT_ID))); assertThat(productWithImage.getMasterData().getStaged().getMasterVariant().getImages()).isEqualTo(asList(image)); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(productWithImage, RemoveImage.of(image, MASTER_VARIANT_ID))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).hasSize(0); return updatedProduct; }); }
public static AddExternalImage ofVariantId(final Integer variantId, final Image image, @Nullable final Boolean staged) { return new AddExternalImage(image, variantId, null, staged); }
public void addExternalImageByVariantIdWithStaged(final Boolean staged) { withUpdateableProduct(client(), (Product product) -> { assertThat(product.getMasterData().getStaged().getMasterVariant().getImages()).hasSize(0); assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Image image = createExternalImage(); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, AddExternalImage.ofVariantId(MASTER_VARIANT_ID, image, staged))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).isEqualTo(asList(image)); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
public void removeImageBySkuWithStaged(final Boolean staged) { final Image image = createExternalImage(); withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final String sku = product.getMasterData().getStaged().getMasterVariant().getSku(); final Product productWithImage = client().executeBlocking(ProductUpdateCommand.of(product, AddExternalImage.ofSku(sku, image, staged))); assertThat(productWithImage.getMasterData().getStaged().getMasterVariant().getImages()).isEqualTo(asList(image)); assertThat(productWithImage.getMasterData().hasStagedChanges()).isEqualTo(staged); final Product publishedProduct = client().executeBlocking(ProductUpdateCommand.of(productWithImage, Publish.of())); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(publishedProduct, RemoveImage.ofSku(sku, image, staged))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).hasSize(0); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }