use of com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_NAME_2 in project commercetools-sync-java by commercetools.
the class ProductTypeSyncIT method sync_WithErrorCreatingTheProductType_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter.
@Test
void sync_WithErrorCreatingTheProductType_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter() {
// preparation
// Invalid attribute definition due to having the same name as an already existing one but
// different
// type.
final AttributeDefinitionDraftDsl invalidAttrDefinition = AttributeDefinitionDraftBuilder.of(ATTRIBUTE_DEFINITION_DRAFT_1).attributeType(MoneyAttributeType.of()).attributeConstraint(AttributeConstraint.COMBINATION_UNIQUE).build();
final ProductTypeDraft newProductTypeDraft = ProductTypeDraft.ofAttributeDefinitionDrafts(PRODUCT_TYPE_KEY_2, PRODUCT_TYPE_NAME_2, PRODUCT_TYPE_DESCRIPTION_2, 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);
}).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 create draft with key: 'key_2'.");
assertThat(exceptions).hasSize(1).singleElement().matches(throwable -> {
assertThat(throwable).hasCauseExactlyInstanceOf(ErrorResponseException.class);
assertThat(throwable).hasMessageContaining("AttributeDefinitionTypeConflict");
return true;
});
assertThat(productTypeSyncStatistics).hasValues(1, 0, 0, 1, 0);
}
Aggregations