@Test public void addAsset() { withCategory(client(), category -> { final AssetSource assetSource = AssetSourceBuilder.ofUri("https://commercetools.com/binaries/content/gallery/commercetoolswebsite/homepage/cases/rewe.jpg") .key("rewe-showcase") .contentType("image/jpg") .dimensionsOfWidthAndHeight(1934, 1115) .build(); final LocalizedString name = LocalizedString.ofEnglish("REWE show case"); final LocalizedString description = LocalizedString.ofEnglish("screenshot of the REWE webshop on a mobile and a notebook"); final AssetDraft assetDraft = AssetDraftBuilder.of(singletonList(assetSource), name) .description(description) .tags("desktop-sized", "jpg-format", "REWE", "awesome") .build(); final CategoryUpdateCommand command = CategoryUpdateCommand.of(category, AddAsset.of(assetDraft,0)); final Category updatedCategory = client().executeBlocking(command); final List<Asset> assets = updatedCategory.getAssets(); assertThat(assets).hasSize(1); final Asset asset = assets.get(0); assertThat(asset.getId()).isNotEmpty(); assertThat(asset.getDescription()).isEqualTo(description); assertThat(asset.getName()).isEqualTo(name); assertThat(asset.getSources()).hasSize(1); final AssetSource source = asset.getSources().get(0); assertThat(source.getUri()).isEqualTo("https://commercetools.com/binaries/content/gallery/commercetoolswebsite/homepage/cases/rewe.jpg"); assertThat(source.getKey()).isEqualTo("rewe-showcase"); assertThat(source.getContentType()).isEqualTo("image/jpg"); assertThat(source.getDimensions()).isEqualTo(AssetDimensions.ofWidthAndHeight(1934, 1115)); }); }
@Test public void addAssetByVariantId() { withProduct(client(), (Product product) -> { final AssetSource assetSource = AssetSourceBuilder.ofUri("https://commercetools.com/binaries/content/gallery/commercetoolswebsite/homepage/cases/rewe.jpg") .key("rewe-showcase") .contentType("image/jpg") .dimensionsOfWidthAndHeight(1934, 1115) .build(); final LocalizedString name = LocalizedString.ofEnglish("REWE show case"); final LocalizedString description = LocalizedString.ofEnglish("screenshot of the REWE webshop on a mobile and a notebook"); final AssetDraft assetDraft = AssetDraftBuilder.of(singletonList(assetSource), name) .description(description) .tags("desktop-sized", "jpg-format", "REWE", "awesome") .build(); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, AddAsset.ofVariantId(MASTER_VARIANT_ID, assetDraft))); final List<Asset> assets = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets(); assertThat(assets).hasSize(1); final Asset asset = assets.get(0); assertThat(asset.getId()).isNotEmpty(); assertThat(asset.getDescription()).isEqualTo(description); assertThat(asset.getName()).isEqualTo(name); assertThat(asset.getSources()).hasSize(1); final AssetSource source = asset.getSources().get(0); assertThat(source.getUri()).isEqualTo("https://commercetools.com/binaries/content/gallery/commercetoolswebsite/homepage/cases/rewe.jpg"); assertThat(source.getKey()).isEqualTo("rewe-showcase"); assertThat(source.getContentType()).isEqualTo("image/jpg"); assertThat(source.getDimensions()).isEqualTo(AssetDimensions.ofWidthAndHeight(1934, 1115)); }); }
private static AssetDraft getAssetDraft1() { final AssetSource assetSource1 = AssetSourceBuilder.ofUri("https://commercetools.com/binaries/content/gallery/commercetoolswebsite/homepage/cases/rewe.jpg") .key(randomKey()) .contentType("image/jpg") .dimensionsOfWidthAndHeight(1934, 1115) .build(); final LocalizedString name = LocalizedString.ofEnglish("REWE show case"); final LocalizedString description = LocalizedString.ofEnglish("screenshot of the REWE webshop on a mobile and a notebook"); return AssetDraftBuilder.of(singletonList(assetSource1), name) .key("asset1Key") .description(description) .tags("desktop-sized", "jpg-format", "REWE", "awesome") .build(); }
.key("rewe-showcase") .contentType("image/jpg") .dimensionsOfWidthAndHeight(1934, 1115) .build(); final LocalizedString name = LocalizedString.ofEnglish("REWE show case");
private static AssetDraft getAssetDraft1() { final AssetSource assetSource1 = AssetSourceBuilder.ofUri("https://commercetools.com/binaries/content/gallery/commercetoolswebsite/homepage/cases/rewe.jpg") .key(randomKey()) .contentType("image/jpg") .dimensionsOfWidthAndHeight(1934, 1115) .build(); final LocalizedString name = LocalizedString.ofEnglish("REWE show case"); final LocalizedString description = LocalizedString.ofEnglish("screenshot of the REWE webshop on a mobile and a notebook"); return AssetDraftBuilder.of(singletonList(assetSource1), name) .description(description) .key(randomKey()) .tags("desktop-sized", "jpg-format", "REWE", "awesome") .build(); }