Search in sources :

Example 16 with InventorySyncOptions

use of com.commercetools.sync.inventories.InventorySyncOptions in project commercetools-sync-java by commercetools.

the class InventorySyncIT method sync_WithKeyToExistingSupplyChannelInPlaceOfId_ShouldUpdateInventory.

@Test
void sync_WithKeyToExistingSupplyChannelInPlaceOfId_ShouldUpdateInventory() {
    /*
     * Fetch existing Channel of key SUPPLY_CHANNEL_KEY_1 from target project.
     * This is done only for test assertion reasons, not necessary for sync.
     */
    final Optional<Channel> supplyChannel = getChannelByKey(CTP_TARGET_CLIENT, SUPPLY_CHANNEL_KEY_1);
    assertThat(supplyChannel).isNotEmpty();
    /*
     * Prepare InventoryEntryDraft of sku SKU_1 and reference to supply channel of key SUPPLY_CHANNEL_KEY_1.
     */
    final ResourceIdentifier<Channel> supplyChannelReference = ResourceIdentifier.ofKey(SUPPLY_CHANNEL_KEY_1);
    final InventoryEntryDraft newInventoryDraft = InventoryEntryDraftBuilder.of(SKU_1, QUANTITY_ON_STOCK_2, EXPECTED_DELIVERY_2, RESTOCKABLE_IN_DAYS_2, supplyChannelReference).build();
    // Ensure old entry values before sync.
    final Optional<InventoryEntry> oldInventoryBeforeSync = getInventoryEntryBySkuAndSupplyChannel(CTP_TARGET_CLIENT, SKU_1, supplyChannel.get().toReference());
    assertThat(oldInventoryBeforeSync).isPresent();
    assertValues(oldInventoryBeforeSync.get(), QUANTITY_ON_STOCK_1, EXPECTED_DELIVERY_1, RESTOCKABLE_IN_DAYS_1);
    // Prepare sync options and perform sync of draft to target project.
    final InventorySyncOptions inventorySyncOptions = InventorySyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
    final InventorySync inventorySync = new InventorySync(inventorySyncOptions);
    final InventorySyncStatistics inventorySyncStatistics = inventorySync.sync(singletonList(newInventoryDraft)).toCompletableFuture().join();
    assertThat(inventorySyncStatistics).hasValues(1, 0, 1, 0);
    // Ensure old entry values after sync.
    final Optional<InventoryEntry> oldInventoryAfterSync = getInventoryEntryBySkuAndSupplyChannel(CTP_TARGET_CLIENT, SKU_1, supplyChannel.get().toReference());
    assertThat(oldInventoryAfterSync).isPresent();
    assertValues(oldInventoryAfterSync.get(), QUANTITY_ON_STOCK_2, EXPECTED_DELIVERY_2, RESTOCKABLE_IN_DAYS_2);
}
Also used : InventoryEntryDraft(io.sphere.sdk.inventory.InventoryEntryDraft) InventorySync(com.commercetools.sync.inventories.InventorySync) Channel(io.sphere.sdk.channels.Channel) InventoryITUtils.getInventoryEntryBySkuAndSupplyChannel(com.commercetools.sync.integration.inventories.utils.InventoryITUtils.getInventoryEntryBySkuAndSupplyChannel) InventorySyncStatistics(com.commercetools.sync.inventories.helpers.InventorySyncStatistics) InventoryEntry(io.sphere.sdk.inventory.InventoryEntry) InventorySyncOptions(com.commercetools.sync.inventories.InventorySyncOptions) Test(org.junit.jupiter.api.Test)

Aggregations

InventorySyncOptions (com.commercetools.sync.inventories.InventorySyncOptions)16 InventoryEntryDraft (io.sphere.sdk.inventory.InventoryEntryDraft)15 Test (org.junit.jupiter.api.Test)14 InventorySync (com.commercetools.sync.inventories.InventorySync)13 InventorySyncStatistics (com.commercetools.sync.inventories.helpers.InventorySyncStatistics)13 InventoryEntry (io.sphere.sdk.inventory.InventoryEntry)12 InventoryITUtils.getInventoryEntryBySkuAndSupplyChannel (com.commercetools.sync.integration.inventories.utils.InventoryITUtils.getInventoryEntryBySkuAndSupplyChannel)6 Channel (io.sphere.sdk.channels.Channel)6 UpdateAction (io.sphere.sdk.commands.UpdateAction)5 SyncException (com.commercetools.sync.commons.exceptions.SyncException)4 QuadConsumer (com.commercetools.sync.commons.utils.QuadConsumer)4 InventorySyncOptionsBuilder (com.commercetools.sync.inventories.InventorySyncOptionsBuilder)4 ChannelQuery (io.sphere.sdk.channels.queries.ChannelQuery)4 InventoryEntryQuery (io.sphere.sdk.inventory.queries.InventoryEntryQuery)4 AssertionsForStatistics.assertThat (com.commercetools.sync.commons.asserts.statistics.AssertionsForStatistics.assertThat)3 ChannelITUtils.deleteChannelsFromTargetAndSource (com.commercetools.sync.integration.commons.utils.ChannelITUtils.deleteChannelsFromTargetAndSource)3 ITUtils.deleteTypesFromTargetAndSource (com.commercetools.sync.integration.commons.utils.ITUtils.deleteTypesFromTargetAndSource)3 CTP_SOURCE_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_SOURCE_CLIENT)3 CTP_TARGET_CLIENT (com.commercetools.sync.integration.commons.utils.SphereClientUtils.CTP_TARGET_CLIENT)3 EXPECTED_DELIVERY_1 (com.commercetools.sync.integration.inventories.utils.InventoryITUtils.EXPECTED_DELIVERY_1)3