本文整理匯總了Java中io.sphere.sdk.products.commands.ProductCreateCommand類的典型用法代碼示例。如果您正苦於以下問題:Java ProductCreateCommand類的具體用法?Java ProductCreateCommand怎麽用?Java ProductCreateCommand使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ProductCreateCommand類屬於io.sphere.sdk.products.commands包,在下文中一共展示了ProductCreateCommand類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sync_withNewProductWithExistingCategoryAndProductTypeReferences_ShouldCreateProduct
import io.sphere.sdk.products.commands.ProductCreateCommand; //導入依賴的package包/類
@Test
public void sync_withNewProductWithExistingCategoryAndProductTypeReferences_ShouldCreateProduct() {
final ProductDraft productDraft = createProductDraft(PRODUCT_KEY_1_RESOURCE_PATH,
productTypeSource.toReference(), oldTaxCategory.toReference(), oldProductState.toReference(),
categoryReferencesWithIds, createRandomCategoryOrderHints(categoryReferencesWithIds));
CTP_SOURCE_CLIENT.execute(ProductCreateCommand.of(productDraft)).toCompletableFuture().join();
final List<Product> products = CTP_SOURCE_CLIENT.execute(productQuery)
.toCompletableFuture().join().getResults();
final List<ProductDraft> productDrafts = replaceProductsReferenceIdsWithKeys(products);
final ProductSyncStatistics syncStatistics = productSync.sync(productDrafts).toCompletableFuture().join();
assertThat(syncStatistics).hasValues(1, 1, 0, 0);
assertThat(errorCallBackMessages).isEmpty();
assertThat(errorCallBackExceptions).isEmpty();
assertThat(warningCallBackMessages).hasSize(1);
assertThat(warningCallBackMessages.get(0)).matches("ProductType with id: '.*' has no key"
+ " set. Keys are required for productType matching.");
}
示例2: sync_withNewProductWithNoProductTypeKey_ShouldFailCreatingTheProduct
import io.sphere.sdk.products.commands.ProductCreateCommand; //導入依賴的package包/類
@Test
public void sync_withNewProductWithNoProductTypeKey_ShouldFailCreatingTheProduct() {
final ProductDraft productDraft = createProductDraft(PRODUCT_KEY_1_RESOURCE_PATH,
noKeyProductTypeSource.toReference(), oldTaxCategory.toReference(), oldProductState.toReference(),
categoryReferencesWithIds, createRandomCategoryOrderHints(categoryReferencesWithIds));
CTP_SOURCE_CLIENT.execute(ProductCreateCommand.of(productDraft)).toCompletableFuture().join();
final List<Product> products = CTP_SOURCE_CLIENT.execute(productQuery)
.toCompletableFuture().join().getResults();
final List<ProductDraft> productDrafts = replaceProductsReferenceIdsWithKeys(products);
final ProductSyncStatistics syncStatistics = productSync.sync(productDrafts).toCompletableFuture().join();
assertThat(syncStatistics).hasValues(1, 0, 0, 1);
assertThat(errorCallBackMessages).hasSize(1);
assertThat(errorCallBackMessages.get(0)).isEqualTo(format("Failed to resolve references on ProductDraft with"
+ " key:'%s'. Reason: %s: Failed to resolve product type reference on ProductDraft with key:'%s'."
+ " Reason: Reference 'id' field value is blank (null/empty).",
productDraft.getKey(), ReferenceResolutionException.class.getCanonicalName(), productDraft.getKey()));
assertThat(errorCallBackExceptions).hasSize(1);
assertThat(errorCallBackExceptions.get(0)).isExactlyInstanceOf(ReferenceResolutionException.class);
assertThat(warningCallBackMessages).isEmpty();
}
示例3: sync_withChangesOnly_ShouldUpdateProducts
import io.sphere.sdk.products.commands.ProductCreateCommand; //導入依賴的package包/類
@Test
public void sync_withChangesOnly_ShouldUpdateProducts() {
final ProductDraft existingProductDraft = createProductDraft(PRODUCT_KEY_1_RESOURCE_PATH,
targetProductType.toReference(), targetTaxCategory.toReference(), targetProductState.toReference(),
targetCategoryReferencesWithIds, createRandomCategoryOrderHints(targetCategoryReferencesWithIds));
CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(existingProductDraft)).toCompletableFuture().join();
final ProductDraft newProductDraft = createProductDraft(PRODUCT_KEY_1_CHANGED_RESOURCE_PATH,
sourceProductType.toReference(), sourceTaxCategory.toReference(), sourceProductState.toReference(),
sourceCategoryReferencesWithIds, createRandomCategoryOrderHints(sourceCategoryReferencesWithIds));
CTP_SOURCE_CLIENT.execute(ProductCreateCommand.of(newProductDraft)).toCompletableFuture().join();
final List<Product> products = CTP_SOURCE_CLIENT.execute(buildProductQuery())
.toCompletableFuture().join().getResults();
final List<ProductDraft> productDrafts = replaceProductsReferenceIdsWithKeys(products);
final ProductSyncStatistics syncStatistics = productSync.sync(productDrafts).toCompletableFuture().join();
assertThat(syncStatistics).hasValues(1, 0, 1, 0);
assertThat(errorCallBackMessages).isEmpty();
assertThat(errorCallBackExceptions).isEmpty();
assertThat(warningCallBackMessages).isEmpty();
}
示例4: cacheKeysToIds_ShouldCacheProductKeysOnlyFirstCall
import io.sphere.sdk.products.commands.ProductCreateCommand; //導入依賴的package包/類
@Test
public void cacheKeysToIds_ShouldCacheProductKeysOnlyFirstCall() {
Map<String, String> cache = productService.cacheKeysToIds().toCompletableFuture().join();
assertThat(cache).hasSize(1);
// Create new product without caching
final ProductDraft productDraft = createProductDraft(PRODUCT_KEY_2_RESOURCE_PATH, productType.toReference(),
null, null, categoryReferencesWithIds,
createRandomCategoryOrderHints(categoryReferencesWithIds));
CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(productDraft)).toCompletableFuture().join();
cache = productService.cacheKeysToIds().toCompletableFuture().join();
assertThat(cache).hasSize(1);
assertThat(errorCallBackExceptions).isEmpty();
assertThat(errorCallBackMessages).isEmpty();
}
示例5: fetchCachedProductId_ByDefault_ShouldCacheProductKeysOnlyFirstTime
import io.sphere.sdk.products.commands.ProductCreateCommand; //導入依賴的package包/類
@Test
public void fetchCachedProductId_ByDefault_ShouldCacheProductKeysOnlyFirstTime() {
// Fetch any product to populate cache
productService.fetchCachedProductId("anyKey").toCompletableFuture().join();
final ProductDraft productDraft = createProductDraftBuilder(PRODUCT_KEY_2_RESOURCE_PATH,
productType.toReference())
.taxCategory(null)
.state(null)
.categories(emptyList())
.categoryOrderHints(null)
.build();
CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(productDraft)).toCompletableFuture().join();
final Optional<String> newProductId =
productService.fetchCachedProductId(productDraft.getKey()).toCompletableFuture().join();
assertThat(newProductId).isEmpty();
assertThat(errorCallBackExceptions).isEmpty();
assertThat(errorCallBackMessages).isEmpty();
}
示例6: createProduct
import io.sphere.sdk.products.commands.ProductCreateCommand; //導入依賴的package包/類
public static Product createProduct(final BlockingSphereClient sphereClient) {
return withPrice(priceDraft -> {
final String sku = RandomStringUtils.randomAlphabetic(10);
final ProductType productType = createProductType(sphereClient);
final ProductDraftBuilder productDraftBuilder = ProductDraftBuilder.of(productType, LocalizedString.of(Locale.ENGLISH, "product-name"),
LocalizedString.of(Locale.ENGLISH, RandomStringUtils.randomAlphabetic(10)), ProductVariantDraftBuilder.of().sku(sku).build());
final Product product = sphereClient.executeBlocking(ProductCreateCommand.of(productDraftBuilder.publish(true).build()));
final AddPrice addPrice = AddPrice.of(product.getMasterData().getCurrent().getMasterVariant().getId(), priceDraft);
Product productWithPrice = sphereClient.executeBlocking(ProductUpdateCommand.of(product, asList(addPrice, Publish.of())));
return productWithPrice;
});
}
示例7: createProductWithSkus
import io.sphere.sdk.products.commands.ProductCreateCommand; //導入依賴的package包/類
public static Product createProductWithSkus(final BlockingSphereClient sphereClient, Set<String> skus) {
PriceDraft priceDraft = PriceDraft.of(MoneyImpl.of(new BigDecimal("123456"), "EUR")).withCountry(CountryCode.DE);
List<ProductVariantDraft> productVariantDrafts = skus.stream().map(sku -> ProductVariantDraftBuilder.of().sku(sku).build()).collect(Collectors.toList());
final ProductType productType = createProductType(sphereClient);
final ProductDraftBuilder productDraftBuilder = ProductDraftBuilder.of(productType, LocalizedString.of(Locale.ENGLISH, "product-name"),
LocalizedString.of(Locale.ENGLISH, RandomStringUtils.randomAlphabetic(10)), productVariantDrafts);
final Product product = sphereClient.executeBlocking(ProductCreateCommand.of(productDraftBuilder.publish(true).build()));
final AddPrice addPrice = AddPrice.of(product.getMasterData().getCurrent().getMasterVariant().getId(), priceDraft);
Product productWithPrice = sphereClient.executeBlocking(ProductUpdateCommand.of(product, asList(addPrice, Publish.of())));
return productWithPrice;
}
開發者ID:commercetools,項目名稱:commercetools-sunrise-data,代碼行數:13,代碼來源:OrdersImportJobConfigurationIntegrationTest.java
示例8: setupPerTest
import io.sphere.sdk.products.commands.ProductCreateCommand; //導入依賴的package包/類
/**
* 1. Clears all sync collections used for test assertions.
* 2. Deletes all products from target CTP project
* 3. Creates an instance for {@link ProductSyncOptions} that will be used in the test.
* 4. Creates a product in the target CTP project with 1 variant other than the master
* variant.
*/
@Before
public void setupPerTest() {
clearSyncTestCollections();
deleteAllProducts(CTP_TARGET_CLIENT);
syncOptions = getProductSyncOptions();
final ProductDraft productDraft =
createProductDraftBuilder(PRODUCT_WITH_VARS_RESOURCE_PATH, productType.toReference())
.build();
oldProduct = executeBlocking(CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(productDraft)));
}
示例9: sync_withChangesOnlyAndUnPublish_ShouldUpdateProducts
import io.sphere.sdk.products.commands.ProductCreateCommand; //導入依賴的package包/類
@Test
public void sync_withChangesOnlyAndUnPublish_ShouldUpdateProducts() {
final ProductDraft existingProductDraft = createProductDraft(PRODUCT_KEY_1_RESOURCE_PATH,
targetProductType.toReference(), targetTaxCategory.toReference(), targetProductState.toReference(),
targetCategoryReferencesWithIds, createRandomCategoryOrderHints(targetCategoryReferencesWithIds));
CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(existingProductDraft)).toCompletableFuture().join();
final ProductDraft newProductDraft = createProductDraftBuilder(PRODUCT_KEY_1_CHANGED_RESOURCE_PATH,
sourceProductType.toReference())
.taxCategory(sourceTaxCategory)
.state(sourceProductState)
.categories(sourceCategoryReferencesWithIds)
.categoryOrderHints(createRandomCategoryOrderHints(sourceCategoryReferencesWithIds))
.publish(false).build();
CTP_SOURCE_CLIENT.execute(ProductCreateCommand.of(newProductDraft)).toCompletableFuture().join();
final List<Product> products = CTP_SOURCE_CLIENT.execute(buildProductQuery())
.toCompletableFuture().join().getResults();
final List<ProductDraft> productDrafts = replaceProductsReferenceIdsWithKeys(products);
final ProductSyncStatistics syncStatistics = productSync.sync(productDrafts).toCompletableFuture().join();
assertThat(syncStatistics).hasValues(1, 0, 1, 0);
assertThat(errorCallBackMessages).isEmpty();
assertThat(errorCallBackExceptions).isEmpty();
assertThat(warningCallBackMessages).isEmpty();
}
示例10: sync_withPriceChannels_ShouldUpdateProducts
import io.sphere.sdk.products.commands.ProductCreateCommand; //導入依賴的package包/類
@Test
public void sync_withPriceChannels_ShouldUpdateProducts() {
final ProductDraft existingProductDraft = createProductDraft(PRODUCT_KEY_1_WITH_PRICES_RESOURCE_PATH,
targetProductType.toReference(), targetTaxCategory.toReference(), targetProductState.toReference(),
targetCategoryReferencesWithIds, createRandomCategoryOrderHints(targetCategoryReferencesWithIds));
final ProductDraft existingDraftWithPriceChannelReferences =
getDraftWithPriceChannelReferences(existingProductDraft, targetPriceChannel.toReference());
CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(existingDraftWithPriceChannelReferences))
.toCompletableFuture().join();
final ProductDraft newProductDraft = createProductDraftBuilder(PRODUCT_KEY_1_CHANGED_WITH_PRICES_RESOURCE_PATH,
sourceProductType.toReference())
.taxCategory(sourceTaxCategory)
.state(sourceProductState)
.categories(sourceCategoryReferencesWithIds)
.categoryOrderHints(createRandomCategoryOrderHints(sourceCategoryReferencesWithIds))
.publish(false).build();
final ProductDraft newDraftWithPriceChannelReferences =
getDraftWithPriceChannelReferences(newProductDraft, sourcePriceChannel.toReference());
CTP_SOURCE_CLIENT.execute(ProductCreateCommand.of(newDraftWithPriceChannelReferences))
.toCompletableFuture().join();
final List<Product> products = CTP_SOURCE_CLIENT.execute(buildProductQuery())
.toCompletableFuture().join().getResults();
final List<ProductDraft> productDrafts = replaceProductsReferenceIdsWithKeys(products);
final ProductSyncStatistics syncStatistics = productSync.sync(productDrafts).toCompletableFuture().join();
assertThat(syncStatistics).hasValues(1, 0, 1, 0);
assertThat(errorCallBackMessages).isEmpty();
assertThat(errorCallBackExceptions).isEmpty();
assertThat(warningCallBackMessages).isEmpty();
}
示例11: setupTest
import io.sphere.sdk.products.commands.ProductCreateCommand; //導入依賴的package包/類
/**
* Deletes Products and Types from target CTP projects, then it populates target CTP project with product test
* data.
*/
@Before
public void setupTest() {
errorCallBackMessages = new ArrayList<>();
errorCallBackExceptions = new ArrayList<>();
warningCallBackMessages = new ArrayList<>();
deleteAllProducts(CTP_TARGET_CLIENT);
final ProductSyncOptions productSyncOptions = ProductSyncOptionsBuilder.of(CTP_TARGET_CLIENT)
.errorCallback(
(errorMessage, exception) -> {
errorCallBackMessages
.add(errorMessage);
errorCallBackExceptions
.add(exception);
})
.warningCallback(warningMessage ->
warningCallBackMessages
.add(warningMessage))
.build();
// Create a mock new product in the target project.
final ProductDraft productDraft = createProductDraft(PRODUCT_KEY_1_RESOURCE_PATH,
productType.toReference(), null, null, categoryReferencesWithIds,
createRandomCategoryOrderHints(categoryReferencesWithIds));
product = CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(productDraft))
.toCompletableFuture().join();
productService = new ProductServiceImpl(productSyncOptions);
}
示例12: cacheKeysToIds_WithTargetProductsWithBlankKeys_ShouldGiveAWarningAboutKeyNotSetAndNotCacheKey
import io.sphere.sdk.products.commands.ProductCreateCommand; //導入依賴的package包/類
@Test
public void cacheKeysToIds_WithTargetProductsWithBlankKeys_ShouldGiveAWarningAboutKeyNotSetAndNotCacheKey() {
// Create new product without key
final ProductDraft productDraftWithNullKey = createProductDraftBuilder(PRODUCT_KEY_2_RESOURCE_PATH,
productType.toReference())
.taxCategory(null)
.state(null)
.key(null)
.build();
final ProductDraft productDraftWithEmptyKey = createProductDraftBuilder(PRODUCT_KEY_2_RESOURCE_PATH,
productType.toReference())
.key(StringUtils.EMPTY)
.taxCategory(null)
.state(null)
.slug(LocalizedString.of(Locale.ENGLISH, "newSlug"))
.masterVariant(ProductVariantDraftBuilder.of().build())
.build();
final Product productWithNullKey = CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(productDraftWithNullKey))
.toCompletableFuture().join();
final Product productWithEmptyKey = CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(productDraftWithEmptyKey))
.toCompletableFuture().join();
final Map<String, String> cache = productService.cacheKeysToIds().toCompletableFuture().join();
assertThat(cache).hasSize(1);
assertThat(errorCallBackExceptions).isEmpty();
assertThat(errorCallBackMessages).isEmpty();
assertThat(warningCallBackMessages).hasSize(2);
// Since the order of fetch is not ensured, so we assert in whole list of warning messages (as string):
assertThat(warningCallBackMessages.toString()).contains(format("Product with id: '%s' has no key set. Keys are"
+ " required for product matching.", productWithNullKey.getId()));
assertThat(warningCallBackMessages.toString()).contains(format("Product with id: '%s' has no key set. Keys are"
+ " required for product matching.", productWithEmptyKey.getId()));
}
示例13: updateProduct_WithInvalidChanges_ShouldNotUpdateProduct
import io.sphere.sdk.products.commands.ProductCreateCommand; //導入依賴的package包/類
@Test
@SuppressWarnings("ConstantConditions")
public void updateProduct_WithInvalidChanges_ShouldNotUpdateProduct() {
final ProductDraft productDraft1 = createProductDraftBuilder(PRODUCT_KEY_2_RESOURCE_PATH,
productType.toReference())
.categories(Collections.emptyList())
.taxCategory(null)
.state(null)
.categoryOrderHints(null)
.build();
CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(productDraft1)).toCompletableFuture().join();
final ChangeSlug changeSlugUpdateAction = ChangeSlug.of(productDraft1.getSlug());
productService.updateProduct(product, Collections.singletonList(changeSlugUpdateAction))
.exceptionally(exception -> {
assertThat(exception).isNotNull();
assertThat(exception.getMessage()).contains(format("A duplicate value '\"%s\"' exists for "
+ "field 'slug.en'", productDraft1.getSlug().get(Locale.ENGLISH)));
return null;
})
.toCompletableFuture().join();
//assert CTP state
final Optional<Product> fetchedProductOptional = CTP_TARGET_CLIENT
.execute(ProductQuery.of()
.withPredicates(QueryPredicate.of(format("key = \"%s\"", product.getKey()))))
.toCompletableFuture().join().head();
assertThat(fetchedProductOptional).isNotEmpty();
final Product fetchedProduct = fetchedProductOptional.get();
assertThat(fetchedProduct.getMasterData().getCurrent().getSlug()).isNotEqualTo(productDraft1.getSlug());
}
示例14: setupPerTest
import io.sphere.sdk.products.commands.ProductCreateCommand; //導入依賴的package包/類
/**
* 1. Deletes all products from target CTP project
* 2. Clears all sync collections used for test assertions.
* 3. Creates an instance for {@link ProductSyncOptionsBuilder} that will be used in the tests to build
* {@link ProductSyncOptions} instances.
* 4. Create a product in the target CTP project.
*/
@Before
public void setupPerTest() {
clearSyncTestCollections();
deleteAllProducts(CTP_TARGET_CLIENT);
syncOptionsBuilder = getProductSyncOptionsBuilder();
final ProductDraft productDraft = createProductDraft(PRODUCT_KEY_1_RESOURCE_PATH, productType.toReference(),
null, null, categoryReferencesWithIds, createRandomCategoryOrderHints(categoryReferencesWithIds));
executeBlocking(CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(productDraft)));
}
示例15: assertProductSyncShouldNotBuildImageUpdateActions
import io.sphere.sdk.products.commands.ProductCreateCommand; //導入依賴的package包/類
private void assertProductSyncShouldNotBuildImageUpdateActions(@Nonnull final String oldProductDraftJsonResource,
@Nonnull final String newProductDraftJsonResource) {
// Prepare existing product before sync.
final ProductDraft oldProductDraft =
ProductDraftBuilder.of(readObjectFromResource(oldProductDraftJsonResource, ProductDraft.class))
.productType(productType.toReference())
.build();
executeBlocking(CTP_TARGET_CLIENT.execute(ProductCreateCommand.of(oldProductDraft)));
// Prepare new product to feed into sync.
final ProductDraft newProduct =
ProductDraftBuilder.of(readObjectFromResource(newProductDraftJsonResource, ProductDraft.class))
.productType(ProductType.referenceOfId(productType.getKey()))
.build();
// Sync
executeBlocking(productSync.sync(Collections.singletonList(newProduct)));
// Assert Update Actions are built correctly.
assertThat(errorCallBackExceptions).isEmpty();
assertThat(errorCallBackMessages).isEmpty();
assertThat(warningCallBackMessages).isEmpty();
updateActionsBuiltBySync.forEach(updateAction -> {
assertThat(updateAction).isNotExactlyInstanceOf(MoveImageToPosition.class);
assertThat(updateAction).isNotExactlyInstanceOf(AddExternalImage.class);
assertThat(updateAction).isNotExactlyInstanceOf(RemoveImage.class);
});
// Assert product state after sync.
final Product productAfterSync = executeBlocking(
CTP_TARGET_CLIENT.execute(ProductByKeyGet.of(oldProductDraft.getKey())));
assertImagesAreSyncedCorrectly(newProduct, productAfterSync);
}
開發者ID:commercetools,項目名稱:commercetools-sync-java,代碼行數:34,代碼來源:BuildProductVariantImageUpdateActionsIT.java