use of com.commercetools.sync.types.helpers.TypeSyncStatistics in project commercetools-sync-java by commercetools.
the class TypeSyncIT method sync_WithUpdates_ShouldReturnProperStatistics.
@Test
void sync_WithUpdates_ShouldReturnProperStatistics() {
// preparation
final List<Type> types = CTP_SOURCE_CLIENT.execute(TypeQuery.of()).toCompletableFuture().join().getResults();
final List<TypeDraft> typeDrafts = types.stream().map(type -> TypeDraftBuilder.of(type.getKey(), LocalizedString.ofEnglish("updated_name"), type.getResourceTypeIds()).description(type.getDescription()).fieldDefinitions(type.getFieldDefinitions())).map(TypeDraftBuilder::build).collect(Collectors.toList());
final List<String> errorMessages = new ArrayList<>();
final List<Throwable> exceptions = new ArrayList<>();
final TypeSyncOptions typeSyncOptions = TypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, updateActions) -> {
errorMessages.add(exception.getMessage());
exceptions.add(exception.getCause());
}).build();
final TypeSync typeSync = new TypeSync(typeSyncOptions);
// test
final TypeSyncStatistics typeSyncStatistics = typeSync.sync(typeDrafts).toCompletableFuture().join();
// assertion
assertThat(errorMessages).isEmpty();
assertThat(exceptions).isEmpty();
assertThat(typeSyncStatistics).hasValues(2, 1, 1, 0);
assertThat(typeSyncStatistics.getReportMessage()).isEqualTo("Summary: 2 types were processed in total" + " (1 created, 1 updated and 0 failed to sync).");
}
Aggregations