use of com.commercetools.sync.producttypes.ProductTypeSyncOptions in project commercetools-sync-java by commercetools.
the class BuildAttributeDefinitionUpdateActionsTest method buildAttributesUpdateActions_WithDuplicateAttributeNames_ShouldNotBuildActionsAndTriggerErrorCb.
@Test
void buildAttributesUpdateActions_WithDuplicateAttributeNames_ShouldNotBuildActionsAndTriggerErrorCb() {
final ProductType oldProductType = readObjectFromResource(PRODUCT_TYPE_WITH_ATTRIBUTES_ABC, ProductType.class);
final ProductTypeDraft newProductTypeDraft = readObjectFromResource(PRODUCT_TYPE_WITH_ATTRIBUTES_ABB, ProductTypeDraft.class);
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();
final List<UpdateAction<ProductType>> updateActions = buildAttributesUpdateActions(oldProductType, newProductTypeDraft, syncOptions);
assertThat(updateActions).isEmpty();
assertThat(errorMessages).hasSize(1);
assertThat(errorMessages.get(0)).matches("Failed to build update actions for the attributes definitions of the " + "product type with the key 'key'. Reason: .*DuplicateNameException: Attribute definitions drafts " + "have duplicated names. Duplicated attribute definition name: 'b'. Attribute definitions names are " + "expected to be unique inside their product type.");
assertThat(exceptions).hasSize(1);
assertThat(exceptions.get(0)).isExactlyInstanceOf(BuildUpdateActionException.class);
assertThat(exceptions.get(0).getMessage()).contains("Attribute definitions drafts have duplicated names. " + "Duplicated attribute definition name: 'b'. Attribute definitions names are expected to be unique " + "inside their product type.");
assertThat(exceptions.get(0).getCause()).isExactlyInstanceOf(DuplicateNameException.class);
}
Aggregations