Search in sources :

Example 46 with ProductTypeSyncOptions

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

the class AttributeDefinitionReferenceResolverTest method resolveReferences_WithSetOfNestedTypeWithInvalidProductTypeReference_ShouldNotResolveReferences.

@Test
void resolveReferences_WithSetOfNestedTypeWithInvalidProductTypeReference_ShouldNotResolveReferences() {
    // preparation
    final NestedAttributeType nestedAttributeType = NestedAttributeType.of(ProductType.reference(""));
    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.empty()));
    final AttributeDefinitionReferenceResolver attributeDefinitionReferenceResolver = new AttributeDefinitionReferenceResolver(syncOptions, productTypeService);
    // test and assertion
    assertThat(attributeDefinitionReferenceResolver.resolveReferences(attributeDefinitionDraft)).failsWithin(1, TimeUnit.SECONDS).withThrowableOfType(ExecutionException.class).withCauseExactlyInstanceOf(ReferenceResolutionException.class).withMessageContaining("Failed to resolve references on attribute definition with name 'foo'");
}
Also used : ProductTypeService(com.commercetools.sync.services.ProductTypeService) ProductTypeSyncOptions(com.commercetools.sync.producttypes.ProductTypeSyncOptions) AttributeDefinitionDraft(io.sphere.sdk.products.attributes.AttributeDefinitionDraft) ReferenceResolutionException(com.commercetools.sync.commons.exceptions.ReferenceResolutionException) NestedAttributeType(io.sphere.sdk.products.attributes.NestedAttributeType) SetAttributeType(io.sphere.sdk.products.attributes.SetAttributeType) Test(org.junit.jupiter.api.Test)

Example 47 with ProductTypeSyncOptions

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

the class AttributeDefinitionReferenceResolverTest method resolveReferences_WithSetOfNonNestedType_ShouldResolveReferences.

@Test
void resolveReferences_WithSetOfNonNestedType_ShouldResolveReferences() {
    // preparation
    final SetAttributeType setAttributeType = SetAttributeType.of(StringAttributeType.of());
    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);
    // 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) SetAttributeType(io.sphere.sdk.products.attributes.SetAttributeType) Test(org.junit.jupiter.api.Test)

Example 48 with ProductTypeSyncOptions

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

the class ProductTypeReferenceResolverTest method resolveReferences_WithNoNestedTypeReferences_ShouldResolveReferences.

@Test
void resolveReferences_WithNoNestedTypeReferences_ShouldResolveReferences() {
    // preparation
    final AttributeDefinitionDraft attributeDefinitionDraft = AttributeDefinitionDraftBuilder.of(StringAttributeType.of(), "string attr", ofEnglish("string attr label"), 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 ProductTypeDraftDsl expectedResolvedProductTypeDraft = ProductTypeDraftBuilder.of(productTypeDraft).attributes(singletonList(attributeDefinitionDraft)).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) ProductTypeDraft(io.sphere.sdk.producttypes.ProductTypeDraft) Test(org.junit.jupiter.api.Test)

Example 49 with ProductTypeSyncOptions

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

the class ProductTypeReferenceResolverTest 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 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 AttributeDefinitionDraft expectedResolvedAttrDef = AttributeDefinitionDraftBuilder.of(attributeDefinitionDraft).attributeType(expectedResolvedNestedAttributeType).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) Test(org.junit.jupiter.api.Test)

Example 50 with ProductTypeSyncOptions

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

the class ProductTypeReferenceResolverTest method resolveReferences_WithManyNestedTypeWithExistingProductTypeReference_ShouldResolveReferences.

@Test
void resolveReferences_WithManyNestedTypeWithExistingProductTypeReference_ShouldResolveReferences() {
    // preparation
    final NestedAttributeType nestedAttributeType = NestedAttributeType.of(ProductType.reference("x"));
    final AttributeDefinitionDraft attributeDefinitionDraft = AttributeDefinitionDraftBuilder.of(nestedAttributeType, "foo", ofEnglish("foo"), true).build();
    final ProductTypeDraft productTypeDraft = ProductTypeDraftBuilder.of("foo", "foo", "desc", asList(attributeDefinitionDraft, 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 AttributeDefinitionDraft expectedResolvedAttrDef = AttributeDefinitionDraftBuilder.of(attributeDefinitionDraft).attributeType(expectedResolvedNestedAttributeType).build();
    final ProductTypeDraftDsl expectedResolvedProductTypeDraft = ProductTypeDraftBuilder.of(productTypeDraft).attributes(asList(expectedResolvedAttrDef, 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) 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