Search in sources :

Example 56 with ProductTypeSyncOptions

use of com.commercetools.sync.producttypes.ProductTypeSyncOptions in project commercetools-sync-java by commercetools.

the class BuildAttributeDefinitionUpdateActionsTest method buildAttributesUpdateActions_WithDuplicateAttributeNames_ShouldNotBuildActionsAndTriggerErrorCb.

@Test
void buildAttributesUpdateActions_WithDuplicateAttributeNames_ShouldNotBuildActionsAndTriggerErrorCb() {
    final ProductType oldProductType = readObjectFromResource(PRODUCT_TYPE_WITH_ATTRIBUTES_ABC, ProductType.class);
    final ProductTypeDraft newProductTypeDraft = readObjectFromResource(PRODUCT_TYPE_WITH_ATTRIBUTES_ABB, ProductTypeDraft.class);
    final List<String> errorMessages = new ArrayList<>();
    final List<Throwable> exceptions = new ArrayList<>();
    final ProductTypeSyncOptions syncOptions = ProductTypeSyncOptionsBuilder.of(mock(SphereClient.class)).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errorMessages.add(exception.getMessage());
        exceptions.add(exception.getCause());
    }).build();
    final List<UpdateAction<ProductType>> updateActions = buildAttributesUpdateActions(oldProductType, newProductTypeDraft, syncOptions);
    assertThat(updateActions).isEmpty();
    assertThat(errorMessages).hasSize(1);
    assertThat(errorMessages.get(0)).matches("Failed to build update actions for the attributes definitions of the " + "product type with the key 'key'. Reason: .*DuplicateNameException: Attribute definitions drafts " + "have duplicated names. Duplicated attribute definition name: 'b'. Attribute definitions names are " + "expected to be unique inside their product type.");
    assertThat(exceptions).hasSize(1);
    assertThat(exceptions.get(0)).isExactlyInstanceOf(BuildUpdateActionException.class);
    assertThat(exceptions.get(0).getMessage()).contains("Attribute definitions drafts have duplicated names. " + "Duplicated attribute definition name: 'b'. Attribute definitions names are expected to be unique " + "inside their product type.");
    assertThat(exceptions.get(0).getCause()).isExactlyInstanceOf(DuplicateNameException.class);
}
Also used : ChangeIsSearchable(io.sphere.sdk.producttypes.commands.updateactions.ChangeIsSearchable) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UpdateAction(io.sphere.sdk.commands.UpdateAction) LocalizedEnumAttributeType(io.sphere.sdk.products.attributes.LocalizedEnumAttributeType) AddAttributeDefinition(io.sphere.sdk.producttypes.commands.updateactions.AddAttributeDefinition) Collections.singletonList(java.util.Collections.singletonList) ChangeAttributeConstraint(io.sphere.sdk.producttypes.commands.updateactions.ChangeAttributeConstraint) ChangePlainEnumValueLabel(io.sphere.sdk.producttypes.commands.updateactions.ChangePlainEnumValueLabel) StringAttributeType(io.sphere.sdk.products.attributes.StringAttributeType) Arrays.asList(java.util.Arrays.asList) ChangeEnumValueOrder(io.sphere.sdk.producttypes.commands.updateactions.ChangeEnumValueOrder) SphereClient(io.sphere.sdk.client.SphereClient) ProductTypeUpdateActionUtils.buildAttributesUpdateActions(com.commercetools.sync.producttypes.utils.ProductTypeUpdateActionUtils.buildAttributesUpdateActions) EnumValue(io.sphere.sdk.models.EnumValue) AttributeDefinition(io.sphere.sdk.products.attributes.AttributeDefinition) AddLocalizedEnumValue(io.sphere.sdk.producttypes.commands.updateactions.AddLocalizedEnumValue) ProductTypeDraftBuilder(io.sphere.sdk.producttypes.ProductTypeDraftBuilder) Collections.emptyList(java.util.Collections.emptyList) Test(org.junit.jupiter.api.Test) LocalizedString(io.sphere.sdk.models.LocalizedString) List(java.util.List) LocalizedString.ofEnglish(io.sphere.sdk.models.LocalizedString.ofEnglish) TextInputHint(io.sphere.sdk.models.TextInputHint) AttributeConstraint(io.sphere.sdk.products.attributes.AttributeConstraint) BuildUpdateActionException(com.commercetools.sync.commons.exceptions.BuildUpdateActionException) AttributeDefinitionDraft(io.sphere.sdk.products.attributes.AttributeDefinitionDraft) Mockito.mock(org.mockito.Mockito.mock) SphereJsonUtils.readObjectFromResource(io.sphere.sdk.json.SphereJsonUtils.readObjectFromResource) ProductType(io.sphere.sdk.producttypes.ProductType) LocalizedStringAttributeType(io.sphere.sdk.products.attributes.LocalizedStringAttributeType) ArrayList(java.util.ArrayList) ProductTypeSyncOptionsBuilder(com.commercetools.sync.producttypes.ProductTypeSyncOptionsBuilder) ChangeAttributeDefinitionLabel(io.sphere.sdk.producttypes.commands.updateactions.ChangeAttributeDefinitionLabel) ChangeLocalizedEnumValueLabel(io.sphere.sdk.producttypes.commands.updateactions.ChangeLocalizedEnumValueLabel) AttributeDefinitionBuilder(io.sphere.sdk.products.attributes.AttributeDefinitionBuilder) SetAttributeType(io.sphere.sdk.products.attributes.SetAttributeType) AttributeDefinitionDraftBuilder(io.sphere.sdk.products.attributes.AttributeDefinitionDraftBuilder) ChangeAttributeOrderByName(io.sphere.sdk.producttypes.commands.updateactions.ChangeAttributeOrderByName) EnumAttributeType(io.sphere.sdk.products.attributes.EnumAttributeType) LocalizedEnumValue(io.sphere.sdk.models.LocalizedEnumValue) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) Mockito.when(org.mockito.Mockito.when) DuplicateNameException(com.commercetools.sync.commons.exceptions.DuplicateNameException) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) ChangeLocalizedEnumValueOrder(io.sphere.sdk.producttypes.commands.updateactions.ChangeLocalizedEnumValueOrder) NestedAttributeType(io.sphere.sdk.products.attributes.NestedAttributeType) RemoveAttributeDefinition(io.sphere.sdk.producttypes.commands.updateactions.RemoveAttributeDefinition) RemoveEnumValues(io.sphere.sdk.producttypes.commands.updateactions.RemoveEnumValues) AddEnumValue(io.sphere.sdk.producttypes.commands.updateactions.AddEnumValue) Collections(java.util.Collections) ChangeInputHint(io.sphere.sdk.producttypes.commands.updateactions.ChangeInputHint) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) UpdateAction(io.sphere.sdk.commands.UpdateAction) SphereClient(io.sphere.sdk.client.SphereClient) ProductType(io.sphere.sdk.producttypes.ProductType) ArrayList(java.util.ArrayList) LocalizedString(io.sphere.sdk.models.LocalizedString) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) Test(org.junit.jupiter.api.Test)

