Search in sources :

Example 1 with CategoryCustomActionBuilder

use of com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder in project commercetools-sync-java by commercetools.

the class CategoryCustomUpdateActionUtilsTest method buildSetCustomFieldAction_WithCategoryResource_ShouldBuildCategoryUpdateAction.

@Test
void buildSetCustomFieldAction_WithCategoryResource_ShouldBuildCategoryUpdateAction() {
    final JsonNode customFieldValue = JsonNodeFactory.instance.textNode("foo");
    final String customFieldName = "name";
    final UpdateAction<Category> updateAction = new CategoryCustomActionBuilder().buildSetCustomFieldAction(null, null, customFieldName, customFieldValue);
    assertThat(updateAction).isInstanceOf(SetCustomField.class);
    assertThat((SetCustomField) updateAction).hasValues("setCustomField", customFieldName, customFieldValue);
}
Also used : Category(io.sphere.sdk.categories.Category) JsonNode(com.fasterxml.jackson.databind.JsonNode) CategoryCustomActionBuilder(com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder) SetCustomField(io.sphere.sdk.categories.commands.updateactions.SetCustomField) Test(org.junit.jupiter.api.Test)

Example 2 with CategoryCustomActionBuilder

use of com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder in project commercetools-sync-java by commercetools.

the class ResourceCustomUpdateActionUtilsTest method buildSetCustomFieldsUpdateActions_WithEmptyCustomFields_ShouldNotBuildUpdateActions.

