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