MNT-20740 BinDuplicationHotFixSqlRefactor

This commit is contained in:
Sara Aspery
2019-07-30 16:35:48 +01:00
parent 075794981b
commit 7c4d8e91ab
9 changed files with 142 additions and 54 deletions

View File

@@ -28,6 +28,8 @@
package org.alfresco.module.org_alfresco_module_rm.util;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.query.RecordsManagementQueryDAO;
import org.alfresco.repo.domain.contentdata.ContentUrlEntity;
import org.alfresco.repo.policy.BehaviourFilter;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
@@ -39,6 +41,8 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -63,6 +67,9 @@ public class ContentBinDuplicationUtilityUnitTest
@Mock
private ContentWriter contentWriter;
@Mock
private RecordsManagementQueryDAO recordsManagementQueryDAO;
@InjectMocks
private ContentBinDuplicationUtility contentBinDuplicationUtility;
@@ -99,6 +106,41 @@ public class ContentBinDuplicationUtilityUnitTest
checkBehaviours(1);
}
/**
* Test hasAtLeastOneOtherReference returns true when node has another reference to it
*/
@Test
public void testHasAtLeastOneOtherReference()
{
NodeRef nodeRef = new NodeRef("some://test/noderef");
String contentUrl = "someContentUrl";
when(contentService.getReader(nodeRef, ContentModel.PROP_CONTENT)).thenReturn(contentReader);
when(contentService.getReader(nodeRef, ContentModel.PROP_CONTENT).getContentUrl()).thenReturn(contentUrl);
when(recordsManagementQueryDAO.getContentUrlEntityUnreferenced(contentUrl)).thenReturn(null);
boolean hasReference = contentBinDuplicationUtility.hasAtLeastOneOtherReference(nodeRef);
assertTrue(hasReference);
}
/**
* Test hasAtLeastOneOtherReference returns false when node has no other reference to it
*/
@Test
public void testHasNoOtherReference()
{
NodeRef nodeRef = new NodeRef("some://test/noderef");
String contentUrl = "someContentUrl";
ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
when(contentService.getReader(nodeRef, ContentModel.PROP_CONTENT)).thenReturn(contentReader);
when(contentService.getReader(nodeRef, ContentModel.PROP_CONTENT).getContentUrl()).thenReturn(contentUrl);
when(recordsManagementQueryDAO.getContentUrlEntityUnreferenced(contentUrl)).thenReturn(contentUrlEntity);
boolean hasReference = contentBinDuplicationUtility.hasAtLeastOneOtherReference(nodeRef);
assertFalse(hasReference);
}
/**
* Check that the behaviours are disabled and re-enabled the correct number of times
* @param times the times the behaviours should be called