From 3cf0d61d328d564d72318027fb8b2c464b81f539 Mon Sep 17 00:00:00 2001 From: Alexandru Epure Date: Thu, 22 Jun 2017 12:57:06 +0000 Subject: [PATCH] REPO-2520: Community: SiteMembership Java API calls should tell which site resulted in errors Changed tests asserts from (actual value, expected value) to (expected value, actual value) as recommended in the Junit Assert Javadoc. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@137771 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/repository/upload/upload.post.js | 31 ++++++----------- .../repo/web/scripts/site/AllSiteTests.java | 6 ++-- .../rest/api/tests/TestNodeComments.java | 34 +++++++++++++++---- 3 files changed, 42 insertions(+), 29 deletions(-) diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/upload/upload.post.js b/config/alfresco/templates/webscripts/org/alfresco/repository/upload/upload.post.js index be2b6430c8..a745d4ad0f 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/upload/upload.post.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/upload/upload.post.js @@ -272,29 +272,20 @@ function main() if (updateNameAndMimetype) { - //update node name with the new extension if type is changed - var existingFileName = updateNode.getName(), - dotIndexExistingFile = existingFileName.lastIndexOf("."), - dotIndexNewFile = filename.lastIndexOf("."); - - var existingFileExtension = (dotIndexExistingFile !== -1) ? existingFileName.substring(dotIndexExistingFile) : "", - newFileExtension = (dotIndexNewFile !== -1) ? filename.substring(dotIndexNewFile) : ""; - if (existingFileExtension != newFileExtension) + //check to see if name is already used in folder + var existingFile = updateNode.getParent().childByNamePath(filename), + newFilename = filename; + var existingFileNodeRef = (existingFile !== null) ? String(existingFile.nodeRef) : '', + updateFileNodeRef = String(updateNodeRef); + if (existingFile !== null && existingFileNodeRef !== updateFileNodeRef) { - var newFileName = ((dotIndexExistingFile !== -1) ? existingFileName.substring(0, dotIndexExistingFile) : existingFileName) + newFileExtension; - var alreadyExistsFile = updateNode.getParent().childByNamePath(newFileName); - - var existingFileNodeRef = (alreadyExistsFile !== null) ? String(alreadyExistsFile.nodeRef) : '', - updateFileNodeRef = String(updateNodeRef); - if (alreadyExistsFile !== null && existingFileNodeRef !== updateFileNodeRef) - { - //name it's already used for other than node to update; create a new one - newFileName = createUniqueNameInFolder(newFileName, updateNode.getParent()); - } - updateNode.setName(newFileName); + //name it's already used for other than node to update; create a new one + newFilename = createUniqueNameInFolder(filename, updateNode.getParent()); } + //update node name + updateNode.setName(newFilename); } - + var workingcopy = updateNode.hasAspect("cm:workingcopy"); if (!workingcopy && updateNode.isLocked) { diff --git a/source/test-java/org/alfresco/repo/web/scripts/site/AllSiteTests.java b/source/test-java/org/alfresco/repo/web/scripts/site/AllSiteTests.java index 87c7a789f1..dc84456ac3 100644 --- a/source/test-java/org/alfresco/repo/web/scripts/site/AllSiteTests.java +++ b/source/test-java/org/alfresco/repo/web/scripts/site/AllSiteTests.java @@ -29,7 +29,8 @@ import org.alfresco.repo.activities.SiteActivityTestCaseSensitivity; import org.alfresco.repo.activities.SiteActivityTestCaseInsensitivity; import org.alfresco.repo.site.SiteServiceImplMoreTest; import org.alfresco.repo.site.SiteServiceImplTest; -import org.alfresco.service.cmr.site.SiteService; +import org.alfresco.service.cmr.site.SiteService; +import org.alfresco.repo.site.SiteMembershipTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; @@ -48,7 +49,8 @@ import org.junit.runners.Suite; SiteServiceTest.class, SiteExportServiceTest.class, SiteActivityTestCaseSensitivity.class, - SiteActivityTestCaseInsensitivity.class + SiteActivityTestCaseInsensitivity.class, + SiteMembershipTest.class }) public class AllSiteTests { diff --git a/source/test-java/org/alfresco/rest/api/tests/TestNodeComments.java b/source/test-java/org/alfresco/rest/api/tests/TestNodeComments.java index 17d6a1b914..ab07fc8365 100644 --- a/source/test-java/org/alfresco/rest/api/tests/TestNodeComments.java +++ b/source/test-java/org/alfresco/rest/api/tests/TestNodeComments.java @@ -788,6 +788,7 @@ public class TestNodeComments extends EnterpriseTestApi Comments commentsProxy = publicApiClient.comments(); // locked node - cannot add/edit/delete comments (MNT-14945, MNT-16446) + // only the lock owner can (ALF-21907) try { @@ -805,15 +806,15 @@ public class TestNodeComments extends EnterpriseTestApi repoService.lockNode(nodeRef1); return null; } - }, person11.getId(), network1.getId()); + }, person13.getId(), network1.getId()); - publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId())); + // change to not lock owner + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person14.getId())); // test GET for a locked node - - int skipCount = 0; - int maxItems = Integer.MAX_VALUE; - Paging paging = getPaging(skipCount, maxItems); + int skipCount = 0; + int maxItems = Integer.MAX_VALUE; + Paging paging = getPaging(skipCount, maxItems); commentsProxy.getNodeComments(nodeRef1.getId(), createParams(paging, null)); // test POST for a locked node @@ -853,8 +854,27 @@ public class TestNodeComments extends EnterpriseTestApi } catch (PublicApiException e) { - assertEquals(HttpStatus.SC_CONFLICT, e.getHttpResponse().getStatusCode()); + assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode()); } + + // change to lock owner + publicApiClient.setRequestContext(new RequestContext(network1.getId(), person13.getId())); + + // test GET for a locked node + commentsProxy.getNodeComments(nodeRef1.getId(), createParams(paging, null)); + + // test POST for a locked node + comment = new Comment(); + comment.setContent("my other comment"); + createdComment = commentsProxy.createNodeComment(nodeRef1.getId(), comment); + + // test PUT for a locked node + Comment updatedComment = new Comment(); + updatedComment.setContent("my comment"); + commentsProxy.updateNodeComment(nodeRef1.getId(), createdComment.getId(), updatedComment); + + // test DELETE for a locked node + commentsProxy.removeNodeComment(nodeRef1.getId(), createdComment.getId()); } finally {