use of com.commercetools.sync.commons.exceptions.SyncException in project commercetools-project-sync by commercetools.
the class SyncUtilsTest method logErrorCallbackWithResource_ShouldLogErrorWithCorrectMessage.
@Test
void logErrorCallbackWithResource_ShouldLogErrorWithCorrectMessage() {
final TestLogger testLogger = TestLoggerFactory.getTestLogger(SyncUtilsTest.class);
final SyncException exception = new SyncException("test sync exception");
final UpdateAction<WithKey> updateAction1 = mock(UpdateAction.class);
when(updateAction1.toString()).thenReturn("updateAction1");
final UpdateAction<WithKey> updateAction2 = mock(UpdateAction.class);
when(updateAction2.toString()).thenReturn("updateAction2");
final WithKey resource = mock(WithKey.class);
when(resource.getKey()).thenReturn("test identifier");
logErrorCallback(testLogger, "test resource", exception, Optional.of(resource), 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 SyncUtilsTest method logWarningCallbackWithResource_ShouldLogWarningWithCorrectMessage.
@Test
void logWarningCallbackWithResource_ShouldLogWarningWithCorrectMessage() {
final TestLogger testLogger = TestLoggerFactory.getTestLogger(SyncUtilsTest.class);
SyncException exception = new SyncException("test sync exception");
WithKey resource = mock(WithKey.class);
when(resource.getKey()).thenReturn("test identifier");
logWarningCallback(testLogger, "test resource", exception, Optional.of(resource));
assertThat(testLogger.getAllLoggingEvents()).hasSize(1);
final LoggingEvent loggingEvent = testLogger.getAllLoggingEvents().get(0);
assertThat(loggingEvent.getMessage()).isEqualTo("Warning when trying to sync test resource. Existing key: test identifier");
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 SyncUtilsTest method logErrorCallbackWithResourceAndNullUpdateActions_ShouldLogErrorWithCorrectMessage.
@Test
void logErrorCallbackWithResourceAndNullUpdateActions_ShouldLogErrorWithCorrectMessage() {
final TestLogger testLogger = TestLoggerFactory.getTestLogger(SyncUtilsTest.class);
final SyncException exception = new SyncException("test sync exception");
final WithKey resource = mock(WithKey.class);
when(resource.getKey()).thenReturn("test identifier");
logErrorCallback(testLogger, "test resource", exception, Optional.of(resource), null);
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: []");
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 ShoppingListSyncer method of.
public static ShoppingListSyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock) {
final QuadConsumer<SyncException, Optional<ShoppingListDraft>, Optional<ShoppingList>, List<UpdateAction<ShoppingList>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> logErrorCallback(LOGGER, "shoppingList", exception, oldResource.map(ShoppingList::getKey).orElse(IDENTIFIER_NOT_PRESENT), updateActions);
final TriConsumer<SyncException, Optional<ShoppingListDraft>, Optional<ShoppingList>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "shoppingList", exception, oldResource.map(ShoppingList::getKey).orElse(IDENTIFIER_NOT_PRESENT));
final ShoppingListSyncOptions shoppingListSyncOptions = ShoppingListSyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
final ShoppingListSync shoppingListSync = new ShoppingListSync(shoppingListSyncOptions);
final CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
return new ShoppingListSyncer(shoppingListSync, sourceClient, targetClient, customObjectService, clock);
}
use of com.commercetools.sync.commons.exceptions.SyncException in project commercetools-project-sync by commercetools.
the class CartDiscountSyncer method of.
@Nonnull
public static CartDiscountSyncer of(@Nonnull final SphereClient sourceClient, @Nonnull final SphereClient targetClient, @Nonnull final Clock clock) {
final QuadConsumer<SyncException, Optional<CartDiscountDraft>, Optional<CartDiscount>, List<UpdateAction<CartDiscount>>> logErrorCallback = (exception, newResourceDraft, oldResource, updateActions) -> logErrorCallback(LOGGER, "cart discount", exception, oldResource, updateActions);
final TriConsumer<SyncException, Optional<CartDiscountDraft>, Optional<CartDiscount>> logWarningCallback = (exception, newResourceDraft, oldResource) -> logWarningCallback(LOGGER, "cart discount", exception, oldResource);
final CartDiscountSyncOptions syncOptions = CartDiscountSyncOptionsBuilder.of(targetClient).errorCallback(logErrorCallback).warningCallback(logWarningCallback).build();
final CartDiscountSync cartDiscountSync = new CartDiscountSync(syncOptions);
final CustomObjectService customObjectService = new CustomObjectServiceImpl(targetClient);
return new CartDiscountSyncer(cartDiscountSync, sourceClient, targetClient, customObjectService, clock);
}
Aggregations