public static void withProductInCategory(final BlockingSphereClient client, final BiConsumer<Product, Category> consumer) { withCategory(client, category -> { final Consumer<Product> user = product -> consumer.accept(product, category); withProduct(client, "withProductAndCategory", product -> { final Product productWithCategory = client.executeBlocking(ProductUpdateCommand.of(product, AddToCategory.of(category))); consumer.accept(productWithCategory, category); }); }); }
@Test public void publish() throws Exception { withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().isPublished()).isFalse(); final Product publishedProduct = client().executeBlocking(ProductUpdateCommand.of(product, Publish.of())); assertThat(publishedProduct.getMasterData().isPublished()).isTrue(); final Product unpublishedProduct = client().executeBlocking(ProductUpdateCommand.of(publishedProduct, Unpublish.of())); assertThat(unpublishedProduct.getMasterData().isPublished()).isFalse(); return unpublishedProduct; }); }
public void changeSlugWithStaged(final Boolean staged) { withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final LocalizedString newSlug = LocalizedString.ofEnglish("new-slug-" + RANDOM.nextInt()); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, ChangeSlug.of(newSlug, staged))); assertThat(updatedProduct.getMasterData().getStaged().getSlug()).isEqualTo(newSlug); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
public void setDescriptionWithStaged(final Boolean staged) { withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final LocalizedString newDescription = LocalizedString.ofEnglish("new description " + RANDOM.nextInt()); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetDescription.of(newDescription, staged)); final Product updatedProduct = client().executeBlocking(cmd); assertThat(updatedProduct.getMasterData().getStaged().getDescription()).isEqualTo(newDescription); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
@Test public void removePrice() throws Exception { withUpdateablePricedProduct(client(), product -> { final Price oldPrice = getFirstPrice(product); final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, RemovePrice.of(oldPrice))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant() .getPrices().stream().anyMatch(p -> p.equals(oldPrice))).isFalse(); return updatedProduct; }); }
public void changeNameWithStaged(final Boolean staged) { withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final LocalizedString newName = LocalizedString.ofEnglish("newName " + RANDOM.nextInt()); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, ChangeName.of(newName, staged))); assertThat(updatedProduct.getMasterData().getStaged().getName()).isEqualTo(newName); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
public void setSearchKeywordsWithStaged(final Boolean staged) { withUpdateableProduct(client(), product -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final SearchKeywords searchKeywords = SearchKeywords.of(Locale.ENGLISH, asList(SearchKeyword.of("Raider", CustomSuggestTokenizer.of(singletonList("Twix"))))); final ProductUpdateCommand command = ProductUpdateCommand.of(product, SetSearchKeywords.of(searchKeywords, staged)); final Product updatedProduct = client().executeBlocking(command); final SearchKeywords actualKeywords = updatedProduct.getMasterData().getStaged().getSearchKeywords(); assertThat(actualKeywords).isEqualTo(searchKeywords); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); return updatedProduct; }); }
@Test public void setKey() throws Exception { final String key = randomKey(); withProduct(client(), (Product product) -> { final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, SetKey.of(key))); assertThat(updatedProduct.getKey()).isEqualTo(key); }); }
@Test public void updateWithWrongType() throws Exception { final Product product = createProduct(); assertThatThrownBy(() -> client().executeBlocking(ProductUpdateCommand.of(product, SetAttribute.of(1, AttributeDraft.of(LAUNDRY_SYMBOLS_ATTR_NAME, "cold"))))) .isInstanceOf(ErrorResponseException.class) .matches(e -> ((ErrorResponseException)e).hasErrorCode(InvalidField.CODE)); }
@Test public void setDescription() throws Exception { withUpdateableProduct(client(), product -> { final LocalizedString newDescription = LocalizedString.ofEnglish("new description " + RANDOM.nextInt()); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetDescription.of(newDescription)); final Product updatedProduct = client().executeBlocking(cmd); assertThat(updatedProduct.getMasterData().getStaged().getDescription()).isEqualTo(newDescription); return updatedProduct; }); }
@Test public void setPricesEmptyList() { withUpdateablePricedProduct(client(), product -> { final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, SetPrices.of(1, emptyList()))); final List<Price> newPrices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices(); assertThat(newPrices).isEmpty(); return updatedProduct; }); }
@Test public void setTaxCategory() throws Exception { TaxCategoryFixtures.withTransientTaxCategory(client(), taxCategory -> withUpdateableProduct(client(), product -> { assertThat(product.getTaxCategory()).isNotEqualTo(taxCategory); final ProductUpdateCommand command = ProductUpdateCommand.of(product, SetTaxCategory.of(taxCategory)); final Product updatedProduct = client().executeBlocking(command); assertThat(updatedProduct.getTaxCategory()).isEqualTo(taxCategory.toReference()); return updatedProduct; }) ); }
public void setProductVariantKeyByVariantIdWithStaged(final Boolean staged) { final String key = randomKey(); withProduct(client(), (Product product) -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final Integer variantId = product.getMasterData().getStaged().getMasterVariant().getId(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetProductVariantKey.ofKeyAndVariantId(key, variantId, staged)); final Product updatedProduct = client().executeBlocking(cmd); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getKey()).isEqualTo(key); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); }); }
public void setProductVariantKeyBySkuWithStaged(final Boolean staged) { final String key = randomKey(); withProduct(client(), (Product product) -> { assertThat(product.getMasterData().hasStagedChanges()).isFalse(); final String sku = product.getMasterData().getStaged().getMasterVariant().getSku(); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetProductVariantKey.ofKeyAndSku(key, sku, staged)); final Product updatedProduct = client().executeBlocking(cmd); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getKey()).isEqualTo(key); assertThat(updatedProduct.getMasterData().hasStagedChanges()).isEqualTo(staged); }); }
@Test public void setCategoryOrderHint() throws Exception { withProductInCategory(client(), (product, category) -> { final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, SetCategoryOrderHint.of(category.getId(), "0.1234"))); final CategoryOrderHints actual = updatedProduct.getMasterData().getStaged().getCategoryOrderHints(); assertThat(actual).isEqualTo(CategoryOrderHints.of(category.getId(), "0.1234")); assertThat(actual.getAsMap()).isEqualTo(Collections.singletonMap(category.getId(), "0.1234")); }); }
@Test public void removeImageByVariantId() throws Exception { final Image image = createExternalImage(); withUpdateableProduct(client(), product -> { final Product productWithImage = client().executeBlocking(ProductUpdateCommand.of(product, AddExternalImage.ofVariantId(MASTER_VARIANT_ID, image))); assertThat(productWithImage.getMasterData().getStaged().getMasterVariant().getImages()).isEqualTo(asList(image)); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(productWithImage, RemoveImage.ofVariantId(MASTER_VARIANT_ID, image))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).hasSize(0); return updatedProduct; }); }
@Test public void removeImageBySku() throws Exception { final Image image = createExternalImage(); withUpdateableProduct(client(), product -> { final String sku = product.getMasterData().getStaged().getMasterVariant().getSku(); final Product productWithImage = client().executeBlocking(ProductUpdateCommand.of(product, AddExternalImage.ofSku(sku, image))); assertThat(productWithImage.getMasterData().getStaged().getMasterVariant().getImages()).isEqualTo(asList(image)); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(productWithImage, RemoveImage.ofSku(sku, image))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).hasSize(0); return updatedProduct; }); }
@Test public void addExternalImage() throws Exception { withUpdateableProduct(client(), (Product product) -> { assertThat(product.getMasterData().getStaged().getMasterVariant().getImages()).hasSize(0); final Image image = createExternalImage(); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, AddExternalImage.of(image, MASTER_VARIANT_ID))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).isEqualTo(asList(image)); return updatedProduct; }); }
@Test public void updateAttributesBooks() throws Exception { final Product product = createBookProduct(); final int masterVariantId = 1; final AttributeDraft attributeDraft = AttributeDraft.of(ISBN_ATTR_NAME, "978-3-86680-192-8"); final SetAttribute updateAction = SetAttribute.of(masterVariantId, attributeDraft); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, updateAction)); final ProductVariant masterVariant = updatedProduct.getMasterData().getStaged().getMasterVariant(); assertThat(masterVariant.findAttribute(ISBN_ATTR_NAME, AttributeAccess.ofText())) .contains("978-3-86680-192-8"); }
@Test public void queryBySku() throws Exception { withProduct(client(), product -> { final String sku = "sku-" + randomString(); final Product productWithSku = client().executeBlocking(ProductUpdateCommand.of(product, SetSku.of(MASTER_VARIANT_ID, sku))); final QueryPredicate<ProductProjection> predicate = model().masterVariant().sku().is(sku); checkOneResult(productWithSku, predicate); }); }