Search in sources :

Example 11 with ChannelService

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

the class InventorySyncTest method sync_WithOnlyDraftsToCreate_ShouldCallBeforeCreateCallback.

@Test
void sync_WithOnlyDraftsToCreate_ShouldCallBeforeCreateCallback() {
    // preparation
    final InventoryEntryDraft inventoryEntryDraft = InventoryEntryDraftBuilder.of("newSKU", 1L).build();
    final InventorySyncOptions optionsSpy = spy(getInventorySyncOptions(1, false));
    final InventoryService inventoryService = getMockInventoryService(existingInventories, mock(InventoryEntry.class), mock(InventoryEntry.class));
    final ChannelService channelService = getMockChannelService(getMockSupplyChannel(REF_3, KEY_3));
    final InventorySync inventorySync = new InventorySync(optionsSpy, inventoryService, channelService, mock(TypeService.class));
    // test
    inventorySync.sync(singletonList(inventoryEntryDraft)).toCompletableFuture().join();
    // assertion
    verify(optionsSpy).applyBeforeCreateCallback(any());
    verify(optionsSpy, never()).applyBeforeUpdateCallback(any(), any(), any());
}
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) 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 ChannelService

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

the class InventorySyncMockUtils method getMockChannelService.

/**
 * Returns mock instance of {@link InventoryService} with the specified parameters as mock results
 * of calling the {@link ChannelService#createAndCacheChannel(String)} and {@link
 * ChannelService#fetchCachedChannelId(String)} (String)} of the mock channel service.
 *
 * @param createdSupplyChannel result of future resulting from calling {@link
 *     ChannelService#createAndCacheChannel(String)}
 * @return mock instance of {@link InventoryService}.
 */
public static ChannelService getMockChannelService(@Nonnull final Channel createdSupplyChannel) {
    final String createdSupplyChannelId = createdSupplyChannel.getId();
    final ChannelService channelService = mock(ChannelService.class);
    when(channelService.fetchCachedChannelId(anyString())).thenReturn(completedFuture(Optional.of(createdSupplyChannelId)));
    when(channelService.createAndCacheChannel(any())).thenReturn(completedFuture(Optional.of(createdSupplyChannel)));
    return channelService;
}
Also used : ChannelService(com.commercetools.sync.services.ChannelService) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

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