Search in sources :

Example 6 with ProductTypeSyncOptions

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

the class ProductTypeServiceImplIT method createProductType_WithInvalidProductType_ShouldHaveEmptyOptionalAsAResult.

@Test
void createProductType_WithInvalidProductType_ShouldHaveEmptyOptionalAsAResult() {
    // preparation
    final ProductTypeDraft newProductTypeDraft = ProductTypeDraft.ofAttributeDefinitionDrafts("", PRODUCT_TYPE_NAME_1, PRODUCT_TYPE_DESCRIPTION_1, singletonList(ATTRIBUTE_DEFINITION_DRAFT_1));
    final ProductTypeSyncOptions options = ProductTypeSyncOptionsBuilder.of(CTP_TARGET_CLIENT).errorCallback((exception, oldResource, newResource, updateActions) -> {
        errorCallBackMessages.add(exception.getMessage());
        errorCallBackExceptions.add(exception.getCause());
    }).build();
    final ProductTypeService service = new ProductTypeServiceImpl(options);
    // test
    final Optional<ProductType> result = service.createProductType(newProductTypeDraft).toCompletableFuture().join();
    // assertion
    assertThat(result).isEmpty();
    assertThat(errorCallBackMessages).containsExactly("Failed to create draft with key: ''. Reason: Draft key is blank!");
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ProductType(io.sphere.sdk.producttypes.ProductType) Mockito.spy(org.mockito.Mockito.spy) CompletableFutureUtils(io.sphere.sdk.utils.CompletableFutureUtils) DuplicateFieldError(io.sphere.sdk.models.errors.DuplicateFieldError) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) ProductTypeSyncOptionsBuilder(com.commercetools.sync.producttypes.ProductTypeSyncOptionsBuilder) HashSet(java.util.HashSet) AfterAll(org.junit.jupiter.api.AfterAll) Collections.singleton(java.util.Collections.singleton) Assertions.as(org.assertj.core.api.Assertions.as) Locale(java.util.Locale) ProductTypeService(com.commercetools.sync.services.ProductTypeService) Map(java.util.Map) SphereClient(io.sphere.sdk.client.SphereClient) PRODUCT_TYPE_KEY_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_KEY_1) ProductTypeITUtils.createProductType(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.createProductType) BadGatewayException(io.sphere.sdk.client.BadGatewayException) ProductTypeQuery(io.sphere.sdk.producttypes.queries.ProductTypeQuery) PRODUCT_TYPE_NAME_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_NAME_1) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) SetKey(io.sphere.sdk.producttypes.commands.updateactions.SetKey) Mockito.when(org.mockito.Mockito.when) AttributeMetaData(com.commercetools.sync.products.AttributeMetaData) ChangeName(io.sphere.sdk.producttypes.commands.updateactions.ChangeName) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) Mockito.verify(org.mockito.Mockito.verify) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ProductTypeServiceImpl(com.commercetools.sync.services.impl.ProductTypeServiceImpl) ErrorResponseException(io.sphere.sdk.client.ErrorResponseException) ProductTypeITUtils.deleteProductTypes(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.deleteProductTypes) Optional(java.util.Optional) PRODUCT_TYPE_DESCRIPTION_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.PRODUCT_TYPE_DESCRIPTION_1) STRING(org.assertj.core.api.InstanceOfAssertFactories.STRING) Collections(java.util.Collections) CTP_TARGET_CLIENT(com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT) ATTRIBUTE_DEFINITION_DRAFT_1(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.ATTRIBUTE_DEFINITION_DRAFT_1) ProductTypeService(com.commercetools.sync.services.ProductTypeService) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) ProductType(io.sphere.sdk.producttypes.ProductType) ProductTypeITUtils.createProductType(com.commercetools.sync.integration.commons.utils.ProductTypeITUtils.createProductType) ProductTypeServiceImpl(com.commercetools.sync.services.impl.ProductTypeServiceImpl) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) Test(org.junit.jupiter.api.Test)

Example 7 with ProductTypeSyncOptions

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

the class AttributeDefinitionReferenceResolverTest method resolveReferences_WithNoNestedTypeReferences_ShouldNotResolveReferences.

@Test
void resolveReferences_WithNoNestedTypeReferences_ShouldNotResolveReferences() {
    // preparation
    final AttributeDefinitionDraft attributeDefinitionDraft = AttributeDefinitionDraftBuilder.of(StringAttributeType.of(), "foo", ofEnglish("foo"), true).build();
    final ProductTypeSyncOptions syncOptions = ProductTypeSyncOptionsBuilder.of(mock(SphereClient.class)).build();
    final AttributeDefinitionReferenceResolver attributeDefinitionReferenceResolver = new AttributeDefinitionReferenceResolver(syncOptions, mock(ProductTypeService.class));
    // test and assertion
    assertThat(attributeDefinitionReferenceResolver.resolveReferences(attributeDefinitionDraft)).isCompletedWithValue(attributeDefinitionDraft);
}
Also used : ProductTypeService(com.commercetools.sync.services.ProductTypeService) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) AttributeDefinitionDraft(io.sphere.sdk.products.attributes.AttributeDefinitionDraft) Test(org.junit.jupiter.api.Test)

