Search in sources :

Example 51 with ProductTypeSyncOptions

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

the class ProductTypeReferenceResolverTest method resolveReferences_WithOneSetOfNestedTypeWithExistingProductTypeReference_ShouldResolveReferences.

@Test
void resolveReferences_WithOneSetOfNestedTypeWithExistingProductTypeReference_ShouldResolveReferences() {
    // preparation
    final NestedAttributeType nestedAttributeType = NestedAttributeType.of(ProductType.reference("x"));
    final SetAttributeType setAttributeType = SetAttributeType.of(nestedAttributeType);
    final AttributeDefinitionDraft attributeDefinitionDraft = AttributeDefinitionDraftBuilder.of(setAttributeType, "foo", ofEnglish("foo"), true).build();
    final ProductTypeDraft productTypeDraft = ProductTypeDraftBuilder.of("foo", "foo", "desc", singletonList(attributeDefinitionDraft)).build();
    final ProductTypeSyncOptions syncOptions = ProductTypeSyncOptionsBuilder.of(mock(SphereClient.class)).build();
    final ProductTypeService productTypeService = mock(ProductTypeService.class);
    when(productTypeService.fetchCachedProductTypeId(any())).thenReturn(CompletableFuture.completedFuture(Optional.of("foo")));
    final ProductTypeReferenceResolver productTypeReferenceResolver = new ProductTypeReferenceResolver(syncOptions, productTypeService);
    final NestedAttributeType expectedResolvedNestedAttributeType = NestedAttributeType.of(ProductType.referenceOfId("foo"));
    final SetAttributeType expectedSetAttributeType = SetAttributeType.of(expectedResolvedNestedAttributeType);
    final AttributeDefinitionDraft expectedResolvedAttrDef = AttributeDefinitionDraftBuilder.of(attributeDefinitionDraft).attributeType(expectedSetAttributeType).build();
    final ProductTypeDraftDsl expectedResolvedProductTypeDraft = ProductTypeDraftBuilder.of(productTypeDraft).attributes(singletonList(expectedResolvedAttrDef)).build();
    // test and assertion
    assertThat(productTypeReferenceResolver.resolveReferences(productTypeDraft)).isCompletedWithValue(expectedResolvedProductTypeDraft);
}
Also used : ProductTypeService(com.commercetools.sync.services.ProductTypeService) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) ProductTypeDraftDsl(io.sphere.sdk.producttypes.ProductTypeDraftDsl) AttributeDefinitionDraft(io.sphere.sdk.products.attributes.AttributeDefinitionDraft) NestedAttributeType(io.sphere.sdk.products.attributes.NestedAttributeType) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) SetAttributeType(io.sphere.sdk.products.attributes.SetAttributeType) Test(org.junit.jupiter.api.Test)

Example 52 with ProductTypeSyncOptions

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

the class ProductTypeReferenceResolverTest method resolveReferences_WithNullAttributes_ShouldNotResolveReferences.

@Test
void resolveReferences_WithNullAttributes_ShouldNotResolveReferences() {
    // preparation
    final ProductTypeDraft productTypeDraft = ProductTypeDraftBuilder.of("foo", "foo", "desc", null).build();
    final ProductTypeSyncOptions syncOptions = ProductTypeSyncOptionsBuilder.of(mock(SphereClient.class)).build();
    final ProductTypeService productTypeService = mock(ProductTypeService.class);
    when(productTypeService.fetchCachedProductTypeId(any())).thenReturn(CompletableFuture.completedFuture(Optional.of("foo")));
    final ProductTypeReferenceResolver productTypeReferenceResolver = new ProductTypeReferenceResolver(syncOptions, productTypeService);
    final ProductTypeDraftDsl expectedResolvedProductTypeDraft = ProductTypeDraftBuilder.of(productTypeDraft).build();
    // test and assertion
    assertThat(productTypeReferenceResolver.resolveReferences(productTypeDraft)).isCompletedWithValue(expectedResolvedProductTypeDraft);
}
Also used : ProductTypeService(com.commercetools.sync.services.ProductTypeService) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) ProductTypeDraftDsl(io.sphere.sdk.producttypes.ProductTypeDraftDsl) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) Test(org.junit.jupiter.api.Test)

Example 53 with ProductTypeSyncOptions

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

the class ProductTypeServiceImplTest method fetchProductType_WithEmptyKey_ShouldNotFetchProductType.

@Test
void fetchProductType_WithEmptyKey_ShouldNotFetchProductType() {
    // preparation
    final SphereClient sphereClient = mock(SphereClient.class);
    final ProductTypeSyncOptions syncOptions = ProductTypeSyncOptionsBuilder.of(sphereClient).build();
    final ProductTypeService productTypeService = new ProductTypeServiceImpl(syncOptions);
    // test
    final CompletionStage<Optional<ProductType>> result = productTypeService.fetchProductType("");
    // assertions
    assertThat(result).isCompletedWithValue(Optional.empty());
    verify(sphereClient, never()).execute(any());
}
Also used : ProductTypeService(com.commercetools.sync.services.ProductTypeService) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) Optional(java.util.Optional) SphereClient(io.sphere.sdk.client.SphereClient) Test(org.junit.jupiter.api.Test)

Example 54 with ProductTypeSyncOptions

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

the class ProductTypeServiceImplTest method fetchProductType_WithNullKey_ShouldNotFetchProductType.

@Test
void fetchProductType_WithNullKey_ShouldNotFetchProductType() {
    // preparation
    final SphereClient sphereClient = mock(SphereClient.class);
    final ProductTypeSyncOptions syncOptions = ProductTypeSyncOptionsBuilder.of(sphereClient).build();
    final ProductTypeService productTypeService = new ProductTypeServiceImpl(syncOptions);
    // test
    final CompletionStage<Optional<ProductType>> result = productTypeService.fetchProductType(null);
    // assertions
    assertThat(result).isCompletedWithValue(Optional.empty());
    verify(sphereClient, never()).execute(any());
}
Also used : ProductTypeService(com.commercetools.sync.services.ProductTypeService) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) Optional(java.util.Optional) SphereClient(io.sphere.sdk.client.SphereClient) Test(org.junit.jupiter.api.Test)

Example 55 with ProductTypeSyncOptions

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

the class BuildAttributeDefinitionUpdateActionsTest method buildAttributesUpdateActions_WithOldLenumAndNewAsNonLenum_ShouldNotBuildActionsAndTriggerErrorCb.

@Test
void buildAttributesUpdateActions_WithOldLenumAndNewAsNonLenum_ShouldNotBuildActionsAndTriggerErrorCb() {
    // preparation
    final AttributeDefinitionDraft newDefinition = AttributeDefinitionDraftBuilder.of(StringAttributeType.of(), "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"), LocalizedEnumAttributeType.of(singletonList(LocalizedEnumValue.of("foo", ofEnglish("bar"))))).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)

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