use of com.commercetools.sync.products.helpers.AssetCustomActionBuilder in project commercetools-sync-java by commercetools.
the class CustomUpdateActionUtilsTest method buildSetCustomFieldsUpdateActions_WithNullJsonNodeNewValue_ShouldBuildAction.
@Test
void buildSetCustomFieldsUpdateActions_WithNullJsonNodeNewValue_ShouldBuildAction() {
// preparation
final Map<String, JsonNode> oldCustomFieldsMap = new HashMap<>();
oldCustomFieldsMap.put("setOfBooleans", JsonNodeFactory.instance.arrayNode().add(JsonNodeFactory.instance.booleanNode(false)));
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.nullNode());
// 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", null, true));
}
use of com.commercetools.sync.products.helpers.AssetCustomActionBuilder in project commercetools-sync-java by commercetools.
the class CustomUpdateActionUtilsTest method buildCustomUpdateActions_WithNullNewCustomFields_ShouldBuildUpdateActions.
@Test
void buildCustomUpdateActions_WithNullNewCustomFields_ShouldBuildUpdateActions() {
final Asset oldAsset = mock(Asset.class);
final String oldAssetId = "oldAssetId";
when(oldAsset.getId()).thenReturn(oldAssetId);
when(oldAsset.getCustom()).thenReturn(mock(CustomFields.class));
final AssetDraft newAssetDraft = AssetDraftBuilder.of(emptyList(), ofEnglish("assetName")).custom(null).build();
final List<UpdateAction<Product>> updateActions = buildCustomUpdateActions(maiNewResource, oldAsset, newAssetDraft, new AssetCustomActionBuilder(), 10, Asset::getId, asset -> Asset.resourceTypeId(), Asset::getKey, ProductSyncOptionsBuilder.of(CTP_CLIENT).build());
// Should remove custom type from old asset.
assertThat(updateActions).isNotNull();
assertThat(updateActions).hasSize(1);
assertThat(updateActions.get(0)).isInstanceOf(SetAssetCustomType.class);
}
use of com.commercetools.sync.products.helpers.AssetCustomActionBuilder in project commercetools-sync-java by commercetools.
the class CustomUpdateActionUtilsTest method buildSetCustomFieldsUpdateActions_WithEmptyArrayAsDiffValue_ShouldBuildSetAction.
@Test
void buildSetCustomFieldsUpdateActions_WithEmptyArrayAsDiffValue_ShouldBuildSetAction() {
// preparation
final Map<String, JsonNode> oldCustomFieldsMap = new HashMap<>();
oldCustomFieldsMap.put("setOfBooleans", JsonNodeFactory.instance.arrayNode().add(JsonNodeFactory.instance.booleanNode(false)));
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_WithEmptyCustomFieldValues_ShouldNotBuildUpdateActions.
@Test
void buildSetCustomFieldsUpdateActions_WithEmptyCustomFieldValues_ShouldNotBuildUpdateActions() {
final Map<String, JsonNode> oldCustomFields = new HashMap<>();
oldCustomFields.put("backgroundColor", JsonNodeFactory.instance.objectNode());
final Map<String, JsonNode> newCustomFields = new HashMap<>();
newCustomFields.put("backgroundColor", JsonNodeFactory.instance.objectNode());
final List<UpdateAction<Product>> updateActions = buildSetCustomFieldsUpdateActions(oldCustomFields, newCustomFields, mock(Asset.class), new AssetCustomActionBuilder(), 1, Asset::getId);
assertThat(updateActions).isNotNull();
assertThat(updateActions).isEmpty();
}
use of com.commercetools.sync.products.helpers.AssetCustomActionBuilder in project commercetools-sync-java by commercetools.
the class CustomUpdateActionUtilsTest method buildSetCustomFieldsUpdateActions_WithEmptyArrayAsNewValue_ShouldBuildSetAction.
@Test
void buildSetCustomFieldsUpdateActions_WithEmptyArrayAsNewValue_ShouldBuildSetAction() {
// 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", JsonNodeFactory.instance.arrayNode());
// test
final List<UpdateAction<Product>> updateActions = buildSetCustomFieldsUpdateActions(new HashMap<>(), newCustomFieldsMap, mock(Asset.class), new AssetCustomActionBuilder(), 1, Asset::getId);
// assertion
assertThat(updateActions).containsExactly(SetAssetCustomField.ofVariantIdUsingJsonAndAssetKey(1, oldAsset.getKey(), "setOfBooleans", JsonNodeFactory.instance.arrayNode(), true));
}
Aggregations