Example 8 with ProductTypeSyncOptions

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

the class AttributeDefinitionReferenceResolverTest method resolveReferences_WithSetOfNestedTypeWithExistingProductTypeReference_ShouldResolveReferences.

@Test
void resolveReferences_WithSetOfNestedTypeWithExistingProductTypeReference_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 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 AttributeDefinitionReferenceResolver attributeDefinitionReferenceResolver = new AttributeDefinitionReferenceResolver(syncOptions, productTypeService);
    final NestedAttributeType expectedResolvedNestedAttributeType = NestedAttributeType.of(ProductType.referenceOfId("foo"));
    final SetAttributeType expectedResolvedSetAttributeType = SetAttributeType.of(expectedResolvedNestedAttributeType);
    final AttributeDefinitionDraft expectedResolvedAttrDef = AttributeDefinitionDraftBuilder.of(attributeDefinitionDraft).attributeType(expectedResolvedSetAttributeType).build();
    // test and assertion
    assertThat(attributeDefinitionReferenceResolver.resolveReferences(attributeDefinitionDraft)).isCompletedWithValue(expectedResolvedAttrDef);
}
Also used : ProductTypeService(com.commercetools.sync.services.ProductTypeService) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) AttributeDefinitionDraft(io.sphere.sdk.products.attributes.AttributeDefinitionDraft) NestedAttributeType(io.sphere.sdk.products.attributes.NestedAttributeType) SetAttributeType(io.sphere.sdk.products.attributes.SetAttributeType) Test(org.junit.jupiter.api.Test)

Example 9 with ProductTypeSyncOptions

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

the class AttributeDefinitionReferenceResolverTest method resolveReferences_WithOneNestedTypeWithExistingProductTypeReference_ShouldResolveReferences.

@Test
void resolveReferences_WithOneNestedTypeWithExistingProductTypeReference_ShouldResolveReferences() {
    // preparation
    final NestedAttributeType nestedAttributeType = NestedAttributeType.of(ProductType.reference("x"));
    final AttributeDefinitionDraft attributeDefinitionDraft = AttributeDefinitionDraftBuilder.of(nestedAttributeType, "foo", ofEnglish("foo"), true).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 AttributeDefinitionReferenceResolver attributeDefinitionReferenceResolver = new AttributeDefinitionReferenceResolver(syncOptions, productTypeService);
    final NestedAttributeType expectedResolvedNestedAttributeType = NestedAttributeType.of(ProductType.referenceOfId("foo"));
    final AttributeDefinitionDraft expectedResolvedAttrDef = AttributeDefinitionDraftBuilder.of(attributeDefinitionDraft).attributeType(expectedResolvedNestedAttributeType).build();
    // test and assertion
    assertThat(attributeDefinitionReferenceResolver.resolveReferences(attributeDefinitionDraft)).isCompletedWithValue(expectedResolvedAttrDef);
}
Also used : ProductTypeService(com.commercetools.sync.services.ProductTypeService) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) AttributeDefinitionDraft(io.sphere.sdk.products.attributes.AttributeDefinitionDraft) NestedAttributeType(io.sphere.sdk.products.attributes.NestedAttributeType) Test(org.junit.jupiter.api.Test)

Example 10 with ProductTypeSyncOptions

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

the class AttributeDefinitionReferenceResolverTest method resolveReferences_WithOneNestedTypeWithNonExistingProductTypeReference_ShouldNotResolveReferences.

@Test
void resolveReferences_WithOneNestedTypeWithNonExistingProductTypeReference_ShouldNotResolveReferences() {
    // preparation
    final NestedAttributeType nestedAttributeType = NestedAttributeType.of(ProductType.reference("x"));
    final AttributeDefinitionDraft attributeDefinitionDraft = AttributeDefinitionDraftBuilder.of(nestedAttributeType, "foo", ofEnglish("foo"), true).build();
    final ProductTypeSyncOptions syncOptions = ProductTypeSyncOptionsBuilder.of(mock(SphereClient.class)).build();
    final ProductTypeService productTypeService = mock(ProductTypeService.class);
    when(productTypeService.fetchCachedProductTypeId(any())).thenReturn(CompletableFuture.completedFuture(Optional.empty()));
    final AttributeDefinitionReferenceResolver attributeDefinitionReferenceResolver = new AttributeDefinitionReferenceResolver(syncOptions, productTypeService);
    // test and assertion
    assertThat(attributeDefinitionReferenceResolver.resolveReferences(attributeDefinitionDraft)).isCompletedWithValue(attributeDefinitionDraft);
}
Also used : ProductTypeService(com.commercetools.sync.services.ProductTypeService) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) AttributeDefinitionDraft(io.sphere.sdk.products.attributes.AttributeDefinitionDraft) NestedAttributeType(io.sphere.sdk.products.attributes.NestedAttributeType) 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