Search in sources :

Example 16 with ProductTypeSyncOptions

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

the class BuildAttributeDefinitionUpdateActionsTest method buildAttributesUpdateActions_WithNewLenumAndOldAsNonLenum_ShouldNotBuildActionsAndTriggerErrorCb.

@Test
void buildAttributesUpdateActions_WithNewLenumAndOldAsNonLenum_ShouldNotBuildActionsAndTriggerErrorCb() {
    // preparation
    final AttributeDefinitionDraft newDefinition = AttributeDefinitionDraftBuilder.of(LocalizedEnumAttributeType.of(LocalizedEnumValue.of("foo", ofEnglish("bar"))), "a", ofEnglish("new_label"), true).build();
    final ProductTypeDraft productTypeDraft = ProductTypeDraftBuilder.of("foo", "name", "desc", singletonList(newDefinition)).build();
    final AttributeDefinition oldDefinition = AttributeDefinitionBuilder.of("a", ofEnglish("new_label"), StringAttributeType.of()).build();
    final ProductType productType = mock(ProductType.class);
    when(productType.getAttributes()).thenReturn(singletonList(oldDefinition));
    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();
    // test
    final List<UpdateAction<ProductType>> updateActions = buildAttributesUpdateActions(productType, productTypeDraft, syncOptions);
    // assertions
    assertThat(updateActions).isEmpty();
    assertThat(errorMessages).hasSize(1);
    assertThat(exceptions.get(0)).isExactlyInstanceOf(BuildUpdateActionException.class);
    assertThat(exceptions.get(0).getMessage()).contains("changing the attribute definition type (attribute name='a') is not supported programmatically");
    assertThat(exceptions.get(0).getCause()).isExactlyInstanceOf(UnsupportedOperationException.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) UpdateAction(io.sphere.sdk.commands.UpdateAction) ProductType(io.sphere.sdk.producttypes.ProductType) ArrayList(java.util.ArrayList) AddAttributeDefinition(io.sphere.sdk.producttypes.commands.updateactions.AddAttributeDefinition) AttributeDefinition(io.sphere.sdk.products.attributes.AttributeDefinition) RemoveAttributeDefinition(io.sphere.sdk.producttypes.commands.updateactions.RemoveAttributeDefinition) AttributeDefinitionDraft(io.sphere.sdk.products.attributes.AttributeDefinitionDraft) LocalizedString(io.sphere.sdk.models.LocalizedString) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) SphereClient(io.sphere.sdk.client.SphereClient) Test(org.junit.jupiter.api.Test)

Example 17 with ProductTypeSyncOptions

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

the class BuildAttributeDefinitionUpdateActionsTest method buildAttributesUpdateActions_WithDifferentSetAttributeType_ShouldNotBuildActionsAndTriggerErrorCb.

@Test
void buildAttributesUpdateActions_WithDifferentSetAttributeType_ShouldNotBuildActionsAndTriggerErrorCb() {
    // preparation
    final AttributeDefinitionDraft newDefinition = AttributeDefinitionDraftBuilder.of(SetAttributeType.of(StringAttributeType.of()), "a", ofEnglish("new_label"), true).build();
    final AttributeDefinition oldDefinition = AttributeDefinitionBuilder.of("a", ofEnglish("old_label"), SetAttributeType.of(LocalizedStringAttributeType.of())).isRequired(true).build();
    final ProductTypeDraft productTypeDraft = ProductTypeDraftBuilder.of("foo", "name", "desc", singletonList(newDefinition)).build();
    final ProductType productType = mock(ProductType.class);
    when(productType.getAttributes()).thenReturn(singletonList(oldDefinition));
    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();
    // test
    final List<UpdateAction<ProductType>> updateActions = buildAttributesUpdateActions(productType, productTypeDraft, syncOptions);
    // assertions
    assertThat(updateActions).isEmpty();
    assertThat(errorMessages).hasSize(1);
    assertThat(exceptions.get(0)).isExactlyInstanceOf(BuildUpdateActionException.class);
    assertThat(exceptions.get(0).getMessage()).contains("changing the attribute definition type (attribute name='a') is not supported programmatically");
    assertThat(exceptions.get(0).getCause()).isExactlyInstanceOf(UnsupportedOperationException.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) UpdateAction(io.sphere.sdk.commands.UpdateAction) ProductType(io.sphere.sdk.producttypes.ProductType) ArrayList(java.util.ArrayList) AddAttributeDefinition(io.sphere.sdk.producttypes.commands.updateactions.AddAttributeDefinition) AttributeDefinition(io.sphere.sdk.products.attributes.AttributeDefinition) RemoveAttributeDefinition(io.sphere.sdk.producttypes.commands.updateactions.RemoveAttributeDefinition) AttributeDefinitionDraft(io.sphere.sdk.products.attributes.AttributeDefinitionDraft) LocalizedString(io.sphere.sdk.models.LocalizedString) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) SphereClient(io.sphere.sdk.client.SphereClient) Test(org.junit.jupiter.api.Test)

