Files
alfresco-community-repo/source/test-java/org/alfresco/repo/webdav/WebDAVHelperIntegrationTest.java
Alan Davis da8101a5ba Merged 5.2.N (5.2.1) to HEAD (5.2)
125781 rmunteanu: Merged 5.1.N (5.1.2) to 5.2.N (5.2.1)
      125603 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2)
         125484 slanglois: MNT-16155 Update source headers - remove old Copyrights from Java and JSP dource files


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@127808 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2016-06-03 16:40:56 +00:00

119 lines
4.4 KiB
Java

package org.alfresco.repo.webdav;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.util.UUID;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.model.FileNotFoundException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.util.ApplicationContextHelper;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
/**
* Integration tests for the {@link WebDAVHelper} class.
*
* @author Matt Ward
*/
public class WebDAVHelperIntegrationTest
{
private static ApplicationContext ctx;
private WebDAVHelper webDAVHelper;
private FileFolderService fileFolderService;
private NodeRef rootNodeRef;
private NodeRef rootFolder;
private NodeService nodeService;
// private EventPublisherForTestingOnly eventPublisher;
@BeforeClass
public static void setUpSpring()
{
ctx = ApplicationContextHelper.getApplicationContext();
}
@Before
public void setUp()
{
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
webDAVHelper = (WebDAVHelper) ctx.getBean("webDAVHelper");
fileFolderService = (FileFolderService) ctx.getBean("FileFolderService");
nodeService = (NodeService) ctx.getBean("NodeService");
StoreRef storeRef = nodeService.createStore("workspace", "WebDAVHelperTest-"+UUID.randomUUID());
rootNodeRef = nodeService.getRootNode(storeRef);
rootFolder = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN,
ContentModel.ASSOC_CHILDREN, ContentModel.TYPE_FOLDER).getChildRef();
//eventPublisher = (EventPublisherForTestingOnly) ctx.getBean("eventPublisher");
}
@Test
public void canGetNodeForPathWithCorrectCase() throws FileNotFoundException
{
FileInfo folderInfo = fileFolderService.create(rootFolder, "my_folder", ContentModel.TYPE_FOLDER);
FileInfo fileInfo = fileFolderService.create(folderInfo.getNodeRef(), "my_file.txt", ContentModel.TYPE_CONTENT);
FileInfo found = webDAVHelper.getNodeForPath(rootFolder, "my_folder/my_file.txt");
// Sanity check, but the main test is that we haven't have a FileNotFoundException thrown.
assertEquals(fileInfo, found);
found = webDAVHelper.getNodeForPath(rootFolder, "my_folder");
assertEquals(folderInfo, found);
}
@Test
public void cannotGetNodeForPathWithIncorrectCase() throws FileNotFoundException
{
FileInfo folderInfo = fileFolderService.create(rootFolder, "my_folder", ContentModel.TYPE_FOLDER);
fileFolderService.create(folderInfo.getNodeRef(), "my_file.txt", ContentModel.TYPE_CONTENT);
try
{
webDAVHelper.getNodeForPath(rootFolder, "My_Folder/My_File.txt");
fail("FileNotFoundException should have been thrown.");
}
catch (FileNotFoundException e)
{
// Got here, good.
}
}
@Test
public void cannotGetNodeForFolderPathWithIncorrectCase() throws FileNotFoundException
{
FileInfo folderInfo = fileFolderService.create(rootFolder, "my_folder", ContentModel.TYPE_FOLDER);
fileFolderService.create(folderInfo.getNodeRef(), "my_file.txt", ContentModel.TYPE_CONTENT);
try
{
webDAVHelper.getNodeForPath(rootFolder, "My_Folder");
fail("FileNotFoundException should have been thrown.");
}
catch (FileNotFoundException e)
{
// Got here, good.
}
}
@Test
public void canGetNodeForRootFolderPath() throws FileNotFoundException
{
FileInfo folderInfo = fileFolderService.create(rootFolder, "my_folder", ContentModel.TYPE_FOLDER);
fileFolderService.create(folderInfo.getNodeRef(), "my_file.txt", ContentModel.TYPE_CONTENT);
FileInfo found = webDAVHelper.getNodeForPath(rootFolder, "/");
assertEquals(rootFolder, found.getNodeRef());
}
}