mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.0/Cloud)
87777: Merged V4.2-BUG-FIX (4.2.4) to HEAD-BUG-FIX (5.0/Cloud) 87727: Merged DEV (4.2.4) to V4.2-BUG-FIX (4.2.4) 82329: MNT-11909 : Folder created from template has incorrect primary path or name Fixed the webscript to use setName instead of directly modifying the name property. Added JUnit test. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@94552 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -26,7 +26,7 @@ function main()
|
|||||||
status.setCode(status.STATUS_NOT_FOUND, "Source or destination node is missing for copy operation.");
|
status.setCode(status.STATUS_NOT_FOUND, "Source or destination node is missing for copy operation.");
|
||||||
}
|
}
|
||||||
var copy = sourceNode.copy(parentNode, true);
|
var copy = sourceNode.copy(parentNode, true);
|
||||||
copy.properties["cm:name"] = json.get("prop_cm_name").toString();
|
copy.setName(json.get("prop_cm_name").toString());
|
||||||
copy.properties["cm:description"] = json.get("prop_cm_description").toString();
|
copy.properties["cm:description"] = json.get("prop_cm_description").toString();
|
||||||
copy.properties["cm:title"] = json.get("prop_cm_title").toString();
|
copy.properties["cm:title"] = json.get("prop_cm_title").toString();
|
||||||
copy.save();
|
copy.save();
|
||||||
|
@@ -52,6 +52,7 @@ import org.alfresco.repo.web.scripts.transfer.TransferWebScriptTest;
|
|||||||
import org.alfresco.repo.web.scripts.workflow.ActivitiWorkflowRestApiTest;
|
import org.alfresco.repo.web.scripts.workflow.ActivitiWorkflowRestApiTest;
|
||||||
import org.alfresco.repo.web.scripts.workflow.JBPMWorkflowRestApiTest;
|
import org.alfresco.repo.web.scripts.workflow.JBPMWorkflowRestApiTest;
|
||||||
import org.alfresco.repo.web.scripts.workflow.WorkflowModelBuilderTest;
|
import org.alfresco.repo.web.scripts.workflow.WorkflowModelBuilderTest;
|
||||||
|
import org.alfresco.slingshot.documentlibrary.FolderTemplateTest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Web Scripts test suite
|
* Web Scripts test suite
|
||||||
@@ -99,6 +100,7 @@ public class WebScriptTestSuite extends TestSuite
|
|||||||
suite.addTestSuite( SubscriptionServiceRestApiTest.class );
|
suite.addTestSuite( SubscriptionServiceRestApiTest.class );
|
||||||
suite.addTestSuite( FacetRestApiTest.class );
|
suite.addTestSuite( FacetRestApiTest.class );
|
||||||
suite.addTestSuite( CommentsApiTest.class );
|
suite.addTestSuite( CommentsApiTest.class );
|
||||||
|
suite.addTestSuite( FolderTemplateTest.class );
|
||||||
|
|
||||||
// This uses a slightly different context
|
// This uses a slightly different context
|
||||||
// As such, we can't run it in the same suite as the others,
|
// As such, we can't run it in the same suite as the others,
|
||||||
|
@@ -0,0 +1,148 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2014 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.alfresco.slingshot.documentlibrary;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.transaction.UserTransaction;
|
||||||
|
|
||||||
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.repo.model.Repository;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
|
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
|
||||||
|
import org.alfresco.service.cmr.model.FileFolderService;
|
||||||
|
import org.alfresco.service.cmr.model.FileInfo;
|
||||||
|
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.namespace.QName;
|
||||||
|
import org.alfresco.service.transaction.TransactionService;
|
||||||
|
import org.alfresco.util.GUID;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
import org.springframework.extensions.webscripts.Status;
|
||||||
|
import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JUnit test for folder-templates API
|
||||||
|
*
|
||||||
|
* @author alex.mukha
|
||||||
|
* @since 4.2.4
|
||||||
|
*/
|
||||||
|
public class FolderTemplateTest extends BaseWebScriptTest
|
||||||
|
{
|
||||||
|
private AuthenticationComponent authenticationComponent;
|
||||||
|
private Repository repositoryHelper;
|
||||||
|
private NodeService nodeService;
|
||||||
|
private TransactionService transactionService;
|
||||||
|
private SearchService searchService;
|
||||||
|
private FileFolderService fileFolderService;
|
||||||
|
private NodeRef companyHome;
|
||||||
|
private NodeRef template;
|
||||||
|
private NodeRef destination;
|
||||||
|
private String templateName;
|
||||||
|
private String destinationName;
|
||||||
|
private UserTransaction txn;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
|
||||||
|
this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent");
|
||||||
|
this.repositoryHelper = (Repository)getServer().getApplicationContext().getBean("repositoryHelper");
|
||||||
|
this.nodeService = (NodeService)getServer().getApplicationContext().getBean("NodeService");
|
||||||
|
this.transactionService = (TransactionService) getServer().getApplicationContext().getBean("TransactionService");
|
||||||
|
this.searchService = (SearchService) getServer().getApplicationContext().getBean("SearchService");
|
||||||
|
this.fileFolderService = (FileFolderService) getServer().getApplicationContext().getBean("FileFolderService");
|
||||||
|
|
||||||
|
this.authenticationComponent.setSystemUserAsCurrentUser();
|
||||||
|
|
||||||
|
txn = transactionService.getUserTransaction();
|
||||||
|
txn.begin();
|
||||||
|
|
||||||
|
companyHome = this.repositoryHelper.getCompanyHome();
|
||||||
|
|
||||||
|
// Create template folder
|
||||||
|
Map<QName, Serializable> propsTemplate = new HashMap<QName, Serializable>(1);
|
||||||
|
templateName = "templateFolder" + GUID.generate();
|
||||||
|
propsTemplate.put(ContentModel.PROP_NAME, templateName);
|
||||||
|
template = nodeService.createNode(companyHome, ContentModel.ASSOC_CHILDREN, QName.createQName(templateName), ContentModel.TYPE_FOLDER, propsTemplate).getChildRef();
|
||||||
|
|
||||||
|
// Create destination
|
||||||
|
Map<QName, Serializable> propsDestination = new HashMap<QName, Serializable>(1);
|
||||||
|
destinationName = "destinationFolder" + GUID.generate();
|
||||||
|
propsTemplate.put(ContentModel.PROP_NAME, destinationName);
|
||||||
|
destination = nodeService.createNode(companyHome, ContentModel.ASSOC_CHILDREN, QName.createQName(destinationName), ContentModel.TYPE_FOLDER, propsDestination).getChildRef();
|
||||||
|
|
||||||
|
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void tearDown() throws Exception
|
||||||
|
{
|
||||||
|
txn.rollback();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for MNT-11909
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void testFolderTemplatesPost() throws Exception
|
||||||
|
{
|
||||||
|
String url = "/slingshot/doclib/folder-templates";
|
||||||
|
String newName = "FolderName" + GUID.generate();
|
||||||
|
String newDescription = "FolderDescription" + GUID.generate();
|
||||||
|
String newTitle = "FolderTitle" + GUID.generate();
|
||||||
|
|
||||||
|
JSONObject body = new JSONObject();
|
||||||
|
body.put("sourceNodeRef", template.toString());
|
||||||
|
body.put("parentNodeRef", destination.toString());
|
||||||
|
body.put("prop_cm_name", newName);
|
||||||
|
body.put("prop_cm_description", newDescription);
|
||||||
|
body.put("prop_cm_title", newTitle);
|
||||||
|
|
||||||
|
sendRequest(new PostRequest(url, body.toString(), "application/json"), Status.STATUS_OK);
|
||||||
|
|
||||||
|
// Check the new folder
|
||||||
|
String newFolderQuery = "/app:company_home/" + destinationName + "/" + newName;
|
||||||
|
ResultSet result = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_XPATH, newFolderQuery);
|
||||||
|
if (result.length() == 0)
|
||||||
|
{
|
||||||
|
fail("The folder with name " + newName + " was not created in " + destinationName);
|
||||||
|
}
|
||||||
|
FileInfo newFolder = fileFolderService.getFileInfo(result.getRow(0).getNodeRef());
|
||||||
|
assertNotNull("The folder is not found.", newFolder);
|
||||||
|
assertTrue("The node should be a folder.", newFolder.isFolder());
|
||||||
|
assertEquals("The folder's name should be " + newName +
|
||||||
|
", but was " + newFolder.getName(),
|
||||||
|
newName, newFolder.getName());
|
||||||
|
assertEquals("The folder's description should be " + newDescription +
|
||||||
|
", but was " + newFolder.getProperties().get(ContentModel.PROP_DESCRIPTION),
|
||||||
|
newDescription, newFolder.getProperties().get(ContentModel.PROP_DESCRIPTION));
|
||||||
|
assertEquals("The folder's title should be " + newTitle +
|
||||||
|
", but was " + newFolder.getProperties().get(ContentModel.PROP_TITLE),
|
||||||
|
newTitle, newFolder.getProperties().get(ContentModel.PROP_TITLE));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user