RM-6873 code review changes

This commit is contained in:
Ross Gale
2019-08-14 11:20:18 +01:00
parent d5278c4ec7
commit dff5b452d9
3 changed files with 38 additions and 47 deletions

View File

@@ -192,11 +192,7 @@ 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>) () -> {
{
@Override
public Void doWork()
{
if (nodeService.exists(nodeRef) && if (nodeService.exists(nodeRef) &&
(isRecord(nodeRef) || instanceOf(nodeRef, TYPE_CONTENT))) (isRecord(nodeRef) || instanceOf(nodeRef, TYPE_CONTENT)))
{ {
@@ -207,15 +203,14 @@ public class FrozenAspect extends BaseBehaviourBean
if (nodeService.hasAspect(owningFolder, ASPECT_HELD_CHILDREN)) if (nodeService.hasAspect(owningFolder, ASPECT_HELD_CHILDREN))
{ {
// decrement current count // decrement current count
int currentCount = (Integer)nodeService.getProperty(owningFolder, PROP_HELD_CHILDREN_COUNT); int currentCount = (Integer) nodeService.getProperty(owningFolder, PROP_HELD_CHILDREN_COUNT);
if (currentCount > 0) if (currentCount > 0)
{ {
nodeService.setProperty(owningFolder, PROP_HELD_CHILDREN_COUNT, currentCount - 1 ); nodeService.setProperty(owningFolder, PROP_HELD_CHILDREN_COUNT, currentCount - 1);
} }
} }
} }
return null; return null;
}
}); });
} }

View File

@@ -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);
} }
}); });
} }

View File

@@ -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);
} }
} }