Acs 4400 multiple same categories can be linked from content or folder (#1675)

ACS-4400: Multiple same categories can be linked from content or folder
This commit is contained in:
krdabrowski
2023-01-16 11:40:37 +01:00
committed by GitHub
parent 2b363fb315
commit c228bfac1f
4 changed files with 106 additions and 0 deletions

View File

@@ -193,6 +193,7 @@ public class CategoriesImpl implements Categories
.filter(Objects::nonNull)
.map(Category::getId)
.filter(StringUtils::isNotEmpty)
.distinct()
.map(this::getCategoryNodeRef)
.collect(Collectors.toList());

View File

@@ -1000,6 +1000,26 @@ public class CategoriesImplTest
.hasMessageContaining(NOT_A_VALID_CATEGORY);
}
@Test
public void testLinkNodeToCategories_withTwoIdenticalCategories()
{
final List<Category> categoryLinks = List.of(CATEGORY, CATEGORY);
final NodeRef categoryParentNodeRef = createNodeRefWithId(PARENT_ID);
final ChildAssociationRef parentAssociation = createAssociationOf(categoryParentNodeRef, CATEGORY_NODE_REF);
given(nodesMock.getNode(any())).willReturn(prepareCategoryNode());
given(nodeServiceMock.getPrimaryParent(any())).willReturn(parentAssociation);
// when
final List<Category> actualLinkedCategories = objectUnderTest.linkNodeToCategories(CONTENT_NODE_ID, categoryLinks);
final Map<QName, Serializable> expectedProperties = Map.of(ContentModel.PROP_CATEGORIES, (Serializable) List.of(CATEGORY_NODE_REF));
then(nodeServiceMock).should().addAspect(CONTENT_NODE_REF, ContentModel.ASPECT_GEN_CLASSIFIABLE, expectedProperties);
final List<Category> expectedLinkedCategories = List.of(CATEGORY);
assertThat(actualLinkedCategories)
.isNotNull().usingRecursiveComparison()
.isEqualTo(expectedLinkedCategories);
}
@Test
public void testListCategoriesForNode()
{