Search in sources :

Example 1 with TypeSyncOptionsBuilder

use of com.commercetools.sync.types.TypeSyncOptionsBuilder in project commercetools-sync-java by commercetools.

the class TypeSyncIT method sync_WithSeveralBatches_ShouldReturnProperStatistics.

@Test
void sync_WithSeveralBatches_ShouldReturnProperStatistics() {
    // preparation
    // Default batch size is 50 (check TypeSyncOptionsBuilder) so we have 2 batches of 50
    final List<TypeDraft> typeDrafts = IntStream.range(0, 100).mapToObj(i -> TypeDraftBuilder.of("key__" + Integer.toString(i), LocalizedString.ofEnglish("name__" + Integer.toString(i)), ResourceTypeIdsSetBuilder.of().addCategories().build()).description(LocalizedString.ofEnglish("description__" + Integer.toString(i))).fieldDefinitions(singletonList(FIELD_DEFINITION_1)).build()).collect(Collectors.toList());
    final TypeSyncOptions typeSyncOptions = TypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
    final TypeSync typeSync = new TypeSync(typeSyncOptions);
    // test
    final TypeSyncStatistics typeSyncStatistics = typeSync.sync(typeDrafts).toCompletableFuture().join();
    // assertion
    assertThat(typeSyncStatistics).hasValues(100, 100, 0, 0);
}
Also used : TypeDraft(io.sphere.sdk.types.TypeDraft) BeforeEach(org.junit.jupiter.api.BeforeEach) TYPE_DESCRIPTION_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_DESCRIPTION_1) TYPE_DESCRIPTION_2(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_DESCRIPTION_2) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Collections.singletonList(java.util.Collections.singletonList) FieldDefinition(io.sphere.sdk.types.FieldDefinition) LocalizedEnumFieldType(io.sphere.sdk.types.LocalizedEnumFieldType) AfterAll(org.junit.jupiter.api.AfterAll) FIELD_DEFINITION_LABEL_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_LABEL_1) Arrays.asList(java.util.Arrays.asList) SphereClient(io.sphere.sdk.client.SphereClient) CompletableFutureUtils.exceptionallyCompletedFuture(io.sphere.sdk.utils.CompletableFutureUtils.exceptionallyCompletedFuture) EnumValue(io.sphere.sdk.models.EnumValue) ITUtils.deleteTypes(com.commercetools.sync.integration.commons.utils.ITUtils.deleteTypes) BadGatewayException(io.sphere.sdk.client.BadGatewayException) TypeSyncStatistics(com.commercetools.sync.types.helpers.TypeSyncStatistics) TypeSync(com.commercetools.sync.types.TypeSync) CompletionException(java.util.concurrent.CompletionException) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) FIELD_DEFINITION_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_1) Test(org.junit.jupiter.api.Test) TYPE_KEY_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_KEY_1) LocalizedString(io.sphere.sdk.models.LocalizedString) FIELD_DEFINITION_3(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_3) List(java.util.List) FIELD_DEFINITION_2(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_2) LocalizedString.ofEnglish(io.sphere.sdk.models.LocalizedString.ofEnglish) TextInputHint(io.sphere.sdk.models.TextInputHint) TYPE_KEY_2(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_KEY_2) TypeITUtils.populateTargetProject(com.commercetools.sync.integration.commons.utils.TypeITUtils.populateTargetProject) Optional(java.util.Optional) Mockito.any(org.mockito.Mockito.any) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) IntStream(java.util.stream.IntStream) TypeSyncOptionsBuilder(com.commercetools.sync.types.TypeSyncOptionsBuilder) TypeUpdateCommand(io.sphere.sdk.types.commands.TypeUpdateCommand) ResourceTypeIdsSetBuilder(io.sphere.sdk.types.ResourceTypeIdsSetBuilder) AssertionsForStatistics.assertThat(com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat) CompletableFuture(java.util.concurrent.CompletableFuture) Mockito.spy(org.mockito.Mockito.spy) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) ArrayList(java.util.ArrayList) Assertions.as(org.assertj.core.api.Assertions.as) TypeQuery(io.sphere.sdk.types.queries.TypeQuery) TypeDraftBuilder(io.sphere.sdk.types.TypeDraftBuilder) Nonnull(javax.annotation.Nonnull) StringFieldType(io.sphere.sdk.types.StringFieldType) TYPE_NAME_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_NAME_1) FIELD_DEFINITION_NAME_1(com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_NAME_1) TYPE_NAME_2(com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_NAME_2) TypeCreateCommand(io.sphere.sdk.types.commands.TypeCreateCommand) LocalizedEnumValue(io.sphere.sdk.models.LocalizedEnumValue) Mockito.when(org.mockito.Mockito.when) ErrorResponseException(io.sphere.sdk.client.ErrorResponseException) PagedQueryResult(io.sphere.sdk.queries.PagedQueryResult) ConcurrentModificationException(io.sphere.sdk.client.ConcurrentModificationException) EnumFieldType(io.sphere.sdk.types.EnumFieldType) TypeITUtils.getTypeByKey(com.commercetools.sync.integration.commons.utils.TypeITUtils.getTypeByKey) STRING(org.assertj.core.api.InstanceOfAssertFactories.STRING) Collections(java.util.Collections) SetFieldType(io.sphere.sdk.types.SetFieldType) Type(io.sphere.sdk.types.Type) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) TypeSyncStatistics(com.commercetools.sync.types.helpers.TypeSyncStatistics) TypeDraft(io.sphere.sdk.types.TypeDraft) TypeSync(com.commercetools.sync.types.TypeSync) Test(org.junit.jupiter.api.Test)

Aggregations

AssertionsForStatistics.assertThat (com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat)1 ITUtils.deleteTypes (com.commercetools.sync.integration.commons.utils.ITUtils.deleteTypes)1 CTP_TARGET_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT)1 FIELD_DEFINITION_1 (com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_1)1 FIELD_DEFINITION_2 (com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_2)1 FIELD_DEFINITION_3 (com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_3)1 FIELD_DEFINITION_LABEL_1 (com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_LABEL_1)1 FIELD_DEFINITION_NAME_1 (com.commercetools.sync.integration.commons.utils.TypeITUtils.FIELD_DEFINITION_NAME_1)1 TYPE_DESCRIPTION_1 (com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_DESCRIPTION_1)1 TYPE_DESCRIPTION_2 (com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_DESCRIPTION_2)1 TYPE_KEY_1 (com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_KEY_1)1 TYPE_KEY_2 (com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_KEY_2)1 TYPE_NAME_1 (com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_NAME_1)1 TYPE_NAME_2 (com.commercetools.sync.integration.commons.utils.TypeITUtils.TYPE_NAME_2)1 TypeITUtils.getTypeByKey (com.commercetools.sync.integration.commons.utils.TypeITUtils.getTypeByKey)1 TypeITUtils.populateTargetProject (com.commercetools.sync.integration.commons.utils.TypeITUtils.populateTargetProject)1 TypeSync (com.commercetools.sync.types.TypeSync)1 TypeSyncOptions (com.commercetools.sync.types.TypeSyncOptions)1 TypeSyncOptionsBuilder (com.commercetools.sync.types.TypeSyncOptionsBuilder)1 TypeSyncStatistics (com.commercetools.sync.types.helpers.TypeSyncStatistics)1