Aggregations

ProductTypeSyncOptions (com.commercetools.sync.producttypes.ProductTypeSyncOptions)56 Test (org.junit.jupiter.api.Test)54 ProductTypeDraft (io.sphere.sdk.producttypes.ProductTypeDraft)45 AttributeDefinitionDraft (io.sphere.sdk.products.attributes.AttributeDefinitionDraft)41 ProductType (io.sphere.sdk.producttypes.ProductType)38 ProductTypeSyncOptionsBuilder (com.commercetools.sync.producttypes.ProductTypeSyncOptionsBuilder)31 List (java.util.List)31 ArrayList (java.util.ArrayList)30 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)30 SphereClient (io.sphere.sdk.client.SphereClient)29 UpdateAction (io.sphere.sdk.commands.UpdateAction)26 AttributeDefinitionDraftBuilder (io.sphere.sdk.products.attributes.AttributeDefinitionDraftBuilder)26 SetAttributeType (io.sphere.sdk.products.attributes.SetAttributeType)26 ProductTypeSync (com.commercetools.sync.producttypes.ProductTypeSync)25 ProductTypeSyncStatistics (com.commercetools.sync.producttypes.helpers.ProductTypeSyncStatistics)25 Collections.singletonList (java.util.Collections.singletonList)25 Mockito.when (org.mockito.Mockito.when)25 LocalizedString.ofEnglish (io.sphere.sdk.models.LocalizedString.ofEnglish)24 ProductTypeDraftBuilder (io.sphere.sdk.producttypes.ProductTypeDraftBuilder)24 ProductTypeQuery (io.sphere.sdk.producttypes.queries.ProductTypeQuery)24