mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud)
57245: Merged V4.2-BUG-FIX (4.2.1) to HEAD-BUG-FIX (Cloud/4.3) 57225: Reverse Merged as it caused the MoveMethodTest build error in https://bamboo.alfresco.com/bamboo/browse/ALF-ENTERPRISEV42BUGFIX-25 57176: Merged V4.1-BUG-FIX (4.1.7) to V4.2-BUG-FIX (4.2.0) 56965 : Merged DEV to V4.1-BUG-FIX (4.1.7) 55964 : MNT-9662 : HTTP error 500 when renaming a space with a numerical name via WebDAV - Prevent folders to take part in any kind of shuffle operation. 56308 : MNT-9662 : HTTP error 500 when renaming a space with a numerical name via WebDAV - Unit test that demonstrate issue. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@61800 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -198,7 +198,7 @@ public class MoveMethod extends HierarchicalMethod
|
|||||||
}
|
}
|
||||||
// ALF-7079 fix, if destination exists then its content is updated with source content and source is deleted if
|
// ALF-7079 fix, if destination exists then its content is updated with source content and source is deleted if
|
||||||
// this is a move
|
// this is a move
|
||||||
if (!sourceFileInfo.isFolder() && destFileInfo != null && !sourceParentNodeRef.equals(destParentNodeRef))
|
if (destFileInfo != null && !sourceParentNodeRef.equals(destParentNodeRef))
|
||||||
{
|
{
|
||||||
copyContentOnly(sourceFileInfo, destFileInfo, fileFolderService);
|
copyContentOnly(sourceFileInfo, destFileInfo, fileFolderService);
|
||||||
fileFolderService.setHidden(destFileInfo.getNodeRef(), false);
|
fileFolderService.setHidden(destFileInfo.getNodeRef(), false);
|
||||||
|
@@ -18,10 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.repo.webdav;
|
package org.alfresco.repo.webdav;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -30,27 +26,15 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
|
||||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
|
||||||
import org.alfresco.service.cmr.model.FileFolderService;
|
import org.alfresco.service.cmr.model.FileFolderService;
|
||||||
import org.alfresco.service.cmr.model.FileInfo;
|
import org.alfresco.service.cmr.model.FileInfo;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
|
||||||
import org.alfresco.service.cmr.repository.StoreRef;
|
|
||||||
import org.alfresco.service.cmr.search.ResultSet;
|
|
||||||
import org.alfresco.service.cmr.search.SearchService;
|
|
||||||
import org.alfresco.service.transaction.TransactionService;
|
|
||||||
import org.alfresco.util.ApplicationContextHelper;
|
|
||||||
import org.alfresco.util.GUID;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.mock.web.MockHttpServletRequest;
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
import org.springframework.mock.web.MockHttpServletResponse;
|
import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
|
|
||||||
@@ -62,14 +46,12 @@ import org.springframework.mock.web.MockHttpServletResponse;
|
|||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class MoveMethodTest
|
public class MoveMethodTest
|
||||||
{
|
{
|
||||||
private static ApplicationContext ctx;
|
|
||||||
|
|
||||||
private MoveMethod moveMethod;
|
private MoveMethod moveMethod;
|
||||||
private @Mock WebDAVHelper davHelper;
|
private @Mock WebDAVHelper davHelper;
|
||||||
private MockHttpServletRequest req;
|
private MockHttpServletRequest req;
|
||||||
private MockHttpServletResponse resp;
|
private MockHttpServletResponse resp;
|
||||||
private NodeRef rootNode;
|
private NodeRef rootNode;
|
||||||
private @Mock FileFolderService mockFileFolderService;
|
private @Mock FileFolderService fileFolderService;
|
||||||
private @Mock WebDAVLockService davLockService;
|
private @Mock WebDAVLockService davLockService;
|
||||||
private String destPath;
|
private String destPath;
|
||||||
private String sourcePath;
|
private String sourcePath;
|
||||||
@@ -78,34 +60,6 @@ public class MoveMethodTest
|
|||||||
private NodeRef destParentNodeRef;
|
private NodeRef destParentNodeRef;
|
||||||
private NodeRef sourceNodeRef;
|
private NodeRef sourceNodeRef;
|
||||||
|
|
||||||
private SearchService searchService;
|
|
||||||
private FileFolderService fileFolderService;
|
|
||||||
private NodeService nodeService;
|
|
||||||
private TransactionService transactionService;
|
|
||||||
private WebDAVHelper webDAVHelper;
|
|
||||||
|
|
||||||
private NodeRef companyHomeNodeRef;
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpBeforeClass() throws Exception
|
|
||||||
{
|
|
||||||
ctx = ApplicationContextHelper.getApplicationContext(new String[]
|
|
||||||
{
|
|
||||||
"classpath:alfresco/application-context.xml", "classpath:alfresco/web-scripts-application-context.xml",
|
|
||||||
"classpath:alfresco/remote-api-context.xml"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown()
|
|
||||||
{
|
|
||||||
moveMethod = null;
|
|
||||||
req = null;
|
|
||||||
resp = null;
|
|
||||||
|
|
||||||
AuthenticationUtil.clearCurrentSecurityContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception
|
public void setUp() throws Exception
|
||||||
{
|
{
|
||||||
@@ -138,7 +92,7 @@ public class MoveMethodTest
|
|||||||
sourcePath = "/path/to/source.doc";
|
sourcePath = "/path/to/source.doc";
|
||||||
moveMethod.m_strPath = sourcePath;
|
moveMethod.m_strPath = sourcePath;
|
||||||
|
|
||||||
when(davHelper.getFileFolderService()).thenReturn(mockFileFolderService);
|
when(davHelper.getFileFolderService()).thenReturn(fileFolderService);
|
||||||
|
|
||||||
List<String> sourcePathSplit = Arrays.asList("path", "to", "source.doc");
|
List<String> sourcePathSplit = Arrays.asList("path", "to", "source.doc");
|
||||||
when(davHelper.splitAllPaths(sourcePath)).thenReturn(sourcePathSplit);
|
when(davHelper.splitAllPaths(sourcePath)).thenReturn(sourcePathSplit);
|
||||||
@@ -148,10 +102,10 @@ public class MoveMethodTest
|
|||||||
when(davHelper.splitAllPaths(destPath)).thenReturn(destPathSplit);
|
when(davHelper.splitAllPaths(destPath)).thenReturn(destPathSplit);
|
||||||
|
|
||||||
|
|
||||||
when(mockFileFolderService.resolveNamePath(rootNode, sourcePathSplit)).thenReturn(sourceFileInfo);
|
when(fileFolderService.resolveNamePath(rootNode, sourcePathSplit)).thenReturn(sourceFileInfo);
|
||||||
|
|
||||||
FileInfo destFileInfo = Mockito.mock(FileInfo.class);
|
FileInfo destFileInfo = Mockito.mock(FileInfo.class);
|
||||||
when(mockFileFolderService.resolveNamePath(rootNode, destPathSplit)).thenReturn(destFileInfo);
|
when(fileFolderService.resolveNamePath(rootNode, destPathSplit)).thenReturn(destFileInfo);
|
||||||
|
|
||||||
sourceParentNodeRef = new NodeRef("workspace://SpacesStore/parent");
|
sourceParentNodeRef = new NodeRef("workspace://SpacesStore/parent");
|
||||||
destParentNodeRef = new NodeRef("workspace://SpacesStore/parent");
|
destParentNodeRef = new NodeRef("workspace://SpacesStore/parent");
|
||||||
@@ -160,29 +114,6 @@ public class MoveMethodTest
|
|||||||
sourceNodeRef = new NodeRef("workspace://SpacesStore/sourcefile");
|
sourceNodeRef = new NodeRef("workspace://SpacesStore/sourcefile");
|
||||||
|
|
||||||
when(davHelper.getLockService()).thenReturn(davLockService);
|
when(davHelper.getLockService()).thenReturn(davLockService);
|
||||||
|
|
||||||
searchService = ctx.getBean("SearchService", SearchService.class);
|
|
||||||
fileFolderService = ctx.getBean("FileFolderService", FileFolderService.class);
|
|
||||||
nodeService = ctx.getBean("NodeService", NodeService.class);
|
|
||||||
transactionService = ctx.getBean("transactionService", TransactionService.class);
|
|
||||||
webDAVHelper = ctx.getBean("webDAVHelper", WebDAVHelper.class);
|
|
||||||
|
|
||||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
|
||||||
|
|
||||||
companyHomeNodeRef = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<NodeRef>()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public NodeRef execute() throws Throwable
|
|
||||||
{
|
|
||||||
// find "Company Home"
|
|
||||||
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
|
|
||||||
ResultSet resultSet = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, "PATH:\"/app:company_home\"");
|
|
||||||
NodeRef result = resultSet.getNodeRef(0);
|
|
||||||
resultSet.close();
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -191,9 +122,9 @@ public class MoveMethodTest
|
|||||||
{
|
{
|
||||||
moveMethod.moveOrCopy(sourceNodeRef, sourceParentNodeRef, destParentNodeRef, "dest.doc");
|
moveMethod.moveOrCopy(sourceNodeRef, sourceParentNodeRef, destParentNodeRef, "dest.doc");
|
||||||
|
|
||||||
verify(mockFileFolderService).rename(sourceNodeRef, "dest.doc");
|
verify(fileFolderService).rename(sourceNodeRef, "dest.doc");
|
||||||
verify(davLockService).unlock(sourceNodeRef);
|
verify(davLockService).unlock(sourceNodeRef);
|
||||||
verify(mockFileFolderService, never()).create(destParentNodeRef, "dest.doc", ContentModel.TYPE_CONTENT);
|
verify(fileFolderService, never()).create(destParentNodeRef, "dest.doc", ContentModel.TYPE_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -207,51 +138,8 @@ public class MoveMethodTest
|
|||||||
moveMethod.moveOrCopy(sourceNodeRef, sourceParentNodeRef, destParentNodeRef, "dest.doc");
|
moveMethod.moveOrCopy(sourceNodeRef, sourceParentNodeRef, destParentNodeRef, "dest.doc");
|
||||||
|
|
||||||
|
|
||||||
verify(mockFileFolderService).rename(sourceNodeRef, "dest.doc");
|
verify(fileFolderService).rename(sourceNodeRef, "dest.doc");
|
||||||
verify(davLockService).unlock(sourceNodeRef);
|
verify(davLockService).unlock(sourceNodeRef);
|
||||||
verify(mockFileFolderService, never()).create(destParentNodeRef, "dest.doc", ContentModel.TYPE_CONTENT);
|
verify(fileFolderService, never()).create(destParentNodeRef, "dest.doc", ContentModel.TYPE_CONTENT);
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMNT_9662()
|
|
||||||
{
|
|
||||||
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public Object execute() throws Throwable
|
|
||||||
{
|
|
||||||
// create test folder with name that doesn't match getDAVHelper().isRenameShuffle()
|
|
||||||
FileInfo testFileInfo = fileFolderService.create(companyHomeNodeRef, "folder-" + GUID.generate().substring(29), ContentModel.TYPE_FOLDER);
|
|
||||||
|
|
||||||
req = new MockHttpServletRequest(WebDAV.METHOD_MOVE, "/alfresco/webdav/" + testFileInfo.getName());
|
|
||||||
resp = new MockHttpServletResponse();
|
|
||||||
req.setServerPort(8080);
|
|
||||||
req.setServletPath("/webdav");
|
|
||||||
|
|
||||||
moveMethod = new MoveMethod();
|
|
||||||
moveMethod.setDetails(req, resp, webDAVHelper, companyHomeNodeRef);
|
|
||||||
|
|
||||||
// generate new name that matches getDAVHelper().isRenameShuffle()
|
|
||||||
String newName = GUID.generate().substring(28);
|
|
||||||
req.addHeader(WebDAV.HEADER_DESTINATION, "http://localhost:8080/alfresco/webdav/" + newName);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
moveMethod.execute();
|
|
||||||
|
|
||||||
assertTrue(nodeService.exists(testFileInfo.getNodeRef()));
|
|
||||||
assertEquals(newName, nodeService.getProperty(testFileInfo.getNodeRef(), ContentModel.PROP_NAME));
|
|
||||||
}
|
|
||||||
catch (WebDAVServerException e)
|
|
||||||
{
|
|
||||||
fail("Fail to rename folder: " + (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
nodeService.deleteNode(testFileInfo.getNodeRef());
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user