import org.alfresco.service.cmr.download.DownloadStatus; //导入方法依赖的package包/类
@Test
public void testCreateDownload() throws Exception
{
setRequestContext(customModelAdmin);
final String modelName = "testModel" + System.currentTimeMillis();
final String modelExportFileName = modelName + ".xml";
final String shareExtExportFileName = "CMM_" + modelName + "_module.xml";
Pair namespacePair = getTestNamespaceUriPrefixPair();
// Create the model as a Model Administrator
createCustomModel(modelName, namespacePair, ModelStatus.DRAFT, null, "Mark Moe");
// Add type
String typeBaseName = "testTypeBase" + System.currentTimeMillis();
createTypeAspect(CustomType.class, modelName, typeBaseName, "test typeBase title", "test typeBase Desc", "cm:content");
// Create Share extension module
downloadTestUtil.createShareExtModule(modelName);
setRequestContext(nonAdminUserName);
// Try to create download the model as a non Admin user
post("cmm/" + modelName + "/download", RestApiUtil.toJsonAsString(new CustomModelDownload()), getExtModuleQS(false), 403);
setRequestContext(customModelAdmin);
// Create download for custom model only
HttpResponse response = post("cmm/" + modelName + "/download", RestApiUtil.toJsonAsString(new CustomModelDownload()), getExtModuleQS(false), 201);
CustomModelDownload returnedDownload = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelDownload.class);
assertNotNull(returnedDownload);
assertNotNull(returnedDownload.getNodeRef());
NodeRef downloadNode = new NodeRef(returnedDownload.getNodeRef());
DownloadStatus status = downloadTestUtil.getDownloadStatus(downloadNode);
while (status.getStatus() == DownloadStatus.Status.PENDING)
{
Thread.sleep(PAUSE_TIME);
status = downloadTestUtil.getDownloadStatus(downloadNode);
}
Set entries = downloadTestUtil.getDownloadEntries(downloadNode);
assertEquals(1, entries.size());
String modelEntry = downloadTestUtil.getDownloadEntry(entries, modelExportFileName);
assertNotNull(modelEntry);
assertEquals(modelEntry, modelExportFileName);
// Create download for custom model and its share extension module
response = post("cmm/" + modelName + "/download", RestApiUtil.toJsonAsString(new CustomModelDownload()), getExtModuleQS(true), 201);
returnedDownload = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModelDownload.class);
assertNotNull(returnedDownload);
assertNotNull(returnedDownload.getNodeRef());
downloadNode = new NodeRef(returnedDownload.getNodeRef());
status = downloadTestUtil.getDownloadStatus(downloadNode);
while (status.getStatus() == DownloadStatus.Status.PENDING)
{
Thread.sleep(PAUSE_TIME);
status = downloadTestUtil.getDownloadStatus(downloadNode);
}
entries = downloadTestUtil.getDownloadEntries(downloadNode);
assertEquals(2, entries.size());
modelEntry = downloadTestUtil.getDownloadEntry(entries, modelExportFileName);
assertNotNull(modelEntry);
assertEquals(modelEntry, modelExportFileName);
String shareExtEntry = downloadTestUtil.getDownloadEntry(entries, shareExtExportFileName);
assertNotNull(shareExtEntry);
assertEquals(shareExtEntry, shareExtExportFileName);
}