use of com.commercetools.sync.products.helpers.AssetCustomActionBuilder in project commercetools-sync-java by commercetools.
the class CustomUpdateActionUtilsTest method buildNonNullCustomFieldsUpdateActions_WithBothNullCustomFields_ShouldNotBuildUpdateActions.
@Test
void buildNonNullCustomFieldsUpdateActions_WithBothNullCustomFields_ShouldNotBuildUpdateActions() {
final Asset oldAsset = mock(Asset.class);
when(oldAsset.getCustom()).thenReturn(null);
final AssetDraft newAssetDraft = mock(AssetDraft.class);
when(newAssetDraft.getCustom()).thenReturn(null);
// Mock custom options error callback
final ArrayList<Object> callBackResponses = new ArrayList<>();
final QuadConsumer<SyncException, Optional<ProductDraft>, Optional<ProductProjection>, List<UpdateAction<Product>>> errorCallback = (exception, newResource, oldResource, updateActions) -> {
callBackResponses.add(exception.getMessage());
callBackResponses.add(exception.getCause());
};
// Mock sync options
final ProductSyncOptions productSyncOptions = ProductSyncOptionsBuilder.of(CTP_CLIENT).errorCallback(errorCallback).build();
final List<UpdateAction<Product>> updateActions = buildCustomUpdateActions(maiNewResource, oldAsset, newAssetDraft, new AssetCustomActionBuilder(), 10, Asset::getId, asset -> Asset.resourceTypeId(), Asset::getKey, productSyncOptions);
assertThat(updateActions).isNotNull();
assertThat(updateActions).isEmpty();
assertThat(callBackResponses).isEmpty();
}
use of com.commercetools.sync.products.helpers.AssetCustomActionBuilder in project commercetools-sync-java by commercetools.
the class CustomUpdateActionUtilsTest method buildSetCustomFieldsUpdateActions_WithEmptyArrayAndNullNodeOldValue_ShouldBuildSetAction.
@Test
void buildSetCustomFieldsUpdateActions_WithEmptyArrayAndNullNodeOldValue_ShouldBuildSetAction() {
// preparation
final Map<String, JsonNode> oldCustomFieldsMap = new HashMap<>();
oldCustomFieldsMap.put("setOfBooleans", JsonNodeFactory.instance.nullNode());
final CustomFields oldCustomFields = mock(CustomFields.class);
when(oldCustomFields.getFieldsJsonMap()).thenReturn(oldCustomFieldsMap);
final Asset oldAsset = mock(Asset.class);
when(oldAsset.getCustom()).thenReturn(oldCustomFields);
final Map<String, JsonNode> newCustomFieldsMap = new HashMap<>();
newCustomFieldsMap.put("setOfBooleans", JsonNodeFactory.instance.arrayNode());
// test
final List<UpdateAction<Product>> updateActions = buildSetCustomFieldsUpdateActions(oldCustomFieldsMap, newCustomFieldsMap, mock(Asset.class), new AssetCustomActionBuilder(), 1, Asset::getId);
// assertion
assertThat(updateActions).containsExactly(SetAssetCustomField.ofVariantIdUsingJsonAndAssetKey(1, oldAsset.getKey(), "setOfBooleans", JsonNodeFactory.instance.arrayNode(), true));
}
use of com.commercetools.sync.products.helpers.AssetCustomActionBuilder in project commercetools-sync-java by commercetools.
the class CustomUpdateActionUtilsTest method buildSetCustomFieldsUpdateActions_WithNullNewValueOfNewField_ShouldNotBuildAction.
@Test
void buildSetCustomFieldsUpdateActions_WithNullNewValueOfNewField_ShouldNotBuildAction() {
// preparation
final CustomFields oldCustomFields = mock(CustomFields.class);
when(oldCustomFields.getFieldsJsonMap()).thenReturn(new HashMap<>());
final Asset oldAsset = mock(Asset.class);
when(oldAsset.getCustom()).thenReturn(oldCustomFields);
final Map<String, JsonNode> newCustomFieldsMap = new HashMap<>();
newCustomFieldsMap.put("setOfBooleans", null);
// test
final List<UpdateAction<Product>> updateActions = buildSetCustomFieldsUpdateActions(new HashMap<>(), newCustomFieldsMap, mock(Asset.class), new AssetCustomActionBuilder(), 1, Asset::getId);
// assertion
assertThat(updateActions).isEmpty();
}
use of com.commercetools.sync.products.helpers.AssetCustomActionBuilder in project commercetools-sync-java by commercetools.
the class ProductAssetCustomUpdateActionUtilsTest method buildTypedSetCustomTypeUpdateAction_WithProductAsset_ShouldBuildProductUpdateAction.
@Test
void buildTypedSetCustomTypeUpdateAction_WithProductAsset_ShouldBuildProductUpdateAction() {
final Asset asset = mock(Asset.class);
when(asset.getKey()).thenReturn("assetKey");
final String newCustomTypeId = UUID.randomUUID().toString();
final int variantId = 1;
final UpdateAction<Product> updateAction = buildTypedSetCustomTypeUpdateAction(newCustomTypeId, new HashMap<>(), asset, new AssetCustomActionBuilder(), variantId, Asset::getId, assetResource -> Asset.resourceTypeId(), Asset::getKey, ProductSyncOptionsBuilder.of(mock(SphereClient.class)).build()).orElse(null);
assertThat(updateAction).isInstanceOf(SetAssetCustomType.class);
assertThat((SetAssetCustomType) updateAction).hasValues("setAssetCustomType", asset.getId(), null, variantId, true, emptyMap(), ofId(newCustomTypeId));
}
use of com.commercetools.sync.products.helpers.AssetCustomActionBuilder in project commercetools-sync-java by commercetools.
the class ProductAssetCustomUpdateActionUtilsTest method buildSetCustomFieldAction_WithProductAsset_ShouldBuildProductUpdateAction.
@Test
void buildSetCustomFieldAction_WithProductAsset_ShouldBuildProductUpdateAction() {
final JsonNode customFieldValue = JsonNodeFactory.instance.textNode("foo");
final String customFieldName = "name";
final String assetKey = "assetKey";
final int variantId = 1;
final UpdateAction<Product> updateAction = new AssetCustomActionBuilder().buildSetCustomFieldAction(variantId, assetKey, customFieldName, customFieldValue);
assertThat(updateAction).isInstanceOf(SetAssetCustomField.class);
assertThat((SetAssetCustomField) updateAction).hasValues("setAssetCustomField", null, null, variantId, true, customFieldName, customFieldValue);
}
Aggregations