use of com.commercetools.sync.inventories.helpers.InventorySyncStatistics in project commercetools-sync-java by commercetools.
the class InventorySyncIT method sync_WithBatchProcessing_ShouldCreateAllGivenInventories.
@Disabled
@Test
void sync_WithBatchProcessing_ShouldCreateAllGivenInventories() {
// Ensure inventory entries amount in target project before sync.
final List<InventoryEntry> oldEntriesBeforeSync = CTP_TARGET_CLIENT.execute(InventoryEntryQuery.of()).toCompletableFuture().join().getResults();
assertThat(oldEntriesBeforeSync).hasSize(2);
// Create 10 drafts of new inventories.
final List<InventoryEntryDraft> newInventories = LongStream.range(0, 10).mapToObj(l -> InventoryEntryDraftBuilder.of(String.valueOf(l), l).build()).collect(toList());
// Set batch size of number less that new inventories size.
final InventorySyncOptions inventorySyncOptions = InventorySyncOptionsBuilder.of(CTP_TARGET_CLIENT).batchSize(3).build();
final InventorySync inventorySync = new InventorySync(inventorySyncOptions);
// Perform sync and ensure its results.
final InventorySyncStatistics inventorySyncStatistics = inventorySync.sync(newInventories).toCompletableFuture().join();
assertThat(inventorySyncStatistics).hasValues(10, 10, 0, 0);
// Ensure inventory entries amount in target project after sync.
final List<InventoryEntry> oldEntriesAfterSync = CTP_TARGET_CLIENT.execute(InventoryEntryQuery.of()).toCompletableFuture().join().getResults();
assertThat(oldEntriesAfterSync).hasSize(12);
}
use of com.commercetools.sync.inventories.helpers.InventorySyncStatistics in project commercetools-sync-java by commercetools.
the class InventorySyncIT method sync_WithUpdatedInventory_ShouldUpdateInventory.
@Test
void sync_WithUpdatedInventory_ShouldUpdateInventory() {
// Ensure that old entry has correct values before sync.
final Optional<InventoryEntry> oldInventoryBeforeSync = getInventoryEntryBySkuAndSupplyChannel(CTP_TARGET_CLIENT, SKU_1, null);
assertThat(oldInventoryBeforeSync).isNotEmpty();
assertValues(oldInventoryBeforeSync.get(), QUANTITY_ON_STOCK_1, EXPECTED_DELIVERY_1, RESTOCKABLE_IN_DAYS_1);
// Prepare sync data.
final InventoryEntryDraft newInventoryDraft = InventoryEntryDraftBuilder.of(SKU_1, QUANTITY_ON_STOCK_2, EXPECTED_DELIVERY_2, RESTOCKABLE_IN_DAYS_2, null).build();
final InventorySyncOptions inventorySyncOptions = InventorySyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
final InventorySync inventorySync = new InventorySync(inventorySyncOptions);
// Sync and ensure that proper statistics were returned.
final InventorySyncStatistics inventorySyncStatistics = inventorySync.sync(singletonList(newInventoryDraft)).toCompletableFuture().join();
assertThat(inventorySyncStatistics).hasValues(1, 0, 1, 0);
// Ensure that old entry has correct values after sync.
final Optional<InventoryEntry> oldInventoryAfterSync = getInventoryEntryBySkuAndSupplyChannel(CTP_TARGET_CLIENT, SKU_1, null);
assertThat(oldInventoryAfterSync).isNotEmpty();
assertValues(oldInventoryAfterSync.get(), QUANTITY_ON_STOCK_2, EXPECTED_DELIVERY_2, RESTOCKABLE_IN_DAYS_2);
}
use of com.commercetools.sync.inventories.helpers.InventorySyncStatistics in project commercetools-sync-java by commercetools.
the class InventorySyncTest method sync_WithDraftsWithNullSku_ShouldNotSync.
@Test
void sync_WithDraftsWithNullSku_ShouldNotSync() {
final InventoryEntryDraft draftWithNullSku = InventoryEntryDraft.of(null, 12);
final InventorySync inventorySync = getInventorySync(30, false);
final InventorySyncStatistics stats = inventorySync.sync(singletonList(draftWithNullSku)).toCompletableFuture().join();
assertThat(stats).hasValues(1, 0, 0, 1);
assertThat(errorCallBackMessages).hasSize(1);
assertThat(errorCallBackMessages.get(0)).isEqualTo("InventoryEntryDraft doesn't have a SKU." + " Please make sure all inventory entry drafts have SKUs.");
assertThat(errorCallBackExceptions).hasSize(1);
assertThat(errorCallBackExceptions.get(0)).isEqualTo(null);
}
use of com.commercetools.sync.inventories.helpers.InventorySyncStatistics in project commercetools-sync-java by commercetools.
the class InventorySyncTest method sync_WithExceptionWhenCreatingNewSupplyChannel_ShouldTriggerErrorCallbackAndIncrementFailed.
@Test
void sync_WithExceptionWhenCreatingNewSupplyChannel_ShouldTriggerErrorCallbackAndIncrementFailed() {
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()));
when(channelService.createAndCacheChannel(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, 0, 0, 1);
assertThat(errorCallBackMessages).isNotEmpty();
assertThat(errorCallBackMessages.get(0)).contains(format("Failed to resolve supply channel resource identifier" + " on InventoryEntryDraft with SKU:'%s'. Reason: Failed to create supply channel with key: '%s'", SKU_1, "channel-key_3"));
assertThat(errorCallBackExceptions).isNotEmpty();
assertThat(errorCallBackExceptions.get(0)).isExactlyInstanceOf(CompletionException.class);
assertThat(errorCallBackExceptions.get(0).getCause()).isExactlyInstanceOf(ReferenceResolutionException.class);
assertThat(errorCallBackExceptions.get(0).getCause().getCause()).isExactlyInstanceOf(CompletionException.class);
}
use of com.commercetools.sync.inventories.helpers.InventorySyncStatistics in project commercetools-sync-java by commercetools.
the class InventorySyncTest method sync_WithEmptyList_ShouldNotSync.
@Test
void sync_WithEmptyList_ShouldNotSync() {
final InventorySync inventorySync = getInventorySync(30, false);
final InventorySyncStatistics stats = inventorySync.sync(emptyList()).toCompletableFuture().join();
assertThat(stats).hasValues(0, 0, 0, 0);
assertThat(errorCallBackMessages).hasSize(0);
assertThat(errorCallBackExceptions).hasSize(0);
}
Aggregations