RM-6869 extracting actions utils to a class

This commit is contained in:
Ross Gale
2019-06-05 09:27:38 +01:00
parent 3e31a5f85d
commit 0b6ca3fc08
3 changed files with 131 additions and 56 deletions

View File

@@ -41,6 +41,8 @@ import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChildCollection;
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChildEntry;
import org.alfresco.rest.rm.community.model.recordfolder.RecordFolderCollection;
import org.alfresco.rest.rm.community.util.ActionEvaluator;
import org.alfresco.rest.rm.community.util.ActionExecutorUtil;
import org.alfresco.test.AlfrescoTest;
import org.alfresco.utility.Utility;
import org.alfresco.utility.model.FileModel;
@@ -60,11 +62,14 @@ public class RejectRecordTests extends BaseRMRestTest
private RecordCategory recordCategory;
private RecordCategoryChild recordFolder;
private ActionExecutorUtil actionExecuterUtil;
private RecordCategoryChildCollection recordFolders;
@BeforeClass (alwaysRun = true)
public void setUp() throws Exception
{
actionExecuterUtil = new ActionExecutorUtil();
publicSite = dataSite.usingAdmin().createPublicRandomSite();
recordCategory = createRootCategory(getRandomName("recordCategory"));
recordFolder = createFolder(recordCategory.getId(), getRandomName("recordFolder"));
@@ -90,7 +95,7 @@ public class RejectRecordTests extends BaseRMRestTest
STEP("Link record to new folder");
getRestAPIFactory().getActionsAPI().linkRecord(testFile, recordCategory.getName() + "/" + recordFolder.getName() + "_2");
recordFolders = null;
checkActionExecution(new LinkEvaluator());
actionExecuterUtil.checkActionExecution(new LinkEvaluator());
Optional<RecordCategoryChildEntry> linkedFolder = recordFolders.getEntries().stream().filter(child -> child.getEntry().getName().equals(recordFolder.getName() + "_2"))
.findFirst();
@@ -101,7 +106,7 @@ public class RejectRecordTests extends BaseRMRestTest
STEP("Reject record");
getRestAPIFactory().getActionsAPI().rejectRecord(testFile, "Just because");
checkActionExecution(new RejectEvaluator());
actionExecuterUtil.checkActionExecution(new RejectEvaluator());
STEP("Check record has been rejected");
assertFalse("Record rejection failure", isMatchingRecordInRecordFolder(testFile, recordFolder));
@@ -122,60 +127,6 @@ public class RejectRecordTests extends BaseRMRestTest
dataSite.deleteSite(publicSite);
}
/**
* Method to wait and retry when using the actions api
* @param evaluator the action specific check for completion
*/
private void checkActionExecution(ActionEvaluator evaluator)
{
int counter = 0;
int waitInMilliSeconds = 7000;
while (counter < 4)
{
synchronized (this)
{
try
{
this.wait(waitInMilliSeconds);
} catch (InterruptedException e)
{
// Restore interrupted state...
Thread.currentThread().interrupt();
}
}
if (evaluator.evaluate())
{
break;
} else
{
counter++;
}
}
if(counter == 4)
{
fail(evaluator.getErrorMessage());
}
}
/**
* Generic interface for checking action execution
*/
private interface ActionEvaluator
{
/**
* The check for completion
* @return boolean for if the action has been successfully executed
*/
boolean evaluate();
/**
* Error message for an action not completed
* @return String action specific error message
*/
String getErrorMessage();
}
/**
* Check for completion of link action
*/