diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/folder-templates.post.json.js b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/folder-templates.post.json.js
index 4c1ca8c9da..a35fd5645a 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/folder-templates.post.json.js
+++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/folder-templates.post.json.js
@@ -26,7 +26,7 @@ function main()
status.setCode(status.STATUS_NOT_FOUND, "Source or destination node is missing for copy operation.");
}
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:title"] = json.get("prop_cm_title").toString();
copy.save();
diff --git a/source/test-java/org/alfresco/repo/web/scripts/WebScriptTestSuite.java b/source/test-java/org/alfresco/repo/web/scripts/WebScriptTestSuite.java
index 2c8f456314..3da0e0b94b 100644
--- a/source/test-java/org/alfresco/repo/web/scripts/WebScriptTestSuite.java
+++ b/source/test-java/org/alfresco/repo/web/scripts/WebScriptTestSuite.java
@@ -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.JBPMWorkflowRestApiTest;
import org.alfresco.repo.web.scripts.workflow.WorkflowModelBuilderTest;
+import org.alfresco.slingshot.documentlibrary.FolderTemplateTest;
/**
* Web Scripts test suite
@@ -99,6 +100,7 @@ public class WebScriptTestSuite extends TestSuite
suite.addTestSuite( SubscriptionServiceRestApiTest.class );
suite.addTestSuite( FacetRestApiTest.class );
suite.addTestSuite( CommentsApiTest.class );
+ suite.addTestSuite( FolderTemplateTest.class );
// This uses a slightly different context
// As such, we can't run it in the same suite as the others,
diff --git a/source/test-java/org/alfresco/slingshot/documentlibrary/FolderTemplateTest.java b/source/test-java/org/alfresco/slingshot/documentlibrary/FolderTemplateTest.java
new file mode 100644
index 0000000000..ded4de9c3c
--- /dev/null
+++ b/source/test-java/org/alfresco/slingshot/documentlibrary/FolderTemplateTest.java
@@ -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 .
+ */
+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 propsTemplate = new HashMap(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 propsDestination = new HashMap(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));
+ }
+}