Search in sources :

Example 1 with SyncException

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);
}
Also used : LoggingEvent(uk.org.lidalia.slf4jtest.LoggingEvent) WithKey(io.sphere.sdk.models.WithKey) SyncException(com.commercetools.sync.commons.exceptions.SyncException) TestLogger(uk.org.lidalia.slf4jtest.TestLogger) Test(org.junit.jupiter.api.Test)

Example 2 with SyncException

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);
}
Also used : LoggingEvent(uk.org.lidalia.slf4jtest.LoggingEvent) WithKey(io.sphere.sdk.models.WithKey) SyncException(com.commercetools.sync.commons.exceptions.SyncException) TestLogger(uk.org.lidalia.slf4jtest.TestLogger) Test(org.junit.jupiter.api.Test)

Example 3 with SyncException

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);
}
Also used : LoggingEvent(uk.org.lidalia.slf4jtest.LoggingEvent) WithKey(io.sphere.sdk.models.WithKey) SyncException(com.commercetools.sync.commons.exceptions.SyncException) TestLogger(uk.org.lidalia.slf4jtest.TestLogger) Test(org.junit.jupiter.api.Test)

Example 4 with SyncException

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);
}
Also used : SyncException(com.commercetools.sync.commons.exceptions.SyncException) ShoppingListSyncOptions(com.commercetools.sync.shoppinglists.ShoppingListSyncOptions) LoggerFactory(org.slf4j.LoggerFactory) UpdateAction(io.sphere.sdk.commands.UpdateAction) QuadConsumer(com.commercetools.sync.commons.utils.QuadConsumer) ShoppingList(io.sphere.sdk.shoppinglists.ShoppingList) ShoppingListQuery(io.sphere.sdk.shoppinglists.queries.ShoppingListQuery) ShoppingListSyncOptionsBuilder(com.commercetools.sync.shoppinglists.ShoppingListSyncOptionsBuilder) SyncUtils.logWarningCallback(com.commercetools.project.sync.util.SyncUtils.logWarningCallback) SphereClient(io.sphere.sdk.client.SphereClient) TriConsumer(com.commercetools.sync.commons.utils.TriConsumer) Nonnull(javax.annotation.Nonnull) SyncUtils.logErrorCallback(com.commercetools.project.sync.util.SyncUtils.logErrorCallback) Logger(org.slf4j.Logger) ShoppingListSync(com.commercetools.sync.shoppinglists.ShoppingListSync) ShoppingListSyncStatistics(com.commercetools.sync.shoppinglists.helpers.ShoppingListSyncStatistics) IDENTIFIER_NOT_PRESENT(com.commercetools.project.sync.util.SyncUtils.IDENTIFIER_NOT_PRESENT) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) ShoppingListTransformUtils.toShoppingListDrafts(com.commercetools.sync.shoppinglists.utils.ShoppingListTransformUtils.toShoppingListDrafts) ShoppingListReferenceResolutionUtils.buildShoppingListQuery(com.commercetools.sync.shoppinglists.utils.ShoppingListReferenceResolutionUtils.buildShoppingListQuery) ShoppingListDraft(io.sphere.sdk.shoppinglists.ShoppingListDraft) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Syncer(com.commercetools.project.sync.Syncer) Clock(java.time.Clock) Optional(java.util.Optional) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) Optional(java.util.Optional) ShoppingList(io.sphere.sdk.shoppinglists.ShoppingList) ShoppingListSync(com.commercetools.sync.shoppinglists.ShoppingListSync) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) ShoppingListSyncOptions(com.commercetools.sync.shoppinglists.ShoppingListSyncOptions) ShoppingList(io.sphere.sdk.shoppinglists.ShoppingList) List(java.util.List) SyncException(com.commercetools.sync.commons.exceptions.SyncException)

Example 5 with SyncException

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);
}
Also used : SyncException(com.commercetools.sync.commons.exceptions.SyncException) CartDiscount(io.sphere.sdk.cartdiscounts.CartDiscount) LoggerFactory(org.slf4j.LoggerFactory) UpdateAction(io.sphere.sdk.commands.UpdateAction) CartDiscountSyncOptionsBuilder(com.commercetools.sync.cartdiscounts.CartDiscountSyncOptionsBuilder) QuadConsumer(com.commercetools.sync.commons.utils.QuadConsumer) CartDiscountQuery(io.sphere.sdk.cartdiscounts.queries.CartDiscountQuery) CartDiscountTransformUtils.toCartDiscountDrafts(com.commercetools.sync.cartdiscounts.utils.CartDiscountTransformUtils.toCartDiscountDrafts) CartDiscountSyncOptions(com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions) SyncUtils.logWarningCallback(com.commercetools.project.sync.util.SyncUtils.logWarningCallback) CartDiscountSyncStatistics(com.commercetools.sync.cartdiscounts.helpers.CartDiscountSyncStatistics) SphereClient(io.sphere.sdk.client.SphereClient) CartDiscountSync(com.commercetools.sync.cartdiscounts.CartDiscountSync) CartDiscountDraft(io.sphere.sdk.cartdiscounts.CartDiscountDraft) TriConsumer(com.commercetools.sync.commons.utils.TriConsumer) Nonnull(javax.annotation.Nonnull) SyncUtils.logErrorCallback(com.commercetools.project.sync.util.SyncUtils.logErrorCallback) Logger(org.slf4j.Logger) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Syncer(com.commercetools.project.sync.Syncer) Clock(java.time.Clock) Optional(java.util.Optional) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) CustomObjectService(com.commercetools.project.sync.service.CustomObjectService) CartDiscountSync(com.commercetools.sync.cartdiscounts.CartDiscountSync) Optional(java.util.Optional) CustomObjectServiceImpl(com.commercetools.project.sync.service.impl.CustomObjectServiceImpl) List(java.util.List) SyncException(com.commercetools.sync.commons.exceptions.SyncException) CartDiscount(io.sphere.sdk.cartdiscounts.CartDiscount) CartDiscountSyncOptions(com.commercetools.sync.cartdiscounts.CartDiscountSyncOptions) Nonnull(javax.annotation.Nonnull)

Aggregations

SyncException (com.commercetools.sync.commons.exceptions.SyncException)74 Nonnull (javax.annotation.Nonnull)47 UpdateAction (io.sphere.sdk.commands.UpdateAction)45 Optional (java.util.Optional)39 List (java.util.List)37 CompletionStage (java.util.concurrent.CompletionStage)25 SphereClient (io.sphere.sdk.client.SphereClient)24 String.format (java.lang.String.format)23 ArrayList (java.util.ArrayList)21 Map (java.util.Map)20 Test (org.junit.jupiter.api.Test)20 TriConsumer (com.commercetools.sync.commons.utils.TriConsumer)18 Set (java.util.Set)17 CompletableFuture (java.util.concurrent.CompletableFuture)17 Nullable (javax.annotation.Nullable)16 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)14 Category (io.sphere.sdk.categories.Category)13 BaseSync (com.commercetools.sync.commons.BaseSync)12 QuadConsumer (com.commercetools.sync.commons.utils.QuadConsumer)12