use of com.commercetools.sync.producttypes.helpers.ProductTypeSyncStatistics in project commercetools-sync-java by commercetools.
the class ProductTypeSyncIT method sync_WithNewProductType_ShouldCreateProductType.
@Test
void sync_WithNewProductType_ShouldCreateProductType() {
// preparation
final ProductTypeDraft newProductTypeDraft = ProductTypeDraft.ofAttributeDefinitionDrafts(PRODUCT_TYPE_KEY_2, PRODUCT_TYPE_NAME_2, PRODUCT_TYPE_DESCRIPTION_2, singletonList(ATTRIBUTE_DEFINITION_DRAFT_1));
final ProductTypeSyncOptions productTypeSyncOptions = ProductTypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
final ProductTypeSync productTypeSync = new ProductTypeSync(productTypeSyncOptions);
// tests
final ProductTypeSyncStatistics productTypeSyncStatistics = productTypeSync.sync(singletonList(newProductTypeDraft)).toCompletableFuture().join();
// assertions
assertThat(productTypeSyncStatistics).hasValues(1, 1, 0, 0, 0);
final Optional<ProductType> oldProductTypeAfter = getProductTypeByKey(CTP_TARGET_CLIENT, PRODUCT_TYPE_KEY_2);
assertThat(oldProductTypeAfter).hasValueSatisfying(productType -> {
assertThat(productType.getName()).isEqualTo(PRODUCT_TYPE_NAME_2);
assertThat(productType.getDescription()).isEqualTo(PRODUCT_TYPE_DESCRIPTION_2);
assertAttributesAreEqual(productType.getAttributes(), singletonList(ATTRIBUTE_DEFINITION_DRAFT_1));
});
}
use of com.commercetools.sync.producttypes.helpers.ProductTypeSyncStatistics in project commercetools-sync-java by commercetools.
the class ProductTypeSyncIT method sync_WithUpdatedProductType_ChangingAttributeOrder_ShouldUpdateProductTypeChangingAttributeOrder.
@Test
void sync_WithUpdatedProductType_ChangingAttributeOrder_ShouldUpdateProductTypeChangingAttributeOrder() {
// Changing order from ATTRIBUTE_DEFINITION_DRAFT_1, ATTRIBUTE_DEFINITION_DRAFT_2 to
// ATTRIBUTE_DEFINITION_DRAFT_2, ATTRIBUTE_DEFINITION_DRAFT_1
final ProductTypeDraft newProductTypeDraft = ProductTypeDraft.ofAttributeDefinitionDrafts(PRODUCT_TYPE_KEY_1, PRODUCT_TYPE_NAME_1, PRODUCT_TYPE_DESCRIPTION_1, asList(ATTRIBUTE_DEFINITION_DRAFT_2, ATTRIBUTE_DEFINITION_DRAFT_1));
final ArrayList<UpdateAction<ProductType>> builtUpdateActions = new ArrayList<>();
final ProductTypeSyncOptions productTypeSyncOptions = ProductTypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).beforeUpdateCallback((actions, draft, oldProductType) -> {
builtUpdateActions.addAll(actions);
return actions;
}).build();
final ProductTypeSync productTypeSync = new ProductTypeSync(productTypeSyncOptions);
final ProductTypeSyncStatistics productTypeSyncStatistics = productTypeSync.sync(singletonList(newProductTypeDraft)).toCompletableFuture().join();
assertThat(productTypeSyncStatistics).hasValues(1, 0, 1, 0, 0);
final Optional<ProductType> oldProductTypeAfter = getProductTypeByKey(CTP_TARGET_CLIENT, PRODUCT_TYPE_KEY_1);
assertThat(oldProductTypeAfter).hasValueSatisfying(productType -> assertAttributesAreEqual(productType.getAttributes(), asList(ATTRIBUTE_DEFINITION_DRAFT_2, ATTRIBUTE_DEFINITION_DRAFT_1)));
assertThat(builtUpdateActions).containsExactly(ChangeAttributeOrderByName.of(asList(ATTRIBUTE_DEFINITION_DRAFT_2.getName(), ATTRIBUTE_DEFINITION_DRAFT_1.getName())));
}
use of com.commercetools.sync.producttypes.helpers.ProductTypeSyncStatistics in project commercetools-sync-java by commercetools.
the class ProductTypeSyncIT method sync_WithUpdatedProductType_WithNewAttribute_ShouldUpdateProductTypeAddingAttribute.
@Test
void sync_WithUpdatedProductType_WithNewAttribute_ShouldUpdateProductTypeAddingAttribute() {
// preparation
// Adding ATTRIBUTE_DEFINITION_DRAFT_3
final ProductTypeDraft newProductTypeDraft = ProductTypeDraft.ofAttributeDefinitionDrafts(PRODUCT_TYPE_KEY_1, PRODUCT_TYPE_NAME_1, PRODUCT_TYPE_DESCRIPTION_1, asList(ATTRIBUTE_DEFINITION_DRAFT_1, ATTRIBUTE_DEFINITION_DRAFT_2, ATTRIBUTE_DEFINITION_DRAFT_3));
final ProductTypeSyncOptions productTypeSyncOptions = ProductTypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
final ProductTypeSync productTypeSync = new ProductTypeSync(productTypeSyncOptions);
// tests
final ProductTypeSyncStatistics productTypeSyncStatistics = productTypeSync.sync(singletonList(newProductTypeDraft)).toCompletableFuture().join();
// assertions
assertThat(productTypeSyncStatistics).hasValues(1, 0, 1, 0, 0);
final Optional<ProductType> oldProductTypeAfter = getProductTypeByKey(CTP_TARGET_CLIENT, PRODUCT_TYPE_KEY_1);
assertThat(oldProductTypeAfter).hasValueSatisfying(productType -> assertAttributesAreEqual(productType.getAttributes(), asList(ATTRIBUTE_DEFINITION_DRAFT_1, ATTRIBUTE_DEFINITION_DRAFT_2, ATTRIBUTE_DEFINITION_DRAFT_3)));
}
use of com.commercetools.sync.producttypes.helpers.ProductTypeSyncStatistics 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);
}
use of com.commercetools.sync.producttypes.helpers.ProductTypeSyncStatistics in project commercetools-sync-java by commercetools.
the class ProductTypeSyncIT method sync_WithUpdatedProductType_WithoutOldAttribute_ShouldUpdateProductTypeRemovingAttribute.
@Test
void sync_WithUpdatedProductType_WithoutOldAttribute_ShouldUpdateProductTypeRemovingAttribute() {
// Removing ATTRIBUTE_DEFINITION_DRAFT_2
final ProductTypeDraft newProductTypeDraft = ProductTypeDraft.ofAttributeDefinitionDrafts(PRODUCT_TYPE_KEY_1, PRODUCT_TYPE_NAME_1, PRODUCT_TYPE_DESCRIPTION_1, singletonList(ATTRIBUTE_DEFINITION_DRAFT_1));
final ProductTypeSyncOptions productTypeSyncOptions = ProductTypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
final ProductTypeSync productTypeSync = new ProductTypeSync(productTypeSyncOptions);
final ProductTypeSyncStatistics productTypeSyncStatistics = productTypeSync.sync(singletonList(newProductTypeDraft)).toCompletableFuture().join();
assertThat(productTypeSyncStatistics).hasValues(1, 0, 1, 0, 0);
final Optional<ProductType> oldProductTypeAfter = getProductTypeByKey(CTP_TARGET_CLIENT, PRODUCT_TYPE_KEY_1);
assertThat(oldProductTypeAfter).hasValueSatisfying(productType -> assertAttributesAreEqual(productType.getAttributes(), singletonList(ATTRIBUTE_DEFINITION_DRAFT_1)));
}
Aggregations