Search in sources :

Example 26 with CategoryCustomActionBuilder

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

the class ResourceCustomUpdateActionUtilsTest method buildResourceCustomUpdateActions_WithNullIds_ShouldCallSyncOptionsCallBack.

@Test
void buildResourceCustomUpdateActions_WithNullIds_ShouldCallSyncOptionsCallBack() {
    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);
    // Mock old Category
    final Category oldCategory = mock(Category.class);
    when(oldCategory.getId()).thenReturn("oldCategoryId");
    when(oldCategory.toReference()).thenReturn(Category.referenceOfId("oldCategoryId"));
    when(oldCategory.getCustom()).thenReturn(oldCustomFieldsMock);
    // Mock new Category
    final CategoryDraft newCategoryDraft = mock(CategoryDraft.class);
    when(newCategoryDraft.getCustom()).thenReturn(newCustomFieldsMock);
    final List<UpdateAction<Category>> updateActions = buildPrimaryResourceCustomUpdateActions(oldCategory, newCategoryDraft, new CategoryCustomActionBuilder(), categorySyncOptions);
    assertThat(errorMessages).hasSize(1);
    assertThat(exceptions).hasSize(1);
    assertThat(errorMessages.get(0)).isEqualTo("Failed to build custom fields update actions on the category" + " with id 'oldCategoryId'. Reason: Custom type ids are not set for both the old and new category.");
    assertThat(exceptions.get(0)).isInstanceOf(BuildUpdateActionException.class);
    assertThat(updateActions).isEmpty();
}
Also used : 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) UpdateAction(io.sphere.sdk.commands.UpdateAction) CategoryDraft(io.sphere.sdk.categories.CategoryDraft) 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