Example 18 with ProductTypeSyncOptions

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

the class BuildAttributeDefinitionUpdateActionsTest method buildAttributesUpdateActions_WithDifferentNestedAttributeRefs_ShouldNotBuildActionsAndTriggerErrorCb.

@Test
void buildAttributesUpdateActions_WithDifferentNestedAttributeRefs_ShouldNotBuildActionsAndTriggerErrorCb() {
    // preparation
    final AttributeDefinition ofNestedType = AttributeDefinitionBuilder.of("nested", ofEnglish("label"), NestedAttributeType.of(ProductType.referenceOfId("foo"))).build();
    final AttributeDefinition ofSetOfNestedType = AttributeDefinitionBuilder.of("set-of-nested", ofEnglish("label"), SetAttributeType.of(NestedAttributeType.of(ProductType.referenceOfId("foo")))).build();
    final AttributeDefinition ofSetOfSetOfNestedType = AttributeDefinitionBuilder.of("set-of-set-of-nested", ofEnglish("label"), SetAttributeType.of(SetAttributeType.of(NestedAttributeType.of(ProductType.referenceOfId("foo"))))).build();
    final AttributeDefinitionDraft ofNestedTypeDraft = AttributeDefinitionDraftBuilder.of(ofNestedType).attributeType(NestedAttributeType.of(ProductType.referenceOfId("bar"))).build();
    final AttributeDefinitionDraft ofSetOfNestedTypeDraft = AttributeDefinitionDraftBuilder.of(ofSetOfNestedType).attributeType(SetAttributeType.of(NestedAttributeType.of(ProductType.referenceOfId("bar")))).build();
    final AttributeDefinitionDraft ofSetOfSetOfNestedTypeDraft = AttributeDefinitionDraftBuilder.of(ofSetOfSetOfNestedType).attributeType(SetAttributeType.of(SetAttributeType.of(NestedAttributeType.of(ProductType.referenceOfId("bar"))))).build();
    final ProductType oldProductType = mock(ProductType.class);
    when(oldProductType.getAttributes()).thenReturn(asList(ofNestedType, ofSetOfNestedType, ofSetOfSetOfNestedType));
    final ProductTypeDraft newProductTypeDraft = mock(ProductTypeDraft.class);
    when(newProductTypeDraft.getAttributes()).thenReturn(asList(ofNestedTypeDraft, ofSetOfNestedTypeDraft, ofSetOfSetOfNestedTypeDraft));
    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();
    // test
    final List<UpdateAction<ProductType>> updateActions = buildAttributesUpdateActions(oldProductType, newProductTypeDraft, syncOptions);
    // assertions
    assertThat(updateActions).isEmpty();
    assertThat(errorMessages).hasSize(1);
    assertThat(exceptions.get(0)).isExactlyInstanceOf(BuildUpdateActionException.class);
    assertThat(exceptions.get(0).getMessage()).contains("changing the attribute definition type (attribute name='nested') is not supported programmatically");
    assertThat(exceptions.get(0).getCause()).isExactlyInstanceOf(UnsupportedOperationException.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) UpdateAction(io.sphere.sdk.commands.UpdateAction) ProductType(io.sphere.sdk.producttypes.ProductType) ArrayList(java.util.ArrayList) AddAttributeDefinition(io.sphere.sdk.producttypes.commands.updateactions.AddAttributeDefinition) AttributeDefinition(io.sphere.sdk.products.attributes.AttributeDefinition) RemoveAttributeDefinition(io.sphere.sdk.producttypes.commands.updateactions.RemoveAttributeDefinition) AttributeDefinitionDraft(io.sphere.sdk.products.attributes.AttributeDefinitionDraft) LocalizedString(io.sphere.sdk.models.LocalizedString) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) SphereClient(io.sphere.sdk.client.SphereClient) Test(org.junit.jupiter.api.Test)

Example 19 with ProductTypeSyncOptions

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

