Search in sources :

Example 6 with CategoryCustomActionBuilder

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);
}
Also used : Category(io.sphere.sdk.categories.Category) HashMap(java.util.HashMap) UpdateAction(io.sphere.sdk.commands.UpdateAction) JsonNode(com.fasterxml.jackson.databind.JsonNode) LocalizedString(io.sphere.sdk.models.LocalizedString) CategoryCustomActionBuilder(com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder) Test(org.junit.jupiter.api.Test)

Example 7 with CategoryCustomActionBuilder

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();
}
Also used : Category(io.sphere.sdk.categories.Category) HashMap(java.util.HashMap) UpdateAction(io.sphere.sdk.commands.UpdateAction) JsonNode(com.fasterxml.jackson.databind.JsonNode) LocalizedString(io.sphere.sdk.models.LocalizedString) CategoryCustomActionBuilder(com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder) Test(org.junit.jupiter.api.Test)

Example 8 with CategoryCustomActionBuilder

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();
}
Also used : CustomFields(io.sphere.sdk.types.CustomFields) HashMap(java.util.HashMap) UpdateAction(io.sphere.sdk.commands.UpdateAction) Asset(io.sphere.sdk.models.Asset) JsonNode(com.fasterxml.jackson.databind.JsonNode) LocalizedString(io.sphere.sdk.models.LocalizedString) CategoryCustomActionBuilder(com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder) Test(org.junit.jupiter.api.Test)

Example 9 with CategoryCustomActionBuilder

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);
}
Also used : CustomFields(io.sphere.sdk.types.CustomFields) Category(io.sphere.sdk.categories.Category) UpdateAction(io.sphere.sdk.commands.UpdateAction) CategoryDraft(io.sphere.sdk.categories.CategoryDraft) CategoryCustomActionBuilder(com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder) Test(org.junit.jupiter.api.Test)

Example 10 with CategoryCustomActionBuilder

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();
}
Also used : Category(io.sphere.sdk.categories.Category) HashMap(java.util.HashMap) UpdateAction(io.sphere.sdk.commands.UpdateAction) JsonNode(com.fasterxml.jackson.databind.JsonNode) LocalizedString(io.sphere.sdk.models.LocalizedString) CategoryCustomActionBuilder(com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

CategoryCustomActionBuilder (com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder)26 Test (org.junit.jupiter.api.Test)26 UpdateAction (io.sphere.sdk.commands.UpdateAction)24 Category (io.sphere.sdk.categories.Category)21 JsonNode (com.fasterxml.jackson.databind.JsonNode)16 LocalizedString (io.sphere.sdk.models.LocalizedString)16 HashMap (java.util.HashMap)15 CustomFields (io.sphere.sdk.types.CustomFields)13 CustomFieldsDraft (io.sphere.sdk.types.CustomFieldsDraft)9 CategoryDraft (io.sphere.sdk.categories.CategoryDraft)7 SetCustomType (io.sphere.sdk.categories.commands.updateactions.SetCustomType)6 Asset (io.sphere.sdk.models.Asset)6 Type (io.sphere.sdk.types.Type)5 BooleanNode (com.fasterxml.jackson.databind.node.BooleanNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 SetCustomField (io.sphere.sdk.categories.commands.updateactions.SetCustomField)2 CategorySyncMockUtils (com.commercetools.sync.categories.CategorySyncMockUtils)1 CategorySyncOptions (com.commercetools.sync.categories.CategorySyncOptions)1 CategorySyncOptionsBuilder (com.commercetools.sync.categories.CategorySyncOptionsBuilder)1 BuildUpdateActionException (com.commercetools.sync.commons.exceptions.BuildUpdateActionException)1