use of com.commercetools.sync.commons.exceptions.SyncException in project commercetools-project-sync by commercetools.
the class SyncUtilsTest method logErrorCallbackWithStringResourceIdentifier_ShouldLogErrorWithCorrectMessage.
@Test
void logErrorCallbackWithStringResourceIdentifier_ShouldLogErrorWithCorrectMessage() {
final TestLogger testLogger = TestLoggerFactory.getTestLogger(SyncUtilsTest.class);
SyncException exception = new SyncException("test sync exception");
UpdateAction<ResourceView> updateAction1 = mock(UpdateAction.class);
when(updateAction1.toString()).thenReturn("updateAction1");
UpdateAction<ResourceView> updateAction2 = mock(UpdateAction.class);
when(updateAction2.toString()).thenReturn("updateAction2");
logErrorCallback(testLogger, "test resource", exception, "test identifier", Arrays.asList(updateAction1, updateAction2));
assertThat(testLogger.getAllLoggingEvents()).hasSize(1);
final LoggingEvent loggingEvent = testLogger.getAllLoggingEvents().get(0);
assertThat(loggingEvent.getMessage()).isEqualTo("Error when trying to sync test resource. Existing key: test identifier. Update actions: updateAction1,updateAction2");
assertThat(loggingEvent.getThrowable().isPresent()).isTrue();
assertThat(loggingEvent.getThrowable().get()).isInstanceOf(SyncException.class);
}
use of com.commercetools.sync.commons.exceptions.SyncException in project commercetools-project-sync by commercetools.
the class ProductSyncer method of.
@Nonnull
public static ProductSyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock, @Nullable final ProductSyncCustomRequest productSyncCustomRequest) {
final QuadConsumer<SyncException, Optional<ProductDraft>, Optional<ProductProjection>, List<UpdateAction<Product>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> {
final String resourceKey = oldResource.map(WithKey::getKey).orElse(IDENTIFIER_NOT_PRESENT);
logErrorCallback(LOGGER, "product", exception, resourceKey, updateActions);
};
final TriConsumer<SyncException, Optional<ProductDraft>, Optional<ProductProjection>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "product", exception, oldResource);
final ProductSyncOptions syncOptions = ProductSyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
final ProductSync productSync = new ProductSync(syncOptions);
final CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
return new ProductSyncer(productSync, sourceClient, targetClient, customObjectService, clock, productSyncCustomRequest);
}
use of com.commercetools.sync.commons.exceptions.SyncException in project commercetools-project-sync by commercetools.
the class ProductTypeSyncer method of.
@Nonnull
public static ProductTypeSyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock) {
final QuadConsumer<SyncException, Optional<ProductTypeDraft>, Optional<ProductType>, List<UpdateAction<ProductType>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> logErrorCallback(LOGGER, "product type", exception, oldResource, updateActions);
final TriConsumer<SyncException, Optional<ProductTypeDraft>, Optional<ProductType>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "product type", exception, oldResource);
final ProductTypeSyncOptions syncOptions = ProductTypeSyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
final ProductTypeSync productTypeSync = new ProductTypeSync(syncOptions);
final CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
return new ProductTypeSyncer(productTypeSync, sourceClient, targetClient, customObjectService, clock);
}
use of com.commercetools.sync.commons.exceptions.SyncException in project commercetools-project-sync by commercetools.
the class StateSyncer method of.
public static StateSyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock) {
final QuadConsumer<SyncException, Optional<StateDraft>, Optional<State>, List<UpdateAction<State>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> logErrorCallback(LOGGER, "state", exception, oldResource, updateActions);
final TriConsumer<SyncException, Optional<StateDraft>, Optional<State>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "state", exception, oldResource);
StateSyncOptions syncOptions = StateSyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
StateSync stateSync = new StateSync(syncOptions);
CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
return new StateSyncer(stateSync, sourceClient, targetClient, customObjectService, clock);
}
use of com.commercetools.sync.commons.exceptions.SyncException in project commercetools-project-sync by commercetools.
the class TaxCategorySyncer method of.
@Nonnull
public static TaxCategorySyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock) {
final QuadConsumer<SyncException, Optional<TaxCategoryDraft>, Optional<TaxCategory>, List<UpdateAction<TaxCategory>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> logErrorCallback(LOGGER, "tax category", exception, oldResource, updateActions);
final TriConsumer<SyncException, Optional<TaxCategoryDraft>, Optional<TaxCategory>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "tax category", exception, oldResource);
final TaxCategorySyncOptions syncOptions = TaxCategorySyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
final TaxCategorySync taxCategorySync = new TaxCategorySync(syncOptions);
final CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
return new TaxCategorySyncer(taxCategorySync, sourceClient, targetClient, customObjectService, clock);
}
Aggregations