use of com.commercetools.sync.producttypes.ProductTypeSync in project commercetools-sync-java by commercetools.
the class ProductTypeSyncIT method sync_WithUpdates_ShouldReturnProperStatistics.
@Test
void sync_WithUpdates_ShouldReturnProperStatistics() {
// preparation
final List<ProductType> productTypes = CTP_SOURCE_CLIENT.execute(ProductTypeQuery.of()).toCompletableFuture().join().getResults();
final List<ProductTypeDraft> productTypeDrafts = productTypes.stream().map(productType -> {
final List<AttributeDefinitionDraft> attributeDefinitionDrafts = productType.getAttributes().stream().map(attribute -> AttributeDefinitionDraftBuilder.of(attribute).build()).collect(Collectors.toList());
return ProductTypeDraftBuilder.of(productType.getKey(), "newName", productType.getDescription(), attributeDefinitionDrafts).build();
}).collect(Collectors.toList());
final List<String> errorMessages = new ArrayList<>();
final List<Throwable> exceptions = new ArrayList<>();
final ProductTypeSyncOptions productTypeSyncOptions = ProductTypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, updateActions) -> {
errorMessages.add(exception.getMessage());
exceptions.add(exception.getCause());
}).build();
final ProductTypeSync productTypeSync = new ProductTypeSync(productTypeSyncOptions);
// test
final ProductTypeSyncStatistics productTypeSyncStatistics = productTypeSync.sync(productTypeDrafts).toCompletableFuture().join();
// assertion
assertThat(errorMessages).isEmpty();
assertThat(exceptions).isEmpty();
assertThat(productTypeSyncStatistics).hasValues(2, 1, 1, 0, 0);
assertThat(productTypeSyncStatistics.getReportMessage()).isEqualTo("Summary: 2 product types were processed in total" + " (1 created, 1 updated, 0 failed to sync and 0 product types with at least one NestedType or a Set" + " of NestedType attribute definition(s) referencing a missing product type).");
}
use of com.commercetools.sync.producttypes.ProductTypeSync in project commercetools-sync-java by commercetools.
the class ProductTypeWithNestedAttributeSyncIT method sync_WithoutUpdates_ShouldReturnProperStatistics.
@Test
void sync_WithoutUpdates_ShouldReturnProperStatistics() {
// preparation
populateProjectWithNestedAttributes(CTP_TARGET_CLIENT);
final List<ProductType> productTypes = CTP_SOURCE_CLIENT.execute(ProductTypeQuery.of()).toCompletableFuture().join().getResults();
final List<ProductTypeDraft> productTypeDrafts = ProductTypeTransformUtils.toProductTypeDrafts(CTP_SOURCE_CLIENT, referenceIdToKeyCache, productTypes).join();
final ProductTypeSync productTypeSync = new ProductTypeSync(productTypeSyncOptions);
// test
final ProductTypeSyncStatistics productTypeSyncStatistics = productTypeSync.sync(productTypeDrafts).toCompletableFuture().join();
// assertion
assertThat(errorMessages).isEmpty();
assertThat(exceptions).isEmpty();
assertThat(builtUpdateActions).isEmpty();
assertThat(productTypeSyncStatistics).hasValues(4, 0, 0, 0, 0);
assertThat(productTypeSyncStatistics.getReportMessage()).isEqualTo("Summary: 4 product types were processed in total" + " (0 created, 0 updated, 0 failed to sync and 0 product types with at least one NestedType or a Set" + " of NestedType attribute definition(s) referencing a missing product type).");
}
use of com.commercetools.sync.producttypes.ProductTypeSync in project commercetools-sync-java by commercetools.
the class ProductTypeWithNestedAttributeSyncIT method sync_WithEmptyTargetProject_ShouldReturnProperStatistics.
@Test
void sync_WithEmptyTargetProject_ShouldReturnProperStatistics() {
// preparation
final List<ProductType> productTypes = CTP_SOURCE_CLIENT.execute(ProductTypeQuery.of()).toCompletableFuture().join().getResults();
final List<ProductTypeDraft> productTypeDrafts = ProductTypeTransformUtils.toProductTypeDrafts(CTP_SOURCE_CLIENT, referenceIdToKeyCache, productTypes).join();
final ProductTypeSync productTypeSync = new ProductTypeSync(productTypeSyncOptions);
// test
final ProductTypeSyncStatistics productTypeSyncStatistics = productTypeSync.sync(productTypeDrafts).toCompletableFuture().join();
// assertion
assertThat(errorMessages).isEmpty();
assertThat(exceptions).isEmpty();
assertThat(builtUpdateActions).isEmpty();
assertThat(productTypeSyncStatistics).hasValues(4, 4, 0, 0, 0);
assertThat(productTypeSyncStatistics.getReportMessage()).isEqualTo("Summary: 4 product types were processed in total" + " (4 created, 0 updated, 0 failed to sync and 0 product types with at least one NestedType or a Set" + " of NestedType attribute definition(s) referencing a missing product type).");
}
use of com.commercetools.sync.producttypes.ProductTypeSync in project commercetools-sync-java by commercetools.
the class ProductTypeSyncBenchmark method sync_NewProductTypes_ShouldCreateProductTypes.
@Test
void sync_NewProductTypes_ShouldCreateProductTypes() throws IOException {
// preparation
final List<ProductTypeDraft> productTypeDrafts = buildProductTypeDrafts(NUMBER_OF_RESOURCE_UNDER_TEST);
final ProductTypeSync productTypeSync = new ProductTypeSync(productTypeSyncOptions);
// benchmark
final long beforeSyncTime = System.currentTimeMillis();
final ProductTypeSyncStatistics syncStatistics = executeBlocking(productTypeSync.sync(productTypeDrafts));
final long totalTime = System.currentTimeMillis() - beforeSyncTime;
// assert on threshold (based on history of benchmarks; highest was ~12 seconds)
// double of the highest benchmark
final int threshold = 24000;
assertThat(totalTime).withFailMessage(format(THRESHOLD_EXCEEDED_ERROR, totalTime, threshold)).isLessThan(threshold);
// Assert actual state of CTP project (total number of existing product types)
final CompletableFuture<Integer> totalNumberOfProductTypes = CTP_TARGET_CLIENT.execute(ProductTypeQuery.of()).thenApply(PagedQueryResult::getTotal).thenApply(Long::intValue).toCompletableFuture();
executeBlocking(totalNumberOfProductTypes);
assertThat(totalNumberOfProductTypes).isCompletedWithValue(NUMBER_OF_RESOURCE_UNDER_TEST);
assertThat(syncStatistics).hasValues(NUMBER_OF_RESOURCE_UNDER_TEST, NUMBER_OF_RESOURCE_UNDER_TEST, 0, 0);
assertThat(errorCallBackExceptions).isEmpty();
assertThat(errorCallBackMessages).isEmpty();
assertThat(warningCallBackMessages).isEmpty();
saveNewResult(PRODUCT_TYPE_SYNC, CREATES_ONLY, totalTime);
}
use of com.commercetools.sync.producttypes.ProductTypeSync in project commercetools-sync-java by commercetools.
the class ProductTypeSyncBenchmark method sync_ExistingProductTypes_ShouldUpdateProductTypes.
@Test
void sync_ExistingProductTypes_ShouldUpdateProductTypes() throws IOException {
// preparation
final List<ProductTypeDraft> productTypeDrafts = buildProductTypeDrafts(NUMBER_OF_RESOURCE_UNDER_TEST);
// Create drafts to target project with different attribute definition name
CompletableFuture.allOf(productTypeDrafts.stream().map(ProductTypeDraftBuilder::of).map(ProductTypeSyncBenchmark::applyAttributeDefinitionNameChange).map(ProductTypeDraftBuilder::build).map(draft -> CTP_TARGET_CLIENT.execute(ProductTypeCreateCommand.of(draft))).map(CompletionStage::toCompletableFuture).toArray(CompletableFuture[]::new)).join();
final ProductTypeSync productTypeSync = new ProductTypeSync(productTypeSyncOptions);
// benchmark
final long beforeSyncTime = System.currentTimeMillis();
final ProductTypeSyncStatistics syncStatistics = executeBlocking(productTypeSync.sync(productTypeDrafts));
final long totalTime = System.currentTimeMillis() - beforeSyncTime;
// assert on threshold (based on history of benchmarks; highest was ~13 seconds)
// double of the highest benchmark
final int threshold = 26000;
assertThat(totalTime).withFailMessage(format(THRESHOLD_EXCEEDED_ERROR, totalTime, threshold)).isLessThan(threshold);
// Assert actual state of CTP project (number of updated product types)
final CompletableFuture<Integer> totalNumberOfUpdatedProductTypes = CTP_TARGET_CLIENT.execute(ProductTypeQuery.of().withPredicates(p -> p.attributes().name().is("attr_name_1"))).thenApply(PagedQueryResult::getTotal).thenApply(Long::intValue).toCompletableFuture();
executeBlocking(totalNumberOfUpdatedProductTypes);
assertThat(totalNumberOfUpdatedProductTypes).isCompletedWithValue(NUMBER_OF_RESOURCE_UNDER_TEST);
// Assert actual state of CTP project (total number of existing product types)
final CompletableFuture<Integer> totalNumberOfProductTypes = CTP_TARGET_CLIENT.execute(ProductTypeQuery.of()).thenApply(PagedQueryResult::getTotal).thenApply(Long::intValue).toCompletableFuture();
executeBlocking(totalNumberOfProductTypes);
assertThat(totalNumberOfProductTypes).isCompletedWithValue(NUMBER_OF_RESOURCE_UNDER_TEST);
// Assert statistics
assertThat(syncStatistics).hasValues(NUMBER_OF_RESOURCE_UNDER_TEST, 0, NUMBER_OF_RESOURCE_UNDER_TEST, 0);
assertThat(errorCallBackExceptions).isEmpty();
assertThat(errorCallBackMessages).isEmpty();
assertThat(warningCallBackMessages).isEmpty();
saveNewResult(PRODUCT_TYPE_SYNC, UPDATES_ONLY, totalTime);
}
Aggregations