Search in sources :

Example 6 with TypeSyncOptions

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

the class TypeSyncIT method sync_WithoutFieldDefinitionType_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter.

@Test
void sync_WithoutFieldDefinitionType_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter() {
    // preparation
    final FieldDefinition fieldDefinition = FieldDefinition.of(null, FIELD_DEFINITION_NAME_1, FIELD_DEFINITION_LABEL_1, true, TextInputHint.SINGLE_LINE);
    final TypeDraft newTypeDraft = TypeDraftBuilder.of(TYPE_KEY_1, null, ResourceTypeIdsSetBuilder.of().addCategories().build()).description(TYPE_DESCRIPTION_1).fieldDefinitions(singletonList(fieldDefinition)).build();
    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(singletonList(newTypeDraft)).toCompletableFuture().join();
    // assertions
    assertThat(errorMessages).hasSize(1).singleElement(as(STRING)).contains("Failed to update type with key: 'key_1'.");
    assertThat(exceptions).hasSize(1).singleElement().matches(throwable -> {
        assertThat(throwable).isExactlyInstanceOf(CompletionException.class);
        assertThat(throwable).hasCauseExactlyInstanceOf(ErrorResponseException.class);
        assertThat(throwable).hasMessageContaining("Missing required value");
        return true;
    });
    assertThat(typeSyncStatistics).hasValues(1, 0, 0, 1);
}
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) FieldDefinition(io.sphere.sdk.types.FieldDefinition) ArrayList(java.util.ArrayList) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) LocalizedString(io.sphere.sdk.models.LocalizedString) 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)

Example 7 with TypeSyncOptions

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

the class TypeSyncIT method sync_WithNullDraft_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter.

@Test
void sync_WithNullDraft_ShouldExecuteCallbackOnErrorAndIncreaseFailedCounter() {
    // preparation
    final TypeDraft newTypeDraft = null;
    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(singletonList(newTypeDraft)).toCompletableFuture().join();
    // assertions
    assertThat(errorMessages).hasSize(1).singleElement(as(STRING)).isEqualTo("TypeDraft is null.");
    assertThat(exceptions).hasSize(1).singleElement().isNull();
    assertThat(typeSyncStatistics).hasValues(1, 0, 0, 1);
}
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) ArrayList(java.util.ArrayList) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) LocalizedString(io.sphere.sdk.models.LocalizedString) 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)

Example 8 with TypeSyncOptions

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

the class TypeSyncIT method sync__WithConcurrentModificationExceptionAndUnexpectedDelete_ShouldFailToReFetchAndUpdate.

@Test
void sync__WithConcurrentModificationExceptionAndUnexpectedDelete_ShouldFailToReFetchAndUpdate() {
    // preparation
    final SphereClient spyClient = buildClientWithConcurrentModificationUpdateAndNotFoundFetchOnRetry();
    final TypeDraft typeDraft = TypeDraftBuilder.of("typeKey", LocalizedString.ofEnglish("typeName"), ResourceTypeIdsSetBuilder.of().addChannels()).build();
    CTP_TARGET_CLIENT.execute(TypeCreateCommand.of(typeDraft)).toCompletableFuture().join();
    final LocalizedString newTypeName = LocalizedString.ofEnglish("typeName_updated");
    final TypeDraft updatedDraft = TypeDraftBuilder.of(typeDraft).name(newTypeName).build();
    final List<String> errorMessages = new ArrayList<>();
    final List<Throwable> errors = new ArrayList<>();
    final TypeSyncOptions typeSyncOptions = TypeSyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errorMessages.add(exception.getMessage());
        errors.add(exception.getCause());
    }).build();
    final TypeSync typeSync = new TypeSync(typeSyncOptions);
    // test
    final TypeSyncStatistics statistics = typeSync.sync(Collections.singletonList(updatedDraft)).toCompletableFuture().join();
    // Assertion
    assertThat(statistics).hasValues(1, 0, 0, 1);
    assertThat(errorMessages).hasSize(1);
    assertThat(errors).hasSize(1);
    assertThat(errorMessages.get(0)).contains(format("Failed to update type with key: '%s'. Reason: Not found when attempting to fetch while " + "retrying after concurrency modification.", typeDraft.getKey()));
}
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) SphereClient(io.sphere.sdk.client.SphereClient) ArrayList(java.util.ArrayList) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) LocalizedString(io.sphere.sdk.models.LocalizedString) LocalizedString(io.sphere.sdk.models.LocalizedString) 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)

Example 9 with TypeSyncOptions

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

the class TypeSyncIT method sync_WithConcurrentModificationExceptionAndFailedFetch_ShouldFailToReFetchAndUpdate.

