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);
}
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();
}
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();
}
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();
}
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);
}
Aggregations