RM-6869 extracting actions utils to a class

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

View File

@@ -0,0 +1,51 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2019 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rest.rm.community.util;
/**
* Generic interface for checking action execution
*
* @author Ross Gale
* @since 3.1
*/
public 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();
}

View File

@@ -0,0 +1,73 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2019 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rest.rm.community.util;
import static org.testng.AssertJUnit.fail;
/**
* @author Ross Gale
* @since 3.1
*/
public class ActionExecutorUtil
{
/**
* Method to wait and retry when using the actions api
*
* @param evaluator the action specific check for completion
*/
public 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());
}
}
}

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.RecordCategoryChildCollection;
import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChildEntry; import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChildEntry;
import org.alfresco.rest.rm.community.model.recordfolder.RecordFolderCollection; 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.test.AlfrescoTest;
import org.alfresco.utility.Utility; import org.alfresco.utility.Utility;
import org.alfresco.utility.model.FileModel; import org.alfresco.utility.model.FileModel;
@@ -60,11 +62,14 @@ public class RejectRecordTests extends BaseRMRestTest
private RecordCategory recordCategory; private RecordCategory recordCategory;
private RecordCategoryChild recordFolder; private RecordCategoryChild recordFolder;
private ActionExecutorUtil actionExecuterUtil;
private RecordCategoryChildCollection recordFolders; private RecordCategoryChildCollection recordFolders;
@BeforeClass (alwaysRun = true) @BeforeClass (alwaysRun = true)
public void setUp() throws Exception public void setUp() throws Exception
{ {
actionExecuterUtil = new ActionExecutorUtil();
publicSite = dataSite.usingAdmin().createPublicRandomSite(); publicSite = dataSite.usingAdmin().createPublicRandomSite();
recordCategory = createRootCategory(getRandomName("recordCategory")); recordCategory = createRootCategory(getRandomName("recordCategory"));
recordFolder = createFolder(recordCategory.getId(), getRandomName("recordFolder")); recordFolder = createFolder(recordCategory.getId(), getRandomName("recordFolder"));
@@ -90,7 +95,7 @@ public class RejectRecordTests extends BaseRMRestTest
STEP("Link record to new folder"); STEP("Link record to new folder");
getRestAPIFactory().getActionsAPI().linkRecord(testFile, recordCategory.getName() + "/" + recordFolder.getName() + "_2"); getRestAPIFactory().getActionsAPI().linkRecord(testFile, recordCategory.getName() + "/" + recordFolder.getName() + "_2");
recordFolders = null; recordFolders = null;
checkActionExecution(new LinkEvaluator()); actionExecuterUtil.checkActionExecution(new LinkEvaluator());
Optional<RecordCategoryChildEntry> linkedFolder = recordFolders.getEntries().stream().filter(child -> child.getEntry().getName().equals(recordFolder.getName() + "_2")) Optional<RecordCategoryChildEntry> linkedFolder = recordFolders.getEntries().stream().filter(child -> child.getEntry().getName().equals(recordFolder.getName() + "_2"))
.findFirst(); .findFirst();
@@ -101,7 +106,7 @@ public class RejectRecordTests extends BaseRMRestTest
STEP("Reject record"); STEP("Reject record");
getRestAPIFactory().getActionsAPI().rejectRecord(testFile, "Just because"); getRestAPIFactory().getActionsAPI().rejectRecord(testFile, "Just because");
checkActionExecution(new RejectEvaluator()); actionExecuterUtil.checkActionExecution(new RejectEvaluator());
STEP("Check record has been rejected"); STEP("Check record has been rejected");
assertFalse("Record rejection failure", isMatchingRecordInRecordFolder(testFile, recordFolder)); assertFalse("Record rejection failure", isMatchingRecordInRecordFolder(testFile, recordFolder));
@@ -122,60 +127,6 @@ public class RejectRecordTests extends BaseRMRestTest
dataSite.deleteSite(publicSite); 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 * Check for completion of link action
*/ */