diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java index 907bbe53ab..fd8882e7ba 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/core/RestAPIFactory.java @@ -26,6 +26,8 @@ */ package org.alfresco.rest.core; +import org.alfresco.rest.requests.Node; +import org.alfresco.rest.requests.coreAPI.RestCoreAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.FilePlanComponentAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.FilesAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.RMSiteAPI; @@ -33,6 +35,7 @@ import org.alfresco.rest.rm.community.requests.igCoreAPI.RMUserAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.RecordsAPI; import org.alfresco.rest.rm.community.requests.igCoreAPI.RestIGCoreAPI; import org.alfresco.utility.data.DataUser; +import org.alfresco.utility.model.RepoTestModel; import org.alfresco.utility.model.UserModel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; @@ -68,6 +71,22 @@ public class RestAPIFactory return getRmRestWrapper().withIGCoreAPI(); } + private RestCoreAPI getRestCoreAPI(UserModel userModel) + { + getRmRestWrapper().authenticateUser(userModel != null ? userModel : dataUser.getAdminUser()); + return getRmRestWrapper().withCoreAPI(); + } + + public Node getNodeAPI(RepoTestModel model) throws Exception + { + return getRestCoreAPI(null).usingNode(model); + } + + public Node getNodeAPI(UserModel userModel, RepoTestModel model) throws Exception + { + return getRestCoreAPI(userModel).usingNode(model); + } + public RMSiteAPI getRMSiteAPI() { return getRestIGCoreAPI(null).usingRMSite(); @@ -97,7 +116,7 @@ public class RestAPIFactory { return getRestIGCoreAPI(userModel).usingRecords(); } - + public FilesAPI getFilesAPI() { return getRestIGCoreAPI(null).usingFiles(); @@ -107,12 +126,12 @@ public class RestAPIFactory { return getRestIGCoreAPI(userModel).usingFiles(); } - + public RMUserAPI getRMUserAPI() { return getRestIGCoreAPI(null).usingRMUser(); } - + public RMUserAPI getRMUserAPI(UserModel userModel) { return getRestIGCoreAPI(userModel).usingRMUser(); diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/DeclareDocumentAsRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/DeclareDocumentAsRecordTests.java index 6f6dfcb4f1..41d4532672 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/DeclareDocumentAsRecordTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/DeclareDocumentAsRecordTests.java @@ -39,6 +39,7 @@ import java.util.List; import java.util.stream.Collectors; import org.alfresco.dataprep.CMISUtil; +import org.alfresco.rest.model.RestNodeModel; import org.alfresco.rest.rm.community.base.BaseRMRestTest; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponent; import org.alfresco.rest.rm.community.model.fileplancomponents.FilePlanComponentEntry; @@ -79,15 +80,15 @@ public class DeclareDocumentAsRecordTests extends BaseRMRestTest // create test user and test collaboration site to store documents in testUser = dataUser.createRandomTestUser(); testUserReadOnly = dataUser.createRandomTestUser(); - + testSite = dataSite.usingAdmin().createPublicRandomSite(); - + dataUser.addUserToSite(testUser, testSite, UserRole.SiteContributor); dataUser.addUserToSite(testUserReadOnly, testSite, UserRole.SiteConsumer); - + testFolder = dataContent.usingSite(testSite).usingUser(testUser).createFolder(); } - + /** *
* Given a document that is not a record @@ -103,17 +104,17 @@ public class DeclareDocumentAsRecordTests extends BaseRMRestTest @Test(description = "User with correct permissions can declare document as a record") @AlfrescoTest(jira = "RM-4429") public void userWithPrivilegesCanDeclareDocumentAsRecord() throws Exception - { - // create document in a folder in a collaboration site + { + // create document in a folder in a collaboration site FileModel document = dataContent.usingSite(testSite) .usingUser(testUser) .usingResource(testFolder) .createContent(CMISUtil.DocumentType.TEXT_PLAIN); - + // declare document as record FilePlanComponent record = getRestAPIFactory().getFilesAPI(testUser).declareAsRecord(document.getNodeRefWithoutVersion()); assertStatusCode(CREATED); - + // verify the declared record is in Unfiled Records folder FilePlanComponentAPI filePlanComponentAPI = getRestAPIFactory().getFilePlanComponentsAPI(); ListmatchingRecords = filePlanComponentAPI.listChildComponents(UNFILED_RECORDS_CONTAINER_ALIAS) @@ -125,23 +126,23 @@ public class DeclareDocumentAsRecordTests extends BaseRMRestTest assertEquals(matchingRecords.size(), 1, "More than one record matching document name"); // verify the original file in collaboration site has been renamed to reflect the record identifier - // FIXME: this call uses the FilePlanComponentAPI due to no TAS support for Node API in TAS restapi v 5.2.0-0. See RM-4585 for details. - List filesAfterRename = filePlanComponentAPI.listChildComponents(testFolder.getNodeRefWithoutVersion()) - .getEntries() - .stream() - .filter(f -> f.getFilePlanComponentModel().getId().equals(document.getNodeRefWithoutVersion())) - .collect(Collectors.toList()); + List filesAfterRename = getRestAPIFactory().getNodeAPI(testFolder) + .listChildren() + .getEntries() + .stream() + .filter(f -> f.onModel().getId().equals(document.getNodeRefWithoutVersion())) + .collect(Collectors.toList()); assertEquals(filesAfterRename.size(), 1, "There should be only one file in folder " + testFolder.getName()); // verify the new name has the form of " ( ). " - assertEquals(filesAfterRename.get(0).getFilePlanComponentModel().getName(), - document.getName().replace(".", String.format(" (%s).", record.getProperties().getRecordId()))); + String recordName = filesAfterRename.get(0).onModel().getName(); + assertEquals(recordName, document.getName().replace(".", String.format(" (%s).", record.getProperties().getRecordId()))); // verify the document in collaboration site is now a record, note the file is now renamed hence folder + doc. name concatenation // this also verifies the document is still in the initial folder Document documentPostFiling = dataContent.usingSite(testSite) .usingUser(testUser) - .getCMISDocument(testFolder.getCmisLocation() + "/" + filesAfterRename.get(0).getFilePlanComponentModel().getName()); + .getCMISDocument(testFolder.getCmisLocation() + "/" + recordName); // a document is a record if "Record" is one of its secondary types List documentSecondary = documentPostFiling.getSecondaryTypes() @@ -151,7 +152,7 @@ public class DeclareDocumentAsRecordTests extends BaseRMRestTest assertFalse(documentSecondary.isEmpty(), "Document is not a record"); // verify the document is readable and has same content as corresponding record - try + try ( InputStream recordInputStream = getRestAPIFactory().getRecordsAPI().getRecordContent(record.getId()).asInputStream(); InputStream documentInputStream = documentPostFiling.getContentStream().getStream(); @@ -160,7 +161,7 @@ public class DeclareDocumentAsRecordTests extends BaseRMRestTest assertEquals(DigestUtils.sha1(recordInputStream), DigestUtils.sha1(documentInputStream)); } } - + /** * * Given a document that is not a record @@ -172,26 +173,25 @@ public class DeclareDocumentAsRecordTests extends BaseRMRestTest */ @Test(description = "User with read-only permissions can't declare document a record") @AlfrescoTest(jira = "RM-4429") - public void userWithReadPermissionsCantDeclare() throws Exception + public void userWithReadPermissionsCantDeclare() throws Exception { // create document in a folder in a collaboration site FileModel document = dataContent.usingSite(testSite) .usingUser(testUser) .usingResource(testFolder) .createContent(CMISUtil.DocumentType.TEXT_PLAIN); - + // declare document as record as testUserReadOnly getRestAPIFactory().getFilesAPI(testUserReadOnly).declareAsRecord(document.getNodeRefWithoutVersion()); assertStatusCode(FORBIDDEN); - + // verify the document is still in the original folder - // FIXME: this call uses the FilePlanComponentAPI due to no TAS support for Node API in TAS restapi v 5.2.0-0. See RM-4585 for details. - ListfilesAfterRename = getRestAPIFactory().getFilePlanComponentsAPI() - .listChildComponents(testFolder.getNodeRefWithoutVersion()) - .getEntries() - .stream() - .filter(f -> f.getFilePlanComponentModel().getId().equals(document.getNodeRefWithoutVersion())) - .collect(Collectors.toList()); + List filesAfterRename = getRestAPIFactory().getNodeAPI(testFolder) + .listChildren() + .getEntries() + .stream() + .filter(f -> f.onModel().getId().equals(document.getNodeRefWithoutVersion())) + .collect(Collectors.toList()); assertEquals(filesAfterRename.size(), 1, "Declare as record failed but original document is missing"); } @@ -219,15 +219,15 @@ public class DeclareDocumentAsRecordTests extends BaseRMRestTest FilePlanComponent record = getRestAPIFactory().getFilePlanComponentsAPI() .createFilePlanComponent(nonelectronicRecord, createCategoryFolderInFilePlan().getId()); assertStatusCode(CREATED); - + // try to declare it as a record getRestAPIFactory().getFilesAPI().declareAsRecord(record.getId()); assertStatusCode(UNPROCESSABLE_ENTITY); } - + /** * - * Given a node that is NOT a document + * Given a node that is NOT a document * When I declare the node as a record * Then I get a invalid operation exception *@@ -238,7 +238,7 @@ public class DeclareDocumentAsRecordTests extends BaseRMRestTest public void nonDocumentCantBeDeclaredARecord() throws Exception { FolderModel otherTestFolder = dataContent.usingSite(testSite).usingUser(testUser).createFolder(); - + // try to declare otherTestFolder as a record getRestAPIFactory().getFilesAPI().declareAsRecord(otherTestFolder.getNodeRefWithoutVersion()); assertStatusCode(UNPROCESSABLE_ENTITY);