use of com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder in project commercetools-sync-java by commercetools.
the class ResourceCustomUpdateActionUtilsTest method buildSetCustomFieldsUpdateActions_WithNoNewCustomFieldsInOldCustomFields_ShouldBuildUpdateActions.
@Test
void buildSetCustomFieldsUpdateActions_WithNoNewCustomFieldsInOldCustomFields_ShouldBuildUpdateActions() {
final Map<String, JsonNode> oldCustomFields = new HashMap<>();
final Map<String, JsonNode> newCustomFields = new HashMap<>();
newCustomFields.put("invisibleInShop", JsonNodeFactory.instance.booleanNode(true));
newCustomFields.put("backgroundColor", JsonNodeFactory.instance.objectNode().put("de", "rot"));
newCustomFields.put("url", JsonNodeFactory.instance.objectNode().put("domain", "domain.com"));
newCustomFields.put("size", JsonNodeFactory.instance.objectNode().put("cm", 34));
final List<UpdateAction<Category>> setCustomFieldsUpdateActions = buildSetCustomFieldsUpdateActions(oldCustomFields, newCustomFields, mock(Category.class), new CategoryCustomActionBuilder(), null, category -> null);
assertThat(setCustomFieldsUpdateActions).isNotNull();
assertThat(setCustomFieldsUpdateActions).isNotEmpty();
assertThat(setCustomFieldsUpdateActions).hasSize(4);
}
use of com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder in project commercetools-sync-java by commercetools.
the class ResourceCustomUpdateActionUtilsTest method buildSetCustomFieldsUpdateActions_WithDifferentOrderOfCustomFieldValues_ShouldNotBuildUpdateActions.
@Test
void buildSetCustomFieldsUpdateActions_WithDifferentOrderOfCustomFieldValues_ShouldNotBuildUpdateActions() {
final Map<String, JsonNode> oldCustomFields = new HashMap<>();
oldCustomFields.put("backgroundColor", JsonNodeFactory.instance.objectNode().put("de", "rot").put("es", "rojo"));
final Map<String, JsonNode> newCustomFields = new HashMap<>();
newCustomFields.put("backgroundColor", JsonNodeFactory.instance.objectNode().put("es", "rojo").put("de", "rot"));
final List<UpdateAction<Category>> setCustomFieldsUpdateActions = buildSetCustomFieldsUpdateActions(oldCustomFields, newCustomFields, mock(Category.class), new CategoryCustomActionBuilder(), null, category -> null);
assertThat(setCustomFieldsUpdateActions).isNotNull();
assertThat(setCustomFieldsUpdateActions).isEmpty();
}
use of com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder in project commercetools-sync-java by commercetools.
the class ResourceCustomUpdateActionUtilsTest method buildSetCustomFieldsUpdateActions_WithNullJsonNodeNewValueOfNewField_ShouldNotBuildAction.
@Test
void buildSetCustomFieldsUpdateActions_WithNullJsonNodeNewValueOfNewField_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", JsonNodeFactory.instance.nullNode());
// test
final List<UpdateAction<Category>> updateActions = buildSetCustomFieldsUpdateActions(new HashMap<>(), newCustomFieldsMap, mock(Asset.class), new CategoryCustomActionBuilder(), null, category -> null);
// assertion
assertThat(updateActions).isEmpty();
}
use of com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder in project commercetools-sync-java by commercetools.
the class ResourceCustomUpdateActionUtilsTest method buildResourceCustomUpdateActions_WithNullNewCustomFields_ShouldBuildUpdateActions.
@Test
void buildResourceCustomUpdateActions_WithNullNewCustomFields_ShouldBuildUpdateActions() {
final Category oldCategory = mock(Category.class);
final CustomFields oldCategoryCustomFields = mock(CustomFields.class);
when(oldCategory.getCustom()).thenReturn(oldCategoryCustomFields);
final CategoryDraft newCategoryDraft = mock(CategoryDraft.class);
when(newCategoryDraft.getCustom()).thenReturn(null);
final List<UpdateAction<Category>> updateActions = buildPrimaryResourceCustomUpdateActions(oldCategory, newCategoryDraft, new CategoryCustomActionBuilder(), categorySyncOptions);
// Should remove custom type from old category.
assertThat(errorMessages).isEmpty();
assertThat(exceptions).isEmpty();
assertThat(updateActions).isNotNull();
assertThat(updateActions).hasSize(1);
assertThat(updateActions.get(0)).isInstanceOf(SetCustomType.class);
}
use of com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder in project commercetools-sync-java by commercetools.
the class ResourceCustomUpdateActionUtilsTest 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<Category>> setCustomFieldsUpdateActions = buildSetCustomFieldsUpdateActions(oldCustomFields, newCustomFields, mock(Category.class), new CategoryCustomActionBuilder(), null, category -> null);
assertThat(setCustomFieldsUpdateActions).isNotNull();
assertThat(setCustomFieldsUpdateActions).isEmpty();
}
Aggregations