@Test
void sync_WithConcurrentModificationExceptionAndFailedFetch_ShouldFailToReFetchAndUpdate() {
    // preparation
    final SphereClient spyClient = buildClientWithConcurrentModificationUpdateAndFailedFetchOnRetry();
    final TypeDraft typeDraft = TypeDraftBuilder.of("typeKey", LocalizedString.ofEnglish("typeName"), ResourceTypeIdsSetBuilder.of().addChannels()).build();
    CTP_TARGET_CLIENT.execute(TypeCreateCommand.of(typeDraft)).toCompletableFuture().join();
    final LocalizedString newTypeName = LocalizedString.ofEnglish("typeName_updated");
    final TypeDraft updatedDraft = TypeDraftBuilder.of(typeDraft).name(newTypeName).build();
    final List<String> errorMessages = new ArrayList<>();
    final List<Throwable> errors = new ArrayList<>();
    final TypeSyncOptions typeSyncOptions = TypeSyncOptionsBuilder.of(spyClient).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errorMessages.add(exception.getMessage());
        errors.add(exception.getCause());
    }).build();
    final TypeSync typeSync = new TypeSync(typeSyncOptions);
    // test
    final TypeSyncStatistics statistics = typeSync.sync(Collections.singletonList(updatedDraft)).toCompletableFuture().join();
    // assertion
    assertThat(statistics).hasValues(1, 0, 0, 1);
    assertThat(errorMessages).hasSize(1);
    assertThat(errors).hasSize(1);
    assertThat(errors.get(0).getCause()).isExactlyInstanceOf(BadGatewayException.class);
    assertThat(errorMessages.get(0)).contains(format("Failed to update type with key: '%s'. Reason: Failed to fetch from CTP while retrying " + "after concurrency modification.", typeDraft.getKey()));
}
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) SphereClient(io.sphere.sdk.client.SphereClient) ArrayList(java.util.ArrayList) TypeSyncOptions(com.commercetools.sync.types.TypeSyncOptions) LocalizedString(io.sphere.sdk.models.LocalizedString) LocalizedString(io.sphere.sdk.models.LocalizedString) 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)

Example 10 with TypeSyncOptions

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

the class TypeSyncIT method sync_WithUpdatedType_ChangingFieldDefinitionOrder_ShouldUpdateTypeChangingFieldDefinitionOrder.

@Test
void sync_WithUpdatedType_ChangingFieldDefinitionOrder_ShouldUpdateTypeChangingFieldDefinitionOrder() {
    // preparation
    final TypeDraft newTypeDraft = TypeDraftBuilder.of(TYPE_KEY_1, TYPE_NAME_1, ResourceTypeIdsSetBuilder.of().addCategories().build()).description(TYPE_DESCRIPTION_1).fieldDefinitions(asList(FIELD_DEFINITION_2, FIELD_DEFINITION_3, FIELD_DEFINITION_1)).build();
    final TypeSyncOptions typeSyncOptions = TypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
    final TypeSync typeSync = new TypeSync(typeSyncOptions);
    // test
    final TypeSyncStatistics typeSyncStatistics = typeSync.sync(singletonList(newTypeDraft)).toCompletableFuture().join();
    // assertions
    assertThat(typeSyncStatistics).hasValues(1, 0, 1, 0);
    final Optional<Type> oldTypeAfter = getTypeByKey(CTP_TARGET_CLIENT, TYPE_KEY_1);
    assertThat(oldTypeAfter).hasValueSatisfying(type -> assertFieldDefinitionsAreEqual(type.getFieldDefinitions(), asList(FIELD_DEFINITION_2, FIELD_DEFINITION_3, FIELD_DEFINITION_1)));
}
Also used : LocalizedEnumFieldType(io.sphere.sdk.types.LocalizedEnumFieldType) StringFieldType(io.sphere.sdk.types.StringFieldType) EnumFieldType(io.sphere.sdk.types.EnumFieldType) 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

TypeSyncOptions (com.commercetools.sync.types.TypeSyncOptions)24 Type (io.sphere.sdk.types.Type)24 TypeDraft (io.sphere.sdk.types.TypeDraft)24 Test (org.junit.jupiter.api.Test)23 TypeSync (com.commercetools.sync.types.TypeSync)18 TypeSyncStatistics (com.commercetools.sync.types.helpers.TypeSyncStatistics)18 TypeSyncOptionsBuilder (com.commercetools.sync.types.TypeSyncOptionsBuilder)17 TypeDraftBuilder (io.sphere.sdk.types.TypeDraftBuilder)17 List (java.util.List)17 EnumFieldType (io.sphere.sdk.types.EnumFieldType)16 LocalizedEnumFieldType (io.sphere.sdk.types.LocalizedEnumFieldType)16 SetFieldType (io.sphere.sdk.types.SetFieldType)16 StringFieldType (io.sphere.sdk.types.StringFieldType)16 TypeQuery (io.sphere.sdk.types.queries.TypeQuery)16 ArrayList (java.util.ArrayList)16 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)16 CTP_TARGET_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT)15 SphereClient (io.sphere.sdk.client.SphereClient)15 AfterAll (org.junit.jupiter.api.AfterAll)15 BeforeEach (org.junit.jupiter.api.BeforeEach)15