@Test public void removeAssetById() { withCategoryHavingAssets(client(), category -> { final String assetId = category.getAssets().get(0).getId(); final Category updatedCategory = client().executeBlocking(CategoryUpdateCommand.of(category, RemoveAsset.of(assetId))); final List<Asset> assets = updatedCategory.getAssets(); assertThat(assets).allMatch(asset -> !asset.getId().equals(assetId)); }); }
public void removeAssetByVariantIdWithStaged(final Boolean staged) { withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final List<Asset> originalAssets = product.getMasterData().getStaged().getMasterVariant().getAssets(); final Asset assetToRemove = originalAssets.get(0); final String assetId = assetToRemove.getId(); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, RemoveAsset.ofVariantId(MASTER_VARIANT_ID, assetId, staged))); final List<Asset> assets = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets(); assertThat(assets).hasSize(originalAssets.size() - 1); assertThat(assets).allMatch(asset -> !asset.getId().equals(assetId)); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
@Test public void setAssetTags() { withCategoryHavingAssets(client(), category -> { final Set<String> newTags = new HashSet<>(asList("tag1", "tag2")); final String assetId = category.getAssets().get(0).getId(); final Category updatedCategory = client().executeBlocking(CategoryUpdateCommand.of(category, SetAssetTags.of(assetId, newTags))); final Asset updatedAsset = updatedCategory.getAssets().get(0); assertThat(updatedAsset.getTags()).isEqualTo(newTags); }); } }
@Test public void removeAssetByVariantId() { withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final List<Asset> originalAssets = product.getMasterData().getStaged().getMasterVariant().getAssets(); final Asset assetToRemove = originalAssets.get(0); final String assetId = assetToRemove.getId(); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, RemoveAsset.ofVariantId(MASTER_VARIANT_ID, assetId))); final List<Asset> assets = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets(); assertThat(assets).hasSize(originalAssets.size() - 1); assertThat(assets).allMatch(asset -> !asset.getId().equals(assetId)); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); return updatedProduct; }); }
@Test public void changeAssetNameById() { withCategoryHavingAssets(client(), category -> { final LocalizedString newName = LocalizedString.ofEnglish("new name"); final String assetId = category.getAssets().get(0).getId(); final CategoryUpdateCommand command = CategoryUpdateCommand.of(category, ChangeAssetName.of(assetId, newName)); final Category updatedCategory = client().executeBlocking(command); final Asset updatedAsset = updatedCategory.getAssets().get(0); assertThat(updatedAsset.getName()).isEqualTo(newName); }); }
@Test public void setAssetDescription() { withCategoryHavingAssets(client(), category -> { final LocalizedString newDescription = LocalizedString.ofEnglish("new description"); final String assetId = category.getAssets().get(0).getId(); final Category updatedCategory = client().executeBlocking(CategoryUpdateCommand.of(category, SetAssetDescription.of(assetId, newDescription))); final Asset updatedAsset = updatedCategory.getAssets().get(0); assertThat(updatedAsset.getDescription()).isEqualTo(newDescription); }); }
public void removeAssetBySkuWithStaged(final Boolean staged) { withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final String assetId = masterVariant.getAssets().get(0).getId(); final String sku = masterVariant.getSku(); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, RemoveAsset.ofSku(sku, assetId, staged))); final List<Asset> assets = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets(); assertThat(assets).allMatch(asset -> !asset.getId().equals(assetId)); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
@Test public void removeAssetBySku() { withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final String assetId = masterVariant.getAssets().get(0).getId(); final String sku = masterVariant.getSku(); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, RemoveAsset.ofSku(sku, assetId))); final List<Asset> assets = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets(); assertThat(assets).allMatch(asset -> !asset.getId().equals(assetId)); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); return updatedProduct; }); }
public void changeAssetNameBySkuWithStaged(final Boolean staged) { withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final LocalizedString newName = LocalizedString.ofEnglish("new name"); final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final String assetId = masterVariant.getAssets().get(0).getId(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, ChangeAssetName.ofSku(masterVariant.getSku(), assetId, newName, staged)); final Product updatedProduct = client().executeBlocking(cmd); final Asset updatedAsset = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets().get(0); assertThat(updatedAsset.getName()).isEqualTo(newName); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
public void setAssetDescriptionBySkuWithStaged(final Boolean staged) { withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final LocalizedString newDescription = LocalizedString.ofEnglish("new description"); final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final String assetId = masterVariant.getAssets().get(0).getId(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetAssetDescription.ofSku(masterVariant.getSku(), assetId, newDescription, staged)); final Product updatedProduct = client().executeBlocking(cmd); final Asset updatedAsset = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets().get(0); assertThat(updatedAsset.getDescription()).isEqualTo(newDescription); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
public void changeAssetNameByVariantIdWithStaged(final Boolean staged) { withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final LocalizedString newName = LocalizedString.ofEnglish("new name"); final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final String assetId = masterVariant.getAssets().get(0).getId(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, ChangeAssetName.ofVariantId(masterVariant.getId(), assetId, newName, staged)); final Product updatedProduct = client().executeBlocking(cmd); final Asset updatedAsset = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets().get(0); assertThat(updatedAsset.getName()).isEqualTo(newName); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
public void setAssetDescriptionByVariantIdWithStaged(final Boolean staged) { withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final LocalizedString newDescription = LocalizedString.ofEnglish("new description"); final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final String assetId = masterVariant.getAssets().get(0).getId(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetAssetDescription.ofVariantId(masterVariant.getId(), assetId, newDescription, staged)); final Product updatedProduct = client().executeBlocking(cmd); final Asset updatedAsset = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets().get(0); assertThat(updatedAsset.getDescription()).isEqualTo(newDescription); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
@Test public void setAssetKey() { withCategoryHavingAssets(client(), category -> { final String assetid = category.getAssets().get(0).getId(); final String newAssetKey = randomKey(); final Category updatedCategory = client().executeBlocking(CategoryUpdateCommand.of(category, SetAssetKey.of(assetid,newAssetKey))); final List<Asset> assets = updatedCategory.getAssets(); assertThat(assets).haveAtLeastOne(new Condition<>(asset -> asset.getKey().equals(newAssetKey),"Check if key is updated")); }); }
@Test public void setAssetDescriptionBySku() throws Exception { withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final LocalizedString newDescription = LocalizedString.ofEnglish("new description"); final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final String assetId = masterVariant.getAssets().get(0).getId(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetAssetDescription.ofSku(masterVariant.getSku(), assetId, newDescription)); final Product updatedProduct = client().executeBlocking(cmd); final Asset updatedAsset = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets().get(0); assertThat(updatedAsset.getDescription()).isEqualTo(newDescription); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); return updatedProduct; }); }
public void setAssetTagsByVariantIdWithStaged(final Boolean staged) { withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Set<String> newTags = new HashSet<>(asList("tag1", "tag2")); final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final String assetId = masterVariant.getAssets().get(0).getId(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetAssetTags.ofVariantId(masterVariant.getId(), assetId, newTags, staged)); final Product updatedProduct = client().executeBlocking(cmd); final Asset updatedAsset = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets().get(0); assertThat(updatedAsset.getTags()).isEqualTo(newTags); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
@Test public void setAssetDescriptionByVariantId() throws Exception { withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final LocalizedString newDescription = LocalizedString.ofEnglish("new description"); final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final String assetId = masterVariant.getAssets().get(0).getId(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetAssetDescription.ofVariantId(masterVariant.getId(), assetId, newDescription)); final Product updatedProduct = client().executeBlocking(cmd); final Asset updatedAsset = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets().get(0); assertThat(updatedAsset.getDescription()).isEqualTo(newDescription); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); return updatedProduct; }); }
@Test public void changeAssetNameByVariantId() throws Exception { withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final LocalizedString newName = LocalizedString.ofEnglish("new name"); final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final String assetId = masterVariant.getAssets().get(0).getId(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, ChangeAssetName.ofVariantId(masterVariant.getId(), assetId, newName)); final Product updatedProduct = client().executeBlocking(cmd); final Asset updatedAsset = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets().get(0); assertThat(updatedAsset.getName()).isEqualTo(newName); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); return updatedProduct; }); }
@Test public void setAssetTagsByVariantId() throws Exception { withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Set<String> newTags = new HashSet<>(asList("tag1", "tag2")); final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final String assetId = masterVariant.getAssets().get(0).getId(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetAssetTags.ofVariantId(masterVariant.getId(), assetId, newTags)); final Product updatedProduct = client().executeBlocking(cmd); final Asset updatedAsset = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets().get(0); assertThat(updatedAsset.getTags()).isEqualTo(newTags); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isTrue(); return updatedProduct; }); }
@Test public void removeAssetKey() { withCategoryHavingAssets(client(), category -> { final String assetid = category.getAssets().get(0).getId(); final Category updatedCategory = client().executeBlocking(CategoryUpdateCommand.of(category, SetAssetKey.of(assetid,null))); final List<Asset> assets = updatedCategory.getAssets(); assertThat(assets).haveAtLeastOne(new Condition<>(asset -> asset.getKey() == null,"Check if key is removed")); }); }
@Test public void setAssetTagsBySku() throws Exception { withProductHavingAssets(client(), product -> { final Set<String> newTags = new HashSet<>(asList("tag1", "tag2")); final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final String assetId = masterVariant.getAssets().get(0).getId(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetAssetTags.ofSku(masterVariant.getSku(), assetId, newTags)); final Product updatedProduct = client().executeBlocking(cmd); final Asset updatedAsset = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets().get(0); assertThat(updatedAsset.getTags()).isEqualTo(newTags); return updatedProduct; }); }