use of com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder in project commercetools-sync-java by commercetools.
the class ResourceCustomUpdateActionUtilsTest method buildResourceCustomUpdateActions_WithNonNullCustomFieldsWithDifferentTypes_ShouldBuildUpdateActions.
@Test
void buildResourceCustomUpdateActions_WithNonNullCustomFieldsWithDifferentTypes_ShouldBuildUpdateActions() {
final Category oldCategory = mock(Category.class);
final CustomFields oldCategoryCustomFields = mock(CustomFields.class);
final Reference<Type> oldCategoryCustomFieldsDraftTypeReference = Type.referenceOfId("2");
when(oldCategoryCustomFields.getType()).thenReturn(oldCategoryCustomFieldsDraftTypeReference);
when(oldCategory.getCustom()).thenReturn(oldCategoryCustomFields);
final CategoryDraft newCategoryDraft = mock(CategoryDraft.class);
final CustomFieldsDraft newCategoryCustomFieldsDraft = mock(CustomFieldsDraft.class);
final ResourceIdentifier<Type> typeResourceIdentifier = Type.referenceOfId("1");
when(newCategoryCustomFieldsDraft.getType()).thenReturn(typeResourceIdentifier);
when(newCategoryDraft.getCustom()).thenReturn(newCategoryCustomFieldsDraft);
final List<UpdateAction<Category>> updateActions = buildPrimaryResourceCustomUpdateActions(oldCategory, newCategoryDraft, new CategoryCustomActionBuilder(), categorySyncOptions);
// Should set custom type of 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_WithDifferentCustomFieldValues_ShouldBuildUpdateActions.
@Test
void buildSetCustomFieldsUpdateActions_WithDifferentCustomFieldValues_ShouldBuildUpdateActions() {
final Map<String, JsonNode> oldCustomFields = new HashMap<>();
oldCustomFields.put("invisibleInShop", JsonNodeFactory.instance.booleanNode(false));
oldCustomFields.put("backgroundColor", JsonNodeFactory.instance.objectNode().put("de", "rot").put("en", "red"));
final Map<String, JsonNode> newCustomFields = new HashMap<>();
newCustomFields.put("invisibleInShop", JsonNodeFactory.instance.booleanNode(true));
newCustomFields.put("backgroundColor", JsonNodeFactory.instance.objectNode().put("de", "rot"));
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(2);
final UpdateAction<Category> categoryUpdateAction = setCustomFieldsUpdateActions.get(0);
assertThat(categoryUpdateAction).isNotNull();
assertThat(categoryUpdateAction).isInstanceOf(SetCustomField.class);
}
use of com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder in project commercetools-sync-java by commercetools.
the class CustomUpdateActionUtilsTest method buildSetCustomFieldsUpdateActions_WithSameCustomFieldValues_ShouldNotBuildUpdateActions.
@Test
void buildSetCustomFieldsUpdateActions_WithSameCustomFieldValues_ShouldNotBuildUpdateActions() {
final Map<String, JsonNode> oldCustomFields = new HashMap<>();
oldCustomFields.put("invisibleInShop", JsonNodeFactory.instance.booleanNode(true));
oldCustomFields.put("backgroundColor", JsonNodeFactory.instance.objectNode().put("de", "rot"));
final Map<String, JsonNode> newCustomFields = new HashMap<>();
newCustomFields.put("invisibleInShop", JsonNodeFactory.instance.booleanNode(true));
newCustomFields.put("backgroundColor", JsonNodeFactory.instance.objectNode().put("de", "rot"));
final List<UpdateAction<Category>> updateActions = buildSetCustomFieldsUpdateActions(oldCustomFields, newCustomFields, mock(Asset.class), new CategoryCustomActionBuilder(), 1, Asset::getId);
assertThat(updateActions).isNotNull();
assertThat(updateActions).isEmpty();
}
use of com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder in project commercetools-sync-java by commercetools.
the class CategoryCustomUpdateActionUtilsTest method buildRemoveCustomTypeAction_WithCategoryResource_ShouldBuildCategoryUpdateAction.
@Test
void buildRemoveCustomTypeAction_WithCategoryResource_ShouldBuildCategoryUpdateAction() {
final UpdateAction<Category> updateAction = new CategoryCustomActionBuilder().buildRemoveCustomTypeAction(null, null);
assertThat(updateAction).isInstanceOf(SetCustomType.class);
assertThat((SetCustomType) updateAction).hasValues("setCustomType", null, ofId(null));
}
use of com.commercetools.sync.categories.helpers.CategoryCustomActionBuilder in project commercetools-sync-java by commercetools.
the class ResourceCustomUpdateActionUtilsTest method buildResourceCustomUpdateActions_WithNullOldCustomFields_ShouldBuildUpdateActions.
@Test
void buildResourceCustomUpdateActions_WithNullOldCustomFields_ShouldBuildUpdateActions() {
final Category oldCategory = mock(Category.class);
when(oldCategory.getCustom()).thenReturn(null);
final CategoryDraft newCategoryDraft = CategoryDraftBuilder.of(LocalizedString.ofEnglish("name"), LocalizedString.ofEnglish("testSlug")).key("key").parent(ResourceIdentifier.ofId("parentId")).custom(CustomFieldsDraft.ofTypeIdAndJson("customTypeId", new HashMap<>())).build();
final List<UpdateAction<Category>> updateActions = buildPrimaryResourceCustomUpdateActions(oldCategory, newCategoryDraft, new CategoryCustomActionBuilder(), categorySyncOptions);
// Should add custom type to old category.
assertThat(errorMessages).isEmpty();
assertThat(exceptions).isEmpty();
assertThat(updateActions).isNotNull();
assertThat(updateActions).hasSize(1);
assertThat(updateActions.get(0)).isInstanceOf(SetCustomType.class);
}
Aggregations