Search in sources :

Example 26 with ProductTypeService

use of com.commercetools.sync.services.ProductTypeService 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 27 with ProductTypeService

use of com.commercetools.sync.services.ProductTypeService 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 28 with ProductTypeService

use of com.commercetools.sync.services.ProductTypeService 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)

Example 29 with ProductTypeService

use of com.commercetools.sync.services.ProductTypeService 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 30 with ProductTypeService

use of com.commercetools.sync.services.ProductTypeService 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)

Aggregations

ProductTypeService (com.commercetools.sync.services.ProductTypeService)32 Test (org.junit.jupiter.api.Test)31 ProductTypeDraft (io.sphere.sdk.producttypes.ProductTypeDraft)22 ProductTypeSyncOptions (com.commercetools.sync.producttypes.ProductTypeSyncOptions)20 AttributeDefinitionDraft (io.sphere.sdk.products.attributes.AttributeDefinitionDraft)20 SphereClient (io.sphere.sdk.client.SphereClient)18 NestedAttributeType (io.sphere.sdk.products.attributes.NestedAttributeType)18 ProductTypeQuery (io.sphere.sdk.producttypes.queries.ProductTypeQuery)16 Optional (java.util.Optional)16 ProductTypeServiceImpl (com.commercetools.sync.services.impl.ProductTypeServiceImpl)15 ProductType (io.sphere.sdk.producttypes.ProductType)15 ChangeName (io.sphere.sdk.producttypes.commands.updateactions.ChangeName)13 ArrayList (java.util.ArrayList)13 Collections (java.util.Collections)13 Collections.singleton (java.util.Collections.singleton)13 Collections.singletonList (java.util.Collections.singletonList)13 List (java.util.List)13 ProductTypeCreateCommand (io.sphere.sdk.producttypes.commands.ProductTypeCreateCommand)10 ProductTypeUpdateCommand (io.sphere.sdk.producttypes.commands.ProductTypeUpdateCommand)10 Assertions.as (org.assertj.core.api.Assertions.as)7