Skip to content
This repository has been archived by the owner on Oct 27, 2020. It is now read-only.

Commit

Permalink
MNT-18308 - Added two unit tests to assert correct behaviour for flag…
Browse files Browse the repository at this point in the history
… turned on an flag turned off
  • Loading branch information
evasques committed May 5, 2020
1 parent d5d795e commit db71d2c
Showing 1 changed file with 126 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public class FixedAclUpdaterTest extends TestCase
private Repository repository;
private FixedAclUpdater fixedAclUpdater;
private NodeRef folderNodeRef;
private NodeRef mntFolder1;
private NodeRef mntFolder2;
private PermissionsDaoComponent permissionsDaoComponent;
private PermissionService permissionService;
private NodeDAO nodeDAO;
Expand Down Expand Up @@ -97,6 +99,11 @@ public void setUp() throws Exception
// change setFixedAclMaxTransactionTime to lower value so setInheritParentPermissions on created folder hierarchy require async call
setFixedAclMaxTransactionTime(permissionsDaoComponent, home, 50);

RetryingTransactionCallback<NodeRef> cb2 = createFolderHierchyCallback(home, fileFolderService, "MNT18308_1", filesPerLevel);
mntFolder1 = txnHelper.doInTransaction(cb2);

RetryingTransactionCallback<NodeRef> cb3 = createFolderHierchyCallback(home, fileFolderService, "MNT18308_2", filesPerLevel);
mntFolder2 = txnHelper.doInTransaction(cb3);
}

private static void setFixedAclMaxTransactionTime(PermissionsDaoComponent permissionsDaoComponent, NodeRef folderNodeRef,
Expand All @@ -113,6 +120,19 @@ private static void setFixedAclMaxTransactionTime(PermissionsDaoComponent permis
}
}

private static void setForceAsyncAclCreation(PermissionsDaoComponent permissionsDaoComponent, NodeRef folderNodeRef, boolean forceAsyncAclCreation)
{
if (permissionsDaoComponent instanceof ADMPermissionsDaoComponentImpl)
{
AccessControlListDAO acldao = ((ADMPermissionsDaoComponentImpl) permissionsDaoComponent).getACLDAO(folderNodeRef);
if (acldao instanceof ADMAccessControlListDAO)
{
ADMAccessControlListDAO admAcLDao = (ADMAccessControlListDAO) acldao;
admAcLDao.setForceAsyncAclCreation(forceAsyncAclCreation);
}
}
}

private static RetryingTransactionCallback<NodeRef> createFolderHierchyCallback(final NodeRef root,
final FileFolderService fileFolderService, final String rootName, final int[] filesPerLevel)
{
Expand Down Expand Up @@ -189,8 +209,7 @@ public Void execute() throws Throwable
{
permissionService.setInheritParentPermissions(folderNodeRef, false, true);

Boolean asyncCallRequired = (Boolean) AlfrescoTransactionSupport.getResource(FixedAclUpdater.FIXED_ACL_ASYNC_REQUIRED_KEY);
assertTrue("asyncCallRequired should be true", asyncCallRequired);
assertTrue("asyncCallRequired should be true", isAsyncCallSetAsRequired());

return null;
}
Expand Down Expand Up @@ -226,6 +245,111 @@ public Void execute() throws Throwable
}, false, true);
}

@Test
public void testMNT18308_flagOff()
{
// Test the default behaviour without setting forceAsyncAclCreation
txnHelper.doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
assertFalse("asyncCallRequiredBefore should be false", isAsyncCallSetAsRequired());

//setInheritParentPermissions with sync call
permissionService.setInheritParentPermissions(mntFolder1, false, false);

assertFalse("asyncCallRequiredAfter should remain false", isAsyncCallSetAsRequired());

return null;
}
}, false, true);

// check that there are nodes to process by job
txnHelper.doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
assertTrue("There should not be any nodes with ASPECT_PENDING_FIX_ACL", getNodesCountWithPendingFixedAclAspect() == 0);
return null;
}
}, false, true);
}

@Test
public void testMNT18308_flagOn()
{
// Set property forceAsyncAclCreation to true
setForceAsyncAclCreation(permissionsDaoComponent, repository.getCompanyHome(), true);

txnHelper.doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
assertFalse("asyncCallRequiredBefore should be false", isAsyncCallSetAsRequired());

//setInheritParentPermissions with sync call
permissionService.setInheritParentPermissions(mntFolder2, false, false);

assertTrue("asyncCallRequiredAfter should now be true", isAsyncCallSetAsRequired());

return null;
}
}, false, true);

// check that there are nodes to process
txnHelper.doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
assertTrue("No nodes are set to be processed by job", getNodesCountWithPendingFixedAclAspect() > 0);
return null;
}
}, false, true);

txnHelper.doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
int count = 0;
do
{
count = fixedAclUpdater.execute();
}
while(count > 0);

return null;
}
}, false, true);

// check if nodes with ASPECT_PENDING_FIX_ACL are processed
txnHelper.doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
assertEquals("Not all nodes were processed", 0, getNodesCountWithPendingFixedAclAspect());
return null;
}
}, false, true);

setForceAsyncAclCreation(permissionsDaoComponent, repository.getCompanyHome(), false);
}

private boolean isAsyncCallSetAsRequired() {

if(AlfrescoTransactionSupport.getResource(FixedAclUpdater.FIXED_ACL_ASYNC_REQUIRED_KEY) == null) {
return false;
} else {
return (boolean) AlfrescoTransactionSupport.getResource(FixedAclUpdater.FIXED_ACL_ASYNC_REQUIRED_KEY);
}

}

private static class GetNodesCountWithAspectCallback implements NodeRefQueryCallback
{
int nodesNumber = 0;
Expand Down

0 comments on commit db71d2c

Please sign in to comment.