mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-01 14:41:46 +00:00
ACS-4932 Fix issues around renaming tags. (#1847)
* ACS-4932 Rename tag node without the id changing. * ACS-4932 Use fake tag to fire events for all nodes. * ACS-4932 Use event generator to create events for renamed tags. * ACS-4932 Fix unit test. * ACS-4932 Fix tag update tests. * ACS-4932 Tag names are always lower case. * ACS-4932 Update TAS tag tests to use lowercase tag names.
This commit is contained in:
@@ -25,10 +25,16 @@
|
||||
*/
|
||||
package org.alfresco.repo.tagging;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
|
||||
import static org.alfresco.model.ContentModel.ASPECT_TAGGABLE;
|
||||
import static org.alfresco.model.ContentModel.PROP_TAGS;
|
||||
import static org.alfresco.model.ContentModel.ASSOC_SUBCATEGORIES;
|
||||
import static org.alfresco.model.ContentModel.PROP_NAME;
|
||||
import static org.alfresco.repo.tagging.TaggingServiceImpl.TAG_UPDATES;
|
||||
import static org.alfresco.service.cmr.repository.StoreRef.STORE_REF_WORKSPACE_SPACESSTORE;
|
||||
import static org.alfresco.service.cmr.search.SearchService.LANGUAGE_LUCENE;
|
||||
import static org.alfresco.service.cmr.tagging.TaggingService.TAG_ROOT_NODE_REF;
|
||||
import static org.alfresco.service.namespace.NamespaceService.CONTENT_MODEL_1_0_URI;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.catchThrowable;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -36,16 +42,15 @@ import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.then;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.event2.EventGenerator;
|
||||
import org.alfresco.repo.policy.PolicyComponent;
|
||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
@@ -56,6 +61,7 @@ import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.search.CategoryService;
|
||||
import org.alfresco.service.cmr.search.ResultSet;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -84,6 +90,8 @@ public class TaggingServiceImplUnitTest
|
||||
private ResultSet resultSetMock;
|
||||
@Mock(extraInterfaces = List.class)
|
||||
private Serializable currentTagsMock;
|
||||
@Mock
|
||||
private EventGenerator eventGenerator;
|
||||
|
||||
@InjectMocks
|
||||
private TaggingServiceImpl taggingService;
|
||||
@@ -128,45 +136,25 @@ public class TaggingServiceImplUnitTest
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testChangeTag()
|
||||
{
|
||||
final String newTagName = "new-tag-name";
|
||||
final NodeRef newTagNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, newTagName);
|
||||
given(searchServiceMock.query(any(), any(String.class), any(String.class))).willReturn(resultSetMock);
|
||||
given(resultSetMock.getNodeRefs()).willReturn(List.of(CONTENT_NODE_REF), Collections.emptyList());
|
||||
given(nodeServiceMock.hasAspect(CONTENT_NODE_REF, ASPECT_TAGGABLE)).willReturn(true);
|
||||
given(categoryServiceMock.getRootCategories(STORE_REF_WORKSPACE_SPACESSTORE, ASPECT_TAGGABLE, TAG_NAME, false)).willReturn(childAssociationsOf(TAG_NODE_REF));
|
||||
given(nodeServiceMock.getProperty(CONTENT_NODE_REF, PROP_TAGS)).willReturn(currentTagsMock);
|
||||
given(((List<NodeRef>) currentTagsMock).size()).willReturn(1);
|
||||
given(((List<NodeRef>) currentTagsMock).contains(TAG_NODE_REF)).willReturn(true);
|
||||
given(categoryServiceMock.getRootCategories(STORE_REF_WORKSPACE_SPACESSTORE, ASPECT_TAGGABLE, newTagName, true)).willReturn(childAssociationsOf(newTagNodeRef));
|
||||
given(((List<NodeRef>) currentTagsMock).contains(newTagNodeRef)).willReturn(false);
|
||||
given(searchServiceMock.query(STORE_REF_WORKSPACE_SPACESSTORE, LANGUAGE_LUCENE, "+PATH:\"/cm:taggable/cm:" + TAG_NAME + "/member\"")).willReturn(resultSetMock);
|
||||
given(resultSetMock.getNodeRefs()).willReturn(List.of(CONTENT_NODE_REF));
|
||||
|
||||
//when
|
||||
taggingService.changeTag(STORE_REF_WORKSPACE_SPACESSTORE, TAG_NAME, newTagName);
|
||||
|
||||
then((List<NodeRef>) currentTagsMock).should().remove(TAG_NODE_REF);
|
||||
then((List<NodeRef>) currentTagsMock).should().add(newTagNodeRef);
|
||||
then(nodeServiceMock).should(times(2)).setProperty(CONTENT_NODE_REF, PROP_TAGS, currentTagsMock);
|
||||
then(categoryServiceMock).should().deleteCategory(TAG_NODE_REF);
|
||||
then(categoryServiceMock).should(times(2)).getRootCategories(STORE_REF_WORKSPACE_SPACESSTORE, ASPECT_TAGGABLE, newTagName, true);
|
||||
}
|
||||
then(nodeServiceMock).should().setProperty(TAG_NODE_REF, PROP_NAME, newTagName);
|
||||
then(nodeServiceMock).should().moveNode(TAG_NODE_REF, TAG_ROOT_NODE_REF, ASSOC_SUBCATEGORIES, QName.createQName(CONTENT_MODEL_1_0_URI, newTagName));
|
||||
then(nodeServiceMock).should().getProperties(CONTENT_NODE_REF);
|
||||
then(nodeServiceMock).should().hasAspect(CONTENT_NODE_REF, ContentModel.ASPECT_TAGSCOPE);
|
||||
then(nodeServiceMock).should().getPrimaryParent(CONTENT_NODE_REF);
|
||||
then(nodeServiceMock).shouldHaveNoMoreInteractions();
|
||||
|
||||
@Test
|
||||
public void testChangeOrphanTag()
|
||||
{
|
||||
final String newTagName = "new-tag-name";
|
||||
given(searchServiceMock.query(any(), any(String.class), any(String.class))).willReturn(resultSetMock);
|
||||
given(resultSetMock.getNodeRefs()).willReturn(Collections.emptyList());
|
||||
given(categoryServiceMock.getRootCategories(STORE_REF_WORKSPACE_SPACESSTORE, ASPECT_TAGGABLE, TAG_NAME, false)).willReturn(childAssociationsOf(TAG_NODE_REF));
|
||||
|
||||
//when
|
||||
taggingService.changeTag(STORE_REF_WORKSPACE_SPACESSTORE, TAG_NAME, newTagName);
|
||||
|
||||
then(nodeServiceMock).should(never()).setProperty(any(), any(), any());
|
||||
then(categoryServiceMock).should().deleteCategory(TAG_NODE_REF);
|
||||
then(categoryServiceMock).should().getRootCategories(STORE_REF_WORKSPACE_SPACESSTORE, ASPECT_TAGGABLE, newTagName, true);
|
||||
then(eventGenerator).should().onUpdateProperties(eq(CONTENT_NODE_REF), eq(emptyMap()), any());
|
||||
then(eventGenerator).shouldHaveNoMoreInteractions();
|
||||
}
|
||||
|
||||
private static List<ChildAssociationRef> childAssociationsOf(final NodeRef... childNodeRefs)
|
||||
@@ -175,4 +163,4 @@ public class TaggingServiceImplUnitTest
|
||||
.map(childNodeRef -> new ChildAssociationRef(null, null, null, childNodeRef))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user