@Nullable default ProductData get(final ProductProjectionType productProjectionType) { return productProjectionType == CURRENT ? getCurrent() : getStaged(); } }
@Nullable default ProductData get(final ProductProjectionType productProjectionType) { return productProjectionType == CURRENT ? getCurrent() : getStaged(); } }
public static void withProductOfRestockableInDaysAndChannel(final BlockingSphereClient client, final int restockableInDays, @Nullable final Referenceable<Channel> channelReferenceable, final Consumer<Product> productConsumer) { final Reference<Channel> channelReference = Optional.ofNullable(channelReferenceable).map(Referenceable::toReference).orElse(null); ProductFixtures.withProduct(client, product -> { final String sku = product.getMasterData().getStaged().getMasterVariant().getSku(); final InventoryEntry inventoryEntry = client.executeBlocking(InventoryEntryCreateCommand.of(InventoryEntryDraft.of(sku, 5, null, restockableInDays, channelReference))); productConsumer.accept(product); client.executeBlocking(InventoryEntryDeleteCommand.of(inventoryEntry)); }); }
@Test public void readAttributeWithoutProductTypeWithNamedAccessWithWrongType() throws Exception { final ProductVariant masterVariant = createProduct().getMasterData().getStaged().getMasterVariant(); assertThatThrownBy(() -> masterVariant.findAttribute(SIZE_ATTR_NAME, AttributeAccess.ofBoolean())) .isInstanceOf(JsonException.class); }
private void testAddPrice(final PriceDraft expectedPrice) throws Exception { withUpdateableProduct(client(), product -> { final Product updatedProduct = client() .executeBlocking(ProductUpdateCommand.of(product, AddPrice.of(1, expectedPrice))); final List<Price> prices = updatedProduct.getMasterData().getStaged().getMasterVariant().getPrices(); assertThat(prices).hasSize(1); final Price actualPrice = prices.get(0); assertThat(expectedPrice).isEqualTo(PriceDraft.of(actualPrice)); 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 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 variantIdentifierIsAvailable() throws Exception { withProduct(client(), product -> { final ByIdVariantIdentifier identifier = product.getMasterData().getStaged().getMasterVariant().getIdentifier(); assertThat(identifier).isEqualTo(ByIdVariantIdentifier.of(product.getId(), 1)); }); }
@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 changeName() throws Exception { withUpdateableProduct(client(), product -> { final LocalizedString newName = LocalizedString.ofEnglish("newName " + RANDOM.nextInt()); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, ChangeName.of(newName))); assertThat(updatedProduct.getMasterData().getStaged().getName()).isEqualTo(newName); return updatedProduct; }); }
@Test public void notPresentAttributeRead() throws Exception { final ProductVariant masterVariant = createProduct().getMasterData().getStaged().getMasterVariant(); final Optional<Boolean> attributeOption = masterVariant.findAttribute("notpresent", AttributeAccess.ofBoolean()); assertThat(attributeOption).isEmpty(); }
@Test public void setMetaKeywords() throws Exception { withUpdateableProduct(client(), product -> { final LocalizedString metaKeywords = LocalizedString .of(ENGLISH, "Platform-as-a-Service, e-commerce, http, api, tool"); final SetMetaKeywords action = SetMetaKeywords.of(metaKeywords); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, action)); assertThat(updatedProduct.getMasterData().getStaged().getMetaKeywords()).isEqualTo(metaKeywords); return updatedProduct; }); }
@Test public void setMetaTitle() throws Exception { withUpdateableProduct(client(), product -> { final LocalizedString metaTitle = LocalizedString .of(ENGLISH, "commercetools SPHERE.IO™ - Next generation eCommerce"); final SetMetaTitle action = SetMetaTitle.of(metaTitle); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, action)); assertThat(updatedProduct.getMasterData().getStaged().getMetaTitle()).isEqualTo(metaTitle); return updatedProduct; }); }
@Test public void readAttributeWithoutProductTypeWithName() throws Exception { final ProductVariant masterVariant = createProduct().getMasterData().getStaged().getMasterVariant(); final Optional<EnumValue> attributeOption = masterVariant.findAttribute(SIZE_ATTR_NAME, AttributeAccess.ofEnumValue()); assertThat(attributeOption).contains(EnumValue.of("S", "S")); }
@BeforeClass public static void setupScenario() { data = ProductsScenario1Fixtures.createScenario(client()); masterVariant = data.getProduct1().getMasterData().getStaged().getMasterVariant(); }
@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 readAttributeWithoutProductTypeWithJson() throws Exception { final ProductVariant masterVariant = createProduct().getMasterData().getStaged().getMasterVariant(); final Attribute attr = masterVariant.getAttribute(SIZE_ATTR_NAME); final JsonNode expectedJsonNode = SphereJsonUtils.toJsonNode(EnumValue.of("S", "S")); assertThat(attr.getValue(AttributeAccess.ofJsonNode())).isEqualTo(expectedJsonNode); }
@Test public void selectAPriceByCurrencyInProductByIdGet() { final List<PriceDraft> prices = asList(PriceDraft.of(EURO_30), PriceDraft.of(USD_20)); withProductOfPrices(prices, product -> { final ProductByIdGet request = ProductByIdGet.of(product) .withPriceSelection(PriceSelection.of(EUR));//price selection config final Product result = client().executeBlocking(request); final ProductVariant masterVariant = result.getMasterData().getStaged().getMasterVariant(); assertThat(masterVariant.getPrice()).isNotNull().has(price(PriceDraft.of(EURO_30))); }); }
@Test public void selectAPriceByCurrencyInProductUpdateCommand() { ProductFixtures.withProduct(client(), product -> { final List<PriceDraft> prices = asList(PriceDraft.of(EURO_30), PriceDraft.of(USD_20)); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetPrices.of(1, prices)) .withPriceSelection(PriceSelection.of(EUR)); final Product updatedProduct = client().executeBlocking(cmd); final ProductVariant masterVariant = updatedProduct.getMasterData().getStaged().getMasterVariant(); assertThat(masterVariant.getPrice()).isNotNull().has(price(PriceDraft.of(EURO_30))); }); }
@Test(expected = NotFoundException.class) public void executeInvalidQuery(){ withUpdateableProductDiscount(client(),((productDiscount, product) -> { final ProductVariant masterVariant = product.getMasterData().getStaged().getMasterVariant(); final Price invalidPice = Price.of(MoneyImpl.of(0, DefaultCurrencyUnits.USD)); final ProductDiscount queryedProductDiscount = client().executeBlocking(MatchingProductDiscountGet.of(product.getId(), masterVariant.getId(), true, invalidPice)); return productDiscount; })); }