use of com.commercetools.sync.inventories.helpers.InventoryCustomActionBuilder in project commercetools-sync-java by commercetools.
the class InventoryUpdateActionUtilsIT method buildCustomUpdateActions_ShouldBuildActionThatSetCustomField.
@Test
void buildCustomUpdateActions_ShouldBuildActionThatSetCustomField() {
// Fetch old inventory and ensure it has custom fields.
final Optional<InventoryEntry> oldInventoryOptional = getInventoryEntryBySkuAndSupplyChannel(CTP_TARGET_CLIENT, SKU_1, null);
assertThat(oldInventoryOptional).isNotEmpty();
final InventoryEntry oldInventoryBeforeSync = oldInventoryOptional.get();
assertThat(oldInventoryBeforeSync.getCustom()).isNotNull();
assertThat(oldInventoryBeforeSync.getCustom().getType().getObj()).isNotNull();
assertThat(oldInventoryBeforeSync.getCustom().getType().getObj().getKey()).isEqualTo(CUSTOM_TYPE);
// Prepare draft with updated data.
final CustomFieldsDraft customFieldsDraft = CustomFieldsDraftBuilder.ofTypeId(oldInventoryBeforeSync.getCustom().getType().getId()).addObject(CUSTOM_FIELD_NAME, CUSTOM_FIELD_VALUE).build();
final InventoryEntryDraft newInventory = InventoryEntryDraft.of(SKU_1, QUANTITY_ON_STOCK_2, EXPECTED_DELIVERY_2, RESTOCKABLE_IN_DAYS_2, null).withCustom(customFieldsDraft);
// Build update actions.
final InventorySyncOptions options = InventorySyncOptionsBuilder.of(CTP_TARGET_CLIENT).build();
final List<UpdateAction<InventoryEntry>> updateActions = buildPrimaryResourceCustomUpdateActions(oldInventoryBeforeSync, newInventory, new InventoryCustomActionBuilder(), options);
assertThat(updateActions).isNotEmpty();
// Execute update command and ensure returned entry is properly updated.
final InventoryEntry oldEntryAfterSync = CTP_TARGET_CLIENT.execute(InventoryEntryUpdateCommand.of(oldInventoryBeforeSync, updateActions)).toCompletableFuture().join();
assertThat(oldEntryAfterSync.getCustom()).isNotNull();
assertThat(oldEntryAfterSync.getCustom().getFieldAsString(CUSTOM_FIELD_NAME)).isEqualTo(CUSTOM_FIELD_VALUE);
}
use of com.commercetools.sync.inventories.helpers.InventoryCustomActionBuilder in project commercetools-sync-java by commercetools.
the class InventoryEntryCustomUpdateActionUtilsTest method buildSetCustomFieldAction_WithInventoryResource_ShouldBuildInventoryUpdateAction.
@Test
void buildSetCustomFieldAction_WithInventoryResource_ShouldBuildInventoryUpdateAction() {
final JsonNode customFieldValue = JsonNodeFactory.instance.textNode("foo");
final String customFieldName = "name";
final UpdateAction<InventoryEntry> updateAction = new InventoryCustomActionBuilder().buildSetCustomFieldAction(null, null, customFieldName, customFieldValue);
assertThat(updateAction).isInstanceOf(SetCustomField.class);
assertThat((SetCustomField) updateAction).hasValues("setCustomField", customFieldName, customFieldValue);
}
use of com.commercetools.sync.inventories.helpers.InventoryCustomActionBuilder in project commercetools-sync-java by commercetools.
the class InventoryEntryCustomUpdateActionUtilsTest method buildRemoveCustomTypeAction_WithInventoryResource_ShouldBuildChannelUpdateAction.
@Test
void buildRemoveCustomTypeAction_WithInventoryResource_ShouldBuildChannelUpdateAction() {
final UpdateAction<InventoryEntry> updateAction = new InventoryCustomActionBuilder().buildRemoveCustomTypeAction(null, null);
assertThat(updateAction).isInstanceOf(SetCustomType.class);
assertThat((SetCustomType) updateAction).hasValues("setCustomType", null, ofId(null));
}
Aggregations