Search in sources :

Example 11 with InventorySyncStatistics

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);
}
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 12 with InventorySyncStatistics

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);
}
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 13 with InventorySyncStatistics

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);
}
Also used : InventoryEntryDraft(io.sphere.sdk.inventory.InventoryEntryDraft) InventorySyncStatistics(com.commercetools.sync.inventories.helpers.InventorySyncStatistics) Test(org.junit.jupiter.api.Test)

Example 14 with InventorySyncStatistics

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);
}
Also used : InventorySyncStatistics(com.commercetools.sync.inventories.helpers.InventorySyncStatistics) Test(org.junit.jupiter.api.Test)

Example 15 with InventorySyncStatistics

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();
}
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

InventorySyncStatistics (com.commercetools.sync.inventories.helpers.InventorySyncStatistics)26 Test (org.junit.jupiter.api.Test)26 InventoryEntryDraft (io.sphere.sdk.inventory.InventoryEntryDraft)22 InventoryEntry (io.sphere.sdk.inventory.InventoryEntry)19 InventorySync (com.commercetools.sync.inventories.InventorySync)12 InventorySyncOptions (com.commercetools.sync.inventories.InventorySyncOptions)12 InventorySyncMockUtils.getMockInventoryEntry (com.commercetools.sync.inventories.InventorySyncMockUtils.getMockInventoryEntry)9 InventorySyncMockUtils.getMockInventoryService (com.commercetools.sync.inventories.InventorySyncMockUtils.getMockInventoryService)9 InventoryService (com.commercetools.sync.services.InventoryService)9 TypeService (com.commercetools.sync.services.TypeService)9 InventorySyncMockUtils.getMockChannelService (com.commercetools.sync.inventories.InventorySyncMockUtils.getMockChannelService)8 ChannelService (com.commercetools.sync.services.ChannelService)8 Channel (io.sphere.sdk.channels.Channel)7 InventoryITUtils.getInventoryEntryBySkuAndSupplyChannel (com.commercetools.sync.integration.inventories.utils.InventoryITUtils.getInventoryEntryBySkuAndSupplyChannel)6 AssertionsForStatistics.assertThat (com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat)4 ChannelQuery (io.sphere.sdk.channels.queries.ChannelQuery)4 SyncException (com.commercetools.sync.commons.exceptions.SyncException)3 QuadConsumer (com.commercetools.sync.commons.utils.QuadConsumer)3 ChannelITUtils.deleteChannelsFromTargetAndSource (com.commercetools.sync.integration.commons.utils.ChannelITUtils.deleteChannelsFromTargetAndSource)3 ITUtils.deleteTypesFromTargetAndSource (com.commercetools.sync.integration.commons.utils.ITUtils.deleteTypesFromTargetAndSource)3