From 62b7426b735812a5732b62e0b137356dfbc9c7ad Mon Sep 17 00:00:00 2001 From: Ross Gale Date: Wed, 5 Jun 2019 09:07:35 +0100 Subject: [PATCH] RM-6869 code comment changes --- .../community/records/RejectRecordTests.java | 131 ++++++++++++++++-- .../record/RecordServiceImplUnitTest.java | 1 - 2 files changed, 123 insertions(+), 9 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/RejectRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/RejectRecordTests.java index f2a8bc6c21..3c003d07bf 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/RejectRecordTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/records/RejectRecordTests.java @@ -29,6 +29,7 @@ package org.alfresco.rest.rm.community.records; import static org.alfresco.utility.data.RandomData.getRandomName; import static org.alfresco.utility.report.log.Step.STEP; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; import static org.testng.Assert.assertTrue; import java.util.Optional; @@ -39,6 +40,7 @@ import org.alfresco.rest.rm.community.model.recordcategory.RecordCategory; 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.test.AlfrescoTest; import org.alfresco.utility.Utility; import org.alfresco.utility.model.FileModel; @@ -58,10 +60,11 @@ public class RejectRecordTests extends BaseRMRestTest private RecordCategory recordCategory; private RecordCategoryChild recordFolder; + private RecordCategoryChildCollection recordFolders; + @BeforeClass (alwaysRun = true) public void setUp() throws Exception { - createRMSiteIfNotExists(); publicSite = dataSite.usingAdmin().createPublicRandomSite(); recordCategory = createRootCategory(getRandomName("recordCategory")); recordFolder = createFolder(recordCategory.getId(), getRandomName("recordFolder")); @@ -76,31 +79,39 @@ public class RejectRecordTests extends BaseRMRestTest { STEP("Create a document in the collaboration site"); FileModel testFile = dataContent.usingSite(publicSite) - .usingAdmin() - .createContent(CMISUtil.DocumentType.TEXT_PLAIN); + .usingAdmin() + .createContent(CMISUtil.DocumentType.TEXT_PLAIN); STEP("Declare document as record with a location parameter value"); getRestAPIFactory().getActionsAPI(getAdminUser()).declareAndFile(testFile, Utility.buildPath(recordCategory.getName(), recordFolder.getName())); + assertTrue(isMatchingRecordInRecordFolder(testFile, recordFolder), "Record not declared"); STEP("Link record to new folder"); getRestAPIFactory().getActionsAPI().linkRecord(testFile, recordCategory.getName() + "/" + recordFolder.getName() + "_2"); - RecordCategoryChildCollection recordFolders = getRestAPIFactory().getRecordCategoryAPI().getRecordCategoryChildren(recordCategory.getId()); + recordFolders = null; + checkActionExecution(new LinkEvaluator()); + Optional linkedFolder = recordFolders.getEntries().stream().filter(child -> child.getEntry().getName().equals(recordFolder.getName() + "_2")) - .findFirst(); + .findFirst(); if (linkedFolder.isPresent()) { STEP("Verify the linked record has been added"); - assertFalse(getRestAPIFactory().getRecordFolderAPI().getRecordFolderChildren(linkedFolder.get().getEntry().getId()).isEmpty()); + assertFalse("Linked record not created", getRestAPIFactory().getRecordFolderAPI().getRecordFolderChildren(linkedFolder.get().getEntry().getId()).isEmpty()); STEP("Reject record"); getRestAPIFactory().getActionsAPI().rejectRecord(testFile, "Just because"); + checkActionExecution(new RejectEvaluator()); STEP("Check record has been rejected"); - assertFalse(isMatchingRecordInRecordFolder(testFile, recordFolder)); + assertFalse("Record rejection failure", isMatchingRecordInRecordFolder(testFile, recordFolder)); STEP("Verify the linked record has been removed"); - assertTrue(getRestAPIFactory().getRecordFolderAPI().getRecordFolderChildren(linkedFolder.get().getEntry().getId()).isEmpty()); + assertTrue(getRestAPIFactory().getRecordFolderAPI().getRecordFolderChildren(linkedFolder.get().getEntry().getId()).isEmpty(), "Record link not removed"); + } + else + { + fail("Problem creating linked record"); } } @@ -110,4 +121,108 @@ public class RejectRecordTests extends BaseRMRestTest deleteRecordCategory(recordCategory.getId()); 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 + */ + private class LinkEvaluator implements ActionEvaluator + { + /** + * {@inheritDoc} + */ + @Override + public boolean evaluate() + { + recordFolders = getRestAPIFactory().getRecordCategoryAPI().getRecordCategoryChildren(recordCategory.getId()); + return recordFolders != null && recordFolders.getEntries().size() == 2; + } + + /** + * {@inheritDoc} + */ + @Override + public String getErrorMessage() + { + return "Error creating linked record"; + } + } + + /** + * Check for completion of reject action + */ + private class RejectEvaluator implements ActionEvaluator + { + /** + * {@inheritDoc} + */ + @Override + public boolean evaluate() + { + RecordFolderCollection records = getRestAPIFactory().getRecordFolderAPI().getRecordFolderChildren(recordFolder.getId()); + return records != null && records.getEntries().size() == 0; + } + + /** + * {@inheritDoc} + */ + @Override + public String getErrorMessage() + { + return "Error rejecting record"; + } + } } diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImplUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImplUnitTest.java index b3892b84a6..f1ef96b3d7 100644 --- a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImplUnitTest.java +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImplUnitTest.java @@ -680,7 +680,6 @@ public class RecordServiceImplUnitTest extends BaseUnitTest assocs.add(mockedLinkAssoc); when(mockedNodeService.getParentAssocs(dmNodeRef)).thenReturn(assocs); when(mockedChildAssoc.getParentRef()).thenReturn(originatingLocation); - when(mockedLinkAssoc.getParentRef()).thenReturn(dmNodeRef); when(mockedLinkAssoc.getParentRef()).thenReturn(link); when(mockedNodeService.getType(link)).thenReturn(TYPE_RECORD_FOLDER); when(mockedNodeService.getPrimaryParent(dmNodeRef)).thenReturn(mockedParentAssoc);