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);
}
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);
}
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());
}
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());
}
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);
}
Aggregations