mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
RM-6873 code review changes
This commit is contained in:
@@ -192,30 +192,25 @@ public class FrozenAspect extends BaseBehaviourBean
|
|||||||
)
|
)
|
||||||
public void onRemoveAspect(final NodeRef nodeRef, QName aspectTypeQName)
|
public void onRemoveAspect(final NodeRef nodeRef, QName aspectTypeQName)
|
||||||
{
|
{
|
||||||
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
AuthenticationUtil.runAsSystem((RunAsWork<Void>) () -> {
|
||||||
{
|
if (nodeService.exists(nodeRef) &&
|
||||||
@Override
|
(isRecord(nodeRef) || instanceOf(nodeRef, TYPE_CONTENT)))
|
||||||
public Void doWork()
|
|
||||||
{
|
{
|
||||||
if (nodeService.exists(nodeRef) &&
|
// get the owning folder
|
||||||
(isRecord(nodeRef) || instanceOf(nodeRef, TYPE_CONTENT)))
|
NodeRef owningFolder = nodeService.getPrimaryParent(nodeRef).getParentRef();
|
||||||
|
|
||||||
|
// check that the aspect has been added
|
||||||
|
if (nodeService.hasAspect(owningFolder, ASPECT_HELD_CHILDREN))
|
||||||
{
|
{
|
||||||
// get the owning folder
|
// decrement current count
|
||||||
NodeRef owningFolder = nodeService.getPrimaryParent(nodeRef).getParentRef();
|
int currentCount = (Integer) nodeService.getProperty(owningFolder, PROP_HELD_CHILDREN_COUNT);
|
||||||
|
if (currentCount > 0)
|
||||||
// check that the aspect has been added
|
|
||||||
if (nodeService.hasAspect(owningFolder, ASPECT_HELD_CHILDREN))
|
|
||||||
{
|
{
|
||||||
// decrement current count
|
nodeService.setProperty(owningFolder, PROP_HELD_CHILDREN_COUNT, currentCount - 1);
|
||||||
int currentCount = (Integer)nodeService.getProperty(owningFolder, PROP_HELD_CHILDREN_COUNT);
|
}
|
||||||
if (currentCount > 0)
|
|
||||||
{
|
|
||||||
nodeService.setProperty(owningFolder, PROP_HELD_CHILDREN_COUNT, currentCount - 1 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -109,7 +109,6 @@ public class RemoveActiveContentToHoldTest extends BaseRMTestCase
|
|||||||
{
|
{
|
||||||
private NodeRef hold;
|
private NodeRef hold;
|
||||||
private NodeRef hold2;
|
private NodeRef hold2;
|
||||||
Integer before;
|
|
||||||
|
|
||||||
public void given()
|
public void given()
|
||||||
{
|
{
|
||||||
@@ -121,7 +120,6 @@ public class RemoveActiveContentToHoldTest extends BaseRMTestCase
|
|||||||
|
|
||||||
public void when()
|
public void when()
|
||||||
{
|
{
|
||||||
before = (Integer) nodeService.getProperty(dmFolder, PROP_HELD_CHILDREN_COUNT);
|
|
||||||
holdService.removeFromHold(hold, dmDocument);
|
holdService.removeFromHold(hold, dmDocument);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +137,7 @@ public class RemoveActiveContentToHoldTest extends BaseRMTestCase
|
|||||||
* When I try to remove the active content to the hold without permission
|
* When I try to remove the active content to the hold without permission
|
||||||
* Then an access denied exception is thrown
|
* Then an access denied exception is thrown
|
||||||
*/
|
*/
|
||||||
public void testRemoveDocumentFromHoldFailsWithoutPermission()
|
public void testRemoveDocumentFromHoldFailsWithoutFilingPermission()
|
||||||
{
|
{
|
||||||
doBehaviourDrivenTest(new BehaviourDrivenTest(AccessDeniedException.class)
|
doBehaviourDrivenTest(new BehaviourDrivenTest(AccessDeniedException.class)
|
||||||
{
|
{
|
||||||
@@ -157,7 +155,7 @@ public class RemoveActiveContentToHoldTest extends BaseRMTestCase
|
|||||||
(RunAsWork<Void>) () -> {
|
(RunAsWork<Void>) () -> {
|
||||||
holdService.removeFromHold(hold, dmDocument);
|
holdService.removeFromHold(hold, dmDocument);
|
||||||
return null;
|
return null;
|
||||||
}, recordsManagerName );
|
}, recordsManagerName);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -53,16 +53,16 @@ import org.springframework.context.ApplicationContext;
|
|||||||
public class FrozenAspectUnitTest
|
public class FrozenAspectUnitTest
|
||||||
{
|
{
|
||||||
@Mock
|
@Mock
|
||||||
private NodeService nodeService;
|
private NodeService mockNodeService;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private ApplicationContext applicationContext;
|
private ApplicationContext mockApplicationContext;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private ChildAssociationRef childAssociationRef;
|
private ChildAssociationRef mockChildAssociationRef;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private DictionaryService dictionaryService;
|
private DictionaryService mockDictionaryService;
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private FrozenAspect frozenAspect;
|
private FrozenAspect frozenAspect;
|
||||||
@@ -75,13 +75,11 @@ public class FrozenAspectUnitTest
|
|||||||
public void setUp()
|
public void setUp()
|
||||||
{
|
{
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
when(nodeService.exists(record)).thenReturn(true);
|
when(mockNodeService.exists(record)).thenReturn(true);
|
||||||
when(nodeService.exists(content)).thenReturn(true);
|
when(mockNodeService.exists(content)).thenReturn(true);
|
||||||
when(nodeService.hasAspect(folder, ASPECT_HELD_CHILDREN)).thenReturn(true);
|
when(mockNodeService.hasAspect(folder, ASPECT_HELD_CHILDREN)).thenReturn(true);
|
||||||
when(nodeService.getProperty(folder, PROP_HELD_CHILDREN_COUNT)).thenReturn(1);
|
when(mockNodeService.getProperty(folder, PROP_HELD_CHILDREN_COUNT)).thenReturn(1);
|
||||||
when(applicationContext.getBean("dbNodeService")).thenReturn(nodeService);
|
when(mockApplicationContext.getBean("dbNodeService")).thenReturn(mockNodeService);
|
||||||
when(nodeService.hasAspect(folder, ASPECT_HELD_CHILDREN)).thenReturn(true);
|
|
||||||
when(nodeService.getProperty(folder, PROP_HELD_CHILDREN_COUNT)).thenReturn(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,11 +88,11 @@ public class FrozenAspectUnitTest
|
|||||||
@Test
|
@Test
|
||||||
public void testRemoveAspectForRecords()
|
public void testRemoveAspectForRecords()
|
||||||
{
|
{
|
||||||
when(nodeService.hasAspect(record, ASPECT_RECORD)).thenReturn(true);
|
when(mockNodeService.hasAspect(record, ASPECT_RECORD)).thenReturn(true);
|
||||||
when(nodeService.getPrimaryParent(record)).thenReturn(childAssociationRef);
|
when(mockNodeService.getPrimaryParent(record)).thenReturn(mockChildAssociationRef);
|
||||||
when(childAssociationRef.getParentRef()).thenReturn(folder);
|
when(mockChildAssociationRef.getParentRef()).thenReturn(folder);
|
||||||
frozenAspect.onRemoveAspect(record, null);
|
frozenAspect.onRemoveAspect(record, null);
|
||||||
verify(nodeService, times(1)).setProperty(folder, PROP_HELD_CHILDREN_COUNT, 0);
|
verify(mockNodeService, times(1)).setProperty(folder, PROP_HELD_CHILDREN_COUNT, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,12 +101,12 @@ public class FrozenAspectUnitTest
|
|||||||
@Test
|
@Test
|
||||||
public void testRemoveAspectForContent()
|
public void testRemoveAspectForContent()
|
||||||
{
|
{
|
||||||
when(nodeService.hasAspect(content, ASPECT_RECORD)).thenReturn(false);
|
when(mockNodeService.hasAspect(content, ASPECT_RECORD)).thenReturn(false);
|
||||||
when(nodeService.getType(content)).thenReturn(ContentModel.TYPE_CONTENT);
|
when(mockNodeService.getType(content)).thenReturn(ContentModel.TYPE_CONTENT);
|
||||||
when(nodeService.getPrimaryParent(content)).thenReturn(childAssociationRef);
|
when(mockNodeService.getPrimaryParent(content)).thenReturn(mockChildAssociationRef);
|
||||||
when(childAssociationRef.getParentRef()).thenReturn(folder);
|
when(mockChildAssociationRef.getParentRef()).thenReturn(folder);
|
||||||
frozenAspect.onRemoveAspect(content, null);
|
frozenAspect.onRemoveAspect(content, null);
|
||||||
verify(nodeService, times(1)).setProperty(folder, PROP_HELD_CHILDREN_COUNT, 0);
|
verify(mockNodeService, times(1)).setProperty(folder, PROP_HELD_CHILDREN_COUNT, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,10 +115,10 @@ public class FrozenAspectUnitTest
|
|||||||
@Test
|
@Test
|
||||||
public void testRemoveAspectForContentDoesntUpdateForOtherTypes()
|
public void testRemoveAspectForContentDoesntUpdateForOtherTypes()
|
||||||
{
|
{
|
||||||
when(nodeService.hasAspect(content, ASPECT_RECORD)).thenReturn(false);
|
when(mockNodeService.hasAspect(content, ASPECT_RECORD)).thenReturn(false);
|
||||||
when(nodeService.getType(content)).thenReturn(ContentModel.TYPE_FOLDER);
|
when(mockNodeService.getType(content)).thenReturn(ContentModel.TYPE_FOLDER);
|
||||||
when(dictionaryService.isSubClass(ContentModel.TYPE_FOLDER, ContentModel.TYPE_CONTENT)).thenReturn(false);
|
when(mockDictionaryService.isSubClass(ContentModel.TYPE_FOLDER, ContentModel.TYPE_CONTENT)).thenReturn(false);
|
||||||
frozenAspect.onRemoveAspect(content, null);
|
frozenAspect.onRemoveAspect(content, null);
|
||||||
verify(nodeService, times(0)).setProperty(folder, PROP_HELD_CHILDREN_COUNT, 0);
|
verify(mockNodeService, times(0)).setProperty(folder, PROP_HELD_CHILDREN_COUNT, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user