use of com.commercetools.sync.producttypes.ProductTypeSync in project commercetools-sync-java by commercetools.
the class ProductTypeSyncIT method sync_WithSeveralBatches_ShouldReturnProperStatistics.
@Test
void sync_WithSeveralBatches_ShouldReturnProperStatistics() {
// Default batch size is 50 (check ProductTypeSyncOptionsBuilder) so we have 2 batches of 50
final List<ProductTypeDraft> productTypeDrafts = IntStream.range(0, 100).mapToObj(i -> ProductTypeDraft.ofAttributeDefinitionDrafts("product_type_key_" + Integer.toString(i), "product_type_name_" + Integer.toString(i), "product_type_description_" + Integer.toString(i), singletonList(ATTRIBUTE_DEFINITION_DRAFT_1))).collect(Collectors.toList());
final ProductTypeSyncOptions productTypeSyncOptions = ProductTypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
final ProductTypeSync productTypeSync = new ProductTypeSync(productTypeSyncOptions);
final ProductTypeSyncStatistics productTypeSyncStatistics = productTypeSync.sync(productTypeDrafts).toCompletableFuture().join();
assertThat(productTypeSyncStatistics).hasValues(100, 100, 0, 0, 0);
}
use of com.commercetools.sync.producttypes.ProductTypeSync in project commercetools-sync-java by commercetools.
the class ProductTypeSyncIT method syncDrafts_WithConcurrentModificationException_ShouldRetryToUpdateNewProductTypeWithSuccess.
@Test
void syncDrafts_WithConcurrentModificationException_ShouldRetryToUpdateNewProductTypeWithSuccess() {
// Preparation
final SphereClient spyClient = buildClientWithConcurrentModificationUpdate();
final ProductTypeDraft productTypeDraft = ProductTypeDraftBuilder.of("key", "foo", "description", emptyList()).build();
CTP_TARGET_CLIENT.execute(ProductTypeCreateCommand.of(productTypeDraft)).toCompletableFuture().join();
final String newProductTypeName = "bar";
final ProductTypeDraft updatedDraft = ProductTypeDraftBuilder.of(productTypeDraft).name(newProductTypeName).build();
final ProductTypeSyncOptions syncOptions = ProductTypeSyncOptionsBuilder.of(spyClient).build();
final ProductTypeSync productTypeSync = new ProductTypeSync(syncOptions);
// Test
final ProductTypeSyncStatistics statistics = productTypeSync.sync(singletonList(updatedDraft)).toCompletableFuture().join();
// Assertion
assertThat(statistics).hasValues(1, 0, 1, 0, 0);
// Assert CTP state.
final PagedQueryResult<ProductType> queryResult = CTP_TARGET_CLIENT.execute(ProductTypeQuery.of().plusPredicates(queryModel -> queryModel.key().is(productTypeDraft.getKey()))).toCompletableFuture().join();
assertThat(queryResult.head()).hasValueSatisfying(productType -> assertThat(productType.getName()).isEqualTo(newProductTypeName));
}
use of com.commercetools.sync.producttypes.ProductTypeSync 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.ProductTypeSync 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.ProductTypeSync 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)));
}
Aggregations