/** * 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 AssetDraftBuilder of(final Asset template) { return new AssetDraftBuilder(copyCustom(template.getCustom()), template.getDescription(), template.getKey(), template.getName(), template.getSources(), template.getTags()); } }
@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); }); } }
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 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 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; }); }