use of com.commercetools.sync.inventories.helpers.InventorySyncStatistics in project commercetools-sync-java by commercetools.
the class InventorySyncTest method sync_WithNotEnsuredChannels_ShouldNotSyncEntriesWithUnknownChannels.
@Test
void sync_WithNotEnsuredChannels_ShouldNotSyncEntriesWithUnknownChannels() {
final InventoryEntryDraft draftWithNewChannel = InventoryEntryDraftBuilder.of(SKU_3, QUANTITY_1, DATE_1, RESTOCKABLE_1, ResourceIdentifier.ofKey(KEY_3)).build();
final InventorySyncOptions options = getInventorySyncOptions(30, false);
final InventoryService inventoryService = getMockInventoryService(existingInventories, mock(InventoryEntry.class), mock(InventoryEntry.class));
final ChannelService channelService = mock(ChannelService.class);
when(channelService.fetchCachedChannelId(anyString())).thenReturn(completedFuture(Optional.empty()));
final InventorySync inventorySync = new InventorySync(options, inventoryService, channelService, mock(TypeService.class));
final InventorySyncStatistics stats = inventorySync.sync(singletonList(draftWithNewChannel)).toCompletableFuture().join();
assertThat(stats).hasValues(1, 0, 0, 1);
assertThat(errorCallBackMessages).hasSize(1);
assertThat(errorCallBackMessages.get(0)).isEqualTo(format("Failed to process the InventoryEntryDraft" + " with SKU:'%s'. Reason: %s: Failed to resolve supply channel resource identifier on" + " InventoryEntryDraft with SKU:'%s'. Reason: Channel with key '%s' does not exist.", SKU_3, ReferenceResolutionException.class.getCanonicalName(), SKU_3, KEY_3));
assertThat(errorCallBackExceptions).hasSize(1);
assertThat(errorCallBackExceptions.get(0)).isExactlyInstanceOf(CompletionException.class);
assertThat(errorCallBackExceptions.get(0).getCause()).isExactlyInstanceOf(ReferenceResolutionException.class);
}
use of com.commercetools.sync.inventories.helpers.InventorySyncStatistics in project commercetools-sync-java by commercetools.
the class InventorySyncTest method sync_WithExceptionWhenCreatingOrUpdatingEntries_ShouldNotSync.
@Test
void sync_WithExceptionWhenCreatingOrUpdatingEntries_ShouldNotSync() {
final InventorySyncOptions options = getInventorySyncOptions(3, false);
final InventoryService inventoryService = getMockInventoryService(existingInventories, mock(InventoryEntry.class), mock(InventoryEntry.class));
when(inventoryService.createInventoryEntry(any())).thenReturn(getCompletionStageWithException());
when(inventoryService.updateInventoryEntry(any(), any())).thenReturn(getCompletionStageWithException());
final InventorySync inventorySync = new InventorySync(options, inventoryService, createMockChannelService(), mock(TypeService.class));
final InventorySyncStatistics stats = inventorySync.sync(drafts).toCompletableFuture().join();
assertThat(stats).hasValues(7, 0, 0, 5);
assertThat(errorCallBackMessages).hasSize(5);
assertThat(errorCallBackExceptions).hasSize(5);
}
use of com.commercetools.sync.inventories.helpers.InventorySyncStatistics in project commercetools-sync-java by commercetools.
the class InventorySyncTest method sync_WithEnsuredChannels_ShouldCreateEntriesWithUnknownChannels.
@Test
void sync_WithEnsuredChannels_ShouldCreateEntriesWithUnknownChannels() {
final InventoryEntryDraft draftWithNewChannel = InventoryEntryDraftBuilder.of(SKU_3, QUANTITY_1, DATE_1, RESTOCKABLE_1, ResourceIdentifier.ofKey(KEY_3)).build();
final InventorySync inventorySync = getInventorySync(30, true);
final InventorySyncStatistics stats = inventorySync.sync(singletonList(draftWithNewChannel)).toCompletableFuture().join();
assertThat(stats).hasValues(1, 1, 0, 0);
assertThat(errorCallBackMessages).hasSize(0);
assertThat(errorCallBackExceptions).hasSize(0);
}
use of com.commercetools.sync.inventories.helpers.InventorySyncStatistics in project commercetools-sync-java by commercetools.
the class InventorySyncTest method getStatistics_ShouldReturnProperStatistics.
@Test
void getStatistics_ShouldReturnProperStatistics() {
// preparation
final InventorySync inventorySync = getInventorySync(30, false);
inventorySync.sync(drafts).toCompletableFuture().join();
// test
final InventorySyncStatistics stats = inventorySync.getStatistics();
// assertion
assertThat(stats).hasValues(7, 2, 3, 0);
assertThat(errorCallBackMessages).hasSize(0);
assertThat(errorCallBackExceptions).hasSize(0);
}
use of com.commercetools.sync.inventories.helpers.InventorySyncStatistics in project commercetools-sync-java by commercetools.
the class InventorySyncTest method sync_WithNewSupplyChannelAndEnsure_ShouldSync.
@Test
void sync_WithNewSupplyChannelAndEnsure_ShouldSync() {
final InventorySyncOptions options = getInventorySyncOptions(3, true);
final InventoryService inventoryService = getMockInventoryService(existingInventories, mock(InventoryEntry.class), mock(InventoryEntry.class));
final ChannelService channelService = getMockChannelService(getMockSupplyChannel(REF_3, KEY_3));
when(channelService.fetchCachedChannelId(anyString())).thenReturn(CompletableFuture.completedFuture(Optional.empty()));
final InventoryEntryDraft newInventoryDraft = InventoryEntryDraftBuilder.of(SKU_1, QUANTITY_1, DATE_1, RESTOCKABLE_1, ResourceIdentifier.ofKey(KEY_3)).build();
final InventorySync inventorySync = new InventorySync(options, inventoryService, channelService, mock(TypeService.class));
final InventorySyncStatistics stats = inventorySync.sync(singletonList(newInventoryDraft)).toCompletableFuture().join();
assertThat(stats).hasValues(1, 1, 0, 0);
assertThat(errorCallBackMessages).isEmpty();
assertThat(errorCallBackExceptions).isEmpty();
}
Aggregations