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