public ProductVariantDraftBuilder images(final Image image) { return images(Collections.singletonList(image)); }
public ProductVariantDraftBuilder images(final Image image) { return images(Collections.singletonList(image)); }
public ProductVariantDraftBuilder images(final Image image) { return images(Collections.singletonList(image)); }
public ProductVariantDraftDsl withImages(@Nullable final List<Image> images) { return newBuilder().images(images).build(); }
private void withProductWithImages(final BlockingSphereClient client, final List<String> imageUrls, final Function<Product, Product> productProductFunction) { withUpdateableProduct(client, builder -> { final List<Image> imagesList = new LinkedList<>(); for (final String imageUrl : imageUrls) { imagesList.add(Image.ofWidthAndHeight(imageUrl, 460, 102, "commercetools logo")); } final ProductVariantDraft oldMasterVariant = builder.getMasterVariant(); final ProductVariantDraftBuilder variantDraftBuilder = ProductVariantDraftBuilder.of(oldMasterVariant); variantDraftBuilder.images(imagesList); variantDraftBuilder.sku(randomKey()); return builder.masterVariant(variantDraftBuilder.build()); }, productProductFunction); }
public static void withProductHavingImages(final BlockingSphereClient client, final UnaryOperator<Product> op) { withUpdateableProduct(client, productDraftBuilder -> { final ProductVariantDraft masterVariant = productDraftBuilder.getMasterVariant(); final ProductVariantDraft variantDraft = ProductVariantDraftBuilder.of(masterVariant) .images(createExternalImage()) .sku(randomKey()) .build(); return productDraftBuilder.masterVariant(variantDraft); }, op); }
@Test public void createProductWithExternalImage() throws Exception { withStateByBuilder(client(), stateBuilder -> stateBuilder.initial(true).type(PRODUCT_STATE), initialProductState -> { final ProductType productType = ProductTypeFixtures.defaultProductType(client()); final Image image = Image.ofWidthAndHeight("http://www.commercetools.com/assets/img/ct_logo_farbe.gif", 460, 102, "commercetools logo"); final ProductVariantDraft masterVariant = ProductVariantDraftBuilder.of() .images(image) .build(); final TaxCategory taxCategory = defaultTaxCategory(client()); final SearchKeywords searchKeywords = SearchKeywords.of(Locale.ENGLISH, asList(SearchKeyword.of("foo bar baz", CustomSuggestTokenizer.of(asList("foo, baz"))))); final ProductDraft productDraft = ProductDraftBuilder .of(productType, en("product with external image"), randomSlug(), masterVariant) .taxCategory(taxCategory) .searchKeywords(searchKeywords) .state(initialProductState) .build(); final Product product = client().executeBlocking(ProductCreateCommand.of(productDraft)); final Image loadedImage = product.getMasterData().getStaged().getMasterVariant().getImages().get(0); assertThat(loadedImage).isEqualTo(image); assertThat(product.getTaxCategory()).isEqualTo(taxCategory.toReference()); assertThat(product.getMasterData().getStaged().getSearchKeywords()).isEqualTo(searchKeywords); assertThat(product.getState()).isEqualTo(initialProductState.toReference()); //clean up test client().executeBlocking(ProductDeleteCommand.of(product)); }); }
@Test public void message() { ProductTypeFixtures.withEmptyProductType(client(), productType -> { final String key = randomKey(); final Image image = createExternalImage(); final ProductDraft productDraft = ProductDraftBuilder.of(productType, randomSlug(), randomSlug(), ProductVariantDraftBuilder.of().images(image).build()).key(key).build(); final Product product = client().executeBlocking(ProductCreateCommand.of(productDraft)); final Product deletedProduct = client().executeBlocking(ProductDeleteCommand.ofKey(key, product.getVersion())); Query<ProductDeletedMessage> messageQuery = MessageQuery.of() .withPredicates(m -> m.resource().is(deletedProduct)) .withSort(m -> m.createdAt().sort().desc()) .withExpansionPaths(m -> m.resource()) .withLimit(1L) .forMessageType(ProductDeletedMessage.MESSAGE_HINT); assertEventually(() -> { final PagedQueryResult<ProductDeletedMessage> queryResult = client().executeBlocking(messageQuery); assertThat(queryResult.head()).isPresent(); final ProductDeletedMessage message = queryResult.head().get(); assertThat(message.getResource().getId()).isEqualTo(product.getId()); assertThat(message.getRemovedImageUrls()).containsExactly(image.getUrl()); }); }); } }