the class BuildAttributeDefinitionUpdateActionsTest method buildAttributesUpdateActions_WithIdenticalNestedAttributeRefs_ShouldNotBuildActions.

@Test
void buildAttributesUpdateActions_WithIdenticalNestedAttributeRefs_ShouldNotBuildActions() {
    // preparation
    final AttributeDefinition ofNestedType = AttributeDefinitionBuilder.of("nested", ofEnglish("label"), NestedAttributeType.of(ProductType.referenceOfId("foo"))).build();
    final AttributeDefinition ofSetOfNestedType = AttributeDefinitionBuilder.of("set-of-nested", ofEnglish("label"), SetAttributeType.of(NestedAttributeType.of(ProductType.referenceOfId("foo")))).build();
    final AttributeDefinition ofSetOfSetOfNestedType = AttributeDefinitionBuilder.of("set-of-set-of-nested", ofEnglish("label"), SetAttributeType.of(SetAttributeType.of(NestedAttributeType.of(ProductType.referenceOfId("foo"))))).build();
    final AttributeDefinitionDraft ofNestedTypeDraft = AttributeDefinitionDraftBuilder.of(ofNestedType).build();
    final AttributeDefinitionDraft ofSetOfNestedTypeDraft = AttributeDefinitionDraftBuilder.of(ofSetOfNestedType).build();
    final AttributeDefinitionDraft ofSetOfSetOfNestedTypeDraft = AttributeDefinitionDraftBuilder.of(ofSetOfSetOfNestedType).build();
    final ProductType oldProductType = mock(ProductType.class);
    when(oldProductType.getAttributes()).thenReturn(asList(ofNestedType, ofSetOfNestedType, ofSetOfSetOfNestedType));
    final ProductTypeDraft newProductTypeDraft = mock(ProductTypeDraft.class);
    when(newProductTypeDraft.getAttributes()).thenReturn(asList(ofNestedTypeDraft, ofSetOfNestedTypeDraft, ofSetOfSetOfNestedTypeDraft));
    final ProductTypeSyncOptions syncOptions = ProductTypeSyncOptionsBuilder.of(mock(SphereClient.class)).build();
    // test
    final List<UpdateAction<ProductType>> updateActions = buildAttributesUpdateActions(oldProductType, newProductTypeDraft, syncOptions);
    // assertions
    assertThat(updateActions).isEmpty();
}
Also used : ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) UpdateAction(io.sphere.sdk.commands.UpdateAction) ProductType(io.sphere.sdk.producttypes.ProductType) AddAttributeDefinition(io.sphere.sdk.producttypes.commands.updateactions.AddAttributeDefinition) AttributeDefinition(io.sphere.sdk.products.attributes.AttributeDefinition) RemoveAttributeDefinition(io.sphere.sdk.producttypes.commands.updateactions.RemoveAttributeDefinition) AttributeDefinitionDraft(io.sphere.sdk.products.attributes.AttributeDefinitionDraft) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) Test(org.junit.jupiter.api.Test)

Example 20 with ProductTypeSyncOptions

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

the class ProductTypeServiceImplTest method fetchProductType_WithBadGateWayException_ShouldCompleteExceptionally.

@Test
void fetchProductType_WithBadGateWayException_ShouldCompleteExceptionally() {
    // preparation
    final SphereClient sphereClient = mock(SphereClient.class);
    when(sphereClient.execute(any(ProductTypeQuery.class))).thenReturn(CompletableFutureUtils.exceptionallyCompletedFuture(new BadGatewayException()));
    final ProductTypeSyncOptions syncOptions = ProductTypeSyncOptionsBuilder.of(sphereClient).build();
    final ProductTypeService productTypeService = new ProductTypeServiceImpl(syncOptions);
    // test
    final CompletionStage<Optional<ProductType>> result = productTypeService.fetchProductType("foo");
    // assertions
    assertThat(result).failsWithin(1, TimeUnit.SECONDS).withThrowableOfType(ExecutionException.class).withCauseExactlyInstanceOf(BadGatewayException.class);
}
Also used : ProductTypeService(com.commercetools.sync.services.ProductTypeService) ProductTypeQuery(io.sphere.sdk.producttypes.queries.ProductTypeQuery) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) Optional(java.util.Optional) SphereClient(io.sphere.sdk.client.SphereClient) BadGatewayException(io.sphere.sdk.client.BadGatewayException) ExecutionException(java.util.concurrent.ExecutionException) 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