use of com.commercetools.sync.producttypes.ProductTypeSyncOptions in project commercetools-sync-java by commercetools.
the class ProductTypeSyncIT method sync_WithNullDraft_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter.
@Test
void sync_WithNullDraft_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter() {
// preparation
final ProductTypeDraft newProductTypeDraft = null;
final List<String> errorMessages = new ArrayList<>();
final List<Throwable> exceptions = new ArrayList<>();
final ProductTypeSyncOptions syncOptions = ProductTypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, updateActions) -> {
errorMessages.add(exception.getMessage());
exceptions.add(exception);
}).build();
final ProductTypeSync productTypeSync = new ProductTypeSync(syncOptions);
// test
final ProductTypeSyncStatistics productTypeSyncStatistics = productTypeSync.sync(singletonList(newProductTypeDraft)).toCompletableFuture().join();
// assertions
assertThat(errorMessages).hasSize(1).singleElement(as(STRING)).isEqualTo("ProductTypeDraft is null.");
assertThat(exceptions).hasSize(1).singleElement().matches(throwable -> {
assertThat(throwable).isInstanceOf(SyncException.class);
assertThat(throwable.getMessage()).isEqualTo("ProductTypeDraft is null.");
return true;
});
assertThat(productTypeSyncStatistics).hasValues(1, 0, 0, 1, 0);
}
use of com.commercetools.sync.producttypes.ProductTypeSyncOptions in project commercetools-project-sync by commercetools.
the class ProductTypeSyncer method of.
@Nonnull
public static ProductTypeSyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock) {
final QuadConsumer<SyncException, Optional<ProductTypeDraft>, Optional<ProductType>, List<UpdateAction<ProductType>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> logErrorCallback(LOGGER, "product type", exception, oldResource, updateActions);
final TriConsumer<SyncException, Optional<ProductTypeDraft>, Optional<ProductType>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "product type", exception, oldResource);
final ProductTypeSyncOptions syncOptions = ProductTypeSyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
final ProductTypeSync productTypeSync = new ProductTypeSync(syncOptions);
final CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
return new ProductTypeSyncer(productTypeSync, sourceClient, targetClient, customObjectService, clock);
}
use of com.commercetools.sync.producttypes.ProductTypeSyncOptions in project commercetools-sync-java by commercetools.
the class ProductTypeServiceImplIT method setup.
/**
* Deletes product types from the target CTP project, then it populates the project with test
* data.
*/
@BeforeEach
void setup() {
errorCallBackMessages = new ArrayList<>();
errorCallBackExceptions = new ArrayList<>();
deleteProductTypes(CTP_TARGET_CLIENT);
createProductType(OLD_PRODUCT_TYPE_KEY, OLD_PRODUCT_TYPE_LOCALE, OLD_PRODUCT_TYPE_NAME, CTP_TARGET_CLIENT);
final ProductTypeSyncOptions productTypeSyncOptions = ProductTypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
productTypeService = new ProductTypeServiceImpl(productTypeSyncOptions);
}
use of com.commercetools.sync.producttypes.ProductTypeSyncOptions in project commercetools-sync-java by commercetools.
the class ProductTypeSyncIT method sync_WithoutAttributeType_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter.
@Test
void sync_WithoutAttributeType_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter() {
// preparation
final AttributeDefinitionDraft attributeDefinitionDraft = AttributeDefinitionDraftBuilder.of(null, "attr_name_1", ofEnglish("attr_label_1"), true).attributeConstraint(AttributeConstraint.NONE).inputTip(ofEnglish("inputTip1")).inputHint(TextInputHint.SINGLE_LINE).isSearchable(false).build();
final ProductTypeDraft newProductTypeDraft = ProductTypeDraft.ofAttributeDefinitionDrafts(PRODUCT_TYPE_KEY_1, null, PRODUCT_TYPE_DESCRIPTION_1, singletonList(attributeDefinitionDraft));
final List<String> errorMessages = new ArrayList<>();
final List<Throwable> exceptions = new ArrayList<>();
final ProductTypeSyncOptions syncOptions = ProductTypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, updateActions) -> {
errorMessages.add(exception.getMessage());
exceptions.add(exception.getCause());
}).build();
final ProductTypeSync productTypeSync = new ProductTypeSync(syncOptions);
// test
final ProductTypeSyncStatistics productTypeSyncStatistics = productTypeSync.sync(singletonList(newProductTypeDraft)).toCompletableFuture().join();
// assertions
assertThat(errorMessages).hasSize(1).singleElement(as(STRING)).contains("Failed to update product type with key: 'key_1'.");
assertThat(exceptions).hasSize(1).singleElement().matches(throwable -> {
assertThat(throwable).isExactlyInstanceOf(CompletionException.class);
assertThat(throwable).hasCauseExactlyInstanceOf(ErrorResponseException.class);
assertThat(throwable).hasMessageContaining("Missing required value");
return true;
});
assertThat(productTypeSyncStatistics).hasValues(1, 0, 0, 1, 0);
}
use of com.commercetools.sync.producttypes.ProductTypeSyncOptions in project commercetools-sync-java by commercetools.
the class ProductTypeSyncIT method sync_WithErrorUpdatingTheProductType_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter.
@Test
void sync_WithErrorUpdatingTheProductType_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter() {
// preparation
// Invalid attribute definition due to having an invalid name.
final AttributeDefinitionDraftDsl invalidAttrDefinition = AttributeDefinitionDraftBuilder.of(MoneyAttributeType.of(), "*invalidName*", ofEnglish("description"), true).searchable(false).build();
final ProductTypeDraft newProductTypeDraft = ProductTypeDraft.ofAttributeDefinitionDrafts(PRODUCT_TYPE_KEY_1, PRODUCT_TYPE_NAME_1, PRODUCT_TYPE_DESCRIPTION_1, singletonList(invalidAttrDefinition));
final List<String> errorMessages = new ArrayList<>();
final List<Throwable> exceptions = new ArrayList<>();
final ProductTypeSyncOptions syncOptions = ProductTypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, updateActions) -> {
errorMessages.add(exception.getMessage());
exceptions.add(exception.getCause());
}).build();
final ProductTypeSync productTypeSync = new ProductTypeSync(syncOptions);
// test
final ProductTypeSyncStatistics productTypeSyncStatistics = productTypeSync.sync(singletonList(newProductTypeDraft)).toCompletableFuture().join();
// assertions
assertThat(errorMessages).hasSize(1).singleElement(as(STRING)).contains("Failed to update product type with key: 'key_1'.");
assertThat(exceptions).hasSize(1).singleElement().matches(throwable -> {
assertThat(throwable).isExactlyInstanceOf(CompletionException.class);
assertThat(throwable).hasCauseExactlyInstanceOf(ErrorResponseException.class);
assertThat(throwable).hasMessageContaining("InvalidInput");
return true;
});
assertThat(productTypeSyncStatistics).hasValues(1, 0, 0, 1, 0);
}
Aggregations