Search in sources :

Example 1 with AssetCustomActionBuilder

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

Example 2 with AssetCustomActionBuilder

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);
}
Also used : CustomFields(io.sphere.sdk.types.CustomFields) AssetDraft(io.sphere.sdk.models.AssetDraft) UpdateAction(io.sphere.sdk.commands.UpdateAction) AssetCustomActionBuilder(com.commercetools.sync.products.helpers.AssetCustomActionBuilder) Asset(io.sphere.sdk.models.Asset) Test(org.junit.jupiter.api.Test)

Example 3 with AssetCustomActionBuilder

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

Example 4 with AssetCustomActionBuilder

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

Example 5 with AssetCustomActionBuilder

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

Aggregations

AssetCustomActionBuilder (com.commercetools.sync.products.helpers.AssetCustomActionBuilder)20 Test (org.junit.jupiter.api.Test)20 UpdateAction (io.sphere.sdk.commands.UpdateAction)18 Asset (io.sphere.sdk.models.Asset)18 JsonNode (com.fasterxml.jackson.databind.JsonNode)16 HashMap (java.util.HashMap)15 CustomFields (io.sphere.sdk.types.CustomFields)14 SetAssetCustomType (io.sphere.sdk.products.commands.updateactions.SetAssetCustomType)7 AssetDraft (io.sphere.sdk.models.AssetDraft)6 Product (io.sphere.sdk.products.Product)6 SetAssetCustomField (io.sphere.sdk.products.commands.updateactions.SetAssetCustomField)5 SetProductPriceCustomType (io.sphere.sdk.products.commands.updateactions.SetProductPriceCustomType)5 CustomFieldsDraft (io.sphere.sdk.types.CustomFieldsDraft)5 Type (io.sphere.sdk.types.Type)5 ProductSyncOptionsBuilder (com.commercetools.sync.products.ProductSyncOptionsBuilder)4 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)4 SphereClient (io.sphere.sdk.client.SphereClient)4 CategorySyncOptions (com.commercetools.sync.categories.CategorySyncOptions)3 CategorySyncOptionsBuilder (com.commercetools.sync.categories.CategorySyncOptionsBuilder)3 CategoryCustomActionBuilder (com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder)3