Search in sources :

Example 1 with ChannelService

use of com.commercetools.sync.services.ChannelService 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 ChannelService

use of com.commercetools.sync.services.ChannelService 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 ChannelService

use of com.commercetools.sync.services.ChannelService 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 4 with ChannelService

use of com.commercetools.sync.services.ChannelService 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)

Example 5 with ChannelService

use of com.commercetools.sync.services.ChannelService in project commercetools-sync-java by commercetools.

the class VariantReferenceResolverTest method setup.

@BeforeEach
void setup() {
    final TypeService typeService = getMockTypeService();
    final ChannelService channelService = getMockChannelService(getMockSupplyChannel(CHANNEL_ID, CHANNEL_KEY));
    final ProductSyncOptions syncOptions = ProductSyncOptionsBuilder.of(mock(SphereClient.class)).build();
    referenceResolver = new VariantReferenceResolver(syncOptions, typeService, channelService, mock(CustomerGroupService.class), getMockProductService(PRODUCT_ID), getMockProductTypeService(PRODUCT_TYPE_ID), getMockCategoryService(CATEGORY_ID), getMockCustomObjectService(CUSTOM_OBJECT_ID), getMockStateService(STATE_ID), getMockCustomerService(CUSTOMER_ID));
}
Also used : ChannelService(com.commercetools.sync.services.ChannelService) InventorySyncMockUtils.getMockChannelService(com.commercetools.sync.inventories.InventorySyncMockUtils.getMockChannelService) ProductSyncOptions(com.commercetools.sync.products.ProductSyncOptions) TypeService(com.commercetools.sync.services.TypeService) ProductSyncMockUtils.getMockProductTypeService(com.commercetools.sync.products.ProductSyncMockUtils.getMockProductTypeService) MockUtils.getMockTypeService(com.commercetools.sync.commons.MockUtils.getMockTypeService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ChannelService (com.commercetools.sync.services.ChannelService)12 InventorySyncMockUtils.getMockChannelService (com.commercetools.sync.inventories.InventorySyncMockUtils.getMockChannelService)11 TypeService (com.commercetools.sync.services.TypeService)10 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 InventoryEntry (io.sphere.sdk.inventory.InventoryEntry)9 Test (org.junit.jupiter.api.Test)9 InventoryEntryDraft (io.sphere.sdk.inventory.InventoryEntryDraft)8 InventorySyncStatistics (com.commercetools.sync.inventories.helpers.InventorySyncStatistics)7 MockUtils.getMockTypeService (com.commercetools.sync.commons.MockUtils.getMockTypeService)1 ProductSyncMockUtils.getMockProductTypeService (com.commercetools.sync.products.ProductSyncMockUtils.getMockProductTypeService)1 ProductSyncOptions (com.commercetools.sync.products.ProductSyncOptions)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1