本文整理汇总了Java中io.sphere.sdk.taxcategories.TaxCategory类的典型用法代码示例。如果您正苦于以下问题:Java TaxCategory类的具体用法?Java TaxCategory怎么用?Java TaxCategory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TaxCategory类属于io.sphere.sdk.taxcategories包,在下文中一共展示了TaxCategory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cacheAndFetch
import io.sphere.sdk.taxcategories.TaxCategory; //导入依赖的package包/类
@Nonnull
private CompletionStage<Optional<String>> cacheAndFetch(@Nonnull final String key) {
final Consumer<List<TaxCategory>> taxCategoryPageConsumer = taxCategoryPage ->
taxCategoryPage.forEach(taxCategory -> {
final String fetchedTaxCategoryKey = taxCategory.getKey();
final String id = taxCategory.getId();
if (StringUtils.isNotBlank(fetchedTaxCategoryKey)) {
keyToIdCache.put(fetchedTaxCategoryKey, id);
} else {
syncOptions.applyWarningCallback(format("TaxCategory with id: '%s' has no key set. Keys are"
+ " required for taxCategory matching.", id));
}
});
return CtpQueryUtils.queryAll(syncOptions.getCtpClient(), TaxCategoryQuery.of(), taxCategoryPageConsumer)
.thenApply(result -> Optional.ofNullable(keyToIdCache.get(key)));
}
示例2: fetchCachedTaxCategoryId_WithTaxCategoryExistingWithNoKey_ShouldTriggerWarningCallback
import io.sphere.sdk.taxcategories.TaxCategory; //导入依赖的package包/类
@Test
public void fetchCachedTaxCategoryId_WithTaxCategoryExistingWithNoKey_ShouldTriggerWarningCallback() {
// Create new taxCategory without key
final TaxCategoryDraft taxCategoryDraft = TaxCategoryDraftBuilder
.of("newTaxCategory", singletonList(createTaxRateDraft()), oldTaxCategory.getDescription())
.build();
final TaxCategory newTaxCategory = executeBlocking(
CTP_TARGET_CLIENT.execute(TaxCategoryCreateCommand.of(taxCategoryDraft)));
final Optional<String> taxCategoryId = taxCategoryService.fetchCachedTaxCategoryId(oldTaxCategory.getKey())
.toCompletableFuture()
.join();
assertThat(taxCategoryId).isNotEmpty();
assertThat(warnings).hasSize(1);
assertThat(warnings.get(0)).isEqualTo(format("TaxCategory with id: '%s' has no key"
+ " set. Keys are required for taxCategory matching.", newTaxCategory.getId()));
}
示例3: sync_withEqualProduct_shouldNotUpdateProduct
import io.sphere.sdk.taxcategories.TaxCategory; //导入依赖的package包/类
@Test
@Ignore("TODO: Right now there is always a 'setPrice' update action GITHUB ISSUE: #101")
public void sync_withEqualProduct_shouldNotUpdateProduct() {
final ProductDraft productDraft =
createProductDraft(PRODUCT_KEY_1_RESOURCE_PATH, ProductType.referenceOfId(productType.getKey()),
TaxCategory.referenceOfId(targetTaxCategory.getKey()), State.referenceOfId(targetProductState.getKey()),
categoryReferencesWithIds, categoryOrderHintsWithKeys);
final ProductSync productSync = new ProductSync(syncOptions);
final ProductSyncStatistics syncStatistics =
executeBlocking(productSync.sync(singletonList(productDraft)));
assertThat(syncStatistics).hasValues(1, 0, 0, 0);
assertThat(errorCallBackExceptions).isEmpty();
assertThat(errorCallBackMessages).isEmpty();
assertThat(warningCallBackMessages).isEmpty();
}
示例4: sync_withChangedProduct_shouldUpdateProduct
import io.sphere.sdk.taxcategories.TaxCategory; //导入依赖的package包/类
@Test
public void sync_withChangedProduct_shouldUpdateProduct() {
final ProductDraft productDraft =
createProductDraft(PRODUCT_KEY_1_CHANGED_RESOURCE_PATH, ProductType.referenceOfId(productType.getKey()),
TaxCategory.referenceOfId(targetTaxCategory.getKey()), State.referenceOfId(targetProductState.getKey()),
categoryReferencesWithKeys, categoryOrderHintsWithKeys);
final ProductSync productSync = new ProductSync(syncOptions);
final ProductSyncStatistics syncStatistics =
executeBlocking(productSync.sync(singletonList(productDraft)));
assertThat(syncStatistics).hasValues(1, 0, 1, 0);
assertThat(errorCallBackExceptions).isEmpty();
assertThat(errorCallBackMessages).isEmpty();
assertThat(warningCallBackMessages).isEmpty();
}
示例5: resolveTaxCategoryReference_WithKeysAsUuidSetAndAllowed_ShouldResolveReference
import io.sphere.sdk.taxcategories.TaxCategory; //导入依赖的package包/类
@Test
public void resolveTaxCategoryReference_WithKeysAsUuidSetAndAllowed_ShouldResolveReference() {
final ProductSyncOptions productSyncOptions = ProductSyncOptionsBuilder.of(mock(SphereClient.class))
.allowUuidKeys(true)
.build();
final ProductDraftBuilder productBuilder = getBuilderWithRandomProductTypeUuid()
.taxCategory(TaxCategory.referenceOfId(UUID.randomUUID().toString()));
final ProductReferenceResolver productReferenceResolver = new ProductReferenceResolver(productSyncOptions,
getMockProductTypeService(PRODUCT_TYPE_ID), mock(CategoryService.class), getMockTypeService(),
getMockChannelService(getMockSupplyChannel(CHANNEL_ID, CHANNEL_KEY)), taxCategoryService,
getMockStateService(STATE_ID), getMockProductService(PRODUCT_ID));
final ProductDraftBuilder resolvedDraft = productReferenceResolver.resolveTaxCategoryReference(productBuilder)
.toCompletableFuture().join();
assertThat(resolvedDraft.getTaxCategory()).isNotNull();
assertThat(resolvedDraft.getTaxCategory().getId()).isEqualTo(TAX_CATEGORY_ID);
}
示例6: resolveTaxCategoryReference_WithKeysAsUuidSetAndNotAllowed_ShouldNotResolveReference
import io.sphere.sdk.taxcategories.TaxCategory; //导入依赖的package包/类
@Test
public void resolveTaxCategoryReference_WithKeysAsUuidSetAndNotAllowed_ShouldNotResolveReference() {
final ProductDraftBuilder productBuilder = getBuilderWithRandomProductTypeUuid()
.taxCategory(TaxCategory.referenceOfId(UUID.randomUUID().toString()))
.key("dummyKey");
assertThat(referenceResolver.resolveTaxCategoryReference(productBuilder).toCompletableFuture())
.hasFailed()
.hasFailedWithThrowableThat()
.isExactlyInstanceOf(ReferenceResolutionException.class)
.hasMessage("Failed to resolve reference 'tax-category' on ProductDraft"
+ " with key:'" + productBuilder.getKey() + "'. Reason: Found a UUID"
+ " in the id field. Expecting a key without a UUID value. If you want to"
+ " allow UUID values for reference keys, please use the "
+ "allowUuidKeys(true) option in the sync options.");
}
示例7: resolveTaxCategoryReference_WithExceptionOnTaxCategoryFetch_ShouldNotResolveReference
import io.sphere.sdk.taxcategories.TaxCategory; //导入依赖的package包/类
@Test
public void resolveTaxCategoryReference_WithExceptionOnTaxCategoryFetch_ShouldNotResolveReference() {
final ProductDraftBuilder productBuilder = getBuilderWithRandomProductTypeUuid()
.taxCategory(TaxCategory.referenceOfId("taxCategoryKey"))
.key("dummyKey");
final CompletableFuture<Optional<String>> futureThrowingSphereException = new CompletableFuture<>();
futureThrowingSphereException.completeExceptionally(new SphereException("CTP error on fetch"));
when(taxCategoryService.fetchCachedTaxCategoryId(anyString())).thenReturn(futureThrowingSphereException);
assertThat(referenceResolver.resolveTaxCategoryReference(productBuilder).toCompletableFuture())
.hasFailed()
.hasFailedWithThrowableThat()
.isExactlyInstanceOf(SphereException.class)
.hasMessageContaining("CTP error on fetch");
}
示例8: replaceTaxCategoryReferenceIdWithKey_WithExpandedReferences_ShouldReturnReferencesWithReplacedKeys
import io.sphere.sdk.taxcategories.TaxCategory; //导入依赖的package包/类
@Test
public void replaceTaxCategoryReferenceIdWithKey_WithExpandedReferences_ShouldReturnReferencesWithReplacedKeys() {
final String taxCategoryKey = "taxCategoryKey";
final TaxCategory taxCategory = getTaxCategoryMock(taxCategoryKey);
final Reference<TaxCategory> taxCategoryReference = Reference
.ofResourceTypeIdAndIdAndObj(TaxCategory.referenceTypeId(), taxCategory.getId(), taxCategory);
final Product product = mock(Product.class);
when(product.getTaxCategory()).thenReturn(taxCategoryReference);
final Reference<TaxCategory> taxCategoryReferenceWithKey = ProductReferenceReplacementUtils
.replaceTaxCategoryReferenceIdWithKey(product);
assertThat(taxCategoryReferenceWithKey).isNotNull();
assertThat(taxCategoryReferenceWithKey.getId()).isEqualTo(taxCategoryKey);
}
开发者ID:commercetools,项目名称:commercetools-sync-java,代码行数:17,代码来源:ProductReferenceReplacementUtilsTest.java
示例9: replaceProductsReferenceIdsWithKeys
import io.sphere.sdk.taxcategories.TaxCategory; //导入依赖的package包/类
/**
* Takes a list of Products that are supposed to have their product type, tax category, state and category
* references expanded in order to be able to fetch the keys and replace the reference ids with the corresponding
* keys and then return a new list of product drafts with their references containing keys instead of the ids.
*
* <p><b>Note:</b>If the references are not expanded for a product, the reference ids will not be replaced with keys
* and will still have their ids in place.
*
* @param products the products to replace their reference ids with keys
* @return a list of products drafts with keys instead of ids for references.
*/
@Nonnull
public static List<ProductDraft> replaceProductsReferenceIdsWithKeys(@Nonnull final List<Product> products) {
return products
.stream()
.filter(Objects::nonNull)
.map(product -> {
final ProductDraft productDraft = getDraftBuilderFromStagedProduct(product).build();
final Reference<ProductType> productTypeReferenceWithKey =
replaceProductTypeReferenceIdWithKey(product);
final Reference<TaxCategory> taxCategoryReferenceWithKey =
replaceTaxCategoryReferenceIdWithKey(product);
final Reference<State> stateReferenceWithKey = replaceProductStateReferenceIdWithKey(product);
final CategoryReferencePair categoryReferencePair = replaceCategoryReferencesIdsWithKeys(product);
final List<Reference<Category>> categoryReferencesWithKeys =
categoryReferencePair.getCategoryReferences();
final CategoryOrderHints categoryOrderHintsWithKeys = categoryReferencePair.getCategoryOrderHints();
final List<ProductVariant> allVariants = product.getMasterData().getStaged().getAllVariants();
final List<ProductVariantDraft> variantDraftsWithKeys =
VariantReferenceReplacementUtils.replaceVariantsReferenceIdsWithKeys(allVariants);
final ProductVariantDraft masterVariantDraftWithKeys = variantDraftsWithKeys.remove(0);
return ProductDraftBuilder.of(productDraft)
.masterVariant(masterVariantDraftWithKeys)
.variants(variantDraftsWithKeys)
.productType(productTypeReferenceWithKey)
.categories(categoryReferencesWithKeys)
.categoryOrderHints(categoryOrderHintsWithKeys)
.taxCategory(taxCategoryReferenceWithKey)
.state(stateReferenceWithKey)
.build();
})
.collect(Collectors.toList());
}
示例10: sync_withChangedProductButConcurrentModificationException_shouldRetryAndUpdateProduct
import io.sphere.sdk.taxcategories.TaxCategory; //导入依赖的package包/类
@Test// TODO handle all retry cases
public void sync_withChangedProductButConcurrentModificationException_shouldRetryAndUpdateProduct() {
// Mock sphere client to return ConcurrentModification on the first update request.
final SphereClient spyClient = spy(CTP_TARGET_CLIENT);
when(spyClient.execute(any(ProductUpdateCommand.class)))
.thenReturn(CompletableFutureUtils.exceptionallyCompletedFuture(new ConcurrentModificationException()))
.thenCallRealMethod();
final ProductSyncOptions spyOptions = ProductSyncOptionsBuilder.of(spyClient)
.errorCallback(
(errorMessage, exception) -> {
errorCallBackMessages
.add(errorMessage);
errorCallBackExceptions
.add(exception);
})
.warningCallback(warningMessage ->
warningCallBackMessages
.add(warningMessage))
.build();
final ProductSync spyProductSync = new ProductSync(spyOptions);
final ProductDraft productDraft =
createProductDraft(PRODUCT_KEY_1_CHANGED_RESOURCE_PATH, ProductType.referenceOfId(productType.getKey()),
TaxCategory.referenceOfId(targetTaxCategory.getKey()), State.referenceOfId(targetProductState.getKey()),
categoryReferencesWithKeys, categoryOrderHintsWithKeys);
final ProductSyncStatistics syncStatistics =
executeBlocking(spyProductSync.sync(singletonList(productDraft)));
assertThat(syncStatistics).hasValues(1, 0, 1, 0);
assertThat(errorCallBackExceptions).isEmpty();
assertThat(errorCallBackMessages).isEmpty();
assertThat(warningCallBackMessages).isEmpty();
}
示例11: resolveTaxCategoryReference_WithKeys_ShouldResolveReference
import io.sphere.sdk.taxcategories.TaxCategory; //导入依赖的package包/类
@Test
public void resolveTaxCategoryReference_WithKeys_ShouldResolveReference() {
final ProductDraftBuilder productBuilder = getBuilderWithRandomProductTypeUuid()
.taxCategory(TaxCategory.referenceOfId("taxCategoryKey"));
final ProductDraftBuilder resolvedDraft = referenceResolver.resolveTaxCategoryReference(productBuilder)
.toCompletableFuture().join();
assertThat(resolvedDraft.getTaxCategory()).isNotNull();
assertThat(resolvedDraft.getTaxCategory().getId()).isEqualTo(TAX_CATEGORY_ID);
}
示例12: resolveTaxCategoryReference_WithNonExistentTaxCategory_ShouldNotResolveReference
import io.sphere.sdk.taxcategories.TaxCategory; //导入依赖的package包/类
@Test
public void resolveTaxCategoryReference_WithNonExistentTaxCategory_ShouldNotResolveReference() {
final ProductDraftBuilder productBuilder = getBuilderWithRandomProductTypeUuid()
.taxCategory(TaxCategory.referenceOfId("nonExistentKey"))
.key("dummyKey");
when(taxCategoryService.fetchCachedTaxCategoryId(anyString()))
.thenReturn(CompletableFuture.completedFuture(Optional.empty()));
assertThat(referenceResolver.resolveTaxCategoryReference(productBuilder).toCompletableFuture())
.hasNotFailed()
.isCompletedWithValueMatching(resolvedDraft ->
Objects.nonNull(resolvedDraft.getTaxCategory())
&& Objects.equals(resolvedDraft.getTaxCategory().getId(), "nonExistentKey"));
}
示例13: resolveTaxCategoryReference_WithNullIdOnTaxCategoryReference_ShouldNotResolveReference
import io.sphere.sdk.taxcategories.TaxCategory; //导入依赖的package包/类
@Test
public void resolveTaxCategoryReference_WithNullIdOnTaxCategoryReference_ShouldNotResolveReference() {
final ProductDraftBuilder productBuilder = getBuilderWithRandomProductTypeUuid()
.taxCategory(Reference.of(TaxCategory.referenceTypeId(), (String)null))
.key("dummyKey");
assertThat(referenceResolver.resolveTaxCategoryReference(productBuilder).toCompletableFuture())
.hasFailed()
.hasFailedWithThrowableThat()
.isExactlyInstanceOf(ReferenceResolutionException.class)
.hasMessage("Failed to resolve reference 'tax-category' on ProductDraft with "
+ "key:'" + productBuilder.getKey() + "'. Reason: Reference 'id' field"
+ " value is blank (null/empty).");
}
示例14: resolveTaxCategoryReference_WithEmptyIdOnTaxCategoryReference_ShouldNotResolveReference
import io.sphere.sdk.taxcategories.TaxCategory; //导入依赖的package包/类
@Test
public void resolveTaxCategoryReference_WithEmptyIdOnTaxCategoryReference_ShouldNotResolveReference() {
final ProductDraftBuilder productBuilder = getBuilderWithRandomProductTypeUuid()
.taxCategory(TaxCategory.referenceOfId(""))
.key("dummyKey");
assertThat(referenceResolver.resolveTaxCategoryReference(productBuilder).toCompletableFuture())
.hasFailed()
.hasFailedWithThrowableThat()
.isExactlyInstanceOf(ReferenceResolutionException.class)
.hasMessage("Failed to resolve reference 'tax-category' on ProductDraft with "
+ "key:'" + productBuilder.getKey() + "'. Reason: Reference 'id' field"
+ " value is blank (null/empty).");
}
示例15: mock
import io.sphere.sdk.taxcategories.TaxCategory; //导入依赖的package包/类
@Test
public void
replaceTaxCategoryReferenceIdWithKey_WithNonExpandedReferences_ShouldReturnReferencesWithoutReplacedKeys() {
final String taxCategoryId = UUID.randomUUID().toString();
final Reference<TaxCategory> taxCategoryReference = TaxCategory.referenceOfId(taxCategoryId);
final Product product = mock(Product.class);
when(product.getTaxCategory()).thenReturn(taxCategoryReference);
final Reference<TaxCategory> taxCategoryReferenceWithKey = ProductReferenceReplacementUtils
.replaceTaxCategoryReferenceIdWithKey(product);
assertThat(taxCategoryReferenceWithKey).isNotNull();
assertThat(taxCategoryReferenceWithKey.getId()).isEqualTo(taxCategoryId);
}
开发者ID:commercetools,项目名称:commercetools-sync-java,代码行数:15,代码来源:ProductReferenceReplacementUtilsTest.java