From a5bc540d321c45800b0a059f15d2592d80508b01 Mon Sep 17 00:00:00 2001 From: Alan Davis Date: Sat, 31 Jan 2015 10:59:13 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20HEAD-BUG-FIX=20(5.1/Cloud)=20to=20HEAD?= =?UTF-8?q?=20(5.1/Cloud)=20=20=20=2090760:=20Merged=20V4.2-BUG-FIX=20(4.2?= =?UTF-8?q?.5)=20to=20HEAD-BUG-FIX=20(5.0/Cloud)=20=20=20=20=20=20=2090379?= =?UTF-8?q?:=20Merged=20DEV=20(4.2.4)=20to=20V4.2-BUG-FIX=20(4.2.4)=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20=2090266:=20MNT-9342:=20Calling=20custom?= =?UTF-8?q?=20actions=20having=20properties=20declared=20as=20=C2=AB=20mul?= =?UTF-8?q?tiple=20=C2=BB=20from=20WebServices=20does=20not=20work.=20=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20Added=20JUnit=20test=20to=20simulate=20?= =?UTF-8?q?the=20issue.=20=20=20=20=20=20=2090438:=20MNT-9342:=20Calling?= =?UTF-8?q?=20custom=20actions=20having=20properties=20declared=20as=20?= =?UTF-8?q?=C2=AB=20multiple=20=C2=BB=20from=20WebServices=20does=20not=20?= =?UTF-8?q?work.=20=20=20=20=20=20=20Fixed=20merge=20mistake=20for=20the?= =?UTF-8?q?=20test=20in=20r90379.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@94704 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/RemoteApi01TestSuite.java | 1 + .../action/ActionWebServiceTest.java | 93 +++++++++++++++++++ .../TestMultiplePropertiesActionExecutor.java | 62 +++++++++++++ .../repo/webservice/action/action-test.xml | 12 +++ 4 files changed, 168 insertions(+) create mode 100644 source/test-java/org/alfresco/repo/webservice/action/ActionWebServiceTest.java create mode 100644 source/test-java/org/alfresco/repo/webservice/action/TestMultiplePropertiesActionExecutor.java create mode 100644 source/test-resources/org/alfresco/repo/webservice/action/action-test.xml diff --git a/source/test-java/org/alfresco/RemoteApi01TestSuite.java b/source/test-java/org/alfresco/RemoteApi01TestSuite.java index 642670e5c5..25f82aabcc 100644 --- a/source/test-java/org/alfresco/RemoteApi01TestSuite.java +++ b/source/test-java/org/alfresco/RemoteApi01TestSuite.java @@ -68,6 +68,7 @@ public class RemoteApi01TestSuite extends TestSuite suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.webdav.LockMethodTest.class)); suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.webdav.WebDAVHelperIntegrationTest.class)); suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.webdav.WebDAVMethodTest.class)); + suite.addTestSuite(org.alfresco.repo.webservice.action.ActionWebServiceTest.class); } static void tests4(TestSuite suite) // diff --git a/source/test-java/org/alfresco/repo/webservice/action/ActionWebServiceTest.java b/source/test-java/org/alfresco/repo/webservice/action/ActionWebServiceTest.java new file mode 100644 index 0000000000..d5f6489b98 --- /dev/null +++ b/source/test-java/org/alfresco/repo/webservice/action/ActionWebServiceTest.java @@ -0,0 +1,93 @@ +/* + * 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.repo.webservice.action; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.security.authentication.AuthenticationComponent; +import org.alfresco.repo.webservice.types.NamedValue; +import org.alfresco.repo.webservice.types.ParentReference; +import org.alfresco.repo.webservice.types.Predicate; +import org.alfresco.repo.webservice.types.Reference; +import org.alfresco.repo.webservice.types.Store; +import org.alfresco.util.BaseSpringTest; + +/** + * Test for ActionWebService class. + * + * @author alex.mukha + * @since 4.2.4 + */ +public class ActionWebServiceTest extends BaseSpringTest +{ + private AuthenticationComponent authenticationComponent; + private ActionWebService actionWebService; + + private static String PARAM_PATH = "param-path"; + private static String PARAM_CONTENT = "param-content"; + + @Override + protected String[] getConfigLocations() + { + return new String[] { "classpath:org/alfresco/repo/webservice/action/action-test.xml" }; + } + + @SuppressWarnings("deprecation") + @Override + protected void onSetUpInTransaction() throws Exception + { + this.actionWebService = (ActionWebService) this.applicationContext.getBean("actionWebService"); + this.authenticationComponent = (AuthenticationComponent) this.applicationContext.getBean("authenticationComponent"); + + this.authenticationComponent.setSystemUserAsCurrentUser(); + } + + @SuppressWarnings("deprecation") + @Override + protected void onTearDownInTransaction() throws Exception + { + authenticationComponent.clearCurrentSecurityContext(); + super.onTearDownInTransaction(); + } + + /** + * Test for MNT-9342 + */ + public void testActionMultipleProperties() throws Exception + { + Store storeRef = new Store("workspace", "SpacesStore"); + ParentReference companyHomeParent = new ParentReference(storeRef, null, "/app:company_home", ContentModel.ASSOC_CONTAINS.toString(), null); + Predicate predicate = new Predicate(new Reference[] { companyHomeParent }, null, null); + String[] paramPath = { "path1", "path2", "path4" }; + String[] paramContent = { "content1", "content2", "content3" }; + + // Create the action to create the document + NamedValue[] parameters = new NamedValue[] { new NamedValue(PARAM_PATH, true, null, paramPath), new NamedValue(PARAM_CONTENT, true, null, paramContent) }; + + Action newAction1 = new Action(); + newAction1.setActionName("create-doc-action-test"); + newAction1.setTitle("Create Document"); + newAction1.setDescription("This will create the document an content"); + newAction1.setParameters(parameters); + + ActionExecutionResult[] results = null; + // An exception will be thrown here if the number of parameters passed to action executer will not match + results = actionWebService.executeActions(predicate, new Action[] { newAction1 }); + assertNotNull(results); + } +} diff --git a/source/test-java/org/alfresco/repo/webservice/action/TestMultiplePropertiesActionExecutor.java b/source/test-java/org/alfresco/repo/webservice/action/TestMultiplePropertiesActionExecutor.java new file mode 100644 index 0000000000..c65432a2b2 --- /dev/null +++ b/source/test-java/org/alfresco/repo/webservice/action/TestMultiplePropertiesActionExecutor.java @@ -0,0 +1,62 @@ +/* + * 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.repo.webservice.action; + +import java.util.ArrayList; +import java.util.List; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.repo.action.ParameterDefinitionImpl; +import org.alfresco.repo.action.executer.ActionExecuterAbstractBase; +import org.alfresco.service.cmr.action.ParameterDefinition; +import org.alfresco.service.cmr.dictionary.DataTypeDefinition; +import org.alfresco.service.cmr.repository.NodeRef; + +/** + * Test action executer for {@link ActionWebServiceTest#testActionMultipleProperties()} + * + * @author alex.mukha + * @since 4.2.4 + */ +public class TestMultiplePropertiesActionExecutor extends ActionExecuterAbstractBase +{ + private static String PARAM_PATH = "param-path"; + private static String PARAM_CONTENT = "param-content"; + + @SuppressWarnings("unchecked") + @Override + protected void executeImpl(org.alfresco.service.cmr.action.Action action, NodeRef actionedUponNodeRef) + { + if (((ArrayList) action.getParameterValues().get(PARAM_PATH)).size() != 3) + { + throw new AlfrescoRuntimeException("There should be 3 parameters!"); + } + if (((ArrayList) action.getParameterValues().get(PARAM_CONTENT)).size() != 3) + { + throw new AlfrescoRuntimeException("There should be 3 parameters!"); + } + } + + @Override + protected void addParameterDefinitions(List paramList) + { + paramList.add(new ParameterDefinitionImpl(PARAM_PATH, DataTypeDefinition.TEXT, true, "Path of the file to create", true)); + paramList.add(new ParameterDefinitionImpl(PARAM_CONTENT, DataTypeDefinition.TEXT, true, "String representation of the content", true)); + } +} diff --git a/source/test-resources/org/alfresco/repo/webservice/action/action-test.xml b/source/test-resources/org/alfresco/repo/webservice/action/action-test.xml new file mode 100644 index 0000000000..0dbe28b7de --- /dev/null +++ b/source/test-resources/org/alfresco/repo/webservice/action/action-test.xml @@ -0,0 +1,12 @@ + + + + + + + + + +