diff --git a/e2e-test/java/org/alfresco/rest/RestTest.java b/e2e-test/java/org/alfresco/rest/RestTest.java index bd25d30ff..789d7cca1 100644 --- a/e2e-test/java/org/alfresco/rest/RestTest.java +++ b/e2e-test/java/org/alfresco/rest/RestTest.java @@ -14,6 +14,7 @@ import org.alfresco.utility.data.DataLink; import org.alfresco.utility.data.DataSite; import org.alfresco.utility.data.DataUser; import org.alfresco.utility.data.DataWorkflow; +import org.alfresco.utility.model.SiteModel; import org.alfresco.utility.network.ServerHealth; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -63,11 +64,14 @@ public abstract class RestTest extends AbstractTestNGSpringContextTests @Autowired protected WorkflowService workflow; + protected SiteModel testSite; + @BeforeSuite(alwaysRun = true) public void checkServerHealth() throws Exception { super.springTestContextPrepareTestInstance(); serverHealth.assertServerIsOnline(); + testSite = dataSite.createPublicRandomSite(); } @BeforeMethod(alwaysRun=true) diff --git a/e2e-test/java/org/alfresco/rest/aos/AosApiTest.java b/e2e-test/java/org/alfresco/rest/aos/AosApiTest.java new file mode 100644 index 000000000..6223db2f7 --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/aos/AosApiTest.java @@ -0,0 +1,24 @@ +package org.alfresco.rest.aos; + +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestRequest; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.testng.annotations.Test; + +public class AosApiTest extends RestTest +{ + /* + * @author: Catalin Gornea + * + * simple test for demo purposes on how to use Aos with Rest + */ + @Test(enabled=false) + public void assertResponsIsSuccesufulWhenGetRootDirectory() throws Exception + { + restClient.authenticateUser(dataUser.getAdminUser()).withAosAPI(); + RestRequest request = RestRequest.simpleRequest(HttpMethod.GET, ""); + restClient.process(request); + restClient.assertStatusCodeIs(HttpStatus.OK); + } +} diff --git a/e2e-test/java/org/alfresco/rest/cmis/CmisBrowserTest.java b/e2e-test/java/org/alfresco/rest/cmis/CmisBrowserTest.java new file mode 100644 index 000000000..1e9afbab7 --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/cmis/CmisBrowserTest.java @@ -0,0 +1,25 @@ +package org.alfresco.rest.cmis; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.core.RestResponse; +import org.alfresco.utility.model.FileModel; +import org.testng.annotations.Test; + +public class CmisBrowserTest extends RestTest +{ + /* + * @author: Paul Brodner + * simple test for demo purposes on how to use CMIS browser binding with Rest + */ + @Test(enabled=false) + public void assertContentDispositionHeaderOnCmisFile() throws Exception + { + FileModel document = dataContent.usingUser(dataUser.getAdminUser()) + .usingSite(testSite).createContent(DocumentType.HTML); + + RestResponse response = restClient.authenticateUser(dataUser.getAdminUser()).withCMISApi().getRootObjectByID(document); + response.assertThat().header("Content-Disposition", String.format("attachment; filename=%s", document.getName())); + } + +} diff --git a/e2e-test/java/org/alfresco/rest/comments/AddCommentsFullTests.java b/e2e-test/java/org/alfresco/rest/comments/AddCommentsFullTests.java index 58cd1f92a..91d4b8153 100644 --- a/e2e-test/java/org/alfresco/rest/comments/AddCommentsFullTests.java +++ b/e2e-test/java/org/alfresco/rest/comments/AddCommentsFullTests.java @@ -154,9 +154,9 @@ public class AddCommentsFullTests extends RestTest restClient.processModel(RestCommentModel.class, request); restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST); - restClient.assertLastError().getErrorKey().contains("Unrecognized field \"content2\""); - restClient.assertLastError().containsSummary("Unrecognized field \"content2\""); - restClient.assertLastError().getDescriptionURL().contains("https://api-explorer.alfresco.com"); - restClient.assertLastError().getStackTrace().contains("For security reasons the stack trace is no longer displayed, but the property is kept for previous versions"); + restClient.assertLastError().containsErrorKey(String.format(RestErrorModel.UNRECOGNIZED_FIELD, "content2")); + restClient.assertLastError().containsSummary(String.format(RestErrorModel.UNRECOGNIZED_FIELD, "content2")); + restClient.assertLastError().descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + restClient.assertLastError().stackTraceIs(RestErrorModel.STACKTRACE); } } diff --git a/e2e-test/java/org/alfresco/rest/comments/GetCommentsFullTests.java b/e2e-test/java/org/alfresco/rest/comments/GetCommentsFullTests.java index b7021f602..cf0e38b9f 100644 --- a/e2e-test/java/org/alfresco/rest/comments/GetCommentsFullTests.java +++ b/e2e-test/java/org/alfresco/rest/comments/GetCommentsFullTests.java @@ -207,9 +207,9 @@ public class GetCommentsFullTests extends RestTest restClient.authenticateUser(adminUserModel).withCoreAPI().usingResource(file).usingParams("maxItems=0").getNodeComments(); restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError().containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS); - restClient.assertLastError().getErrorKey().contains("Only positive values supported for maxItems."); - restClient.assertLastError().containsSummary("Only positive values supported for maxItems."); - restClient.assertLastError().getDescriptionURL().contains("https://api-explorer.alfresco.com"); - restClient.assertLastError().getStackTrace().contains("For security reasons the stack trace is no longer displayed, but the property is kept for previous versions"); + restClient.assertLastError().containsErrorKey(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS); + restClient.assertLastError().containsSummary(RestErrorModel.ONLY_POSITIVE_VALUES_MAXITEMS); + restClient.assertLastError().descriptionURLIs(RestErrorModel.RESTAPIEXPLORER); + restClient.assertLastError().stackTraceIs(RestErrorModel.STACKTRACE); } } \ No newline at end of file diff --git a/e2e-test/java/org/alfresco/rest/nodes/NodesContentTests.java b/e2e-test/java/org/alfresco/rest/nodes/NodesContentTests.java new file mode 100644 index 000000000..abc729ab7 --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/nodes/NodesContentTests.java @@ -0,0 +1,62 @@ +package org.alfresco.rest.nodes; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FileType; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +/** + * + * @author mpopa + * + */ +public class NodesContentTests extends RestTest +{ + private UserModel user1, user2; + private SiteModel site1, site2; + private FileModel file1; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + user1 = dataUser.createRandomTestUser(); + user2 = dataUser.createRandomTestUser(); + site1 = dataSite.usingUser(user1).createPublicRandomSite(); + site2 = dataSite.usingUser(user2).createPublicRandomSite(); + file1 = dataContent.usingUser(user1).usingSite(site1).createContent(DocumentType.TEXT_PLAIN); + } + + @TestRail(section = { TestGroup.REST_API,TestGroup.NODES }, executionType = ExecutionType.SANITY, + description = "Verify file name in Content-Disposition header") + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY}) + public void checkFileNameWithRegularCharsInHeader() throws Exception + { + restClient.authenticateUser(user1).withCoreAPI().usingNode(file1).usingParams("attachment=false").getNodeContent(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertHeaderValueContains("Content-Disposition", String.format("filename=\"%s\"", file1.getName())); + } + + @Bug(id="REPO-2112") + @TestRail(section = { TestGroup.REST_API,TestGroup.NODES }, executionType = ExecutionType.REGRESSION, + description = "Verify file name with special chars is escaped in Content-Disposition header") + @Test(groups = { TestGroup.REST_API, TestGroup.NODES, TestGroup.CORE}) + public void checkFileNameWithSpecialCharsInHeader() throws Exception + { + char c1 = 127; + char c2 = 31; + char c3 = 256; + FileModel file = dataContent.usingUser(user2).usingSite(site2).createContent(new FileModel("\ntest\"" + c1 + c2 + c3, FileType.TEXT_PLAIN)); + restClient.authenticateUser(user2).withCoreAPI().usingNode(file).usingParams("attachment=false").getNodeContent(); + restClient.assertStatusCodeIs(HttpStatus.OK); + restClient.assertHeaderValueContains("Content-Disposition","filename=\" test .txt\""); + } + +} diff --git a/e2e-test/java/org/alfresco/rest/renditions/CreateRenditionTests.java b/e2e-test/java/org/alfresco/rest/renditions/CreateRenditionTests.java new file mode 100644 index 000000000..441008d64 --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/renditions/CreateRenditionTests.java @@ -0,0 +1,95 @@ +package org.alfresco.rest.renditions; + +import org.alfresco.dataprep.CMISUtil.DocumentType; +import org.alfresco.rest.RestTest; +import org.alfresco.rest.exception.JsonToModelConversionException; +import org.alfresco.rest.model.RestNodeModel; +import org.alfresco.utility.Utility; +import org.alfresco.utility.model.FileModel; +import org.alfresco.utility.model.FolderModel; +import org.alfresco.utility.model.SiteModel; +import org.alfresco.utility.model.TestGroup; +import org.alfresco.utility.model.UserModel; +import org.alfresco.utility.report.Bug; +import org.alfresco.utility.testrail.ExecutionType; +import org.alfresco.utility.testrail.annotation.TestRail; +import org.springframework.http.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +/** + * Handles tests related to POST api-explorer/#!/renditions + * @author Cristina Axinte + * + */ +public class CreateRenditionTests extends RestTest +{ + private UserModel adminUser, user; + private SiteModel site; + private FileModel document; + + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + adminUser = dataUser.getAdminUser(); + user = dataUser.createRandomTestUser(); + site = dataSite.usingUser(user).createPublicRandomSite(); + } + + @BeforeMethod(alwaysRun = true) + public void createDocument() throws Exception + { + document = dataContent.usingUser(user).usingSite(site).createContent(DocumentType.TEXT_PLAIN); + } + + @Bug(id = "REPO-2042", description = "Should fail only on MAC OS System and Linux" ) + @TestRail(section = { TestGroup.REST_API, TestGroup.RENDITIONS }, executionType = ExecutionType.SANITY, + description = "Verify admin user creates rendition with Rest API and status code is 202") + @Test(groups = { TestGroup.REST_API, TestGroup.RENDITIONS, TestGroup.SANITY }) + public void adminCanCreateRenditionToExistingNode() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(adminUser).withCoreAPI().usingNode(document).createNodeRendition("pdf"); + restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); + + restClient.withCoreAPI().usingNode(document).getNodeRendition("pdf") + .assertThat().field("status").is("CREATED"); + } + + @Bug(id = "REPO-2042", description = "Should fail only on MAC OS System and Linux" ) + @TestRail(section = { TestGroup.REST_API, TestGroup.RENDITIONS }, executionType = ExecutionType.SANITY, + description = "Verify user that created the document can also creates 'pdf' rendition for it with Rest API and status code is 202") + @Test(groups = { TestGroup.REST_API, TestGroup.RENDITIONS, TestGroup.SANITY }) + public void userThatCreatedFileCanCreatePdfRenditionForIt() throws JsonToModelConversionException, Exception + { + restClient.authenticateUser(user).withCoreAPI().usingNode(document).createNodeRendition("pdf"); + restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); + + restClient.withCoreAPI().usingNode(document).getNodeRendition("pdf") + .assertThat().field("status").is("CREATED"); + } + + @Bug(id = "REPO-2042", description = "Should fail only on MAC OS System and Linux" ) + @TestRail(section = { TestGroup.REST_API, TestGroup.RENDITIONS }, executionType = ExecutionType.SANITY, + description = "Verify user that created the document can also creates 'doclib' rendition for it with Rest API and status code is 202") + @Test(groups = { TestGroup.REST_API, TestGroup.RENDITIONS, TestGroup.SANITY }) + public void userThatCreatedFileCanCreateDoclibRenditionForIt() throws JsonToModelConversionException, Exception + { + FolderModel folder = dataContent.usingUser(user).usingSite(site).createFolder(); + restClient.authenticateUser(user) + .configureRequestSpec() + .addMultiPart("filedata", Utility.getResourceTestDataFile("my-file.tif")); + + RestNodeModel fileNode = restClient.authenticateUser(user).withCoreAPI().usingResource(folder).createNode(); + restClient.assertStatusCodeIs(HttpStatus.CREATED); + document = new FileModel("my-file.tif"); + document.setCmisLocation(folder.getCmisLocation() + "/my-file.tif"); + document.setNodeRef(fileNode.getId()); + + restClient.authenticateUser(user).withCoreAPI().usingNode(document).createNodeRendition("doclib"); + restClient.assertStatusCodeIs(HttpStatus.ACCEPTED); + + restClient.withCoreAPI().usingNode(document).getNodeRendition("doclib") + .assertThat().field("status").is("CREATED"); + } +} diff --git a/e2e-test/java/org/alfresco/rest/search/AbstractSearchTest.java b/e2e-test/java/org/alfresco/rest/search/AbstractSearchTest.java index e69a47cce..594105873 100644 --- a/e2e-test/java/org/alfresco/rest/search/AbstractSearchTest.java +++ b/e2e-test/java/org/alfresco/rest/search/AbstractSearchTest.java @@ -35,6 +35,7 @@ import org.testng.annotations.BeforeClass; *