Search in sources :

Example 21 with TypeSyncStatistics

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).");
}
Also used : TypeDraft(io.sphere.sdk.types.TypeDraft) TypeSyncOptionsBuilder(com.commercetools.sync.types.TypeSyncOptionsBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach) CTP_SOURCE_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_SOURCE_CLIENT) ITUtils.deleteTypesFromTargetAndSource(com.commercetools.sync.integration.commons.utils.ITUtils.deleteTypesFromTargetAndSource) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) TypeSyncStatistics(com.commercetools.sync.types.helpers.TypeSyncStatistics) TypeSync(com.commercetools.sync.types.TypeSync) Collectors(java.util.stream.Collectors) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) LocalizedString(io.sphere.sdk.models.LocalizedString) List(java.util.List) TypeITUtils.populateTargetProject(com.commercetools.sync.integration.commons.utils.TypeITUtils.populateTargetProject) TypeQuery(io.sphere.sdk.types.queries.TypeQuery) TypeDraftBuilder(io.sphere.sdk.types.TypeDraftBuilder) TypeITUtils.populateSourceProject(com.commercetools.sync.integration.commons.utils.TypeITUtils.populateSourceProject) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) Type(io.sphere.sdk.types.Type) ArrayList(java.util.ArrayList) LocalizedString(io.sphere.sdk.models.LocalizedString) TypeSyncStatistics(com.commercetools.sync.types.helpers.TypeSyncStatistics) TypeDraft(io.sphere.sdk.types.TypeDraft) Type(io.sphere.sdk.types.Type) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) TypeSync(com.commercetools.sync.types.TypeSync) Test(org.junit.jupiter.api.Test)

Aggregations

TypeSyncStatistics (com.commercetools.sync.types.helpers.TypeSyncStatistics)21 TypeDraft (io.sphere.sdk.types.TypeDraft)21 Test (org.junit.jupiter.api.Test)21 TypeSync (com.commercetools.sync.types.TypeSync)20 Type (io.sphere.sdk.types.Type)18 TypeSyncOptions (com.commercetools.sync.types.TypeSyncOptions)17 EnumFieldType (io.sphere.sdk.types.EnumFieldType)15 LocalizedEnumFieldType (io.sphere.sdk.types.LocalizedEnumFieldType)15 SetFieldType (io.sphere.sdk.types.SetFieldType)15 StringFieldType (io.sphere.sdk.types.StringFieldType)15 AssertionsForStatistics.assertThat (com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat)11 PagedQueryResult (io.sphere.sdk.queries.PagedQueryResult)11 TypeDraftBuilder (io.sphere.sdk.types.TypeDraftBuilder)11 ArrayList (java.util.ArrayList)11 List (java.util.List)11 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)11 CTP_TARGET_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT)10 TypeITUtils.populateTargetProject (com.commercetools.sync.integration.commons.utils.TypeITUtils.populateTargetProject)10 TypeSyncOptionsBuilder (com.commercetools.sync.types.TypeSyncOptionsBuilder)10 LocalizedString (io.sphere.sdk.models.LocalizedString)10