protected Optional<String> createImage(final ProductVariant variant) { return variant.getImages().stream().findFirst().map(Image::getUrl); }
@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()); } }
public void moveImageToPositionByVariantIdWithStaged(final Boolean staged) { withProductWithImages(client(), IMAGE_URLS, (Product product) -> { final List<String> oldImageOrderUrls = product.getMasterData().getStaged().getMasterVariant().getImages() .stream() .map(image -> image.getUrl()) .collect(toList()); assertThat(oldImageOrderUrls).containsExactlyElementsOf(IMAGE_URLS); assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Integer position = 0; final List<Image> images = product.getMasterData().getStaged().getMasterVariant().getImages(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, MoveImageToPosition.ofImageUrlAndVariantId(images.get(1).getUrl(), MASTER_VARIANT_ID, position, staged)); final Product updatedProduct = client().executeBlocking(cmd); final List<String> urls = updatedProduct.getMasterData().getStaged().getMasterVariant().getImages() .stream() .map(image -> image.getUrl()) .collect(toList()); assertThat(urls).containsExactly(URL_2, URL_1, URL_3); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
@Test public void setImageLabel() throws Exception { withProductWithImages(client(), Arrays.asList(URL_1), (Product product) -> { final String changeToImageLabel = "New image label"; final ProductUpdateCommand updateCommand = ProductUpdateCommand.of(product, SetImageLabel.of(1, URL_1, changeToImageLabel, null)); final Product updatedProduct = client().executeBlocking(updateCommand); final Optional<Image> changedImage = updatedProduct.getMasterData().getStaged().getMasterVariant().getImages() .stream() .findFirst(); assertThat(changedImage).isPresent(); final String updatedImageLabel = changedImage.get().getLabel(); assertThat(updatedImageLabel).isEqualTo(changeToImageLabel); return updatedProduct; }); }
@Test public void moveImageToPositionByVariantId() throws Exception { withProductWithImages(client(), IMAGE_URLS, (Product product) -> { final List<String> oldImageOrderUrls = product.getMasterData().getStaged().getMasterVariant().getImages() .stream() .map(image -> image.getUrl()) .collect(toList()); assertThat(oldImageOrderUrls).containsExactlyElementsOf(IMAGE_URLS); assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Integer position = 0; final List<Image> images = product.getMasterData().getStaged().getMasterVariant().getImages(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, MoveImageToPosition.ofImageUrlAndVariantId(images.get(1).getUrl(), MASTER_VARIANT_ID, position)); final Product updatedProduct = client().executeBlocking(cmd); final List<String> urls = updatedProduct.getMasterData().getStaged().getMasterVariant().getImages() .stream() .map(image -> image.getUrl()) .collect(toList()); assertThat(urls).containsExactly(URL_2, URL_1, URL_3); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); return updatedProduct; }); }
@Test public void moveImageToPositionBySku() throws Exception { withProductWithImages(client(), IMAGE_URLS, (Product product) -> { final List<String> oldImageOrderUrls = product.getMasterData().getStaged().getMasterVariant().getImages() .stream() .map(image -> image.getUrl()) .collect(toList()); assertThat(oldImageOrderUrls).containsExactlyElementsOf(IMAGE_URLS); assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Integer position = 0; final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final List<Image> images = masterVariant.getImages(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, MoveImageToPosition.ofImageUrlAndSku(images.get(1).getUrl(), masterVariant.getSku(), position)); final Product updatedProduct = client().executeBlocking(cmd); final List<String> urls = updatedProduct.getMasterData().getStaged().getMasterVariant().getImages() .stream() .map(image -> image.getUrl()) .collect(toList()); assertThat(urls).containsExactly(URL_2, URL_1, URL_3); 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 ProductVariantDraftBuilder of(final ProductVariant template) { return new ProductVariantDraftBuilder(copyAssets(template.getAssets()), copyAttributes(template.getAttributes()), template.getImages(), template.getKey(), copyPrices(template.getPrices()), template.getSku()); } }
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; }); }
@Test public void addExternalImageByVariantId() throws Exception { 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))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).isEqualTo(asList(image)); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); return updatedProduct; }); }
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 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 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 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 void removeImageByVariantIdWithStaged(final Boolean staged) { final Image image = createExternalImage(); withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Product productWithImage = client().executeBlocking(ProductUpdateCommand.of(product, AddExternalImage.ofVariantId(MASTER_VARIANT_ID, 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.ofVariantId(MASTER_VARIANT_ID, image, staged))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).hasSize(0); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
@Test public void removeImageByVariantId() throws Exception { final Image image = createExternalImage(); withUpdateableProduct(client(), product -> { final Product productWithImage = client().executeBlocking(ProductUpdateCommand.of(product, AddExternalImage.ofVariantId(MASTER_VARIANT_ID, image))); assertThat(productWithImage.getMasterData().getStaged().getMasterVariant().getImages()).isEqualTo(asList(image)); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(productWithImage, RemoveImage.ofVariantId(MASTER_VARIANT_ID, image))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).hasSize(0); 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; }); }
@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; }); }
@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; }); }
@Test public void removeImageBySku() throws Exception { final Image image = createExternalImage(); withUpdateableProduct(client(), product -> { final String sku = product.getMasterData().getStaged().getMasterVariant().getSku(); final Product productWithImage = client().executeBlocking(ProductUpdateCommand.of(product, AddExternalImage.ofSku(sku, image))); assertThat(productWithImage.getMasterData().getStaged().getMasterVariant().getImages()).isEqualTo(asList(image)); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(productWithImage, RemoveImage.ofSku(sku, image))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).hasSize(0); return updatedProduct; }); }