@Test
void buildSetCustomFieldsUpdateActions_WithEmptyCustomFields_ShouldNotBuildUpdateActions() {
    final Map<String, JsonNode> oldCustomFields = new HashMap<>();
    final Map<String, JsonNode> newCustomFields = new HashMap<>();
    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 3 with CategoryCustomActionBuilder

use of com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder in project commercetools-sync-java by commercetools.

the class ResourceCustomUpdateActionUtilsTest method buildNonNullCustomFieldsUpdateActions_WithNullIds_ShouldThrowBuildUpdateActionException.

@Test
void buildNonNullCustomFieldsUpdateActions_WithNullIds_ShouldThrowBuildUpdateActionException() {
    final Reference<Type> categoryTypeReference = Type.referenceOfId(null);
    // Mock old CustomFields
    final CustomFields oldCustomFieldsMock = mock(CustomFields.class);
    when(oldCustomFieldsMock.getType()).thenReturn(categoryTypeReference);
    // Mock new CustomFieldsDraft
    final CustomFieldsDraft newCustomFieldsMock = mock(CustomFieldsDraft.class);
    when(newCustomFieldsMock.getType()).thenReturn(categoryTypeReference);
    final Category oldCategory = mock(Category.class);
    when(oldCategory.getId()).thenReturn("oldCategoryId");
    when(oldCategory.toReference()).thenReturn(Category.referenceOfId(null));
    assertThatThrownBy(() -> buildNonNullCustomFieldsUpdateActions(oldCustomFieldsMock, newCustomFieldsMock, oldCategory, new CategoryCustomActionBuilder(), null, Category::getId, category -> category.toReference().getTypeId(), category -> null, categorySyncOptions)).isInstanceOf(BuildUpdateActionException.class).hasMessageMatching("Custom type ids are not set for both the old and new category.");
    assertThat(errorMessages).isEmpty();
    assertThat(exceptions).isEmpty();
}
Also used : CustomFields(io.sphere.sdk.types.CustomFields) SetCustomType(io.sphere.sdk.categories.commands.updateactions.SetCustomType) BeforeEach(org.junit.jupiter.api.BeforeEach) Reference(io.sphere.sdk.models.Reference) SyncException(com.commercetools.sync.commons.exceptions.SyncException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CategorySyncMockUtils(com.commercetools.sync.categories.CategorySyncMockUtils) UpdateAction(io.sphere.sdk.commands.UpdateAction) HashMap(java.util.HashMap) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CategoryDraft(io.sphere.sdk.categories.CategoryDraft) CategoryDraftBuilder(io.sphere.sdk.categories.CategoryDraftBuilder) ArrayList(java.util.ArrayList) CustomUpdateActionUtils.buildNonNullCustomFieldsUpdateActions(com.commercetools.sync.commons.utils.CustomUpdateActionUtils.buildNonNullCustomFieldsUpdateActions) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Locale(java.util.Locale) Map(java.util.Map) CategoryCustomActionBuilder(com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder) SphereClient(io.sphere.sdk.client.SphereClient) JsonNode(com.fasterxml.jackson.databind.JsonNode) CustomUpdateActionUtils.buildSetCustomFieldsUpdateActions(com.commercetools.sync.commons.utils.CustomUpdateActionUtils.buildSetCustomFieldsUpdateActions) Category(io.sphere.sdk.categories.Category) SetCustomField(io.sphere.sdk.categories.commands.updateactions.SetCustomField) Mockito.when(org.mockito.Mockito.when) CategorySyncOptionsBuilder(com.commercetools.sync.categories.CategorySyncOptionsBuilder) UUID(java.util.UUID) String.format(java.lang.String.format) CategorySyncOptions(com.commercetools.sync.categories.CategorySyncOptions) Test(org.junit.jupiter.api.Test) LocalizedString(io.sphere.sdk.models.LocalizedString) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) List(java.util.List) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Optional(java.util.Optional) BooleanNode(com.fasterxml.jackson.databind.node.BooleanNode) Asset(io.sphere.sdk.models.Asset) CustomUpdateActionUtils.buildPrimaryResourceCustomUpdateActions(com.commercetools.sync.commons.utils.CustomUpdateActionUtils.buildPrimaryResourceCustomUpdateActions) BuildUpdateActionException(com.commercetools.sync.commons.exceptions.BuildUpdateActionException) Mockito.mock(org.mockito.Mockito.mock) ResourceIdentifier(io.sphere.sdk.models.ResourceIdentifier) Type(io.sphere.sdk.types.Type) SetCustomType(io.sphere.sdk.categories.commands.updateactions.SetCustomType) Type(io.sphere.sdk.types.Type) CustomFields(io.sphere.sdk.types.CustomFields) Category(io.sphere.sdk.categories.Category) BuildUpdateActionException(com.commercetools.sync.commons.exceptions.BuildUpdateActionException) CategoryCustomActionBuilder(com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) Test(org.junit.jupiter.api.Test)

Example 4 with CategoryCustomActionBuilder

use of com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder in project commercetools-sync-java by commercetools.

the class ResourceCustomUpdateActionUtilsTest method buildSetCustomFieldsUpdateActions_WithSameCustomFieldValues_ShouldNotBuildUpdateActions.

@Test
void buildSetCustomFieldsUpdateActions_WithSameCustomFieldValues_ShouldNotBuildUpdateActions() {
    final BooleanNode oldBooleanFieldValue = JsonNodeFactory.instance.booleanNode(true);
    final ObjectNode oldLocalizedFieldValue = JsonNodeFactory.instance.objectNode().put("de", "rot");
    final Map<String, JsonNode> oldCustomFields = new HashMap<>();
    oldCustomFields.put("invisibleInShop", oldBooleanFieldValue);
    oldCustomFields.put("backgroundColor", oldLocalizedFieldValue);
    final Map<String, JsonNode> newCustomFields = new HashMap<>();
    newCustomFields.put("invisibleInShop", oldBooleanFieldValue);
    newCustomFields.put("backgroundColor", oldLocalizedFieldValue);
    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) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) UpdateAction(io.sphere.sdk.commands.UpdateAction) JsonNode(com.fasterxml.jackson.databind.JsonNode) LocalizedString(io.sphere.sdk.models.LocalizedString) BooleanNode(com.fasterxml.jackson.databind.node.BooleanNode) CategoryCustomActionBuilder(com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder) Test(org.junit.jupiter.api.Test)

Example 5 with CategoryCustomActionBuilder

use of com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder in project commercetools-sync-java by commercetools.

the class ResourceCustomUpdateActionUtilsTest method buildNonNullCustomFieldsUpdateActions_WithNullOldCategoryTypeId_ShouldBuildUpdateActions.

@Test
void buildNonNullCustomFieldsUpdateActions_WithNullOldCategoryTypeId_ShouldBuildUpdateActions() throws BuildUpdateActionException {
    // Mock old CustomFields
    final CustomFields oldCustomFieldsMock = mock(CustomFields.class);
    when(oldCustomFieldsMock.getType()).thenReturn(Type.referenceOfId(null));
    // Mock new CustomFieldsDraft
    final CustomFieldsDraft newCustomFieldsMock = mock(CustomFieldsDraft.class);
    when(newCustomFieldsMock.getType()).thenReturn(Type.referenceOfId("categoryCustomTypeId"));
    final List<UpdateAction<Category>> updateActions = buildNonNullCustomFieldsUpdateActions(oldCustomFieldsMock, newCustomFieldsMock, mock(Category.class), new CategoryCustomActionBuilder(), null, Category::getId, category -> category.toReference().getTypeId(), category -> null, categorySyncOptions);
    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) CategoryCustomActionBuilder(com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder) CustomFieldsDraft(io.sphere.sdk.types.CustomFieldsDraft) 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