use of com.commercetools.sync.producttypes.ProductTypeSyncOptions in project commercetools-sync-java by commercetools.
the class BuildAttributeDefinitionUpdateActionsTest method buildAttributesUpdateActions_WithNewLenumAndOldAsNonLenum_ShouldNotBuildActionsAndTriggerErrorCb.
@Test
void buildAttributesUpdateActions_WithNewLenumAndOldAsNonLenum_ShouldNotBuildActionsAndTriggerErrorCb() {
// preparation
final AttributeDefinitionDraft newDefinition = AttributeDefinitionDraftBuilder.of(LocalizedEnumAttributeType.of(LocalizedEnumValue.of("foo", ofEnglish("bar"))), "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"), StringAttributeType.of()).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_WithDifferentSetAttributeType_ShouldNotBuildActionsAndTriggerErrorCb.
@Test
void buildAttributesUpdateActions_WithDifferentSetAttributeType_ShouldNotBuildActionsAndTriggerErrorCb() {
// preparation
final AttributeDefinitionDraft newDefinition = AttributeDefinitionDraftBuilder.of(SetAttributeType.of(StringAttributeType.of()), "a", ofEnglish("new_label"), true).build();
final AttributeDefinition oldDefinition = AttributeDefinitionBuilder.of("a", ofEnglish("old_label"), SetAttributeType.of(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_WithDifferentNestedAttributeRefs_ShouldNotBuildActionsAndTriggerErrorCb.
@Test
void buildAttributesUpdateActions_WithDifferentNestedAttributeRefs_ShouldNotBuildActionsAndTriggerErrorCb() {
// preparation
final AttributeDefinition ofNestedType = AttributeDefinitionBuilder.of("nested", ofEnglish("label"), NestedAttributeType.of(ProductType.referenceOfId("foo"))).build();
final AttributeDefinition ofSetOfNestedType = AttributeDefinitionBuilder.of("set-of-nested", ofEnglish("label"), SetAttributeType.of(NestedAttributeType.of(ProductType.referenceOfId("foo")))).build();
final AttributeDefinition ofSetOfSetOfNestedType = AttributeDefinitionBuilder.of("set-of-set-of-nested", ofEnglish("label"), SetAttributeType.of(SetAttributeType.of(NestedAttributeType.of(ProductType.referenceOfId("foo"))))).build();
final AttributeDefinitionDraft ofNestedTypeDraft = AttributeDefinitionDraftBuilder.of(ofNestedType).attributeType(NestedAttributeType.of(ProductType.referenceOfId("bar"))).build();
final AttributeDefinitionDraft ofSetOfNestedTypeDraft = AttributeDefinitionDraftBuilder.of(ofSetOfNestedType).attributeType(SetAttributeType.of(NestedAttributeType.of(ProductType.referenceOfId("bar")))).build();
final AttributeDefinitionDraft ofSetOfSetOfNestedTypeDraft = AttributeDefinitionDraftBuilder.of(ofSetOfSetOfNestedType).attributeType(SetAttributeType.of(SetAttributeType.of(NestedAttributeType.of(ProductType.referenceOfId("bar"))))).build();
final ProductType oldProductType = mock(ProductType.class);
when(oldProductType.getAttributes()).thenReturn(asList(ofNestedType, ofSetOfNestedType, ofSetOfSetOfNestedType));
final ProductTypeDraft newProductTypeDraft = mock(ProductTypeDraft.class);
when(newProductTypeDraft.getAttributes()).thenReturn(asList(ofNestedTypeDraft, ofSetOfNestedTypeDraft, ofSetOfSetOfNestedTypeDraft));
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(oldProductType, newProductTypeDraft, 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='nested') 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_WithIdenticalNestedAttributeRefs_ShouldNotBuildActions.
@Test
void buildAttributesUpdateActions_WithIdenticalNestedAttributeRefs_ShouldNotBuildActions() {
// preparation
final AttributeDefinition ofNestedType = AttributeDefinitionBuilder.of("nested", ofEnglish("label"), NestedAttributeType.of(ProductType.referenceOfId("foo"))).build();
final AttributeDefinition ofSetOfNestedType = AttributeDefinitionBuilder.of("set-of-nested", ofEnglish("label"), SetAttributeType.of(NestedAttributeType.of(ProductType.referenceOfId("foo")))).build();
final AttributeDefinition ofSetOfSetOfNestedType = AttributeDefinitionBuilder.of("set-of-set-of-nested", ofEnglish("label"), SetAttributeType.of(SetAttributeType.of(NestedAttributeType.of(ProductType.referenceOfId("foo"))))).build();
final AttributeDefinitionDraft ofNestedTypeDraft = AttributeDefinitionDraftBuilder.of(ofNestedType).build();
final AttributeDefinitionDraft ofSetOfNestedTypeDraft = AttributeDefinitionDraftBuilder.of(ofSetOfNestedType).build();
final AttributeDefinitionDraft ofSetOfSetOfNestedTypeDraft = AttributeDefinitionDraftBuilder.of(ofSetOfSetOfNestedType).build();
final ProductType oldProductType = mock(ProductType.class);
when(oldProductType.getAttributes()).thenReturn(asList(ofNestedType, ofSetOfNestedType, ofSetOfSetOfNestedType));
final ProductTypeDraft newProductTypeDraft = mock(ProductTypeDraft.class);
when(newProductTypeDraft.getAttributes()).thenReturn(asList(ofNestedTypeDraft, ofSetOfNestedTypeDraft, ofSetOfSetOfNestedTypeDraft));
final ProductTypeSyncOptions syncOptions = ProductTypeSyncOptionsBuilder.of(mock(SphereClient.class)).build();
// test
final List<UpdateAction<ProductType>> updateActions = buildAttributesUpdateActions(oldProductType, newProductTypeDraft, syncOptions);
// assertions
assertThat(updateActions).isEmpty();
}
use of com.commercetools.sync.producttypes.ProductTypeSyncOptions in project commercetools-sync-java by commercetools.
the class ProductTypeServiceImplTest method fetchProductType_WithBadGateWayException_ShouldCompleteExceptionally.
@Test
void fetchProductType_WithBadGateWayException_ShouldCompleteExceptionally() {
// preparation
final SphereClient sphereClient = mock(SphereClient.class);
when(sphereClient.execute(any(ProductTypeQuery.class))).thenReturn(CompletableFutureUtils.exceptionallyCompletedFuture(new BadGatewayException()));
final ProductTypeSyncOptions syncOptions = ProductTypeSyncOptionsBuilder.of(sphereClient).build();
final ProductTypeService productTypeService = new ProductTypeServiceImpl(syncOptions);
// test
final CompletionStage<Optional<ProductType>> result = productTypeService.fetchProductType("foo");
// assertions
assertThat(result).failsWithin(1, TimeUnit.SECONDS).withThrowableOfType(ExecutionException.class).withCauseExactlyInstanceOf(BadGatewayException.class);
}
Aggregations