Search in sources :

Example 1 with InventoryService

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);
}
Also used : InventoryEntryDraft(io.sphere.sdk.inventory.InventoryEntryDraft) ChannelService(com.commercetools.sync.services.ChannelService) InventorySyncMockUtils.getMockChannelService(com.commercetools.sync.inventories.InventorySyncMockUtils.getMockChannelService) InventorySyncMockUtils.getMockInventoryService(com.commercetools.sync.inventories.InventorySyncMockUtils.getMockInventoryService) InventoryService(com.commercetools.sync.services.InventoryService) InventorySyncStatistics(com.commercetools.sync.inventories.helpers.InventorySyncStatistics) InventoryEntry(io.sphere.sdk.inventory.InventoryEntry) InventorySyncMockUtils.getMockInventoryEntry(com.commercetools.sync.inventories.InventorySyncMockUtils.getMockInventoryEntry) TypeService(com.commercetools.sync.services.TypeService) Test(org.junit.jupiter.api.Test)

Example 2 with InventoryService

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);
}
Also used : InventoryEntryDraft(io.sphere.sdk.inventory.InventoryEntryDraft) ChannelService(com.commercetools.sync.services.ChannelService) InventorySyncMockUtils.getMockChannelService(com.commercetools.sync.inventories.InventorySyncMockUtils.getMockChannelService) InventorySyncMockUtils.getMockInventoryService(com.commercetools.sync.inventories.InventorySyncMockUtils.getMockInventoryService) InventoryService(com.commercetools.sync.services.InventoryService) InventorySyncStatistics(com.commercetools.sync.inventories.helpers.InventorySyncStatistics) InventoryEntry(io.sphere.sdk.inventory.InventoryEntry) InventorySyncMockUtils.getMockInventoryEntry(com.commercetools.sync.inventories.InventorySyncMockUtils.getMockInventoryEntry) TypeService(com.commercetools.sync.services.TypeService) Test(org.junit.jupiter.api.Test)

Example 3 with InventoryService

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);
}
Also used : InventorySyncMockUtils.getMockInventoryService(com.commercetools.sync.inventories.InventorySyncMockUtils.getMockInventoryService) InventoryService(com.commercetools.sync.services.InventoryService) InventorySyncStatistics(com.commercetools.sync.inventories.helpers.InventorySyncStatistics) InventoryEntry(io.sphere.sdk.inventory.InventoryEntry) InventorySyncMockUtils.getMockInventoryEntry(com.commercetools.sync.inventories.InventorySyncMockUtils.getMockInventoryEntry) TypeService(com.commercetools.sync.services.TypeService) Test(org.junit.jupiter.api.Test)

Example 4 with InventoryService

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();
}
Also used : InventoryEntryDraft(io.sphere.sdk.inventory.InventoryEntryDraft) ChannelService(com.commercetools.sync.services.ChannelService) InventorySyncMockUtils.getMockChannelService(com.commercetools.sync.inventories.InventorySyncMockUtils.getMockChannelService) InventorySyncMockUtils.getMockInventoryService(com.commercetools.sync.inventories.InventorySyncMockUtils.getMockInventoryService) InventoryService(com.commercetools.sync.services.InventoryService) InventorySyncStatistics(com.commercetools.sync.inventories.helpers.InventorySyncStatistics) InventoryEntry(io.sphere.sdk.inventory.InventoryEntry) InventorySyncMockUtils.getMockInventoryEntry(com.commercetools.sync.inventories.InventorySyncMockUtils.getMockInventoryEntry) TypeService(com.commercetools.sync.services.TypeService) Test(org.junit.jupiter.api.Test)

Example 5 with InventoryService

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);
}
Also used : InventoryEntryDraft(io.sphere.sdk.inventory.InventoryEntryDraft) ChannelService(com.commercetools.sync.services.ChannelService) InventorySyncMockUtils.getMockChannelService(com.commercetools.sync.inventories.InventorySyncMockUtils.getMockChannelService) InventorySyncMockUtils.getMockInventoryService(com.commercetools.sync.inventories.InventorySyncMockUtils.getMockInventoryService) InventoryService(com.commercetools.sync.services.InventoryService) InventorySyncStatistics(com.commercetools.sync.inventories.helpers.InventorySyncStatistics) InventoryEntry(io.sphere.sdk.inventory.InventoryEntry) InventorySyncMockUtils.getMockInventoryEntry(com.commercetools.sync.inventories.InventorySyncMockUtils.getMockInventoryEntry) TypeService(com.commercetools.sync.services.TypeService) Test(org.junit.jupiter.api.Test)

Aggregations

InventoryService (com.commercetools.sync.services.InventoryService)12 InventorySyncMockUtils.getMockInventoryEntry (com.commercetools.sync.inventories.InventorySyncMockUtils.getMockInventoryEntry)11 InventorySyncMockUtils.getMockInventoryService (com.commercetools.sync.inventories.InventorySyncMockUtils.getMockInventoryService)11 TypeService (com.commercetools.sync.services.TypeService)11 InventoryEntry (io.sphere.sdk.inventory.InventoryEntry)11 Test (org.junit.jupiter.api.Test)10 InventorySyncMockUtils.getMockChannelService (com.commercetools.sync.inventories.InventorySyncMockUtils.getMockChannelService)9 ChannelService (com.commercetools.sync.services.ChannelService)9 InventorySyncStatistics (com.commercetools.sync.inventories.helpers.InventorySyncStatistics)8 InventoryEntryDraft (io.sphere.sdk.inventory.InventoryEntryDraft)8 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1