use of com.commercetools.sync.producttypes.ProductTypeSyncOptions in project commercetools-sync-java by commercetools.
the class AttributeDefinitionReferenceResolverTest method resolveReferences_WithOneNestedTypeWithInvalidProductTypeReference_ShouldNotResolveReferences.
@Test
void resolveReferences_WithOneNestedTypeWithInvalidProductTypeReference_ShouldNotResolveReferences() {
// preparation
final NestedAttributeType nestedAttributeType = NestedAttributeType.of(ProductType.reference(""));
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)).failsWithin(1, TimeUnit.SECONDS).withThrowableOfType(ExecutionException.class).withCauseExactlyInstanceOf(ReferenceResolutionException.class).withMessageContaining("Failed to resolve references on attribute definition with name 'foo'");
}
use of com.commercetools.sync.producttypes.ProductTypeSyncOptions in project commercetools-sync-java by commercetools.
the class ProductTypeReferenceResolverTest method resolveReferences_WithNestedAndSetOfNestedTypeWithExistingProductTypeReference_ShouldResolveReferences.
@Test
void resolveReferences_WithNestedAndSetOfNestedTypeWithExistingProductTypeReference_ShouldResolveReferences() {
// preparation
final NestedAttributeType nestedAttributeType = NestedAttributeType.of(ProductType.reference("x"));
final SetAttributeType setAttributeType = SetAttributeType.of(nestedAttributeType);
final AttributeDefinitionDraft setAttributeDefinitionDraft = AttributeDefinitionDraftBuilder.of(setAttributeType, "foo", ofEnglish("foo"), true).build();
final AttributeDefinitionDraft nestedAttributeDefinitionDraft = AttributeDefinitionDraftBuilder.of(nestedAttributeType, "foo", ofEnglish("foo"), true).build();
final ProductTypeDraft productTypeDraft = ProductTypeDraftBuilder.of("foo", "foo", "desc", asList(setAttributeDefinitionDraft, nestedAttributeDefinitionDraft)).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 expectedResolvedSetAttributeType = SetAttributeType.of(expectedResolvedNestedAttributeType);
final AttributeDefinitionDraft expectedResolvedSetAttrDef = AttributeDefinitionDraftBuilder.of(setAttributeDefinitionDraft).attributeType(expectedResolvedSetAttributeType).build();
final AttributeDefinitionDraft expectedResolvedNestedAttrDef = AttributeDefinitionDraftBuilder.of(nestedAttributeDefinitionDraft).attributeType(expectedResolvedNestedAttributeType).build();
final ProductTypeDraftDsl expectedResolvedProductTypeDraft = ProductTypeDraftBuilder.of(productTypeDraft).attributes(asList(expectedResolvedSetAttrDef, expectedResolvedNestedAttrDef)).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_WithNoAttributes_ShouldNotResolveReferences.
@Test
void resolveReferences_WithNoAttributes_ShouldNotResolveReferences() {
// preparation
final ProductTypeDraft productTypeDraft = ProductTypeDraftBuilder.of("foo", "foo", "desc", emptyList()).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(emptyList()).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 BuildAttributeDefinitionUpdateActionsTest method buildAttributesUpdateActions_WithDifferentAttributeType_ShouldNotBuildActionsAndTriggerErrorCb.
@Test
void buildAttributesUpdateActions_WithDifferentAttributeType_ShouldNotBuildActionsAndTriggerErrorCb() {
// preparation
final AttributeDefinitionDraft newDefinition = AttributeDefinitionDraftBuilder.of(StringAttributeType.of(), "a", ofEnglish("new_label"), true).build();
final AttributeDefinition oldDefinition = AttributeDefinitionBuilder.of("a", ofEnglish("old_label"), LocalizedStringAttributeType.of()).isRequired(true).build();
final ProductTypeDraft productTypeDraft = ProductTypeDraftBuilder.of("foo", "name", "desc", singletonList(newDefinition)).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);
}
use of com.commercetools.sync.producttypes.ProductTypeSyncOptions in project commercetools-sync-java by commercetools.
the class BuildAttributeDefinitionUpdateActionsTest method buildAttributesUpdateActions_WithOldEnumAndNewAsNonEnum_ShouldNotBuildActionsAndTriggerErrorCb.
@Test
void buildAttributesUpdateActions_WithOldEnumAndNewAsNonEnum_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 LocalizedEnumAttributeType oldLenumType = LocalizedEnumAttributeType.of(singletonList(LocalizedEnumValue.of("foo", ofEnglish("bar"))));
final AttributeDefinition oldDefinition = AttributeDefinitionBuilder.of("a", ofEnglish("new_label"), oldLenumType).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