Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)

123327 jkaabimofrad: RA-865: Added tests for upload content API to test "relativePath" multi-part field. Also, cleaned up MultiPartBuilder.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@126539 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jamal Kaabi-Mofrad
2016-05-10 11:23:56 +00:00
parent e040658433
commit 0f16b721e1
2 changed files with 73 additions and 34 deletions

View File

@@ -1047,6 +1047,72 @@ public class NodeApiTest extends AbstractBaseApiTest
.build();
// Prop prefix is unknown
post(getNodeChildrenUrl(folderA_id), userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 400);
// Test relativePath multi-part field.
// Any folders in the relativePath that do not exist, are created before the content is created.
multiPartBuilder = MultiPartBuilder.create()
.setFileData(new FileData(fileName, file, MimetypeMap.MIMETYPE_TEXT_PLAIN))
.setRelativePath("X/Y/Z");
reqBody = multiPartBuilder.build();
response = post(getNodeChildrenUrl(folderA_id), userOneN1.getId(), reqBody.getBody(), "?include=path", reqBody.getContentType(), 201);
document = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
// Check the upload response
assertEquals(fileName, document.getName());
contentInfo = document.getContent();
assertNotNull(contentInfo);
assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, contentInfo.getMimeType());
// Check the uploaded file parent folders
PathInfo pathInfo = document.getPath();
assertNotNull(pathInfo);
List<ElementInfo> elementInfos = pathInfo.getElements();
assertNotNull(elementInfos);
// /Company Home/Sites/RandomSite<timestamp>/documentLibrary/folder<timestamp>_A/X/Y/Z
assertEquals(8, elementInfos.size());
assertEquals(document.getParentId(), elementInfos.get(7).getId().getId());
assertEquals("Z", elementInfos.get(7).getName());
assertEquals("Y", elementInfos.get(6).getName());
assertEquals("X", elementInfos.get(5).getName());
assertEquals(folderA, elementInfos.get(4).getName());
// Try to create a folder with the same name as the document within the 'Z' folder.
reqBody = MultiPartBuilder.copy(multiPartBuilder)
.setRelativePath("X/Y/Z/" + document.getName())
.build();
post(getNodeChildrenUrl(folderA_id), userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 409);
// Test the same functionality as "mkdir -p x/y/z" which the folders should be created
// as needed but no errors thrown if the path or any part of the path already exists.
// NOTE: white spaces, leading and trailing "/" are ignored.
reqBody = MultiPartBuilder.copy(multiPartBuilder)
.setRelativePath("/X/ Y/Z /CoolFolder/")
.build();
response = post(getNodeChildrenUrl(folderA_id), userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 201);
document = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
// Check the upload response
assertEquals(fileName, document.getName());
contentInfo = document.getContent();
assertNotNull(contentInfo);
assertEquals(MimetypeMap.MIMETYPE_TEXT_PLAIN, contentInfo.getMimeType());
// Retrieve the uploaded file parent folder
response = getSingle(NodesEntityResource.class, userOneN1.getId(), document.getParentId(), null, 200);
Folder coolFolder = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Folder.class);
assertEquals(document.getParentId(), coolFolder.getId());
assertEquals("CoolFolder", coolFolder.getName());
// Try to upload quick-1.txt within coolFolder and set the relativePath to a blank string.
reqBody = MultiPartBuilder.copy(multiPartBuilder)
.setRelativePath(" ")// blank
.build();
// 409 -> as the blank string is ignored and quick-1.txt already exists in the coolFolder
post(getNodeChildrenUrl(coolFolder.getId()), userOneN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 409);
// userTwoN1 tries to upload the same file by creating sub-folders in the folderA of userOneN1
reqBody = MultiPartBuilder.copy(multiPartBuilder)
.setRelativePath("userTwoFolder1/userTwoFolder2")
.build();
post(getNodeChildrenUrl(folderA_id), userTwoN1.getId(), reqBody.getBody(), null, reqBody.getContentType(), 403);
}
/**

View File

@@ -44,10 +44,7 @@ import java.util.Map.Entry;
public class MultiPartBuilder
{
private FileData fileData;
private String siteId;
private String containerId;
private String destination;
private String uploadDirectory;
private String relativePath;
private String updateNodeRef;
private String description;
private String contentTypeQNameStr;
@@ -65,10 +62,7 @@ public class MultiPartBuilder
private MultiPartBuilder(MultiPartBuilder that)
{
this.fileData = that.fileData;
this.siteId = that.siteId;
this.containerId = that.containerId;
this.destination = that.destination;
this.uploadDirectory = that.uploadDirectory;
this.relativePath = that.relativePath;
this.updateNodeRef = that.updateNodeRef;
this.description = that.description;
this.contentTypeQNameStr = that.contentTypeQNameStr;
@@ -96,27 +90,9 @@ public class MultiPartBuilder
return this;
}
public MultiPartBuilder setSiteId(String siteId)
public MultiPartBuilder setRelativePath(String relativePath)
{
this.siteId = siteId;
return this;
}
public MultiPartBuilder setContainerId(String containerId)
{
this.containerId = containerId;
return this;
}
public MultiPartBuilder setDestination(String destination)
{
this.destination = destination;
return this;
}
public MultiPartBuilder setUploadDirectory(String uploadDirectory)
{
this.uploadDirectory = uploadDirectory;
this.relativePath = relativePath;
return this;
}
@@ -275,18 +251,15 @@ public class MultiPartBuilder
parts.add(fp);
addPartIfNotNull(parts, "filename", fileData.getFileName());
}
addPartIfNotNull(parts, "siteid", siteId);
addPartIfNotNull(parts, "containerid", containerId);
addPartIfNotNull(parts, "destination", destination);
addPartIfNotNull(parts, "uploaddirectory", uploadDirectory);
addPartIfNotNull(parts, "relativepath", relativePath);
addPartIfNotNull(parts, "updatenoderef", updateNodeRef);
addPartIfNotNull(parts, "description", description);
addPartIfNotNull(parts, "contenttype", contentTypeQNameStr);
addPartIfNotNull(parts, "aspects", getAspects(aspects));
addPartIfNotNull(parts, "majorversion", majorVersion);
addPartIfNotNull(parts, "overwrite", overwrite);
addPartIfNotNull(parts, "autoRename", autoRename);
addPartIfNotNull(parts, "nodeType", nodeType);
addPartIfNotNull(parts, "autorename", autoRename);
addPartIfNotNull(parts, "nodetype", nodeType);
if (!properties.isEmpty())
{