/** * 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 removeAssetByKey() { withCategoryHavingAssets(client(), category -> { final String assetKey = category.getAssets().get(0).getKey(); final Category updatedCategory = client().executeBlocking(CategoryUpdateCommand.of(category, RemoveAsset.ofKey(assetKey))); final List<Asset> assets = updatedCategory.getAssets(); assertThat(assets).allMatch(asset -> !asset.getKey().equals(assetKey)); }); }
@Test public void changeAssetNameByKey() { withCategoryHavingAssets(client(), category -> { final LocalizedString newName = LocalizedString.ofEnglish("new name"); final String assetKey = category.getAssets().get(0).getKey(); final CategoryUpdateCommand command = CategoryUpdateCommand.of(category, ChangeAssetName.ofKey(assetKey, newName)); final Category updatedCategory = client().executeBlocking(command); final Asset updatedAsset = updatedCategory.getAssets().get(0); assertThat(updatedAsset.getName()).isEqualTo(newName); }); }
public void changeAssetNameByVariantIdAndAssetKeyWithStaged(@Nonnull 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 assetKey = masterVariant.getAssets().get(0).getKey(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, ChangeAssetName.ofAssetKeyAndVariantId(masterVariant.getId(), assetKey, 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; }); }
@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 changeAssetNameByVariantIdAndAssetKey() { withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final LocalizedString newName = LocalizedString.ofEnglish("new name"); final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final String assetKey = masterVariant.getAssets().get(0).getKey(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, ChangeAssetName.ofAssetKeyAndVariantId(masterVariant.getId(), assetKey, 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; }); }
public void setAssetCustomTypeByVariantIdAndAssetKeyWithStaged(@Nonnull final Boolean staged) { withUpdateableType(client(), (Type type) -> { withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final Asset assetWithoutCustomType = masterVariant.getAssets().get(0); final String assetKey = assetWithoutCustomType.getKey(); final CustomFieldsDraft customFieldsDraft = CustomFieldsDraftBuilder.ofType(type).build(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetAssetCustomType.ofVariantIdAndAssetKey(masterVariant.getId(), assetKey, customFieldsDraft, staged)); final Product updatedProductWithCustomTypeInAssets = client().executeBlocking(cmd); final Asset updatedAsset = updatedProductWithCustomTypeInAssets.getMasterData().getStaged() .getMasterVariant().getAssets().get(0); assertThat(updatedAsset.getCustom()).isNotNull(); assertThat(updatedAsset.getCustom().getType().getId()).isEqualTo(type.getId()); assertThat(updatedProductWithCustomTypeInAssets.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProductWithCustomTypeInAssets; }); return type; }); }
@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 setAssetCustomTypeByVariantIdAndAssetKey() { withUpdateableType(client(), (Type type) -> { withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final Asset assetWithoutCustomType = masterVariant.getAssets().get(0); final String assetKey = assetWithoutCustomType.getKey(); final CustomFieldsDraft customFieldsDraft = CustomFieldsDraftBuilder.ofType(type).build(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetAssetCustomType.ofVariantIdAndAssetKey(masterVariant.getId(), assetKey, customFieldsDraft)); final Product updatedProductWithCustomTypeInAssets = client().executeBlocking(cmd); final Asset updatedAsset = updatedProductWithCustomTypeInAssets.getMasterData().getStaged() .getMasterVariant().getAssets().get(0); assertThat(updatedAsset.getCustom()).isNotNull(); assertThat(updatedAsset.getCustom().getType().getId()).isEqualTo(type.getId()); return updatedProductWithCustomTypeInAssets; }); return type; }); }
@Test public void setAssetCustomTypeByVariantSkuAndAssetKey() { withUpdateableType(client(), (Type type) -> { withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final Asset assetWithoutCustomType = masterVariant.getAssets().get(0); final String assetKey = assetWithoutCustomType.getKey(); final CustomFieldsDraft customFieldsDraft = CustomFieldsDraftBuilder.ofType(type).build(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetAssetCustomType.ofSkuAndAssetKey(masterVariant.getSku(), assetKey, customFieldsDraft)); final Product updatedProductWithCustomTypeInAssets = client().executeBlocking(cmd); final Asset updatedAsset = updatedProductWithCustomTypeInAssets.getMasterData().getStaged() .getMasterVariant().getAssets().get(0); assertThat(updatedAsset.getCustom()).isNotNull(); assertThat(updatedAsset.getCustom().getType().getId()).isEqualTo(type.getId()); return updatedProductWithCustomTypeInAssets; }); return type; }); } @Test
final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final Asset assetWithoutCustomType = masterVariant.getAssets().get(0); final String assetKey = assetWithoutCustomType.getKey();
final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final Asset assetWithoutCustomType = masterVariant.getAssets().get(0); final String assetKey = assetWithoutCustomType.getKey();