@Test public void setAssetSources() { withCategoryHavingAssets(client(), category -> { final AssetSource assetSource = AssetSourceBuilder.ofUri("http://dev.commercetools.com/assets/img/CT-logo.svg") .key("commercetools-logo") .contentType("image/svg+xml") .build(); final String assetId = category.getAssets().get(0).getId(); final Category updatedCategory = client().executeBlocking(CategoryUpdateCommand.of(category, SetAssetSources.of(assetId, Collections.singletonList(assetSource)))); final Asset updatedAsset = updatedCategory.getAssets().get(0); assertThat(updatedAsset.getSources()).hasSize(1); final AssetSource source = updatedAsset.getSources().get(0); assertThat(source.getUri()).isEqualTo("http://dev.commercetools.com/assets/img/CT-logo.svg"); assertThat(source.getKey()).isEqualTo("commercetools-logo"); assertThat(source.getContentType()).isEqualTo("image/svg+xml"); }); }
@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)); }); }
public void setAssetSourcesByVariantIdWithStaged(final Boolean staged) { withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final AssetSource assetSource = AssetSourceBuilder.ofUri("http://dev.commercetools.com/assets/img/CT-logo.svg") .key("commercetools-logo") .contentType("image/svg+xml") .build(); final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final String assetId = masterVariant.getAssets().get(0).getId(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetAssetSources.ofVariantId(masterVariant.getId(), assetId, Collections.singletonList(assetSource), staged)); final Product updatedProduct = client().executeBlocking(cmd); AssetSource source = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets().get(0).getSources().get(0); assertThat(source.getUri()).isEqualTo("http://dev.commercetools.com/assets/img/CT-logo.svg"); assertThat(source.getKey()).isEqualTo("commercetools-logo"); assertThat(source.getContentType()).isEqualTo("image/svg+xml"); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
@Test public void setAssetSourcesByVariantId() throws Exception { withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final AssetSource assetSource = AssetSourceBuilder.ofUri("http://dev.commercetools.com/assets/img/CT-logo.svg") .key("commercetools-logo") .contentType("image/svg+xml") .build(); final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final String assetId = masterVariant.getAssets().get(0).getId(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetAssetSources.ofVariantId(masterVariant.getId(), assetId, Collections.singletonList(assetSource))); final Product updatedProduct = client().executeBlocking(cmd); AssetSource source = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets().get(0).getSources().get(0); assertThat(source.getUri()).isEqualTo("http://dev.commercetools.com/assets/img/CT-logo.svg"); assertThat(source.getKey()).isEqualTo("commercetools-logo"); assertThat(source.getContentType()).isEqualTo("image/svg+xml"); return updatedProduct; }); }
@Test public void setAssetSourcesBySku() throws Exception { withProductHavingAssets(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final AssetSource assetSource = AssetSourceBuilder.ofUri("http://dev.commercetools.com/assets/img/CT-logo.svg") .key("commercetools-logo") .contentType("image/svg+xml") .build(); final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final String assetId = masterVariant.getAssets().get(0).getId(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetAssetSources.ofSku(masterVariant.getSku(), assetId, Collections.singletonList(assetSource))); final Product updatedProduct = client().executeBlocking(cmd); AssetSource source = updatedProduct.getMasterData().getStaged().getMasterVariant().getAssets().get(0).getSources().get(0); assertThat(source.getUri()).isEqualTo("http://dev.commercetools.com/assets/img/CT-logo.svg"); assertThat(source.getKey()).isEqualTo("commercetools-logo"); assertThat(source.getContentType()).isEqualTo("image/svg+xml"); return updatedProduct; }); }
@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 getAssetDraft2() { final AssetSource assetSource1 = AssetSourceBuilder.ofUri("http://dev.commercetools.com/assets/img/CT-logo.svg") .key(randomKey()) .contentType("image/svg+xml") .build(); final LocalizedString name = LocalizedString.ofEnglish("commercetools logo"); return AssetDraftBuilder.of(singletonList(assetSource1), name) .key("asset2Key") .tags("desktop-sized", "svg-format", "commercetools", "awesome") .build(); }
private static AssetDraft getAssetDraft2() { final AssetSource assetSource1 = AssetSourceBuilder.ofUri("http://dev.commercetools.com/assets/img/CT-logo.svg") .key(randomKey()) .contentType("image/svg+xml") .build(); final LocalizedString name = LocalizedString.ofEnglish("commercetools logo"); return AssetDraftBuilder.of(singletonList(assetSource1), name) .tags("desktop-sized", "svg-format", "commercetools", "awesome") .key(randomKey()) .build(); } }
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(); }
.contentType("image/jpg") .dimensionsOfWidthAndHeight(1934, 1115) .build();
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(); }