use of com.commercetools.sync.services.InventoryService 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.services.InventoryService 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.services.InventoryService 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.services.InventoryService 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();
}
use of com.commercetools.sync.services.InventoryService in project commercetools-sync-java by commercetools.
the class InventorySyncTest method sync_WithNoNewCreatedInventory_ShouldIncrementFailedStatic.
@Test
void sync_WithNoNewCreatedInventory_ShouldIncrementFailedStatic() {
final InventoryEntryDraft draftWithNewChannel = InventoryEntryDraftBuilder.of(SKU_3, QUANTITY_1, DATE_1, RESTOCKABLE_1, ResourceIdentifier.ofKey(KEY_3)).build();
final InventorySyncOptions options = getInventorySyncOptions(30, true);
final InventoryService inventoryService = getMockInventoryService(existingInventories, null, mock(InventoryEntry.class));
final ChannelService channelService = getMockChannelService(getMockSupplyChannel(REF_2, KEY_2));
InventorySync inventorySync = new InventorySync(options, inventoryService, channelService, mock(TypeService.class));
final InventorySyncStatistics stats = inventorySync.sync(singletonList(draftWithNewChannel)).toCompletableFuture().join();
assertThat(errorCallBackMessages).hasSize(0);
assertThat(errorCallBackExceptions).hasSize(0);
assertThat(stats).hasValues(1, 0, 0, 1);
}
Aggregations